[Pmwiki-users] update on $MaxIncludes
J. Meijer
commentgg
Tue May 4 18:46:34 CDT 2004
Hi, I think I have a better working alternative for $MaxIncludes. The
changes are minimal, however they require patching the pmwiki.php file so I
am submitting them.
jm
Description
Instead of counting (page-)includes, an array $IncludedFiles is maintained.
Includes are only processed when the file has not yet been included, i.e.
the pagename is not yet in the $IncludedFiles array. The array is
initialized with $pagemenu (the page being generated).
Benefits
Besides proving an effective run-away protection similar to $MaxIncludes,
this system has a side-effect that is especially useful when composing menus
in the side-bar using the <!--wiki:$Group.Menu--> syntax in the .tmpl file:
a menu can be listed twice or more, but will be included only once.
F.e. this is a section from .tmpl that includes both a global (main) and a
group-menu:
<!--wiki:$Group.Menu-->
<!--wiki:Main.Menu-->
But when the group is Main the page looks ugly using the $MaxIncludes
version.
Implementation
The current MaxIncludes-code must be replaced in ProcessTextDirectives() and
PrintWikiPage(). The modifications are obvious. Below you see the patch of
pmwiki.php in use now, the changes marked by #NEW.
---------------------
$IncludedFiles = array($pagename); ###NEW
..
function PrintWikiPage($pagename,$wikilist=NULL) {
global $PrintWikiPageNotFoundFmt
,$IncludedFiles; ###NEW
if (is_null($wikilist)) $wikilist=$pagename;
$pagelist = preg_split('/\s+/',$wikilist,-1,PREG_SPLIT_NO_EMPTY);
foreach($pagelist as $p) {
if ( !in_array($p,$IncludedFiles) and PageExists($p) ) { ###NEW
array_push($IncludedFiles,$p); ###NEW
$page = RetrieveAuthPage($p,"read",false);
if ($page['text']) PrintText($pagename,$page['text']);
return;
}
}
if ($PrintWikiPageNotFoundFmt>'')
print FmtPageName(@$PrintWikiPageNotFoundFmt,array_pop($pagelist));
}
function ProcessTextDirectives($pagename,$text="") {
global $Text,$GroupNamePattern,$PageTitlePattern,$MaxIncludes,
$SpaceWikiWords,$GroupHeaderFmt,$GroupFooterFmt,$BrowseDirectives
,$IncludedFiles; ###NEW
if (!$text) $text=$Text;
$text = preg_replace("/\\[\\=(.*?)\\=\\]/se",
"Keep(htmlspecialchars(str_replace('\\\"','\"','$1'),ENT_NOQUOTES))",$text);
while ( preg_match("/\\[\\[include:(.*?)\\]\\]/",$text,$match)
and !in_array($match[1],$IncludedFiles) ) { ###NEW
$inclrepl=$match[0]; $inclname=$match[1]; $incltext='';
array_push($IncludedFiles,$inclname); ###NEW
if (!preg_match("/^$GroupNamePattern([\\/.])$PageTitlePattern\$/",
More information about the pmwiki-users
mailing list