Not logged in. · Lost password · Register
Forum: General Help and Support Features and Functionality RSS
pagenames: display without underscore and allow upper case characters [SOLVED]
Avatar
f_at_lo #1
Member since May 2010 · 16 posts · Location: Zürich, Schweiz
Group memberships: Members
Show profile · Link to this post
Subject: pagenames: display without underscore and allow upper case characters [SOLVED]
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() in the file 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.
This post was edited 3 times, last on 2010-11-06, 14:53 by f_at_lo.
Avatar
xtra2000 #2
Member since May 2010 · 5 posts
Group memberships: Members
Show profile · Link to this post
Good work.
Avatar
tobias.wantzen #3
Member since Sep 2009 · 14 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #1
Thanks f_at_lo for sharing this hacks. Unfortunately I encountered some more problems with allowing uppercase letters in page names:
The page names starting with lower case are completely sorted BEHIND all page names starting with upper case in the sidebar index tree (our main navigation tool).

I spent several hours to search for the sort algorithm for the sidebar index tree.
Can anybody give a helping clue where to fix this?

Cheers
Tobias
Avatar
f_at_lo #4
Member since May 2010 · 16 posts · Location: Zürich, Schweiz
Group memberships: Members
Show profile · Link to this post
Hi Tobias,

as I do not know which sidebar you are using, I did a wild guess and looked at the sidebar plugin:

http://www.dokuwiki.org/plugin:sidebar

Looking at the html-source, this sidebar looks to me like the result which is displayed after you press the "index"-Button at the lower right hand side of the default template ("Uebersicht" in German). The standard index produced after clicing "index" has the same problem you describe: search results are all lower case pagenames after the upper case pagenames. My assumption: both the standard index and the sidebar plugin use the same functions (to be confirmed ...).

As far as I can tell, the standard index is built as follows: user presses "index"-button => doku.php is called with do="index" =>  act_dispatch() of actions.php is called "to do the work". Events are handed (this is still a verrrry hazy process for me) but then act_dispatch() goes on to include => main.php which then uses the function => tpl_content() of template.php to create the wiki page content:

  <div class="page">
    <!-- wikipage start -->
    <?php tpl_content()?>
    <!-- wikipage stop -->
  </div>

tpl_content() does some event handing of its own and then calls => tpl_content_core(). If an index has to be created, tpl_content_core() will call => html_index($IDX) of html.php which will call => search() of search.php to search the files and folders and html_buildlist() to output the result.

So I guess we could either modify search() or html_buildlist() to yield another search sequence which ignores upper and lower case.

search() for instance simply calls the standard php-sort function

    [...]
    sort($files);
    sort($dirs);
    [...]

to do the sorting.

This will have to do for today ... I will come back to this later. Probably a similar hack to (c) in the original post will do the job.

Have a good nite!
f@lo
This post was edited on 2010-05-27, 00:57 by f_at_lo.
Avatar
tobias.wantzen #5
Member since Sep 2009 · 14 posts
Group memberships: Members
Show profile · Link to this post
Thanks f@lo for your investigation! To solve the problem:

Open »search.php«, in function »search(...)« change the lines 41 and 42 from:
41:    sort($files);
42:    sort($dirs);
To:
41:    natcasesort($files);
42:    natcasesort($dirs);

Cheers
Tobias
Avatar
Lebowski #6
Member since Nov 2012 · 9 posts
Group memberships: Members
Show profile · Link to this post
Hi,
thank you for this howto. No i can use uppercase in pagenames.

But, i think there is a quicker solution for make the search for pagenames case insensitive, in inc/fulltext.php in function _ft_pageLookup(&$data) (line 213) just replace strpos with stripos (lines 231,246). stripos is the caseinsensitive variant of strpos.
Avatar
Alex Hofstadter #7
User title: Axel Gebstadter's alter-ego
Member since Dec 2014 · 7 posts · Location: Santiago, Chile
Group memberships: Members
Show profile · Link to this post
I have 3 questions:
1. If I hack the code to make page titles allow spaces, will the URL still show underscores (or whatever stated at sepchar instead of spaces?
2. I don't understand the 3rd hack, the one that makes search case insensitive. You provided two codes, the default and the hack, but didn't specify what to do. I have to comment out everything at pageLookUp() at fulltext.php and add the latter code, right?
3. How can I allow apostrophes on URLs?
"Feminism is the radical notion that women are people" - Cheris Kramadae
Avatar
Klap-in #8
Member since Nov 2009 · 239 posts · Location: Alkmaar, The Netherlands
Group memberships: Documentation Team, Members
Show profile · Link to this post
I have implemented a renderer plugin which beautifies the url titles by replacing the _ by spaces.

See at https://trac.knorrie.org/csrdelft.nl/browser/trunk/htdocs/…
When you are interested, I can publish it at dokuwiki.org as well.
This post was edited on 2015-01-03, 16:00 by Klap-in.
Avatar
garrettlynch #9
Member since Nov 2017 · 5 posts
Group memberships: Members
Show profile · Link to this post
Hi, the link to the plugin here no longer works and I can't find it in the plugin directory - does anyone know where this can be found online?  Thanks.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2018-12-16, 14:29:51 (UTC +01:00)