From c56d18a3e5c4d022741c6457f5c91122699e482f Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Thu, 13 Feb 2014 13:48:52 +0800 Subject: Bug 40896: Bugzilla needs a "preview" mode for comments --- Bugzilla/WebService/Bug.pm | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'Bugzilla/WebService/Bug.pm') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index ab2e85a93..e37d1cd00 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -325,6 +325,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) = @_; @@ -4508,3 +4532,46 @@ this bug. =back =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 + -- cgit v1.2.3-24-g4f1b