MakeClicky

From Request Tracker Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

3.8.x

This is now built-in functionality. From RT_Config.pm:

=item C<@Active_MakeClicky>
 
 MakeClicky detects various formats of data in headers and email messages,
 and extends them with supporting links.  By default, RT provides two formats:
 
 * 'httpurl': detects http:// and https:// URLs and adds '[Open URL]' link after the URL.
 
 * 'httpurl_overwrite': also detects URLs as 'httpurl' format, but replace URL with link
 and *adds spaces* into text if it's longer then 30 chars. This allow browser to wrap long
 URLs and avoid horizontal scrolling.
 
 See F<share/html/Elements/MakeClicky> for documentation on how to add your own.
 
 =cut
 
 Set(@Active_MakeClicky, qw());
 
 

If you're new to this, the option you choose is contained in qw(), frex:

Set(@Active_MakeClicky, qw(httpurl));

Note that httpurl will result in things like

http://www.someplace.tld/path/morepath/etc/target.htm [Open URL]

where the [Open URL] is your clickable link. httpurl_overwrite will make the existing link clickable (oddly enough). Try both and see how it works on your links; don't forget to reload your webserver when you change it.

If you want to add your own actions be aware that the documentation in docs/extending_clickable_links.pod is not correct where it says to create the file ' local/html/MyCallbacks/Elements/MakeClicky/Default' it needs to be ' local/html/Callbacks/MyCallbacks/Elements/MakeClicky/Default' otherwise it will not be picked up by rt. Doc fixed in 3.8.5. NOTE that such things should be reported via bug tracker.

Known Problems

html #anchors
  cp $RTHOME/share/html/Elements/MakeClicky $RTHOME/local/html/Elements/MakeClicky
  $EDITOR $RTHOME/local/html/Elements/MakeClicky

