[dokuwiki] Add event to inc/fulltext.php:ft_backlinks()

  • From: Robin Getz <robin.getz@xxxxxxxxxx>
  • To: "dokuwiki@xxxxxxxxxxxxx" <dokuwiki@xxxxxxxxxxxxx>
  • Date: Tue, 30 Nov 2010 16:40:51 -0500

In a few plugins, (redirect, and include), I want to ensure that the 
backlinks are "fixed" to point to actual pages which link (or include)
things.

To do that, the function must always trigger the event (and the early returns 
need to be removed), as well as to prevent recursion, also pass the page id 
to the event.

The alternative is to make sure that the plugins handle all the recursion 
issues, and try to do it without pushing the id into results...

Comments?


--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -137,7 +137,6 @@ function ft_backlinks($id){
     $matches = idx_lookup(idx_tokenizer($page,$stopwords));  // pagename may 
contain specials (_ or .)
     $docs    = array_keys(ft_resultCombine(array_values($matches)));
     $docs    = array_filter($docs,'isVisiblePage'); // discard hidden pages
-    if(!count($docs)) return $result;

     // check metadata for matching links
     foreach($docs as $match){
@@ -146,8 +145,6 @@ function ft_backlinks($id){
         if (isset($links[$id])) $result[] = $match;
     }

-    if(!count($result)) return $result;
-
     // check ACL permissions
     foreach(array_keys($result) as $idx){
         if(auth_quickaclcheck($result[$idx]) < AUTH_READ){
@@ -155,6 +152,10 @@ function ft_backlinks($id){
         }
     }

+    array_push(&$result, $id);
+    trigger_event('TPL_BACKLINK_RESULTS', &$result);
+    array_pop(&$result);
+
     sort($result);
     return $result;
 }
-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: