From c048675731f016f0b4b7eb1b901ad0c3d8dd69dd Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Thu, 6 Aug 2009 15:02:47 +0000 Subject: Bug 508737: Allow Bugzilla::Template::get_bug_link to take a Bugzilla::Bug object if one is available Patch by Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Template.pm | 72 ++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index d7ebfc055..f90e472b5 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -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 "<missing bug number>"; + if (!$bug) { + return html_quote(''); } - my $quote_bug_num = html_quote($bug_num); - detaint_natural($bug_num) || return "<invalid bug number: $quote_bug_num>"; - 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 = ""; - $post = ""; - } - elsif (!is_open_state($bug_state)) { - $pre = ''; - $title .= ' ' . get_text('get_resolution', {resolution => $bug_res}); - $post = ''; - } - 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$link_text$post}; + $title = get_text('get_status', { status => $bug->bug_status }); + if ($bug->bug_status eq 'UNCONFIRMED') { + $pre = ""; + $post = ""; } - else { - return qq{$link_text}; + if ($bug->resolution) { + $pre .= ''; + $title .= ' ' . get_text('get_resolution', + { resolution => $bug->resolution }); + $post .= ''; + } + 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$link_text$post}; } ############################################################################### -- cgit v1.2.3-24-g4f1b