[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnatsweb/616: Add callbacks for custom field descriptions, mark_urls and
From: |
bug-gnats |
Subject: |
gnatsweb/616: Add callbacks for custom field descriptions, mark_urls and more |
Date: |
Tue, 13 Jun 2006 11:45:02 -0500 (CDT) |
>Number: 616
>Category: gnatsweb
>Synopsis: Add callbacks for custom field descriptions, mark_urls and more
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Tue Jun 13 11:45:01 -0500 2006
>Originator: Stephane Chazelas <address@hidden>
>Release:
>Description:
Hi guys,
I've added a couple of new callbacks, that I thought I'd share.
Here is a useful (IMHO) example of a callback for mark_urls:
sub site_callback {
my $reason = shift;
if ($reason eq "mark_urls") {
my $fieldname = shift;
if ($fieldname eq 'Audit-Trail') {
# for Audit-Trails, build a table of content, and some
# [prev][next] links for easy browsing.
my $i = 0;
my $toc = "";
my $stringref = shift;
$$stringref =~
s{
(?<![^\n])
(?:From | [\w-]+-Changed-From-To):.*?
(?=\r?\n\r?\n)
}
{
$i++;
my $t = $&;
if ($t =~
/^([\w-]+)-Changed-From-To:\s*(.*?)\n.*?Changed-When:\s*(.*?)\n/xs) {
$toc .= "<li>$3: <a href=\"#m$i\">$1 change</a> ($2)\n";
}
elsif ($t =~ /^From:\s*(.*?)\n.*?(?:Date:\s*([^\n]*))/xs) {
$toc .= "<li>$2: <a href=\"#m$i\">email</a> ($1)\n";
}
"<hr/><a name=\"m$i\"><b>$t</b></a>\n<small> " .
($i > 1 ? '<a href="#m' . ($i - 1) . '">[previous]</a> ' : "") .
'<a href="#toc">[list]</a> <a href="#m' . ($i + 1) .
'">[next]</a></small>';
}exgs;
$toc = "<a name=\"toc\"><ol>\n$toc</ol></a>\n" unless ($toc eq "");
$$stringref = $toc . $$stringref . "\n<a name=\"m" . ($i + 1) . "\"/>\n"
if ($i > 0);
}
}
return undef;
}
# Hope this helps
>Fix:
Index: gnatsweb.pl
===================================================================
RCS file: /sources/gnatsweb/gnatsweb/gnatsweb.pl,v
retrieving revision 1.127
diff -u -r1.127 gnatsweb.pl
--- gnatsweb.pl 20 Sep 2004 20:02:51 -0000 1.127
+++ gnatsweb.pl 13 Jun 2006 16:28:04 -0000
@@ -543,6 +543,8 @@
# put human readable values in the popup lists for common
# gnats fields
my $labels;
+ my %user_labels;
+
if ($_[0] eq "Category") {
$labels = \%category_desc;
}
@@ -552,6 +554,11 @@
elsif ($_[0] eq "Submitter-Id") {
$labels = \%submitter_complete;
}
+ else {
+ if (cb("field_labels", $_[0], \%user_labels)) {
+ $labels = \%user_labels;
+ }
+ }
if ($#{$_[1]} >= $popup_menu_becomes_obnoxious)
{
@@ -559,7 +566,8 @@
-size=>$size,
-values=>$_[1],
-labels=>$labels,
- -default=>$_[2]);
+ -default=>$_[2],
+ -id=>$_[0]);
}
else
{
@@ -1460,7 +1468,7 @@
$val =~ s{(\b|PR)(\d+)\b}{'<a
href="'.get_viewpr_url($2)."\">$1$2</a>"}egi;
} else {
# make urls and email addresses into live hrefs
- $val = mark_urls($val);
+ $val = mark_urls($val, $_);
}
if ($description_in_view) {
@@ -1492,7 +1500,8 @@
if($viewaudit)
{
print "\n<h3>Audit Trail:</h3>\n<pre>\n",
- mark_urls($q->escapeHTML($fields{$AUDIT_TRAIL_FIELD})),
+ mark_urls($q->escapeHTML($fields{$AUDIT_TRAIL_FIELD}),
+ $AUDIT_TRAIL_FIELD),
"\n</pre>\n";
}
@@ -1880,7 +1889,11 @@
{
if (fieldinfo($_, 'fieldtype') =~ /enum/)
{
- print "<tr><td valign=top>$_:</td>\n<td>";
+ # The "intro" provides a way for the site callback to print something
+ # at the top of a given field.
+ my $intro = cb("query_intro_$_") || '';
+
+ print "<tr><td valign=top>$_:</td>\n<td>$intro";
my $value_list=fieldinfo($_, 'values');
my @values=('any', @$value_list);
if (fieldinfo($_, 'fieldtype') eq 'enum')
@@ -2166,68 +2179,72 @@
# behavior can be modified by twiddling knobs in the %mark_urls hash.
sub mark_urls {
my $string = shift || '';
+ my $field = shift;
# skip empty strings, or strings longer than the limit
- return $string if ($string =~ /^\s*$/ ||
- length($string) > $mark_urls{'max_length'});
+ if ($string =~ /[^\s]/) {
+ if (length($string) <= $mark_urls{'max_length'}) {
- if ($mark_urls{'urls'})
- {
- # make URLs live
- $string =~ s{
- \b
- (
- (http|telnet|gopher|file|wais|ftp):
- [\w/#~+=&address@hidden:;?\-]+?
- )
- (?=
- [.:?\-]*
- [^\w/#~+=&address@hidden;:?\-]
- |
- $
- )
- }
- {<a href="$1" target="showdoc">$1</a>}igx;
- }
-
- if ($mark_urls{'prs'})
- {
- # make "PR: 12345" into a link to "/cgi-bin/gnats?cmd=view;pr=12345"
- $string =~ s{
- (\WPR[:s#]?\s?) # PR followed by :|s|whitespace
- (\s[a-z0-9-]+\/)? # a category name & a slash (optional)
- ([0-9]+) # the PR number
- }
- {$1.'<a href="'.get_viewpr_url($3).'">'.$2.$3.'</a>'}egix;
- }
-
- if ($mark_urls{'emails'})
- {
- # make email addresses live
- $string =~ s{
- \b
- (
- (?<!ftp://)
- [\w+=%!.\-]+?
- @
- (?:
- [\w\-_]+?
- \.
- )+
- [\w\-_]+?
- )
- (?=
- [.:?\-]*
- (?:
- [^\w\-_]
- |
- \s
- )
- |
- $
- )
- }
- {<a href="mailto:$1">$1</a>}igx;
+ if ($mark_urls{'urls'})
+ {
+ # make URLs live
+ $string =~ s{
+ \b
+ (
+ (http|telnet|gopher|file|wais|ftp):
+ [\w/#~+=&address@hidden:;?\-]+?
+ )
+ (?=
+ [.:?\-]*
+ [^\w/#~+=&address@hidden;:?\-]
+ |
+ $
+ )
+ }
+ {<a href="$1" target="showdoc">$1</a>}igx;
+ }
+
+ if ($mark_urls{'prs'})
+ {
+ # make "PR: 12345" into a link to
"/cgi-bin/gnats?cmd=view;pr=12345"
+ $string =~ s{
+ (\WPR[:s#]?\s?) # PR followed by :|s|whitespace
+ (\s[a-z0-9-]+/)? # a category name & a slash
(optional)
+ ([0-9]+) # the PR number
+ }
+ {$1.'<a
href="'.get_viewpr_url($3).'">'.$2.$3.'</a>'}egix;
+ }
+
+ if ($mark_urls{'emails'})
+ {
+ # make email addresses live
+ $string =~ s{
+ \b
+ (
+ (?<!ftp://)
+ [\w+=%!.\-]+?
+ @
+ (?:
+ [\w\-_]+?
+ \.
+ )+
+ [\w\-_]+?
+ )
+ (?=
+ [.:?\-]*
+ (?:
+ [^\w\-_]
+ |
+ \s
+ )
+ |
+ $
+ )
+ }
+ {<a href="mailto:$1">$1</a>}igx;
+ }
+ }
+ cb("mark_urls", $field, \$string);
}
return $string;
@@ -2488,7 +2505,8 @@
$fieldcontents = make_mailto($fieldcontents);
} else {
# make urls and email addresses into live hrefs
- $fieldcontents = mark_urls($fieldcontents);
+ $fieldcontents = mark_urls($fieldcontents,
+ $columns[$whichfield]);
}
print "<td nowrap>$fieldcontents</td>";
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnatsweb/616: Add callbacks for custom field descriptions, mark_urls and more,
bug-gnats <=