summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Constants.pm5
-rw-r--r--Bugzilla/Template.pm3
-rw-r--r--Bugzilla/Util.pm42
3 files changed, 49 insertions, 1 deletions
diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm
index 768b0e684..3ef3cc634 100644
--- a/Bugzilla/Constants.pm
+++ b/Bugzilla/Constants.pm
@@ -64,6 +64,8 @@ use base qw(Exporter);
DEFAULT_COLUMN_LIST
DEFAULT_QUERY_NAME
+
+ COMMENT_COLS
);
@Bugzilla::Constants::EXPORT_OK = qw(contenttypes);
@@ -212,4 +214,7 @@ use constant DEFAULT_COLUMN_LIST => (
# for the default settings.
use constant DEFAULT_QUERY_NAME => '(Default query)';
+# The column length for displayed (and wrapped) bug comments.
+use constant COMMENT_COLS => 80;
+
1;
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index d4fcbe27c..aea32a2b3 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -378,6 +378,9 @@ sub create {
1
],
+ # Wrap a displayed comment to the appropriate length
+ wrap_comment => \&Bugzilla::Util::wrap_comment,
+
# We force filtering of every variable in key security-critical
# places; we have a none filter for people to use when they
# really, really don't want a variable to be changed.
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index 7bb173e05..6175e0ab2 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -22,6 +22,7 @@
# Jacob Steenhagen <jake@bugzilla.org>
# Bradley Baetz <bbaetz@student.usyd.edu.au>
# Christopher Aillon <christopher@aillon.com>
+# Max Kanat-Alexander <mkanat@kerio.com>
package Bugzilla::Util;
@@ -32,14 +33,37 @@ use base qw(Exporter);
html_quote url_quote value_quote xml_quote
css_class_quote
lsearch max min
- trim diff_strings
+ trim diff_strings wrap_comment
format_time format_time_decimal
file_mod_time);
use Bugzilla::Config;
use Bugzilla::Error;
+use Bugzilla::Constants;
use Date::Parse;
use Date::Format;
+use Text::Autoformat qw(autoformat break_wrap);
+
+our $autoformat_options = {
+ # Reformat all paragraphs, not just the first one.
+ all => 1,
+ # Break only on spaces, and let long lines overflow.
+ break => break_wrap,
+ # Columns are COMMENT_COLS wide.
+ right => COMMENT_COLS,
+ # Don't reformat into perfect paragraphs, just wrap.
+ fill => 0,
+ # Don't compress whitespace.
+ squeeze => 0,
+ # Lines starting with ">" are not wrapped.
+ ignore => qr/^>/,
+ # Don't re-arrange numbered lists.
+ renumber => 0,
+ # Keep short lines at the end of paragraphs as-is.
+ widow => 0,
+ # Even if a paragraph looks centered, don't "auto-center" it.
+ autocentre => 0,
+};
# This is from the perlsec page, slightly modifed to remove a warning
# From that page:
@@ -178,6 +202,11 @@ sub diff_strings {
return ($removed, $added);
}
+sub wrap_comment ($) {
+ my ($comment) = @_;
+ return autoformat($comment, $autoformat_options);
+}
+
sub format_time {
my ($time) = @_;
@@ -277,6 +306,7 @@ Bugzilla::Util - Generic utility functions for bugzilla
# Functions for manipulating strings
$val = trim(" abc ");
($removed, $added) = diff_strings($old, $new);
+ $wrapped = wrap_comment($comment);
# Functions for formatting time
format_time($time);
@@ -402,6 +432,16 @@ compared to the old one. Returns a list, where the first entry is a scalar
containing removed items, and the second entry is a scalar containing added
items.
+=item C<wrap_comment($comment)>
+
+Takes a bug comment, and wraps it to the appropriate length. The length is
+currently specified in C<Bugzilla::Constants::COMMENT_COLS>. Lines beginning
+with ">" are assumed to be quotes, and they will not be wrapped.
+
+The intended use of this function is to wrap comments that are about to be
+displayed or emailed. Generally, wrapped text should not be stored in the
+database.
+
=back
=head2 Formatting Time