Skip to content

Commit ca7f76a

Browse files
committed
Only display the Diff/File buttons when needed
In some cases, it does not make any sense to display the Diff or File buttons (e.g. when a file has been deleted), and the generated target URL may be invalid (HTTP 404). The Changeset View page has been adapted to not show the button when the URL returned by the url_diff() and url_file() methods is empty. It now behaves like the List page (see Source_View_Changesets()). Fixes #401
1 parent 3f320d7 commit ca7f76a

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

Source/pages/view.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,13 @@ function( $p_bug_id ) use ( $t_view_bug_threshold ) {
259259
<td class="small" colspan="<?php echo $t_columns-2 ?>"><?php echo string_display_line( $t_vcs->show_file( $t_repo, $t_changeset, $t_file ) ) ?></td>
260260
<td class="center">
261261
<?php
262-
print_extra_small_button(
263-
$t_vcs->url_diff( $t_repo, $t_changeset, $t_file ),
264-
plugin_lang_get( 'diff', 'Source' )
265-
);
266-
echo ' ';
267-
print_extra_small_button(
268-
$t_vcs->url_file( $t_repo, $t_changeset, $t_file ),
269-
plugin_lang_get( 'file', 'Source' )
270-
);
262+
if( $t_url = $t_vcs->url_diff( $t_repo, $t_changeset, $t_file ) ) {
263+
print_extra_small_button( $t_url, plugin_lang_get( 'diff', 'Source' ) );
264+
}
265+
if( $t_url = $t_vcs->url_file( $t_repo, $t_changeset, $t_file ) ) {
266+
echo "\n";
267+
print_extra_small_button( $t_url, plugin_lang_get( 'file', 'Source' ) );
268+
}
271269
?>
272270
</td>
273271
</tr>

SourceBitBucket/SourceBitBucket.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,22 @@ public function url_changeset( $p_repo, $p_changeset ) {
6161
}
6262

6363
public function url_file( $p_repo, $p_changeset, $p_file ) {
64-
$t_username = $p_repo->info['bit_username'];
65-
$t_reponame = $p_repo->info['bit_reponame'];
64+
# Can't link to a deleted file
65+
if( $p_file->action == SourceFile::DELETED ) {
66+
return '';
67+
}
68+
6669
$t_ref = $p_changeset->revision;
6770
$t_filename = $p_file->filename;
6871
return $this->main_url . "$t_username/$t_reponame/src/$t_ref/$t_filename";
6972
}
7073

7174
public function url_diff( $p_repo, $p_changeset, $p_file ) {
72-
$t_username = $p_repo->info['bit_username'];
73-
$t_reponame = $p_repo->info['bit_reponame'];
75+
# No point viewing the diff to a deleted file
76+
if( $p_file->action == SourceFile::DELETED ) {
77+
return '';
78+
}
79+
7480
$t_ref = $p_changeset->revision;
7581
$t_filename = $p_file->filename;
7682
return $this->main_url . "$t_username/$t_reponame/diff/$t_filename?diff2=$t_ref";

SourceGithub/SourceGithub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ public function url_changeset( $p_repo, $p_changeset ) {
240240
}
241241

242242
public function url_file( $p_repo, $p_changeset, $p_file ) {
243+
# Can't link to a deleted file
244+
if( $p_file->action == SourceFile::DELETED ) {
245+
return '';
246+
}
247+
243248
$t_username = $p_repo->info['hub_username'];
244249
$t_reponame = $p_repo->info['hub_reponame'];
245250
$t_ref = $p_changeset->revision;

0 commit comments

Comments
 (0)