Skip to content
Snippets Groups Projects
Commit a6ef4796 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

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
parent 54662a04
No related branches found
No related tags found
No related merge requests found
<?php
require_once DOKU_INC.'inc/utf8.php';
require_once DOKU_INC.'inc/pageutils.php';
class init_resolve_pageid_test extends UnitTestCase {
function test1(){
global $conf;
// we test multiple cases here
// format: $ns, $page, $output
$tests = array();
// relative current in root
$tests[] = array('','page','page');
$tests[] = array('','.page','page');
$tests[] = array('','.:page','page');
// relative current in namespace
$tests[] = array('lev1:lev2','page','lev1:lev2:page');
$tests[] = array('lev1:lev2','.page','lev1:lev2:page');
$tests[] = array('lev1:lev2','.:page','lev1:lev2:page');
// relative upper in root
$tests[] = array('','..page','page');
$tests[] = array('','..:page','page');
// relative upper in namespace
$tests[] = array('lev1:lev2','..page','lev1:page');
$tests[] = array('lev1:lev2','..:page','lev1:page');
$tests[] = array('lev1:lev2','..:..:page','page');
$tests[] = array('lev1:lev2','..:..:..:page','page');
// strange and broken ones
$tests[] = array('lev1:lev2','....:....:page','lev1:lev2:page');
$tests[] = array('lev1:lev2','..:..:lev3:page','lev3:page');
$tests[] = array('lev1:lev2','..:..:lev3:..:page','page');
$tests[] = array('lev1:lev2','..:..:lev3:..:page:....:...','page');
// now some tests with existing and none existing files
$conf['start'] = 'start';
$tests[] = array('','.:','start');
$tests[] = array('foo','.:','foo:start');
$tests[] = array('','foo:','foo:start');
$tests[] = array('foo','foo:','foo:start');
$tests[] = array('foo','playground:','playground:playground');
foreach($tests as $test){
$page = $test[1];
resolve_pageid($test[0],$page,$foo);
$this->assertEqual($page,$test[2]);
}
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
......@@ -229,7 +229,7 @@ function localeFN($id){
*
* @author <bart at mediawave dot nl>
*/
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment