TimoH

Here is my patch for the way include works:

currently there exists the variable $MaxIncludes in pmwiki.php (default = 10) which limits the number of include directives that get expanded when a page is viewed.

I think it would be better to limit the recursion depth and setting the MaxIncludes to very large number. So i quickly tried it out and it works for me.

Here it is, if you would like to include it (i edited version 1.0.0 but should be trival to adapt to the newest version).

First i set $maxincludes to 100.

And i replaced in pmwiki.php this lines:

 
function ProcessIncludes($pagename,$text="") {
  global $MaxIncludes,$IncludeBadAnchorFmt,$GroupNamePattern,$PageTitlePattern;
  $inclcount=0;
  while ($inclcount<$MaxIncludes &&
      preg_match("/\\[\\[include:(($GroupNamePattern([\\/.]))?$PageTitlePattern)(#(\\w[-.:\\w]*)?(#(\\w[-.:\\w]*)?)?)?\\]\\]/",$text,$match)) {
    list($inclrepl,$inclname,$group,$dot,$a,$aa,$b,$bb) = $match;
    if (!$group) $inclname=FmtPageName('$Group.',$pagename).$inclname;
    $inclpage = RetrieveAuthPage($inclname,"read",false);
    $incltext = $inclpage['text'];
    $badanchor = '';
    if ($bb && !ctype_digit($bb) && strpos($incltext,"[[#$bb]]")===false)
      $badanchor=$bb;
    if ($aa && !ctype_digit($aa) && strpos($incltext,"[[#$aa]]")===false)
      $badanchor=$aa;
    if ($badanchor)
      $incltext=FmtPageName(str_replace('$BadAnchor',$badanchor,
        $IncludeBadAnchorFmt),$inclname);
    if (ctype_digit($bb))
      $incltext=preg_replace("/^(([^\\n]*\\n)\{0,$bb}).*$/s",'$1',$incltext,1);
    elseif ($bb)
      $incltext=preg_replace("/[^\\n]*\\[\\[#$bb\\]\\].*$/s",'',$incltext,1);
    if (ctype_digit($aa)) {
      $aa--; $incltext=preg_replace("/^([^\\n]*\\n)\{0,$aa}/s",'',$incltext,1);
      if (!$b) $incltext=preg_replace("/\\n.*$/s",'',$incltext);
    } elseif ($aa && $b)
      $incltext=preg_replace("/^.*?([^\\n]*\\[\\[#$aa\\]\\])/s",'$1',$incltext,1);
    elseif ($aa)
      $incltext=preg_replace("/^.*?([^\\n]*\\[\\[#$aa\\]\\]( *\\n)?[^\\n]*).*/s",'$1',$incltext,1);
    $text = str_replace($inclrepl,$incltext,$text);
    $inclcount++;
  }
  return $text;
} 

with this:

 
function RecursiveInclude($text,$depth)
{
	global $MaxIncludes;
    list($inclrepl,$inclname,$group,$dot,$a,$aa,$b,$bb) = $text;
    if (!$group) $inclname=FmtPageName('$Group.',$pagename).$inclname;
    $inclpage = RetrieveAuthPage($inclname,"read",false);
    $incltext = $inclpage['text'];
    $badanchor = '';
    if ($bb && !ctype_digit($bb) && strpos($incltext,"[[#$bb]]")===false)
      $badanchor=$bb;
    if ($aa && !ctype_digit($aa) && strpos($incltext,"[[#$aa]]")===false)
      $badanchor=$aa;
    if ($badanchor)
      $incltext=FmtPageName(str_replace('$BadAnchor',$badanchor,
        $IncludeBadAnchorFmt),$inclname);
    if (ctype_digit($bb))
      $incltext=preg_replace("/^(([^\\n]*\\n)\{0,$bb}).*$/s",'$1',$incltext,1);
    elseif ($bb)
      $incltext=preg_replace("/[^\\n]*\\[\\[#$bb\\]\\].*$/s",'',$incltext,1);
    if (ctype_digit($aa)) {
      $aa--; $incltext=preg_replace("/^([^\\n]*\\n)\{0,$aa}/s",'',$incltext,1);
      if (!$b) $incltext=preg_replace("/\\n.*$/s",'',$incltext);
    } elseif ($aa && $b)
      $incltext=preg_replace("/^.*?([^\\n]*\\[\\[#$aa\\]\\])/s",'$1',$incltext,1);
    elseif ($aa)
      $incltext=preg_replace("/^.*?([^\\n]*\\[\\[#$aa\\]\\]( *\\n)?[^\\n]*).*/s",'$1',$incltext,1);

	if ($depth==0) return $incltext;

  while ($inclcount<$MaxIncludes &&
      preg_match("/\\[\\[include:(($GroupNamePattern([\\/.]))?$PageTitlePattern)(#(\\w[-.:\\w]*)?(#(\\w[-.:\\w]*)?)?)?\\]\\]/",$incltext,$match)) {

      list($inclrepl,$inclname,$group,$dot,$a,$aa,$b,$bb) = $match;

      $incltext = str_replace($inclrepl,RecursiveInclude($match,$depth-1),$incltext);
	  $inclcount++;  
      }

  return $incltext;
}

function ProcessIncludes($pagename,$text="") {
  global $MaxIncludes,$IncludeBadAnchorFmt,$GroupNamePattern,$PageTitlePattern;
  $inclcount=0;$maxdepth=2;

  while ($inclcount<$MaxIncludes &&
      preg_match("/\\[\\[include:(($GroupNamePattern([\\/.]))?$PageTitlePattern)(#(\\w[-.:\\w]*)?(#(\\w[-.:\\w]*)?)?)?\\]\\]/",$text,$match)) {

      list($inclrepl,$inclname,$group,$dot,$a,$aa,$b,$bb) = $match;

      $text = str_replace($inclrepl,RecursiveInclude($match,$maxdepth),$text);
	  $inclcount++;  
  }      
  return $text;
}