Skip to content
Snippets Groups Projects
Commit 54f4c056 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

backlinks now use the new index based search

darcs-hash:20050912141042-7ad00-5ef43525c9fd7ba44206720c54bb566450f93250.gz
parent 6793fe33
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,48 @@ function ft_pageSearch($query,&$poswords){
return $docs;
}
/**
* 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
*
......
......@@ -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>';
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment