summaryrefslogtreecommitdiff
path: root/inc/search.php
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-04-22 18:41:53 +0200
committerandi <andi@splitbrain.org>2005-04-22 18:41:53 +0200
commit37e34a5ef6c436d6cf1525ba3643b1597cadc168 (patch)
tree8963802fb170578e997a69d35da0a3c25c100daf /inc/search.php
parent723d78db98a03f01d49b69501be9dc9cf2c52b50 (diff)
downloadrpg-37e34a5ef6c436d6cf1525ba3643b1597cadc168.tar.gz
rpg-37e34a5ef6c436d6cf1525ba3643b1597cadc168.tar.bz2
backlink with camelcase support (untested)
darcs-hash:20050422164153-9977f-443f332fa6e591dfa352448ceb5dd24811d227a2.gz
Diffstat (limited to 'inc/search.php')
-rw-r--r--inc/search.php46
1 files changed, 19 insertions, 27 deletions
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);