Dear community,
I offer the following hacks for comments.
I wanted to achieve the following:
(a) display pagenames in the title without "_" by using spaces instead
(b) allowing upper case characters in the pagenames
(c) make the search for pagenames case insensitive
What I did (please excuse the lack of elegance, I am not a real coder) with the help of various help pages, manual pages and forum posts:
===== (a) display pagenames without "_" by using spaces instead =====
modification in file template.php, around line 1012
function tpl_pagetitle($id=null, $ret=false){
global $conf;
if(is_null($id)){
global $ID;
$id = $ID;
}
require_once(DOKU_INC.'hacks/nicetitle.php'); //brings in function nicetitle()
$name = nicetitle($id); //nicetitle() will replace underscores "_" by " "
if (useHeading('navigation' [... and the code continues]
The file
nicetitle.php contains:
function nicetitle($id) {
$result = preg_replace("/_/"," ",$id);
if ($result) {
return($result);
}
else {
return($id);
}
}
===== (b) allowing upper case characters in the pagenames =====
This modification was actually proposed by another user. Sorry that I lost the original post to acknowledge his contribution. In file pageutils.php "$id = utf8_strtolower($id);" needs to be commented out, i.e.
pageutils.php, line 115
// $id = utf8_strtolower($id); //commented out to allow upper case pagenames
In addition, accent conversion should also be extended to upper case characters and the original post proposed to solve this by changing the second parameter of utf8_deaccent() to "0":
pageutils.php, line126
if($conf['deaccent'] || $ascii) $id = utf8_deaccent($id,0);
Unfortunately, this hack renders the search rather picky: "Example" will from now on find "Example" but not "example" or "eXaMpLe". This leads to the last modification:
===== (c) make the search for pagenames case insensitive =====
As far as I could understand, search for pagenames is actually done with the function
_ft_pageLookup()[/m] in the file [m]fulltext.php.
My fulltext.php now has a lot of commented out code and a new include statement for the hacked code.
function _ft_pageLookup(&$data){
// split out original parameterrs
$id = $data['id'];
$pageonly = $data['pageonly'];
global $conf;
$id = preg_quote($id,'/');
$pages = file($conf['indexdir'].'/page.idx');
include(DOKU_INC.'hacks/_ft_pageLookup(HACK).php');
/* if($id) $pages = array_values(preg_grep('/'.$id.'/',$pages));
$cnt = count($pages);
for($i=0; $i<$cnt; $i++){
if($pageonly){
if(!preg_match('/'.$id.'/',noNS($pages[$i]))){
unset($pages[$i]);
continue;
}
}
if(!page_exists($pages[$i])){
unset($pages[$i]);
continue;
}
}
*/ [... and the code continues]
The file
_ft_pageLookup(HACK).php contains the following code:
if ($id) {
// Prepare search-Index for pagenames in lower case characters
$spages = $pages;
// Travers $spages and convert to lower case
foreach ($spages as &$page) {
$page = strtolower($page);
};
// The search is done without array_values to preserve the array keys
$spages =(preg_grep('/'.strtolower($id).'/',$spages));
// The real or original pagenames are obtained as intersection of the keys.
// To get a comparable result to the original statement, the intersection
// is passed to array_values.
$pages = array_values(array_intersect_key($pages,$spages));
}
// The required post-processing also needs to be done here, because the
// check for namespaces (if $pageonly=true) needs to be case insensitive as well.
// The checks if the page really does exists can be easily done as well.
$cnt = count($pages);
for($i=0; $i<$cnt; $i++){
if($pageonly){
if(!preg_match('/'.strtolower($id).'/',noNS(strtolower($pages[$i])))){
unset($pages[$i]);
continue;
}
}
if(!page_exists($pages[$i])){
unset($pages[$i]);
continue;
}
}
With this hack the search for "Example" will now bring back the desired search results like "example" and "ExAmPlE". The Ajax quicksearch popoup window next to the search input returns the same results as it also uses
_ft_pageLookup().
Could (a) become an official option "display pagenames with space instead of underscore" in a future releases?
Could (b) and (c) this become an option "allow upper case pagenames" in a future release or am I missing issues which will arise on other operating systems? I am using Windows clients with IE8 and a Synology Diskstation as webserver for DokuWiki in my LAN.
The modifications appear to work for me but maybe one of the wizzards will be able to point out the error of my ways and if I have missed something. Anyway, it was an intersting exercise and I feel much closer to "my" DokuWiki now ;-)
Any feedback is appreciated.
f@lo
P.S. and please excuse me if I have chosen the wrong spot to post this.