Now change regex to also match # qr@(?

  my @types = (
    {
        name   => "httpurl",
        regex  => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
        action => "url",
    },
    {
        name   => "httpurl_overwrite",
        #regex  => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
        regex  => qr@(?<!src=["'])https?:([\w\/\@\-~%#?=;,.:+\[\]\(\)]|\&|\[\])+[\w\/]@,
        action => "url_overwrite",
    },
  );

Earlier Versions

This is a patch to make links clickable when displaying a ticket. Works for 3.0, success has been reported for 3.4 too.

Regexp based on work by Abigail. As always, mind the tab damage.

 $ diff -u /usr{,/local}/share/request-tracker3/html/Ticket/Elements/ShowMessageStanza
 --- /usr/share/request-tracker3/html/Ticket/Elements/ShowMessageStanza  2004-02-13 19:21:02.000000000 +0100
 +++ /usr/local/share/request-tracker3/html/Ticket/Elements/ShowMessageStanza   2005-05-08 01:04:15.000000000 +0200
 @@ -37,6 +37,9 @@
          $m->comp('/Elements/Callback', content => \$content, %ARGS);
                  $content =~ s/\n/<br>/gi;
 
 +        # Make URLs in plaintext clickable.  This is dangerous!
 +        $content =~ s@(https?://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:\@&=#])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:\@&=#])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:\@&=#])*))?)?)|(?:ftp://(?:(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;?&=])*)(?::(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;?&=])*))?\@)?(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?))(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[?:\@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[?:\@&=])*))*)(?:;type=[AIDaid])?)?)|(?:mailto:(?:(?:[a-zA-Z\d$\-_.+!*'(),;/?:\@&=]|(?:%[a-fA-F\d]{2}))+))@<a href=\"$1\" target=\"_blank\">$1</a>@g;
 +
  </%perl>
  <%$content |n%><br>
  %       }

Alternatively you could implement this callback by Dirk Pape which goes in

[=$your-rt-path/local/html/Callbacks/MI/Ticket/Elements/ShowMessageStanza/Default]

 <%init>
 my $val = $$content;
 use bytes;
 $val =~ s/https?:([\w\/\@\-~%#?=;,.:+]|\&)+[\w\/]/<a href="$&" target="_blank">$&<\/a>/gi;
 $val =~ s/(s?ftp|ftps):[\w\/\.:+\-]+/<a href="$&">$&<\/a>/gi;
 $val =~ s/(mailto:)?([a-zA-Z0-9_\+\-\.]+\@([a-zA-Z0-9][\w\.\+\-]+\.[a-zA-Z]{2,})(\?([\w\/\@\-~%#?=;,.:+]|\&)+[\w\/])?)/<a href="mailto:$2">$&<\/a>/gi;
 $val =~ s/\<((url:\s*)?\w+:[^&<>]+)\>/<<a href="$1" target="_blank">$1<\/a>>/gi;
 $$content = $val;
 </%init>
 <%args>
 $content => undef
 </%args>

For what it's worth, the above file content worked for me accept for the 6th line, which contains the "mailto:" parsing. My system complained about the syntax of this line. I deleted it from my Default file, and all works well on my resulting RT 3.4.2 system.

-Matt England


There was a typo in line 6. It read "$val =~ s/(mailto ... <\/a>/ gi;" but the space before "gi" is too much. I removed it, and removed the cached file [=/var/cache/request-tracker3.4/mason_data/obj/local/Callbacks/MI/Ticket/Elements/ShowMessageStanza/Default] (on our server). It then worked as expected.

-Andreas


A small enhancement to Disk's Callback method, where long http(s) URL's are truncated when displayed:

 <%init>
 my $val = $$content;
 use bytes;
 my @parts = ();
 my @markup = ();
 
 my $max_length = 67;
 my $http_regex = 'https?:[\w\/\@\-~%#?=;,.:+&]+[\w\/]';
 my $ftp_regex = '(s?ftp|ftps):[\w\/\.:+\-]+';
 my $mail_regex = '(mailto:)?([a-zA-Z0-9_\+\-\.]+\@([a-zA-Z0-9][\w\.\+\-]+\.[a-zA-Z]{2,})(\?([\w\/\@\-~%#?=;,.:+]|\&)+[\w\/])?)';
 my $url_regex = '\<((url:\s*)?\w+:[^&<>]+)\>';
 
 $val =~ s/$ftp_regex/<a href="$&">$&<\/a>/gi;
 $val =~ s/$mail_regex/<a href="mailto:$2">$&<\/a>/gi;
 $val =~ s/$url_regex/<a href="$1" target="_blank">$1<\/a>/gi;
 
 @parts = split(/($http_regex)/, $val);
 foreach my $bit (@parts) {
         if ($bit =~ m/$http_regex/) {
                 if (length($bit) < $max_length) {
                         $bit = '<a href="'.$bit.'" target="_blank">'.$bit.'</a>';
                 } else {
                         $bit = '<a href="'.$bit.'" target="_blank">'.substr($bit, 0, $max_length).'...</a>';
                 }
         }
         push(@markup, $bit);
 }
 
 $$content = join("", @markup);
 </%init>
 
 <%args>
 $content => undef
 </%args>


-Shane PS Copy it in "Edit" mode


URL with special characters

This is not a direct edit of MakeClicky, but it's a fix for a problem that MakeClicky can't and should be handled by the module used by MakeClicky (which is Regexp::Common).

As of RT 4.4.4 (using Regexp::Common Version 2013031301-1 or 2017060201), there is no support for URLs that contain Umlaut characters in their path.

This patch adds support for german Umlauts and other special language characters to Regexp::Common::URI. Note that this is an external Perl module, not directly provided by Bestpractical.

diff -ur /usr/share/perl5/Regexp/Common/URI/RFC2396.pm.orig /usr/share/perl5/Regexp/Common/URI/RFC2396.pm
--- /usr/share/perl5/Regexp/Common/URI/RFC2396.pm.orig	2020-02-05 11:23:35.217557749 +0000
+++ /usr/share/perl5/Regexp/Common/URI/RFC2396.pm	2020-02-05 12:02:50.441450768 +0000
@@ -54,12 +54,12 @@
                                       # unreserved | escaped | [:@&=+$,]
 $uric              =  "(?:[;/?:\@&=+\$,a-zA-Z0-9\\-_.!~*'()]|$escaped)";
                                       # reserved | unreserved | escaped
-$urics             =  "(?:(?:[;/?:\@&=+\$,a-zA-Z0-9\\-_.!~*'()]+|"     .
+$urics             =  "(?:(?:[;/?:\@&=+\$,a-zA-Z0-9\x7f-\xff\\-_.!~*'()]+|"     .
                       "$escaped)*)";
 
 $query             =  $urics;
 $fragment          =  $urics;
-$param             =  "(?:(?:[a-zA-Z0-9\\-_.!~*'():\@&=+\$,]+|$escaped)*)";
+$param             =  "(?:(?:[a-zA-Z0-9\x7f-\xff\\-_.!~*'():\@&=+\$,]+|$escaped)*)";
 $segment           =  "(?:$param(?:;$param)*)";
 $path_segments     =  "(?:$segment(?:/$segment)*)";
 $ftp_segments      =  "(?:$param(?:/$param)*)";   # NOT from RFC 2396.

The character range is currently \x7f-\xff, extend it if you need other characters.

This will parse URLs correctly, that have special characters in them.

If you need support for special character domains, also change $domainlabel.

--- Template:3.8.x Template:Configuration