aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpetko <petko@524c5546-5005-0410-9a3e-e25e191bd360>2024-04-13 18:46:04 +0000
committerpetko <petko@524c5546-5005-0410-9a3e-e25e191bd360>2024-04-13 18:46:04 +0000
commitdfb5a6db75df8d364031ee827fe18a6bd1067df6 (patch)
tree0df44e710ac7f550f2d424fcd1d63c0037fc1b22
parent98009449ee34a0821b8da6ecf0f5f98095af77df (diff)
downloadpmwiki.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
-rw-r--r--pmwiki.php18
-rw-r--r--scripts/stdmarkup.php4
2 files changed, 17 insertions, 5 deletions
diff --git a/pmwiki.php b/pmwiki.php
index a72db3fa..08a9c3cf 100644
--- a/pmwiki.php
+++ b/pmwiki.php
@@ -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');
diff --git a/scripts/stdmarkup.php b/scripts/stdmarkup.php
index 8161b78b..87cf6540 100644
--- a/scripts/stdmarkup.php
+++ b/scripts/stdmarkup.php
@@ -1,5 +1,5 @@
<?php if (!defined('PmWiki')) exit();
-/* Copyright 2004-2022 Patrick R. Michaud (pmichaud@pobox.com)
+/* Copyright 2004-2024 Patrick R. Michaud (pmichaud@pobox.com)
This file is part of PmWiki; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License, or
@@ -91,7 +91,7 @@ SDV($CondTextPattern,
| (?=\\(:(?:if\\1|if\\1end)\\b[^\n]*?:\\) | $)
)
/six");
-// SDV($CondTextReplacement, "CondText2(\$pagename, \$m[0], \$m[1])");
+
SDV($CondTextReplacement, "MarkupCondText2");
Markup('if', 'fulltext', $CondTextPattern, $CondTextReplacement);