summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/fulltext.php42
-rw-r--r--inc/html.php18
-rw-r--r--inc/search.php1
3 files changed, 47 insertions, 14 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 6c4e148a2..ff29f9deb 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -77,6 +77,48 @@ function ft_pageSearch($query,&$poswords){
}
/**
+ * Returns the backlinks for a given page
+ *
+ * Does a quick lookup with the fulltext index, then
+ * evaluates the instructions of the found pages
+ */
+function ft_backlinks($id){
+ global $conf;
+ $result = array();
+
+ // quick lookup of the pagename
+ $page = noNS($id);
+ $matches = idx_lookup(array($page));
+
+ if(!count($matches)) return $result;
+ require_once(DOKU_INC.'inc/parserutils.php');
+
+
+ // check instructions for matching links
+ foreach(array_keys($matches[$page]) as $match){
+ $instructions = p_cached_instructions(wikiFN($match),true);
+ if(is_null($instructions)) continue;
+
+ $match_ns = getNS($match);
+
+ foreach($instructions as $ins){
+ if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){
+ $link = $ins[1][0];
+ resolve_pageid($match_ns,$link,$exists); //exists is not used
+ if($link == $id){
+ //we have a match - finish
+ $result[] = $match;
+ break;
+ }
+ }
+ }
+ }
+
+ sort($result);
+ return $result;
+}
+
+/**
* Quicksearch for pagenames
*
* By default it only matches the pagename and ignores the
diff --git a/inc/html.php b/inc/html.php
index 6797d0467..7c4e62cda 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -668,28 +668,18 @@ function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_backlinks(){
- require_once(DOKU_INC.'inc/search.php');
+ require_once(DOKU_INC.'inc/fulltext.php');
global $ID;
global $conf;
- if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
- $opts['ns'] = $matches[1];
- $opts['name'] = $matches[2];
- }else{
- $opts['ns'] = '';
- $opts['name'] = $ID;
- }
-
print p_locale_xhtml('backlinks');
- $data = array();
- search($data,$conf['datadir'],'search_backlinks',$opts);
- sort($data);
+ $data = ft_backlinks($ID);
print '<ul class="idx">';
- foreach($data as $row){
+ foreach($data as $blink){
print '<li>';
- print html_wikilink(':'.$row['id'],$conf['useheading']?NULL:$row['id']);
+ print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
print '</li>';
}
print '</ul>';
diff --git a/inc/search.php b/inc/search.php
index af7506f78..ffe85adc1 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -252,6 +252,7 @@ function search_allpages(&$data,$base,$file,$type,$lvl,$opts){
* $opts['name'] name of the page without namespace
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @deprecated Replaced by ft_backlinks()
*/
function search_backlinks(&$data,$base,$file,$type,$lvl,$opts){
//we do nothing with directories