diff options
author | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-04-08 22:38:27 +0200 |
---|---|---|
committer | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-04-08 22:38:27 +0200 |
commit | 5e8ffd73fd2a48f7a78e085ca7ed0dda73fb8af7 (patch) | |
tree | 7d6e598c52037249f707989a962e89481ca4afa2 | |
parent | ff482cae0f5a620704d845037d60ae13ab851410 (diff) | |
parent | fda14ffc7c57c4451df9196e8125cd39b1d5c134 (diff) | |
download | dokuwiki-5e8ffd73fd2a48f7a78e085ca7ed0dda73fb8af7.tar.gz dokuwiki-5e8ffd73fd2a48f7a78e085ca7ed0dda73fb8af7.zip |
Merge branch 'master' of git://github.com/splitbrain/dokuwiki
-rw-r--r-- | _test/cases/inc/pageutils_resolve_pageid.test.php | 22 | ||||
-rw-r--r-- | _test/cases/inc/parser/xhtml_links.test.php | 195 | ||||
-rw-r--r-- | _test/cases/inc/safefn.test.php | 35 | ||||
-rw-r--r-- | inc/SafeFN.class.php | 6 | ||||
-rw-r--r-- | inc/indexer.php | 2 | ||||
-rw-r--r-- | inc/pageutils.php | 6 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 9 | ||||
-rw-r--r-- | lib/plugins/safefnrecode/action.php | 68 | ||||
-rw-r--r-- | lib/plugins/safefnrecode/plugin.info.txt | 7 |
9 files changed, 335 insertions, 15 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 0ad96c793..74c39353e 100644 --- a/_test/cases/inc/parser/xhtml_links.test.php +++ b/_test/cases/inc/parser/xhtml_links.test.php @@ -1,6 +1,7 @@ <?php if (!defined('DOKU_BASE')) define('DOKU_BASE','./'); require_once DOKU_INC.'inc/parser/xhtml.php'; +require_once DOKU_INC.'inc/pageutils.php'; class xhtml_links_test extends UnitTestCase { @@ -41,4 +42,198 @@ class xhtml_links_test extends UnitTestCase { $this->assertEqual($p->doc,$expect); } + /** + * Produced by syntax like [[ ]] + */ + function test_empty_internallink(){ + $page = 'my:space'; + + global $ID; + $ID = $page; + + global $conf; + $conf['start'] = 'start'; + + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + + $p = new Doku_Renderer_xhtml(); + $p->internallink(''); + + + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } + + $parts = split(':', $page); + $caption = $parts[count($parts)-1]; + + $expect = '<span class="curid"><a href="/./doku.php?id='.$page.'" class="'.$class.'" title="'.$page.'"'.$rel.'>'.$caption.'</a></span>'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[ |my caption]] + */ + function test_empty_internallink_with_caption(){ + $page = 'my:space'; + $caption = 'my caption'; + + global $ID; + $ID = $page; + + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + + $p = new Doku_Renderer_xhtml(); + $p->internallink('', $caption); + + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } + + $expect = '<span class="curid"><a href="/./doku.php?id='.$page.'" class="'.$class.'" title="'.$page.'"'.$rel.'>'.$caption.'</a></span>'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[?do=index]] + */ + function test_empty_internallink_index(){ + $page = 'my:space'; + + global $ID; + $ID = $page; + + global $conf; + $conf['start'] = 'start'; + + 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'); + + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } + + $parts = split(':', $page); + $caption = $parts[count($parts)-1]; + + $expect = '<span class="curid"><a href="/./doku.php?id='.$page.'&do=index" class="'.$class.'" title="'.$page.'"'.$rel.'>'.$caption.'</a></span>'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[?do=index|my caption]] + */ + function test_empty_internallink_index_with_caption(){ + $page = 'my:space'; + $caption = 'my caption'; + + global $ID; + $ID = $page; + + 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', $caption); + + if (page_exists($page)) { + $class = 'wikilink1'; + $rel = ''; + } + else { + $class = 'wikilink2'; + $rel = ' rel="nofollow"'; + } + + $expect = '<span class="curid"><a href="/./doku.php?id='.$page.'&do=index" class="'.$class.'" title="'.$page.'"'.$rel.'>'.$caption.'</a></span>'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[#test]] + */ + function test_empty_locallink(){ + $page = 'my:spacex'; + global $ID; + $ID = $page; + + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + + $p = new Doku_Renderer_xhtml(); + $p->locallink('test'); + + $expect = '<a href="#test" title="'.$page.' ↵" class="wikilink1">test</a>'; + + $this->assertEqual($p->doc, $expect); + } + + /** + * Produced by syntax like [[#test|my caption]] + */ + function test_empty_locallink_with_caption(){ + $page = 'my:spacex'; + $caption = 'my caption'; + + global $ID; + $ID = $page; + + global $conf; + $conf['basedir'] = '/'; + $conf['useheading'] = 0; + $conf['userewrite'] = 0; + $conf['useslash'] = 0; + $conf['canonical'] = 0; + + $p = new Doku_Renderer_xhtml(); + $p->locallink('test', $caption); + + $expect = '<a href="#test" title="'.$caption.' ↵" class="wikilink1">'.$caption.'</a>'; + + $this->assertEqual($p->doc, $expect); + } } 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 diff --git a/inc/indexer.php b/inc/indexer.php index 110901e58..1db966656 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -1170,7 +1170,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; } 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); 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 ) { diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php new file mode 100644 index 000000000..5d3eaae3a --- /dev/null +++ b/lib/plugins/safefnrecode/action.php @@ -0,0 +1,68 @@ +<?php +/** + * DokuWiki Plugin safefnrecode (Action Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Andreas Gohr <andi@splitbrain.org> + */ + +// 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['mediadir']); + touch($conf['mediadir'].'_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 |