From a6ef4796e22156364843a3b42bdd8f2dc78c0db5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 11 Jun 2006 20:44:53 +0200 Subject: namespace linking first part This patch adds namespace linking - formerly known as globalstart patch. It differs somewhat from the original patch. It is not implemented in getID() but in resolve_pageid(). It is now possible to link to a "default" file of a namespace ending the linkid with a colon: [[foo:bar:]] To which page the link links is dependent on the xistance of certain named files. For the above mentioned link [[foo:bar:]] the following pages are checked: foo:bar:start foo:bar:bar foo:bar The pages are checked in the order above whatever page is found first will be linked to. If no page is found foo:bar:start will be chosen. BTW: 'start' is the value configured in $conf['start'] Note: autoplural linking is not done for those links This is just the first patch. Several other locations of the code need to be adjusted to reflect this change and some testing needs to be done (first test cases are supplied within the patch bundle) Things that maybe need adjustment: - tpl_youarehere (hierarchical breadcrumbs) - tpl_button back - maybe others (search?) Patches would be welcome. The best aproach to fix things that don't work is probably making calls to resolve_pageid() instead of simple cleanID() calls. darcs-hash:20060611184453-7ad00-ba70b0fcf2cb64d4d4f0ce6bd6e437595cd947d3.gz --- _test/cases/inc/pageutils_resolve_pageid.test.php | 60 +++++++++++++++++++++++ inc/pageutils.php | 58 ++++++++++++++++------ 2 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 _test/cases/inc/pageutils_resolve_pageid.test.php diff --git a/_test/cases/inc/pageutils_resolve_pageid.test.php b/_test/cases/inc/pageutils_resolve_pageid.test.php new file mode 100644 index 000000000..2546bd2af --- /dev/null +++ b/_test/cases/inc/pageutils_resolve_pageid.test.php @@ -0,0 +1,60 @@ +assertEqual($page,$test[2]); + } + } + +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/pageutils.php b/inc/pageutils.php index 6adeb85b2..29cb0379c 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -229,7 +229,7 @@ function localeFN($id){ * * @author */ -function resolve_id($ns,$id){ +function resolve_id($ns,$id,$clean=true){ // if the id starts with a dot we need to handle the // relative stuff if($id{0} == '.'){ @@ -260,7 +260,8 @@ function resolve_id($ns,$id){ $id = $ns.':'.$id; } - return cleanID($id); + if($clean) $id = cleanID($id); + return $id; } /** @@ -285,28 +286,53 @@ function resolve_pageid($ns,&$page,&$exists){ //keep hashlink if exists then clean both parts list($page,$hash) = split('#',$page,2); - $page = resolve_id($ns,$page); $hash = cleanID($hash); + $page = resolve_id($ns,$page,false); // resolve but don't clean, yet + // get filename (calls clean itself) $file = wikiFN($page); - //check alternative plural/nonplural form - if(!@file_exists($file)){ - if( $conf['autoplural'] ){ - if(substr($page,-1) == 's'){ - $try = substr($page,0,-1); - }else{ - $try = $page.'s'; - } - if(@file_exists(wikiFN($try))){ - $page = $try; - $exists = true; - } + // if ends with colon we have a namespace link + if(substr($page,-1) == ':'){ + if(@file_exists(wikiFN($page.$conf['start']))){ + // start page inside namespace + $page = $page.$conf['start']; + $exists = true; + }elseif(@file_exists(wikiFN($page.noNS(cleanID($page))))){ + // page named like the NS inside the NS + $page = $page.noNS(cleanID($page)); + $exists = true; + }elseif(@file_exists(wikiFN($page))){ + // page like namespace exists + $page = $page; + $exists = true; + }else{ + // fall back to default + $page = $page.$conf['start']; + $exists = false; } }else{ - $exists = true; + //check alternative plural/nonplural form + if(!@file_exists($file)){ + if( $conf['autoplural'] ){ + if(substr($page,-1) == 's'){ + $try = substr($page,0,-1); + }else{ + $try = $page.'s'; + } + if(@file_exists(wikiFN($try))){ + $page = $try; + $exists = true; + } + } + }else{ + $exists = true; + } } + // now make sure we have a clean page + $page = cleanID($page); + //add hash if any if(!empty($hash)) $page .= '#'.$hash; } -- cgit v1.2.3