]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 508737: Allow Bugzilla::Template::get_bug_link to take a Bugzilla::Bug object...
authormkanat%bugzilla.org <>
Thu, 6 Aug 2009 15:02:47 +0000 (15:02 +0000)
committermkanat%bugzilla.org <>
Thu, 6 Aug 2009 15:02:47 +0000 (15:02 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit

Bugzilla/Template.pm
template/en/default/attachment/create.html.tmpl
template/en/default/attachment/show-multiple.html.tmpl
template/en/default/bug/activity/show.html.tmpl
template/en/default/bug/process/midair.html.tmpl
template/en/default/bug/votes/list-for-user.html.tmpl

index d7ebfc055dcb8ae0814033aaa8382f626b236e02..f90e472b55fb1955f31b00240dad4fa50680e635 100644 (file)
@@ -34,6 +34,7 @@ package Bugzilla::Template;
 
 use strict;
 
+use Bugzilla::Bug;
 use Bugzilla::Constants;
 use Bugzilla::Install::Requirements;
 use Bugzilla::Install::Util qw(install_string template_include_path include_languages);
@@ -52,6 +53,7 @@ use File::Find;
 use File::Path qw(rmtree mkpath);
 use File::Spec;
 use IO::Dir;
+use Scalar::Util qw(blessed);
 
 use base qw(Template);
 
@@ -327,54 +329,46 @@ sub get_attachment_link {
 #    comment in the bug
 
 sub get_bug_link {
-    my ($bug_num, $link_text, $options) = @_;
+    my ($bug, $link_text, $options) = @_;
     my $dbh = Bugzilla->dbh;
 
-    if (!defined($bug_num) || ($bug_num eq "")) {
-        return "&lt;missing bug number&gt;";
+    if (!$bug) {
+        return html_quote('<missing bug number>');
     }
-    my $quote_bug_num = html_quote($bug_num);
-    detaint_natural($bug_num) || return "&lt;invalid bug number: $quote_bug_num&gt;";
 
-    my ($bug_alias, $bug_state, $bug_res, $bug_desc) =
-        $dbh->selectrow_array('SELECT bugs.alias, bugs.bug_status, bugs.resolution, bugs.short_desc
-                               FROM bugs WHERE bugs.bug_id = ?',
-                               undef, $bug_num);
-
-    if ($options->{use_alias} && $link_text =~ /^\d+$/ && $bug_alias) {
-        $link_text = $bug_alias;
+    $bug = blessed($bug) ? $bug : new Bugzilla::Bug($bug);
+    return $link_text if $bug->{error};
+    
+    if ($options->{use_alias} && $link_text =~ /^\d+$/ && $bug->alias) {
+        $link_text = $bug->alias;
     }
 
-    if ($bug_state) {
-        # Initialize these variables to be "" so that we don't get warnings
-        # if we don't change them below (which is highly likely).
-        my ($pre, $title, $post) = ("", "", "");
-
-        $title = get_text('get_status', {status => $bug_state});
-        if ($bug_state eq 'UNCONFIRMED') {
-            $pre = "<i>";
-            $post = "</i>";
-        }
-        elsif (!is_open_state($bug_state)) {
-            $pre = '<span class="bz_closed">';
-            $title .= ' ' . get_text('get_resolution', {resolution => $bug_res});
-            $post = '</span>';
-        }
-        if (Bugzilla->user->can_see_bug($bug_num)) {
-            $title .= " - $bug_desc";
-        }
-        # Prevent code injection in the title.
-        $title = html_quote(clean_text($title));
+    # Initialize these variables to be "" so that we don't get warnings
+    # if we don't change them below (which is highly likely).
+    my ($pre, $title, $post) = ("", "", "");
 
-        my $linkval = "show_bug.cgi?id=$bug_num";
-        if ($options->{comment_num}) {
-            $linkval .= "#c" . $options->{comment_num};
-        }
-        return qq{$pre<a href="$linkval" title="$title">$link_text</a>$post};
+    $title = get_text('get_status', { status => $bug->bug_status });
+    if ($bug->bug_status eq 'UNCONFIRMED') {
+        $pre = "<i>";
+        $post = "</i>";
     }
-    else {
-        return qq{$link_text};
+    if ($bug->resolution) {
+        $pre .= '<span class="bz_closed">';
+        $title .= ' ' . get_text('get_resolution',
+                                 { resolution => $bug->resolution });
+        $post .= '</span>';
+    }
+    if (Bugzilla->user->can_see_bug($bug)) {
+        $title .= " - " . $bug->short_desc;
+    }
+    # Prevent code injection in the title.
+    $title = html_quote(clean_text($title));
+
+    my $linkval = "show_bug.cgi?id=" . $bug->id;
+    if ($options->{comment_num}) {
+        $linkval .= "#c" . $options->{comment_num};
     }
+    return qq{$pre<a href="$linkval" title="$title">$link_text</a>$post};
 }
 
 ###############################################################################
index f725f1076489cf7a7ea2c7a77a52f4befd878f07..c265ae567af0df5abbdf22a540063ab0a927524e 100644 (file)
@@ -26,7 +26,7 @@
 [%# Define strings that will serve as the title and header of this page %]
 [% title = BLOCK %]Create New Attachment for [% terms.Bug %] #[% bug.bug_id %][% END %]
 [% header = BLOCK %]Create New Attachment for
-  [%+ "$terms.Bug $bug.bug_id" FILTER bug_link(bug.bug_id) FILTER none %][% END %]
+  [%+ "$terms.Bug $bug.bug_id" FILTER bug_link(bug) FILTER none %][% END %]
 [% subheader = BLOCK %][% bug.short_desc FILTER html %][% END %]
 
 [% PROCESS global/header.html.tmpl
index 36088c96cf9b012170c68e579b5f0d247c60370e..1f8cab88a4ad8ff04ded9f73e41cdfd790096480 100644 (file)
@@ -21,7 +21,7 @@
 [% PROCESS global/variables.none.tmpl %]
 [% filtered_summary = bugsummary FILTER html %]
 [% header = BLOCK %]View All Attachments for
-  [%+ "$terms.Bug $bug.bug_id" FILTER bug_link(bug.bug_id) FILTER none %][% END %]
+  [%+ "$terms.Bug $bug.id" FILTER bug_link(bug) FILTER none %][% END %]
 
 [% title = BLOCK %]
   View All Attachments for [% terms.Bug %] [%+ bug.bug_id FILTER html %]
index a457df01800f07f56fc296328b79850d6b1d5190..67ac689ca966a1a543783d1ae5b7ede730b68e74 100644 (file)
  %]
 
 <p>
-  [% "Back to $terms.bug $bug.bug_id" FILTER bug_link(bug.bug_id) FILTER none %]
+  [% "Back to $terms.bug $bug.bug_id" FILTER bug_link(bug) FILTER none %]
 </p>
 
 [% PROCESS bug/activity/table.html.tmpl %]
 
 [% IF operations.size > 0 %]
   <p>
-    [% "Back to $terms.bug $bug.bug_id" FILTER bug_link(bug.bug_id) FILTER none %]
+    [% "Back to $terms.bug $bug.bug_id" FILTER bug_link(bug) FILTER none %]
   </p>
 [% END %]
 
index ed3be74d3b1e287dfc613cd32b87542155ef394e..6e0458f24b9f4b25596887bbe78eda34d67a1ab8 100644 (file)
@@ -45,7 +45,7 @@
 
 <p>
   Someone else has made changes to
-  [%+ "$terms.bug $bug.id" FILTER bug_link(bug.id) FILTER none %]
+  [%+ "$terms.bug $bug.id" FILTER bug_link(bug) FILTER none %]
   at the same time you were trying to.
   The changes made were:
 </p>
@@ -101,7 +101,7 @@ You have the following choices:
   [% END %]
   <li>
     Throw away my changes, and
-    [%+ "revisit $terms.bug $bug.id" FILTER bug_link(bug.id) FILTER none %]
+    [%+ "revisit $terms.bug $bug.id" FILTER bug_link(bug) FILTER none %]
   </li>
 </ul>
 
index 50dff7d5ea4ea811acc3536e32ae4aab2ec4449e..2f97616ed69324a056fdff62ea1fa4a6fad81f72 100644 (file)
               [% END %]
             </a></td>
             <td align="center">
-              [% bug.id FILTER bug_link(bug.id) FILTER none %]
+              [% bug.id FILTER bug_link(bug) FILTER none %]
             </td>
             <td>
               [% bug.summary FILTER html %]