diff options
author | andi <andi@splitbrain.org> | 2005-03-28 19:49:03 +0200 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-03-28 19:49:03 +0200 |
commit | e6cfb54057720471b439f9b9eeee07d8da67ca47 (patch) | |
tree | 7b5d1b3f073fecaf10fa428baa55f0cf71ad0893 | |
parent | a77f584692c01151a33d85c32b23f8866b021c7c (diff) | |
download | rpg-e6cfb54057720471b439f9b9eeee07d8da67ca47.tar.gz rpg-e6cfb54057720471b439f9b9eeee07d8da67ca47.tar.bz2 |
fix for display names if none is given (#219)
darcs-hash:20050328174903-9977f-6bb17f3884e7b1817f581b992a59ae1d90094748.gz
-rw-r--r-- | inc/format.php | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/inc/format.php b/inc/format.php index fe4b6fa72..77d2e0d54 100644 --- a/inc/format.php +++ b/inc/format.php @@ -89,47 +89,51 @@ function format_link_wiki($link){ list($link['url'],$hash) = split('#',$link['url'],2); $hash = cleanID($hash); - $link['url'] = cleanID($link['url']); - $link['title'] = $link['url']; + //if no name set, use (unclean) link without namespace + if(empty($link['name'])){ + if($conf['useslash']){ + $nssep = '[:;/]'; + }else{ + $nssep = '[:;]'; + } + $link['name'] = preg_replace('!.*'.$nssep.'!','',$link['url']); + $link['name'] = htmlspecialchars($link['name']); + } + - //set class and name depending on file existence and content $file = wikiFN($link['url']); + $url = cleanID($link['url']); + + //check alternative plural/nonplural form + if(!@file_exists($file) && $conf['autoplural']){ + if(substr($url,-1) == 's'){ + $try = substr($url,0,-1); + }else{ + $try = $url.'s'; + } + $tryfile = wikiFN($try); + if(@file_exists($tryfile)){ + $file = $tryfile; + $url = $try; + } + } + + //set class and name depending on file existence and content if(@file_exists($file)){ $link['class']="wikilink1"; if ($conf['useheading'] && empty($link['name'])) { - $title = getFirstHeading(io_readFile($file)); - if ($title){ - $link['name'] = $title; - } + $hl = getFirstHeading(io_readFile($file)); + if ($hl) $link['name'] = $hl; } }else{ - if($conf['autoplural']){ - //try plural/nonplural - if(substr($link['url'],-1) == 's'){ - $try = substr($link['url'],0,-1); - }else{ - $try = $link['url'].'s'; - } - $file = wikiFN($try); - //check if the other form exists - if(@file_exists($file)){ - $link['class']="wikilink1"; - $link['url'] = $try; - }else{ - $link['class']="wikilink2"; - } - }else{ - //no autoplural is wanted - $link['class']="wikilink2"; - } + $link['class']="wikilink2"; } - //if no name yet, use link without namespace - if(empty($link['name'])) $link['name'] = preg_replace('/.*:/','',$link['url']); - $link['name'] = htmlspecialchars($link['name']); + //set title + $link['title'] = $url; //construct the full link - $link['url'] = wl($link['url']); + $link['url'] = wl($url); //add hash if exists if($hash) $link['url'] .= '#'.$hash; |