summaryrefslogtreecommitdiff
path: root/inc/fulltext.php
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2013-08-03 00:40:34 +0200
committerChristopher Smith <chris@jalakai.co.uk>2013-08-03 00:40:34 +0200
commitb8b64ed77285e4d753d35d4ceab0516be597a2f1 (patch)
tree7cc1a82a5887a9efeb3f9160f98613e65e404ba0 /inc/fulltext.php
parentaf07997c5ff7cc096965159d90158e3710d2d019 (diff)
parent586da9c1028b1013e8dc47911ba430671a389b5b (diff)
downloadrpg-b8b64ed77285e4d753d35d4ceab0516be597a2f1.tar.gz
rpg-b8b64ed77285e4d753d35d4ceab0516be597a2f1.tar.bz2
Merge branch 'master' into configmgr_improvements
Diffstat (limited to 'inc/fulltext.php')
-rw-r--r--inc/fulltext.php60
1 files changed, 25 insertions, 35 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 2f073acea..c03126994 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -125,17 +125,21 @@ function _ft_pageSearch(&$data) {
* Returns the backlinks for a given page
*
* Uses the metadata index.
+ *
+ * @param string $id The id for which links shall be returned
+ * @param bool $ignore_perms Ignore the fact that pages are hidden or read-protected
+ * @return array The pages that contain links to the given page
*/
-function ft_backlinks($id){
- $result = array();
-
+function ft_backlinks($id, $ignore_perms = false){
$result = idx_get_indexer()->lookupKey('relation_references', $id);
if(!count($result)) return $result;
// check ACL permissions
foreach(array_keys($result) as $idx){
- if(isHiddenPage($result[$idx]) || auth_quickaclcheck($result[$idx]) < AUTH_READ || !page_exists($result[$idx], '', false)){
+ if(($ignore_perms !== true && (
+ isHiddenPage($result[$idx]) || auth_quickaclcheck($result[$idx]) < AUTH_READ
+ )) || !page_exists($result[$idx], '', false)){
unset($result[$idx]);
}
}
@@ -147,42 +151,28 @@ function ft_backlinks($id){
/**
* Returns the pages that use a given media file
*
- * Does a quick lookup with the fulltext index, then
- * evaluates the instructions of the found pages
+ * Uses the relation media metadata property and the metadata index.
*
- * Aborts after $max found results
+ * Note that before 2013-07-31 the second parameter was the maximum number of results and
+ * permissions were ignored. That's why the parameter is now checked to be explicitely set
+ * to true (with type bool) in order to be compatible with older uses of the function.
+ *
+ * @param string $id The media id to look for
+ * @param bool $ignore_perms Ignore hidden pages and acls (optional, default: false)
+ * @return array A list of pages that use the given media file
*/
-function ft_mediause($id,$max){
- if(!$max) $max = 1; // need to find at least one
+function ft_mediause($id, $ignore_perms = false){
+ $result = idx_get_indexer()->lookupKey('relation_media', $id);
- $result = array();
+ if(!count($result)) return $result;
- // quick lookup of the mediafile
- // FIXME use metadata key lookup
- $media = noNS($id);
- $matches = idx_lookup(idx_tokenizer($media));
- $docs = array_keys(ft_resultCombine(array_values($matches)));
- if(!count($docs)) return $result;
-
- // go through all found pages
- $found = 0;
- $pcre = preg_quote($media,'/');
- foreach($docs as $doc){
- $ns = getNS($doc);
- preg_match_all('/\{\{([^|}]*'.$pcre.'[^|}]*)(|[^}]+)?\}\}/i',rawWiki($doc),$matches);
- foreach($matches[1] as $img){
- $img = trim($img);
- if(media_isexternal($img)) continue; // skip external images
- list($img) = explode('?',$img); // remove any parameters
- resolve_mediaid($ns,$img,$exists); // resolve the possibly relative img
-
- if($img == $id){ // we have a match
- $result[] = $doc;
- $found++;
- break;
- }
+ // check ACL permissions
+ foreach(array_keys($result) as $idx){
+ if(($ignore_perms !== true && (
+ isHiddenPage($result[$idx]) || auth_quickaclcheck($result[$idx]) < AUTH_READ
+ )) || !page_exists($result[$idx], '', false)){
+ unset($result[$idx]);
}
- if($found >= $max) break;
}
sort($result);