diff options
author | andi <andi@splitbrain.org> | 2005-04-22 18:41:53 +0200 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-04-22 18:41:53 +0200 |
commit | 37e34a5ef6c436d6cf1525ba3643b1597cadc168 (patch) | |
tree | 8963802fb170578e997a69d35da0a3c25c100daf /inc | |
parent | 723d78db98a03f01d49b69501be9dc9cf2c52b50 (diff) | |
download | rpg-37e34a5ef6c436d6cf1525ba3643b1597cadc168.tar.gz rpg-37e34a5ef6c436d6cf1525ba3643b1597cadc168.tar.bz2 |
backlink with camelcase support (untested)
darcs-hash:20050422164153-9977f-443f332fa6e591dfa352448ceb5dd24811d227a2.gz
Diffstat (limited to 'inc')
-rw-r--r-- | inc/pageutils.php | 13 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 6 | ||||
-rw-r--r-- | inc/parserutils.php | 11 | ||||
-rw-r--r-- | inc/search.php | 46 |
4 files changed, 36 insertions, 40 deletions
diff --git a/inc/pageutils.php b/inc/pageutils.php index 367e53625..6334afedd 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -122,14 +122,11 @@ function localeFN($id){ /** * Returns a full media id * - * uses global $ID to resolve relative pages - * * @author Andreas Gohr <andi@splitbrain.org> */ -function resolve_mediaid(&$page,&$exists){ - global $ID; +function resolve_mediaid($ns,&$page,&$exists){ global $conf; - $ns = getNS($ID); + //if links starts with . add current namespace if($page{0} == '.'){ $page = $ns.':'.substr($page,1); @@ -148,14 +145,10 @@ function resolve_mediaid(&$page,&$exists){ /** * Returns a full page id * - * uses global $ID to resolve relative pages - * * @author Andreas Gohr <andi@splitbrain.org> */ -function resolve_pageid(&$page,&$exists){ - global $ID; +function resolve_pageid($ns,&$page,&$exists){ global $conf; - $ns = getNS($ID); //if links starts with . add current namespace if($page{0} == '.'){ diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 0b1531a65..1c26b0645 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -390,9 +390,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer { function internallink($id, $name = NULL, $search=NULL) { global $conf; + global $ID; $name = $this->_getLinkTitle($name, $this->_simpleTitle($id), $isImage, $id); - resolve_pageid($id,$exists); + resolve_pageid(getNS($ID),$id,$exists); if ( !$isImage ) { if ( $exists ) { @@ -644,7 +645,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL) { global $conf; - resolve_mediaid($src, $exists); + global $ID; + resolve_mediaid(getNS($ID),$src, $exists); $link = array(); $link['class'] = 'media'; diff --git a/inc/parserutils.php b/inc/parserutils.php index 4e38e0162..fd66c3f1e 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -111,7 +111,7 @@ function p_cached_xhtml($file){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function p_cached_instructions($file){ +function p_cached_instructions($file,$cacheonly=false){ global $conf; $cache = $conf['datadir'].'/_cache/instructions/'; $cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT']); @@ -119,6 +119,15 @@ function p_cached_instructions($file){ // check if cache can be used $cachetime = @filemtime($cache); // 0 if not exists + // cache forced? + if($cacheonly){ + if($cachetime){ + return unserialize(io_readfile($cache)); + }else{ + return NULL; + } + } + if( @file_exists($file) // does the source exist && $cachetime > @filemtime($file) // cache is fresh && !isset($_REQUEST['purge']) // no purge param was set diff --git a/inc/search.php b/inc/search.php index 9c01b455b..0b2e26c67 100644 --- a/inc/search.php +++ b/inc/search.php @@ -207,13 +207,10 @@ function search_backlinks(&$data,$base,$file,$type,$lvl,$opts){ //only search txt files if(!preg_match('#\.txt$#',$file)) return true;; - //get text - $text = io_readfile($base.'/'.$file); - //absolute search id $sid = cleanID($opts['ns'].':'.$opts['name']); - //construct current namespace + //current id and namespace $cid = pathID($file); $cns = getNS($cid); @@ -222,31 +219,25 @@ function search_backlinks(&$data,$base,$file,$type,$lvl,$opts){ return false; } - //match all links - //FIXME may be incorrect because of code blocks - // CamelCase isn't supported, too - preg_match_all('#\[\[(.+?)\]\]#si',$text,$matches,PREG_SET_ORDER); - foreach($matches as $match){ - //get ID from link and discard most non wikilinks - list($mid) = split('\|',$match[1],2); - if(preg_match("#^(https?|telnet|gopher|file|wais|ftp|ed2k|irc)://#",$mid)) continue; - if(preg_match("#\w+>#",$mid)) continue; - $mns = getNS($mid); - //namespace starting with "." - prepend current namespace - if(strpos($mns,'.')===0){ - $mid = $cns.":".substr($mid,1); - } - if($mns===false){ - //no namespace in link? add current - $mid = "$cns:$mid"; - } - $mid = cleanID($mid); - - if ($mid == $sid){ - $data[]['id'] = $cid; - break; + //fetch instructions + require_once(DOKU_INC.'inc/parserutils.php'); + $instructions = p_cached_instructions($base.$file,true); + if(is_null($instructions)) return false; + + //check all links for match + foreach($instructions as $ins){ + if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){ + $mid = $ins[1][0]; + resolve_pageid($cns,$mid,$exists); //exists is not used + if($mid == $sid){ + //we have a match - finish + $data[]['id'] = $cid; + break; + } } } + + return false; } /** @@ -325,6 +316,7 @@ function sort_search_fulltext($a,$b){ * translates a document path to an ID * * @author Andreas Gohr <andi@splitbrain.org> + * @todo move to pageutils */ function pathID($path){ $id = utf8_decodeFN($path); |