CONSIDER USEHEADING before reading the rest. The useheading option can be set in local.php configuration file of the new Dokuwiki released 2006-10.
This is old, the new release doesn't have inc/format.php. Instead I think you would have to modify the same code in inc/parser/xhtml.php UNDERSCORES ARE ANNOYING. PLEASE
.
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
Those underscores really bug me so…
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
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.
function format_pretty_ref($name){
return 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 ucfirst(strtr($name,'_',' '));
}else{
return ucfirst(substr(strrchr(strtr($name,'_',' '), ':'), 1 ));
}
}
Wrap the function around tpl_pagetitle in lib/tpl/[yourtheme]/main.php.
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){
if(strstr($name, ':') == ''){
return ucfirst(strtr($name,'_',' '));
}else{
if(substr(strrchr($name, ':'), 1 ) == 'start') {
$name = substr($name, 0, strlen($name) - 6);
if(strstr($name, ':') == ''){
return ucfirst(strtr($name,'_',' '));
}else{
return ucfirst(substr(strrchr(strtr($name,'_',' '), ':'), 1 ));
}
}else{
return ucfirst(substr(strrchr(strtr($name,'_',' '), ':'), 1 ));
}
}
}