diff options
author | petko <petko@524c5546-5005-0410-9a3e-e25e191bd360> | 2024-04-13 18:46:04 +0000 |
---|---|---|
committer | petko <petko@524c5546-5005-0410-9a3e-e25e191bd360> | 2024-04-13 18:46:04 +0000 |
commit | dfb5a6db75df8d364031ee827fe18a6bd1067df6 (patch) | |
tree | 0df44e710ac7f550f2d424fcd1d63c0037fc1b22 /pmwiki.php | |
parent | 98009449ee34a0821b8da6ecf0f5f98095af77df (diff) | |
download | pmwiki.svn-dfb5a6db75df8d364031ee827fe18a6bd1067df6.tar.bz2 |
Cache auth conditional results for (:if auth level:).
git-svn-id: svn://pmwiki.org/pmwiki/trunk@4687 524c5546-5005-0410-9a3e-e25e191bd360
Diffstat (limited to 'pmwiki.php')
-rw-r--r-- | pmwiki.php | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -252,9 +252,10 @@ $Conditions['equal'] = 'CompareArgs($condparm) == 0'; function CompareArgs($arg) { $arg = ParseArgs($arg); return strcmp(@$arg[''][0], @$arg[''][1]); } -$Conditions['auth'] = 'NoCache(CondAuth($pagename, $condparm))'; -function CondAuth($pagename, $condparm) { +$Conditions['auth'] = 'NoCache(CondAuth($pagename, $condparm, 1))'; +function CondAuth($pagename, $condparm, $use_cache = 0) { global $AuthList, $HandleAuth; + static $ccache = []; @list($level, $pn) = explode(' ', $condparm, 2); if (@$level && $level[0] == '@') { # user belongs to @group1,@group2 $keys = MatchNames(array_keys((array)@$AuthList), $level, true); @@ -265,7 +266,14 @@ function CondAuth($pagename, $condparm) { } $pn = ($pn > '') ? MakePageName($pagename, $pn) : $pagename; if (@$HandleAuth[$level]>'') $level = $HandleAuth[$level]; - return (boolean)RetrieveAuthPage($pn, $level, false, READPAGE_CURRENT); + + if ($use_cache) { + if (!isset($ccache[$pn][$level])) { + $ccache[$pn][$level] = (boolean)RAPC($pn, $level); + } + return $ccache[$pn][$level]; + } + return (boolean)RAPC($pn, $level); } $Conditions['exists'] = 'CondExists($condparm)'; ## This is an optimized version of the earlier conditional @@ -1744,6 +1752,10 @@ function ListPages($pat=NULL) { return $out; } +function RAPC($pagename, $level, $authprompt=false, $since=READPAGE_CURRENT) { + # helper function, widely used + return RetrieveAuthPage($pagename, $level, $authprompt, $since); +} function RetrieveAuthPage($pagename, $level, $authprompt=true, $since=0) { global $AuthFunction; SDV($AuthFunction,'PmWikiAuth'); |