CONSIDER USEHEADING before reading the rest. The useheading option can be set in local.php configuration file of the new DokuWiki starting from 2006-10 release.
Find function internallink in inc/parser/xhtml.php and replace:
//keep hash if($hash) $link['url'].='#'.$hash; //output formatted if($returnonly){ return $this->_formatLink($link); }else{ $this->doc .= $this->_formatLink($link); }
with:
//keep hash if($hash) $link['url'].='#'.$hash; // replace '_' with ' ' $link['name']=strtr($link['name'],'_',' '); //output formatted if($returnonly){ return $this->_formatLink($link); }else{ $this->doc .= $this->_formatLink($link); }
It will also delete underscores in links in wikipages. — zlotekzlotek
2011/12/26 14:41
function format_pretty_ref($name){ return utf8_ucwords(str_replace(":", " | ", strtr($name,'_',' '))); }
Please update these instructions for use with the latest release. Thank you. adraeus
There is a setting useheading that sort of supercedes this. Sort of, in that it doesn't affect all links in DokuWiki yet. With a little luck maybe someone will extend it to apply to the remaining links.
— Chris 2005-05-31
Useheading only works if you use the first heading as the page title. It appears the format_link_build() function was renamed _formatLink() and moved to inc/parser/xhtml.php (line 885 in the 3/9/2006 release). Kieron's function should be used on lib/tpl/<selected template>/main.php instead. I'll add the breadcrumb fix if I can find it.
– Mike 2006-07-06
Note that the JavaScript function “svchk()” no longer exists (and is now unnecessary) in DokuWiki, and does cause JavaScript errors, so it should be removed.
– todd [at] rollerorgans [dot] com 2007-02-26
Thanks for the great tips on this page! I wanted a few things for my titles: to replace underscores by spaces, add an initial capital and show an abbreviated title when using namespaces. I disliked the idea of using Useheading, so this is what I did:
Add this at the bottom of inc/template.php:
function format_pretty_ref($name){ if(strstr($name, ':') == ''){ return utf8_ucfirst(strtr($name,'_',' ')); }else{ return utf8_ucfirst(substr(strrchr(strtr($name,'_',' '), ':'), 1 )); } }
Wrap the function around tpl_pagetitle in lib/tpl/[yourtheme]/main.php
eg. print(format_pretty_ref(tpl_pagetitle($ID,true)))
Print (or echo) is necessary, read below.
Original wiki:namespace:page_title
Changed to Page title – jayjay 2008-05-08
This one may even be better. The standard start page of a namespace is 'namespace:start'. The above code will show 'Start' as the pagetitle of every namespace start page. The code below will show the namespace title instead of the word 'start'.
eg. 'wine_bottles:french_wine' becomes 'French wine' ; 'wine_bottles:start' becomes 'Wine bottles' – jayjay 2008-05-08
function format_pretty_ref($name){ global $conf; if(strstr($name, ':') == ''){ return utf8_ucfirst(strtr($name,'_',' ')); }else{ if(substr(strrchr($name, ':'), 1 ) == $conf['start']) { $name = substr($name, 0, strlen($name) - strlen($conf['start']) - 1); if(strstr($name, ':') == ''){ return utf8_ucfirst(strtr($name,'_',' ')); }else{ return utf8_ucfirst(substr(strrchr(strtr($name,'_',' '), ':'), 1 )); } }else{ return utf8_ucfirst(substr(strrchr(strtr($name,'_',' '), ':'), 1 )); } } }
Wrap the function around tpl_pagetitle in lib/tpl/[yourtheme]/main.php
eg. print(format_pretty_ref(tpl_pagetitle($ID,true)))
Print (or echo) is necessary, read below.
I tried this and it just made my titles disappear. They didn't even show up in the html output. What am I doing wrong? shrm 2009-05-21
Same problem here. Alexander, 2010-07-02
I replaced “return” with “echo” and it works for me. But this was only try and error. I don't know anything about php. 2011-11-06
Yes, replacing return with echo or print is a good solution. I updated code above with “echo” and “$conf['start']”. — zlotekzlotek
2011/12/25 21:53
This is old, the new release doesn't have inc/format.php.
The below changes are for non-template versions of DokuWiki, that is versions prior to 2005-May-07 release. For that version and more recent versions you should use the configuration setting useheading. Right now that setting only effects internal wiki links with no title specified, breadcrumbs and index pages. For details on how to extend it to search, backlinks and recent changes pages refer Feature Request #354 — Chris 2005-05-31
in inc/format.php, function format_link_build() at about line #19. On new version, in inc/parser/xhtml.php, function “function _formatLink($link)” at about line #925. May also use the str_replace function, e.g str_replace('_', ' ', $link['name']);.
$ret .= '>'; $ret .= strtr($link['name'],'_',' '); // altered from $ret .= $link['name']; $ret .= '</a>';
which takes care of recent, search, index and backlinks pages
for newer version, do the above and forget everything after this tip for the same results: look in inc/template.php at about line #400 change one line (commented) in this function
/** * Print a link * * Just builds a link. * * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_link($url,$name,$more=''){ print '<a href="'.$url.'" '; if ($more) print ' '.$more; print ">".strtr($name,'_',' ')."</a>"; // changed from print ">$name</a>"; return true; }
and you're done for breadcrumbs and backlink / [[ pagetitle ]]!
in inc/html.php function html_breadcrumbs() at about line #151
// orig. line commented, followed by new line // .noNS($crumb). ==> becomes ==> .str(noNS($crumb), '_', ' '). // print '<a href="'.wl($crumb).'" class="breadcrumbs" onclick="return svchk()" onkeypress="return svchk()" title="'.$crumb.'">'.noNS($crumb).'</a>'; print '<a href="'.wl($crumb).'" class="breadcrumbs" onclick="return svchk()" onkeypress="return svchk()">'.strtr($crumb,'_',' ').'</a>';
which takes care of the breadcrumbs
in inc/html.php function html_header() at about line #296
// new line only shown, change is to process $ID through strtr ==> strtr($ID,'_',' ') <div class="pagename"> [[<a href="<?php echo wl($ID,'do=backlink')?>" onclick="return svchk()" onkeypress="return svchk()"><?php echo strtr($ID,'_',' '); ?></a>]] </div>
and finally thats the backlink (eg. [[current page]]) button done.
- Chris
Its also nice to do this to the page title in html.php/html_head().
Another nice change is to upper case the first letter of each word using the same changes (except for format_link_build(), since that will change in-page links) with ucwords($str), for example: ucwords(strtr($ID,'_',' ')).
Namespaces sometimes get in the way of upper casing characters, so I made that nicer by doing a str_replace(”:”,” | ”, $link).
– Kieron
Does anyone know how to edit the feed.php to remove underscores from the RSS feeds titles as well?
Sorry, that wasn't very clear. I meant embed it in the same statement. I created a function to do all of it, and so you should be able to use this wherever you need to make the text “pretty”. This should clear up your issue with the lower case character after a namespace.