From a80bc042383c1d3e7d9a57b6ff1c76e0c84198e7 Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 4 Sep 2012 12:20:49 +0100 Subject: [PATCH] Homepage|Build Repository: Shorten URLs to bug tracker items in the build log Shorten bug tracker URLs in the commit log (cleaner, human-friendly). --- web/includes/utilities.inc.php | 30 ++++++++++++++++----- web/plugins/buildrepository/commitutils.php | 22 +++++++-------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/web/includes/utilities.inc.php b/web/includes/utilities.inc.php index a624789d74..f56c9eab09 100644 --- a/web/includes/utilities.inc.php +++ b/web/includes/utilities.inc.php @@ -232,8 +232,21 @@ function json_encode_clean(&$array, $flags=0, $indent_level=0) function generateHyperlinkHTML($uri, $attributes = array(), $maxLength = 40) { + $shortUri = NULL; + if($uri instanceof Url) { + if(!strcmp($uri->host(), 'sourceforge.net') && + !substr_compare($uri->path(), '/p/deng/bugs/', 0, 13)) + { + $bugStr = substr($uri->path(), 13); + $bugNum = intval(substr($bugStr, 0, strpos($bugStr, '/'))); + + $shortUri = "Bug#$bugNum"; + if(is_null($attributes)) + $attributes = array(); + $attributes['title'] = "View bug report #$bugNum in the tracker"; + } $uri = $uri->toString(); } else @@ -241,13 +254,6 @@ function generateHyperlinkHTML($uri, $attributes = array(), $maxLength = 40) $uri = strval($uri); } - $maxLength = (integer)$maxLength; - if($maxLength < 0) $maxLength = 0; - if($maxLength > 0 && strlen($uri) > $maxLength) - $shortUri = substr($uri, 0, $maxLength).'...'; - else - $shortUri = $uri; - $attribs = ''; if(is_array($attributes)) { @@ -257,6 +263,16 @@ function generateHyperlinkHTML($uri, $attributes = array(), $maxLength = 40) } } + if(!isset($shortUri)) + { + $maxLength = (integer)$maxLength; + if($maxLength < 0) $maxLength = 0; + if($maxLength > 0 && strlen($uri) > $maxLength) + $shortUri = substr($uri, 0, $maxLength).'...'; + else + $shortUri = $uri; + } + $html = "". htmlspecialchars($shortUri) .''; return $html; } diff --git a/web/plugins/buildrepository/commitutils.php b/web/plugins/buildrepository/commitutils.php index 08568f0b52..905397c075 100644 --- a/web/plugins/buildrepository/commitutils.php +++ b/web/plugins/buildrepository/commitutils.php @@ -90,19 +90,19 @@ function formatCommitHTML($msg) htmlspecialchars($msg); // Rules derived from Søren Løvborg's UrlLinker (see: http://www.kwi.dk/projects/php/UrlLinker/) - $rexProtocol = '((http|https|ftp)\:\/\/)'; - $rexDomain = '(?:[-a-zA-Z0-9]{1,63}\.)+[a-zA-Z][-a-zA-Z0-9]{1,62}'; - $rexIp = '(?:[1-9][0-9]{0,2}\.|0\.){3}(?:[1-9][0-9]{0,2}|0)'; - $rexPort = '(:[0-9]{1,5})?'; - $rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?'; - $rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; - $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; - $rexUsername = '[^]\\\\\x00-\x20\"(),:-<>[\x7f-\xff]{1,64}'; - $rexPassword = $rexUsername; // allow the same characters as in the username - $rexUrl = "$rexProtocol(?:($rexUsername)(:$rexPassword)?@)?($rexDomain|$rexIp)($rexPort$rexPath$rexQuery$rexFragment)"; + $rexProtocol = '(https?:\/\/|ftp:\/\/)'; + $rexDomain = '(?:[-a-zA-Z0-9]{1,63}\.)+[a-zA-Z][-a-zA-Z0-9]{1,62}'; + $rexIp = '(?:[1-9][0-9]{0,2}\.|0\.){3}(?:[1-9][0-9]{0,2}|0)'; + $rexPort = '(:[0-9]{1,5})?'; + $rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?'; + $rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; + $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; + $rexUsername = '[^]\\\\\x00-\x20\"(),:-<>[\x7f-\xff]{1,64}'; + $rexPassword = $rexUsername; // allow the same characters as in the username + $rexUrl = "$rexProtocol(?:($rexUsername)(:$rexPassword)?@)?($rexDomain|$rexIp)$rexPort$rexPath$rexQuery$rexFragment"; $msg = preg_replace_callback("&\\b$rexUrl(?=[?.!,;:\"]?(\s|$))&", - "make_pretty_hyperlink", $msg); + "make_pretty_hyperlink", $msg); return $msg; }