[Pmwiki-users] Title markup and ProcessTextDirectives()

J. Perkins jason
Fri Apr 2 10:52:49 CST 2004


I'm going in way over my head here. If I look to be in danger someone
please throw me a line.

I was investigating a method to add a [[pagetitle ...]] markup. That led
me to the browse directives and ProcessTextDirectives(). At the bottom of
this function, it iterates over $BrowseDirectives[] like this:

foreach($BrowseDirectives as $p=>$s) {
  if ($p[0]=='/') $text=preg_replace($p,$s,$text);
  else if (strstr($text,$p)) $text=str_replace($p,eval($s),$text);
}

My understanding of browse directives was that they exist to alter the
"rendering state" of the page. All of the directives in pmwiki.php, and
all that I could find in the addons, work this way. But the code itself
treats them as another search-and-replace operation, except for that call
to eval(), which is what really seems to make everything work. That is,
browse directives never actually replace text, they always change some
state and them remove the directive from the page text.

Assuming that I am not way off the mark in my last paragraph, and if I am
correct that no one is using the browse directives for search-and-replace
(two big ifs): can this function be modified to:

 * match the $p value in the text
 * use the matched text as input to a preg_replace() on $s
 * eval($s)

This would allow markup like the [[pagetitle ...]] I mentioned earlier. I
think. Maybe it would look like this (not tested, may/will have errors):

$BrowseDirectives["/\\[\\[pagetitle (.*?)\\]\\]"] = '$GLOBALS["Title"]=$1';

Jason






More information about the pmwiki-users mailing list