From 344763ad4e90e41c8a94b0a69a527ff2d6319ab5 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sat, 2 Apr 2011 03:32:13 +0100 Subject: FS#2122 alter SafeFN safe and post indicator characters. Note, any filenames encoded with the previous SafeFN scheme will need to be converted to the new scheme. Users of the old SafeFN scheme should not use this new scheme until after converting their filenames. --- _test/cases/inc/safefn.test.php | 35 ++++++++++++++++++++++++----------- inc/SafeFN.class.php | 6 +++--- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/_test/cases/inc/safefn.test.php b/_test/cases/inc/safefn.test.php index c789875ba..1227e5578 100644 --- a/_test/cases/inc/safefn.test.php +++ b/_test/cases/inc/safefn.test.php @@ -10,19 +10,23 @@ class safeFN_test extends UnitTestCase { function test1(){ // we test multiple cases here - format: string, repl, additional, test $tests = array(); - $tests[] = array('äa.txt', '%5g.a.txt'); - $tests[] = array('ä.', '%5g..'); + $tests[] = array('äa.txt', '%5g]a.txt'); + $tests[] = array('ä.', '%5g].'); $tests[] = array('asciistring','asciistring'); $tests[] = array('ascii-_/.string','ascii-_/.string'); - $tests[] = array('AName','%x%1a.ame'); - $tests[] = array('A Name','%x%0%1a.ame'); - $tests[] = array('Another...Name','%x.nother...%1a.ame'); - $tests[] = array('Aß∂ƒName','%x%5b%6oy%aa%1a.ame'); - $tests[] = array('A%ß-∂_.ƒName','%x%%5b.-%6oy._.%aa%1a.ame'); - $tests[] = array('A%%ß-∂_.ƒName','%x%%%5b.-%6oy._.%aa%1a.ame'); - $tests[] = array('데이터도 함께 복원됩니다. 강력한','%zf4%13dg%15ao%zhg%0%164o%yig%0%11at%138w%zk9%zag%zb8..%0%xyt%10cl%164c.'); - $tests[] = array('совместимая','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr.'); - $tests[] = array('нехватка_файлового_пространства_на_сервере_p0-squid.some.domain.1270211897.txt.gz','%t9%t1%th%sy%sw%te%t6%sw._%tg%sw%t5%t7%ta%sy%ta%sz%ta._%tb%tc%ta%td%te%tc%sw%t9%td%te%sy%sw._%t9%sw._%td%t1%tc%sy%t1%tc%t1._p0-squid.some.domain.1270211897.txt.gz'); + $tests[] = array('AName','%x%1a]ame'); + $tests[] = array('A Name','%x%0%1a]ame'); + $tests[] = array('Another...Name','%x]nother...%1a]ame'); + $tests[] = array('Aß∂ƒName','%x%5b%6oy%aa%1a]ame'); + $tests[] = array('A%ß-∂_.ƒName','%x%%5b]-%6oy]_.%aa%1a]ame'); + $tests[] = array('A%%ß-∂_.ƒName','%x%%%5b]-%6oy]_.%aa%1a]ame'); + $tests[] = array('데이터도 함께 복원됩니다. 강력한','%zf4%13dg%15ao%zhg%0%164o%yig%0%11at%138w%zk9%zag%zb8].%0%xyt%10cl%164c]'); + $tests[] = array('совместимая','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr]'); + $tests[] = array('нехватка_файлового_пространства_на_сервере_p0-squid.some.domain.1270211897.txt.gz','%t9%t1%th%sy%sw%te%t6%sw]_%tg%sw%t5%t7%ta%sy%ta%sz%ta]_%tb%tc%ta%td%te%tc%sw%t9%td%te%sy%sw]_%t9%sw]_%td%t1%tc%sy%t1%tc%t1]_p0-squid.some.domain.1270211897.txt.gz'); + + $tests[] = array('name[1]','name[1]'); + $tests[] = array('Name[1]','%1a]ame[1]'); + $tests[] = array('Name[A]','%1a]ame[%x]]'); foreach($tests as $test){ list($utf8,$safe) = $test; @@ -30,6 +34,15 @@ class safeFN_test extends UnitTestCase { $this->assertEqual(SafeFN::decode($safe),$utf8); } } + + function test2(){ + $tests[] = array('совместимая','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr'); + + foreach($tests as $test){ + list($utf8,$safe) = $test; + $this->assertEqual(SafeFN::decode($safe),$utf8); + } + } } //Setup VIM: ex: et ts=4 : diff --git a/inc/SafeFN.class.php b/inc/SafeFN.class.php index ac6698a63..43b19e9ab 100644 --- a/inc/SafeFN.class.php +++ b/inc/SafeFN.class.php @@ -16,9 +16,9 @@ class SafeFN { // 'safe' characters are a superset of $plain, $pre_indicator and $post_indicator - private static $plain = '-/_0123456789abcdefghijklmnopqrstuvwxyz'; // these characters aren't converted + private static $plain = '-./[_0123456789abcdefghijklmnopqrstuvwxyz'; // these characters aren't converted private static $pre_indicator = '%'; - private static $post_indicator = '.'; + private static $post_indicator = ']'; /** * Convert an UTF-8 string to a safe ASCII String @@ -37,7 +37,7 @@ class SafeFN { * - reduce codepoint value for non-printable ASCII characters (0x00 - 0x1f). Space becomes our zero. * - convert reduced value to base36 (0-9a-z) * - append $pre_indicator characater followed by base36 string to output, set converted flag - * continue to next character) + * (continue to next character) * * @param string $filename a utf8 string, should only include printable characters - not 0x00-0x1f * @return string an encoded representation of $filename using only 'safe' ASCII characters -- cgit v1.2.3 From b9d65e9d8e82713e04ebf1172d9c94fddb38df83 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 3 Apr 2011 21:55:50 +0200 Subject: Temporary conversion plugin for new fnencode FS#2197 This plugin converts existing filenames that were stored using the option "safe" in fnencode from using the dot (.) as post_indicator to using a bracket (]) as post_insdicator. It will also add a post_indicator at the end of the file name should it be missing (Bug FS#2122). This plugin needs testing by people using the safe encode option! --- lib/plugins/safefnrecode/action.php | 68 ++++++++++++++++++++++++++++++++ lib/plugins/safefnrecode/plugin.info.txt | 7 ++++ 2 files changed, 75 insertions(+) create mode 100644 lib/plugins/safefnrecode/action.php create mode 100644 lib/plugins/safefnrecode/plugin.info.txt diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php new file mode 100644 index 000000000..6d869c532 --- /dev/null +++ b/lib/plugins/safefnrecode/action.php @@ -0,0 +1,68 @@ + + */ + +// must be run within Dokuwiki +if (!defined('DOKU_INC')) die(); + +require_once DOKU_PLUGIN.'action.php'; + +class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { + + public function register(Doku_Event_Handler &$controller) { + + $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_indexer_tasks_run'); + + } + + public function handle_indexer_tasks_run(Doku_Event &$event, $param) { + global $conf; + if($conf['fnencode'] != 'safe') return; + + if(!file_exists($conf['datadir'].'_safefn.recoded')){ + $this->recode($conf['datadir']); + touch($conf['datadir'].'_safefn.recoded'); + } + + if(!file_exists($conf['olddir'].'_safefn.recoded')){ + $this->recode($conf['olddir']); + touch($conf['olddir'].'_safefn.recoded'); + } + + if(!file_exists($conf['metadir'].'_safefn.recoded')){ + $this->recode($conf['metadir']); + touch($conf['metadir'].'_safefn.recoded'); + } + + if(!file_exists($conf['mediadir'].'_safefn.recoded')){ + $this->recode($conf['metadir']); + touch($conf['metadir'].'_safefn.recoded'); + } + + } + + /** + * Recursive function to rename all safe encoded files to use the new + * square bracket post indicator + */ + private function recode($dir){ + $dh = opendir($dir); + if(!$dh) return; + while (($file = readdir($dh)) !== false) { + if($file == '.' || $file == '..') continue; # cur and upper dir + if(is_dir("$dir/$file")) $this->recode("$dir/$file"); #recurse + if(strpos('%',$file) === false) continue; # no encoding used + $new = preg_replace('/(%.*?)\./','\1]',$file); # new post indicator + if(preg_match('/%[^\.]+$/',$new)) $new .= ']'; # fix end FS#2122 + rename("$dir/$file","$dir/$new"); # rename it + } + closedir($dh); + } + +} + +// vim:ts=4:sw=4:et: diff --git a/lib/plugins/safefnrecode/plugin.info.txt b/lib/plugins/safefnrecode/plugin.info.txt new file mode 100644 index 000000000..b1600060c --- /dev/null +++ b/lib/plugins/safefnrecode/plugin.info.txt @@ -0,0 +1,7 @@ +base safefnrecode +author Andreas Gohr +email andi@splitbrain.org +date 2011-04-03 +name safefnrecode plugin +desc Changes existing page and foldernames for the change in the safe filename encoding +url http://www.dokuwiki.org/plugin:safefnrecode -- cgit v1.2.3 From aa235a708b8f394fab1d95f4c5a3cf23cabffd02 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 3 Apr 2011 22:02:27 +0200 Subject: fix end indicator fix --- lib/plugins/safefnrecode/action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php index 6d869c532..4fa5530df 100644 --- a/lib/plugins/safefnrecode/action.php +++ b/lib/plugins/safefnrecode/action.php @@ -57,7 +57,7 @@ class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { if(is_dir("$dir/$file")) $this->recode("$dir/$file"); #recurse if(strpos('%',$file) === false) continue; # no encoding used $new = preg_replace('/(%.*?)\./','\1]',$file); # new post indicator - if(preg_match('/%[^\.]+$/',$new)) $new .= ']'; # fix end FS#2122 + if(preg_match('/%[^\]]+$/',$new)) $new .= ']'; # fix end FS#2122 rename("$dir/$file","$dir/$new"); # rename it } closedir($dh); -- cgit v1.2.3 From 903e5bc8f1bbb8bd5c9238c020882b571bb8ea85 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 3 Apr 2011 22:06:34 +0200 Subject: safefnrecode: don't double fix filenames --- lib/plugins/safefnrecode/action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php index 4fa5530df..76d02e4c7 100644 --- a/lib/plugins/safefnrecode/action.php +++ b/lib/plugins/safefnrecode/action.php @@ -56,7 +56,7 @@ class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { if($file == '.' || $file == '..') continue; # cur and upper dir if(is_dir("$dir/$file")) $this->recode("$dir/$file"); #recurse if(strpos('%',$file) === false) continue; # no encoding used - $new = preg_replace('/(%.*?)\./','\1]',$file); # new post indicator + $new = preg_replace('/(%[^\]]*?)\./','\1]',$file); # new post indicator if(preg_match('/%[^\]]+$/',$new)) $new .= ']'; # fix end FS#2122 rename("$dir/$file","$dir/$new"); # rename it } -- cgit v1.2.3 From f7f0e633f735842dfb466878eef440245a9bd3e1 Mon Sep 17 00:00:00 2001 From: Myron Turner Date: Wed, 6 Apr 2011 22:00:00 +0200 Subject: fixed two errors in safefnrecode plugin --- lib/plugins/safefnrecode/action.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php index 76d02e4c7..5d3eaae3a 100644 --- a/lib/plugins/safefnrecode/action.php +++ b/lib/plugins/safefnrecode/action.php @@ -39,8 +39,8 @@ class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { } if(!file_exists($conf['mediadir'].'_safefn.recoded')){ - $this->recode($conf['metadir']); - touch($conf['metadir'].'_safefn.recoded'); + $this->recode($conf['mediadir']); + touch($conf['mediadir'].'_safefn.recoded'); } } @@ -55,7 +55,7 @@ class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { while (($file = readdir($dh)) !== false) { if($file == '.' || $file == '..') continue; # cur and upper dir if(is_dir("$dir/$file")) $this->recode("$dir/$file"); #recurse - if(strpos('%',$file) === false) continue; # no encoding used + if(strpos($file,'%') === false) continue; # no encoding used $new = preg_replace('/(%[^\]]*?)\./','\1]',$file); # new post indicator if(preg_match('/%[^\]]+$/',$new)) $new .= ']'; # fix end FS#2122 rename("$dir/$file","$dir/$new"); # rename it -- cgit v1.2.3 From 6a9d97936d8cb7304d0ce22ccddc0d76bc3dba85 Mon Sep 17 00:00:00 2001 From: Kate Arzamastseva Date: Thu, 7 Apr 2011 16:13:57 +0300 Subject: indexer fix updating the search index --- inc/indexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/indexer.php b/inc/indexer.php index 0fbd939be..b42c092fa 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -1146,7 +1146,7 @@ function idx_addPage($page, $verbose=false) { if(@file_exists($idxtag)){ if(trim(io_readFile($idxtag)) == idx_get_version()){ $last = @filemtime($idxtag); - if($last > @filemtime(wikiFN($ID))){ + if($last > @filemtime(wikiFN($page))){ if ($verbose) print("Indexer: index for $page up to date".DOKU_LF); return false; } -- cgit v1.2.3 From c006739e4780df86d205d5ebc6f39af141cbc3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Sun, 20 Mar 2011 23:03:20 +0100 Subject: If the page link is empty, it should link to current page -- FS#2178 --- inc/pageutils.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inc/pageutils.php b/inc/pageutils.php index cd01dcae7..c9bf60135 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -423,8 +423,14 @@ function resolve_mediaid($ns,&$page,&$exists){ */ function resolve_pageid($ns,&$page,&$exists){ global $conf; + global $ID; $exists = false; + //empty address should point to current page + if ($page === "") { + $page = $ID; + } + //keep hashlink if exists then clean both parts if (strpos($page,'#')) { list($page,$hash) = explode('#',$page,2); -- cgit v1.2.3 From 4ab823396c3a43defae8363fec0e0eceb90720e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Mon, 4 Apr 2011 11:06:40 +0200 Subject: Unit test cases for FS 2178 --- _test/cases/inc/parser/xhtml_links.test.php | 89 +++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/_test/cases/inc/parser/xhtml_links.test.php b/_test/cases/inc/parser/xhtml_links.test.php index 0ad96c793..4954086a2 100644 --- a/_test/cases/inc/parser/xhtml_links.test.php +++ b/_test/cases/inc/parser/xhtml_links.test.php @@ -41,4 +41,93 @@ class xhtml_links_test extends UnitTestCase { $this->assertEqual($p->doc,$expect); } + /** + * Produced by syntax like [[ ]] + */ + function test_empty_internallink(){ + global $ID; + $ID = 'my:space'; + + $p = new Doku_Renderer_xhtml(); + $p->internallink(''); + + $expect = 'start'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[ |my caption]] + */ + function test_empty_internallink_with_caption(){ + global $ID; + $ID = 'my:space'; + + $p = new Doku_Renderer_xhtml(); + $p->internallink('', 'my caption'); + + $expect = 'my caption'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[?do=index]] + */ + function test_empty_internallink_index(){ + global $ID; + $ID = 'my:space'; + + $p = new Doku_Renderer_xhtml(); + $p->internallink('?do=index'); + + $expect = 'start'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[?do=index|my caption]] + */ + function test_empty_internallink_index_with_caption(){ + global $ID; + $ID = 'my:space'; + + $p = new Doku_Renderer_xhtml(); + $p->internallink('?do=index', 'my caption'); + + $expect = 'my caption'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[#test]] + */ + function test_empty_locallink(){ + global $ID; + $ID = 'my:space'; + + $p = new Doku_Renderer_xhtml(); + $p->locallink('test'); + + $expect = 'test'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[#test|my caption]] + */ + function test_empty_locallink_with_caption(){ + global $ID; + $ID = 'my:space'; + + $p = new Doku_Renderer_xhtml(); + $p->locallink('test', 'my caption'); + + $expect = 'my caption'; + + $this->assertEqual($p->doc, $expect); + } } -- cgit v1.2.3 From 38574c3529746542183c68d28c6ad6fc1de2d6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Thu, 7 Apr 2011 11:44:16 +0200 Subject: Added configuration variables for empty link testcases and added testcases for resolve_pageid --- _test/cases/inc/pageutils_resolve_pageid.test.php | 22 ++++++++++ _test/cases/inc/parser/xhtml_links.test.php | 50 +++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/_test/cases/inc/pageutils_resolve_pageid.test.php b/_test/cases/inc/pageutils_resolve_pageid.test.php index d9ea89869..c65ed1866 100644 --- a/_test/cases/inc/pageutils_resolve_pageid.test.php +++ b/_test/cases/inc/pageutils_resolve_pageid.test.php @@ -50,6 +50,10 @@ class init_resolve_pageid_test extends UnitTestCase { $tests[] = array('foo','foo:','foo:start'); $tests[] = array('foo','playground:','playground:playground'); + // empty $page + global $ID; + $ID = 'my:space'; + $tests[] = array('my', '', 'my:space'); foreach($tests as $test){ $page = $test[1]; @@ -59,5 +63,23 @@ class init_resolve_pageid_test extends UnitTestCase { } } + /** + * Empty page on homepage should resolve to start page + */ + function test_resolve_pageid_empty_homepage() { + global $ID; + $ID = ''; + + global $conf; + $conf['start'] = 'someverystrangestartname'; + + $ns = ''; + $page = ''; + $exist = true; + + resolve_pageid($ns, $page, $exist); + $this->assertEqual($page, $conf['start']); + } + } //Setup VIM: ex: et ts=4 : diff --git a/_test/cases/inc/parser/xhtml_links.test.php b/_test/cases/inc/parser/xhtml_links.test.php index 4954086a2..11883dd9c 100644 --- a/_test/cases/inc/parser/xhtml_links.test.php +++ b/_test/cases/inc/parser/xhtml_links.test.php @@ -48,10 +48,17 @@ class xhtml_links_test extends UnitTestCase { global $ID; $ID = 'my:space'; + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + $p = new Doku_Renderer_xhtml(); $p->internallink(''); - $expect = 'start'; + $expect = 'start'; $this->assertEqual($p->doc, $expect); } @@ -63,10 +70,17 @@ class xhtml_links_test extends UnitTestCase { global $ID; $ID = 'my:space'; + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + $p = new Doku_Renderer_xhtml(); $p->internallink('', 'my caption'); - $expect = 'my caption'; + $expect = 'my caption'; $this->assertEqual($p->doc, $expect); } @@ -78,10 +92,17 @@ class xhtml_links_test extends UnitTestCase { global $ID; $ID = 'my:space'; + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + $p = new Doku_Renderer_xhtml(); $p->internallink('?do=index'); - $expect = 'start'; + $expect = 'start'; $this->assertEqual($p->doc, $expect); } @@ -93,10 +114,17 @@ class xhtml_links_test extends UnitTestCase { global $ID; $ID = 'my:space'; + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + $p = new Doku_Renderer_xhtml(); $p->internallink('?do=index', 'my caption'); - $expect = 'my caption'; + $expect = 'my caption'; $this->assertEqual($p->doc, $expect); } @@ -108,6 +136,13 @@ class xhtml_links_test extends UnitTestCase { global $ID; $ID = 'my:space'; + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + $p = new Doku_Renderer_xhtml(); $p->locallink('test'); @@ -123,6 +158,13 @@ class xhtml_links_test extends UnitTestCase { global $ID; $ID = 'my:space'; + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + $p = new Doku_Renderer_xhtml(); $p->locallink('test', 'my caption'); -- cgit v1.2.3 From fda14ffc7c57c4451df9196e8125cd39b1d5c134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Izidor=20Matu=C5=A1ov?= Date: Thu, 7 Apr 2011 19:44:54 +0200 Subject: Check if link exists and set right caption --- _test/cases/inc/parser/xhtml_links.test.php | 94 ++++++++++++++++++++++++----- inc/parser/xhtml.php | 9 +++ 2 files changed, 88 insertions(+), 15 deletions(-) diff --git a/_test/cases/inc/parser/xhtml_links.test.php b/_test/cases/inc/parser/xhtml_links.test.php index 11883dd9c..74c39353e 100644 --- a/_test/cases/inc/parser/xhtml_links.test.php +++ b/_test/cases/inc/parser/xhtml_links.test.php @@ -1,6 +1,7 @@ internallink(''); - $expect = 'start'; + + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } + + $parts = split(':', $page); + $caption = $parts[count($parts)-1]; + + $expect = ''.$caption.''; $this->assertEqual($p->doc, $expect); } @@ -67,8 +86,11 @@ class xhtml_links_test extends UnitTestCase { * Produced by syntax like [[ |my caption]] */ function test_empty_internallink_with_caption(){ + $page = 'my:space'; + $caption = 'my caption'; + global $ID; - $ID = 'my:space'; + $ID = $page; global $conf; $conf['basedir'] = '/'; @@ -78,9 +100,18 @@ class xhtml_links_test extends UnitTestCase { $conf['canonical'] = 0; $p = new Doku_Renderer_xhtml(); - $p->internallink('', 'my caption'); + $p->internallink('', $caption); + + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } - $expect = 'my caption'; + $expect = ''.$caption.''; $this->assertEqual($p->doc, $expect); } @@ -89,8 +120,13 @@ class xhtml_links_test extends UnitTestCase { * Produced by syntax like [[?do=index]] */ function test_empty_internallink_index(){ + $page = 'my:space'; + global $ID; - $ID = 'my:space'; + $ID = $page; + + global $conf; + $conf['start'] = 'start'; global $conf; $conf['basedir'] = '/'; @@ -102,7 +138,19 @@ class xhtml_links_test extends UnitTestCase { $p = new Doku_Renderer_xhtml(); $p->internallink('?do=index'); - $expect = 'start'; + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } + + $parts = split(':', $page); + $caption = $parts[count($parts)-1]; + + $expect = ''.$caption.''; $this->assertEqual($p->doc, $expect); } @@ -111,8 +159,11 @@ class xhtml_links_test extends UnitTestCase { * Produced by syntax like [[?do=index|my caption]] */ function test_empty_internallink_index_with_caption(){ + $page = 'my:space'; + $caption = 'my caption'; + global $ID; - $ID = 'my:space'; + $ID = $page; global $conf; $conf['basedir'] = '/'; @@ -122,9 +173,18 @@ class xhtml_links_test extends UnitTestCase { $conf['canonical'] = 0; $p = new Doku_Renderer_xhtml(); - $p->internallink('?do=index', 'my caption'); + $p->internallink('?do=index', $caption); - $expect = 'my caption'; + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } + + $expect = ''.$caption.''; $this->assertEqual($p->doc, $expect); } @@ -133,8 +193,9 @@ class xhtml_links_test extends UnitTestCase { * Produced by syntax like [[#test]] */ function test_empty_locallink(){ + $page = 'my:spacex'; global $ID; - $ID = 'my:space'; + $ID = $page; global $conf; $conf['basedir'] = '/'; @@ -146,7 +207,7 @@ class xhtml_links_test extends UnitTestCase { $p = new Doku_Renderer_xhtml(); $p->locallink('test'); - $expect = 'test'; + $expect = 'test'; $this->assertEqual($p->doc, $expect); } @@ -155,8 +216,11 @@ class xhtml_links_test extends UnitTestCase { * Produced by syntax like [[#test|my caption]] */ function test_empty_locallink_with_caption(){ + $page = 'my:spacex'; + $caption = 'my caption'; + global $ID; - $ID = 'my:space'; + $ID = $page; global $conf; $conf['basedir'] = '/'; @@ -166,9 +230,9 @@ class xhtml_links_test extends UnitTestCase { $conf['canonical'] = 0; $p = new Doku_Renderer_xhtml(); - $p->locallink('test', 'my caption'); + $p->locallink('test', $caption); - $expect = 'my caption'; + $expect = ''.$caption.''; $this->assertEqual($p->doc, $expect); } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 9405d9420..ab295dd01 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -574,11 +574,20 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $params = $parts[1]; } + // For empty $id we need to know the current $ID + // We need this check because _simpleTitle needs + // correct $id and resolve_pageid() use cleanID($id) + // (some things could be lost) + if ($id === '') { + $id = $ID; + } + // default name is based on $id as given $default = $this->_simpleTitle($id); // now first resolve and clean up the $id resolve_pageid(getNS($ID),$id,$exists); + $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); if ( !$isImage ) { if ( $exists ) { -- cgit v1.2.3