diff --git a/inc/common.php b/inc/common.php index 7aaf8098bf29e11f74740151a9021dd0818f8dca..1f7e3f910ca3292d74a8cb0f3c2571d3c29c209b 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1206,4 +1206,27 @@ function preg_quote_cb($string){ return preg_quote($string,'/'); } +/** + * Shorten a given string by removing data from the middle + * + * You can give the string in two parts, teh first part $keep + * will never be shortened. The second part $short will be cut + * in the middle to shorten but only if at least $min chars are + * left to display it. Otherwise it will be left off. + * + * @param string $keep the part to keep + * @param string $short the part to shorten + * @param int $max maximum chars you want for the whole string + * @param int $min minimum number of chars to have left for middle shortening + * @param string $char the shortening character to use + */ +function shorten($keep,$short,$max,$min=9,$char='⌇'){ + $max = $max - utf8_strlen($keep); + if($max < $min) return $keep; + $len = utf8_strlen($short); + if($len <= $max) return $keep.$short; + $half = floor($max/2); + return $keep.utf8_substr($short,0,$half-1).$char.utf8_substr($short,$len-$half); +} + //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/html.php b/inc/html.php index 12ca28c1ff51a3861fc3f8b3b4a67c04e3831003..693bcd68e93157b15bbff7da92ff01b2e61ffa84 100644 --- a/inc/html.php +++ b/inc/html.php @@ -329,7 +329,13 @@ function html_search(){ print '<ul class="search_quickhits">'; foreach($data as $id){ print '<li> '; - print html_wikilink(':'.$id,noNS($id)); + $ns = getNS($id); + if($ns){ + $name = shorten(noNS($id), ' ('.$ns.')',30); + }else{ + $name = $id; + } + print html_wikilink(':'.$id,$name); print '</li> '; } print '</ul> '; diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 5d8a0e4e67fd973ef7fe92c39ca8300eca7e6737..b4bd20b702377a77796b6e1b93da38ca2e1a714e 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -66,7 +66,13 @@ function ajax_qsearch(){ print '<ul>'; foreach($data as $id){ print '<li>'; - print html_wikilink(':'.$id); + $ns = getNS($id); + if($ns){ + $name = shorten(noNS($id), ' ('.$ns.')',30); + }else{ + $name = $id; + } + print html_wikilink(':'.$id,$name); print '</li>'; } print '</ul>';