Skip to content
Snippets Groups Projects
Commit bd2f6c2f authored by Andreas Gohr's avatar Andreas Gohr
Browse files

display the (shortened) namespace for page quicksearch

When displaying pagename matches in the Ajax quick search or normal search,
the namespace of the page is shown behind the pagename. This makes it easier
to distinguish the pages when the same namespace is used in different namespaces.

To avoid breaking the layout in deep nested namespace hierarchies, the namespace
is shortened in the middle when needed.

This patch also disables the effect of the useheadings option in the Ajax quick
search. After all the results should show what was found and since the search
works on pagenames not headings it should show pagenames as result.

darcs-hash:20080814194826-7ad00-9add9c1bbbb4f4ede3c6884d37427644b2cddc56.gz
parent 09a5b61f
No related branches found
No related tags found
No related merge requests found
......@@ -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 :
......@@ -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> ';
......
......@@ -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>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment