From adceb1cda6441d2969ed5a3d6d45add6f33c6df7 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Thu, 13 Feb 2014 13:45:42 +0800 Subject: Bug 40896: Bugzilla needs a "preview" mode for comments r=gerv, a=justdave --- Bugzilla/WebService/Bug.pm | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index de7853092..9ab217b04 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -318,6 +318,30 @@ sub comments { return { bugs => \%bugs, comments => \%comments }; } +sub render_comment { + my ($self, $params) = @_; + + unless (defined $params->{text}) { + ThrowCodeError('params_required', + { function => 'Bug.render_comment', + params => ['text'] }); + } + + Bugzilla->switch_to_shadow_db(); + my $bug = $params->{id} ? Bugzilla::Bug->check($params->{id}) : undef; + + my $tmpl = '[% text FILTER quoteUrls(bug) %]'; + my $html; + my $template = Bugzilla->template; + $template->process( + \$tmpl, + { bug => $bug, text => $params->{text}}, + \$html + ); + + return { html => $html }; +} + # Helper for Bug.comments sub _translate_comment { my ($self, $comment, $filters) = @_; @@ -4682,6 +4706,48 @@ The comment tag provided is longer than the maximum length. =back +=head2 render_comment + +B + +=over + +=item B + +Returns the HTML rendering of the provided comment text. + +=item B + +=over + +=item C + +B C Text comment text to render. + +=item C + +C The ID of the bug to render the comment against. + +=back + +=item B + +C containing the HTML rendering. + +=item B + +This method can throw all of the errors that L throws. + +=item B + +=over + +=item Added in Bugzilla B<5.0>. + +=back + +=back + =head1 B =over -- cgit v1.2.3-24-g4f1b