[pmwiki-users] UpdatePage processing markup again

Patrick R. Michaud pmichaud at pobox.com
Wed Apr 2 16:51:21 CDT 2008


On Wed, Apr 02, 2008 at 10:39:28PM +0200, Peter & Melodye Bowers wrote:
> I just discovered that one of the $EditFunctions within UpdatePage()
> (SaveAttributes() to be specific) calls MarkupToHTML() as part of the
> process of saving a page.
> 
> Obviously all markup expressions get processed along with all other markup
> within MarkupToHTML().
> 
> My problem is in my specific situation I could very easily end up with a
> race condition where PageA contains an MX that writes to PageB and PageB
> contains an MX that writes to PageA.

I think you mean a "recursive condition" as opposed to a "race
condition"?  PmWiki normally avoids race conditions by calling 
Lock(2) prior to any transaction that involves updating
a page or file.

> [...] I'm
> afraid SaveAttributes() gets into some stuff I haven't adequately explored
> and I simply can't figure out what it's doing.  To be honest it looks like a
> "write-only" setting of the $html variable, but maybe there's some PHP
> subtlety that I'm not catching here...  (If it is "write only" there could
> potentially be a noticeable performance gain by removing it...)

SaveAttributes is responsible for setting a variety of attributes
within pages.  In particular, it's the thing that creates the
targets, title, description, and keywords attributes in a page.
We compute these attributes at the time the page is saved so that
we don't have to try to figure them out whenever the page is
read later.

> Also, is there any good, standard way to know whether I am in the context of
> a page being posted or in a normal context?  Is there some global variable
> or something that is set when a page is being posted that is not set
> otherwise?  I tried $EnablePost but it seems to be set always...

$EnablePost says whether or not posts are allowed, not whether
one is occurring.

The way PmWiki checks for a post operation is by looking for a $_POST
control that begins with "post".  In code, this can be done
with:

    if (preg_grep('/^post/', array_keys(@$_POST))) {
      # some sort of 'post' operation is occurring
    }

However, a _much_ cleaner solution might be to enable WikiSh
_only_ when the page is being viewed -- i.e., $action=='browse'.
For all other actions (search, diff, edit, upload, etc.)
the WikiSh markups should probably not be processed.
It might even be as simple as adding the following lines to the
beginning of the wikish script:

    global $action;
    if ($action != 'browse') return;

Pm



More information about the pmwiki-users mailing list