diff options
author | Michael Hamann <michael@content-space.de> | 2013-07-31 17:30:08 +0200 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2013-07-31 18:05:43 +0200 |
commit | ffec100965184c6bf045f0096101768def108b43 (patch) | |
tree | 64d75b55d9d52c14647c0959e0a9d20485faad04 /inc/fulltext.php | |
parent | 07ff0babae240ba072a3bc8b83a989c4305c24cd (diff) | |
download | rpg-ffec100965184c6bf045f0096101768def108b43.tar.gz rpg-ffec100965184c6bf045f0096101768def108b43.tar.bz2 |
Index media file usage in the metadata index and use it in ft_mediause()
Diffstat (limited to 'inc/fulltext.php')
-rw-r--r-- | inc/fulltext.php | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php index 1afff25dd..c03126994 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -151,42 +151,28 @@ function ft_backlinks($id, $ignore_perms = false){ /** * 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); |