[pmwiki-users] Page text variables and PmForm

Petko Yotov 5ko at 5ko.fr
Sat Feb 8 01:42:58 CST 2014

Randy Brown writes:
> Is there any way to prevent a user from entering a page text variable when  
> inputting text via PmForm? (It would also be nice to know how to prevent  
> some specific {(markup expressions)} from being entered via PmForm, although  
> I don't need to do that yet.)

Yes, a search-replace pattern can be entered in $PmFormPostPatterns, it  
works like $ROSPatterns but on the posted form content.

It already replaces "(:" and ":)" with "( :" and ": )" to prevent one type  
of PTV to be entered or split, or to insert another {$:PTV} inside.

I'll give one example for your case below.

> I need to block PTVs from being entered via PmForm because as far as I can  
> tell, PmForm is using the first PTV it finds on the page, while PmWiki is  
> using the last.  For example:
> PTV1: PmForm uses this first line for PTV1
> PTV1: PmWiki uses this last line for PTV1

It is more complex: there are different ways to define PageTextVariables.  
PmWiki scans the page for each of the ways in the order they are defined,  
first Var:Value, then (:Var:Value:), then any custom ways, and uses the last  
one it finds in this process, but not necessarily the last one written in  
the page.

PmForm scans the page in the same order of the "ways" but stops after it  
finds the first matching variable.

> I'm hoping there's a way to fix this without modifying the PmForm recipe,  
> but I imagine I have to customize the script. I've looked at the script, but  
> it's not clear to me what it's doing.

It is possible to change the pmform.php script to scan the page backwards,  
in the reverse order in which pmwiki.php defines the variables, but I wanted  
to ask on the mailing list if there would be no side-effects. An update may  
potentially break existing installations, although I suspect your case is  
very rare.

> Which lines would I change? Also, what regular expression would accomplish  
> my goal of replacing "PTV1:" at the beginning of a line with "PTV :" (that  
> is, add a space between the word and the colon)?

This will not help you as a PTV can have an optional space before the colon.

Something like this may work:

  $PmFormPostPatterns['/^:*\\s*(\\w[-\\w]*)\\s*:/m'] = '[==]$0';

This will scan the posted content for anything that looks like a PTV (start  
of line, optional colon, optional spaces, something looking like a variable  
name, optional spaces, colon) and insert the escaping [==] null markup  
before it. This should prevent PmWiki to use it when defining a PTV.

Note, this will not prevent someone editing the page via the ?action=edit  
interface to insert more than one definitions for the same PTV. In that case  
PmWiki will use the last one, PmForm will update the first one. That's why  
we should probably modify pmform.php to also update the last one?


More information about the pmwiki-users mailing list