[pmwiki-users] PVs in PTVs not resolved by PageTextVar()

Peter Bowers pbowers at pobox.com
Wed Jul 28 07:48:26 CDT 2010

On Wed, Jul 28, 2010 at 11:23 AM, Maxim <maxim at smspower.org> wrote:
> I have a page (e.g. named Scans.Foo) that contains a PTV with a page
> variable inside it:

PageVar() calls PageTextVar() at the very end.  This works great for a
PTV inside a PV, but not for a PV inside a PTV.

> I can't pass the string through FmtPageName because that doesn't
> handle this sort of string.

Why not?  I don't think it would solve your problem (PV inside PTV)
but I can't imagine why it wouldn't be equivalent to the PageVar() or
the PageTextVar().

> Right now my workaround is:
> $filename = strip_tags(MarkupToHTML($pagename, PageTextVar($pagename,
> 'Filename')));
> This seems hacky, is there a better way?

Yes, that's a LOT of processing covering the whole gamut of rules when
really all you want to do is call a single rule a few times...

If you are pretty certain that a single level of "PV inside a PTV" is
the extent of what you need to worry about then this should work:

$foo = FmtPagename($pagename, PageTextVar($pagename, 'Filename'), $pagename);

If you are concerned that there might be multiple levels of "PV inside
PTV" (hopefully not -- this would be pretty confusing from the
perspective of reading page source) then you could do some kind of a

$foo = $foo2 = PageTextVar($pagename, 'Filename');
while ($foo2 != ($foo = FmtPagename($foo, $pagename)))
   $foo2 = $foo;


Note that using FmtPagename() on user-supplied data opens potential
security holdes (http://www.pmwiki.org/wiki/PITS/01206), but chances
are the globals exposed aren't too vital unless you're in a very
security-conscious environment.  (And it looks like from the status on
that PITS entry that there may be a workaround for this problem soon.)
 But that's your call based on how you are going to use the data and
where it comes from and etc.  Forewarned and all that...  (If you're
concerned about it then you could always preg_match() out the
variables explicitly and just use PageVar() and PageTextVar() but that
gets more complicated...)


More information about the pmwiki-users mailing list