diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-08-01 12:04:35 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-08-01 12:04:35 +0200 |
commit | bfe414a6610a39d9d1b05f86f775976dc35ea130 (patch) | |
tree | 234769c02319f8e41fb870b011c7f5c6bfeaec9c | |
parent | d347c5be0ef6d9301c9b048c5cef576e71f43205 (diff) | |
download | dokuwiki-mediarefactor.tar.gz dokuwiki-mediarefactor.zip |
introduce a cached version of te ACL checkingmediarefactor
for iterating over media namespaces
-rw-r--r-- | inc/MediaFile.class.php | 2 | ||||
-rw-r--r-- | inc/auth.php | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/inc/MediaFile.class.php b/inc/MediaFile.class.php index 4b50497f6..91ff780ed 100644 --- a/inc/MediaFile.class.php +++ b/inc/MediaFile.class.php @@ -47,7 +47,7 @@ class MediaFile { $this->id = cleanID($this->id); $this->isexternal = false; $this->file = mediaFN($this->id); - $this->auth = auth_quickaclcheck(getNS($this->id).':*'); + $this->auth = auth_quickaclcheck_cached(getNS($this->id).':*'); } } diff --git a/inc/auth.php b/inc/auth.php index e224b2fb5..c67bffef1 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -653,6 +653,37 @@ function auth_isMember($memberlist, $user, array $groups) { } /** + * Caching wrapper around auth_quickaclcheck() + * + * This will check ACLs only once per request for the given ID. This is mostly useful when iterating over + * a larger list of media files in the same namespace. When in doubt, use the uncached variant! + * + * Cache is done in memory (static variable) + * + * @uthor Andreas Gohr <andi@splitbrain.org> + * @param string $id page ID (needs to be resolved and cleaned) + * @return int permision level + */ +function auth_quickaclcheck_cached($id) { + /* @var Input $INPUT */ + global $INPUT; + $user = $INPUT->server->str('REMOTE_USER'); + + // cache initialization + // the cache is user based even though the user should not change within a request this is + // an additional safe guard + static $aclcache = array(); + if(!isset($aclcache[$user])) $aclcache[$user] = array(); + + // fill cache + if(!isset($aclcache[$user][$id])) { + $aclcache[$user][$id] = auth_quickaclcheck($id); + } + + return $aclcache[$user][$id]; +} + +/** * Convinience function for auth_aclcheck() * * This checks the permissions for the current user |