[pmwiki-users] Hg pattern error
Patrick R. Michaud
pmichaud at pobox.com
Thu Apr 26 09:03:37 CDT 2007
On Thu, Apr 26, 2007 at 08:29:21AM -0500, Patrick R. Michaud wrote:
> On Thu, Apr 26, 2007 at 04:50:54AM -0400, The Editor wrote:
> > On 4/25/07, the Other michael <xraysmalevich at gmail.com> wrote:
> > > I've tried installing Hierarchical groups
> > > (http://www.pmwiki.org/wiki/Cookbook/Hg), but a pattern error(?)
> > > appears at the bottom of every page in the navigation:
> > >
> > > <div id='footnav' class='navbuttons'>pat=/\[\[([\-|\*|\^]+)(.*?)\]\]/e
After looking at things further, this turns out to be a somewhat
illustrative error. :-)
The markup line that is triggering the error is in Site.PageFootMenu
of the triad skin:
*%rel=nofollow%[[*{$Group}.GroupAttributes| $[Group Attributes] ]]
The markup rule given by hg.php (2007-03-07):
Markup('[[hg', '<var',
'/\\[\\[([\\-|\\*|\\^]+)(.*?)\\]\\]/e',
'hgLinks1("$1","$2")');
The rule matches any [[-link that has a hyphen, asterisks,
vertical brace, or caret immediately following the [[.
For the above markup line, we have an asterisk, so the
pattern matches with:
$1 => *
$2 => {$Group}.GroupAttributes| $[Group Attributes]
Since the pattern matches and has /e present, PHP substitutes
the values of $1 and $2 into the replacement string and
executes the result. For the above, this means we get
hgLinks1("*", "{$Group}.GroupAttributes| $[Group Attributes]")
PHP then throws an undefined variable warning here, because
the double-quotes say to do variable interpolation, and there's
no variable called $Group in the current scope. PmWiki traps
this error and issues the "pat=/.../" warning indicating
that the pattern resulted in an error.
Even though PHP throws the warning, it still executes the
function, but after replacing {$Group} with an empty string.
Thus the second parameter to hgLinks1() is
'.GroupAttributes| $[Group Attributes]' (note that the
initial '{$Group}' has been lost).
Lastly, the use of '<var' means that this markup rule
occurs at the very beginning--even before [=...=] and
[@...@] escapes are processed. This means that
the markup:
[=[[*{$Group}.GroupAttributes]]=]
will still end up being processed by the [[hg rule
(thus replacing the '*'), even though it's supposed
to be escaped.
Hope this helps to clarify a few things.
Pm
More information about the pmwiki-users
mailing list