[pmwiki-devel] Anomaly in ROE pattern?

Henrik Bechmann henrik.bechmann at sympatico.ca
Sun May 4 16:36:47 CDT 2008


Patrick,

It appears that ROEPatterns (unexpectedly) changes text on save, not 
just on load, when in scope of the ROE pattern. Is this as designed?

Here is an alternate snippet suggested by Peter Bowers. Does it make sense?

(Below that is my test, based on Peter's new EditMX, that uncovered the 
behaviour).

Thanks,

- Henrik

Peter's code alternative:
> Current code that causes ROE on save:
> ===(snip)===
> function ReplaceOnSave($pagename,&$page,&$new) {
>   global $EnablePost, $ROSPatterns, $ROEPatterns;
>   foreach ((array)@$ROEPatterns as $pat => $rep)
>     $new['text'] = preg_replace($pat, $rep, $new['text']);
>   if (!$EnablePost) return;
>   foreach((array)@$ROSPatterns as $pat=>$rep) 
>     $new['text'] = preg_replace($pat, $rep, $new['text']);
> }
> ===(snip)=== 
>
> Alternate code that prevents ROE on save:
> ===(snip)===
> function ReplaceOnSave($pagename,&$page,&$new) {
>   global $EnablePost, $ROSPatterns, $ROEPatterns;
>   if (!$EnablePost) {
>     foreach ((array)@$ROEPatterns as $pat => $rep)
>       $new['text'] = preg_replace($pat, $rep, $new['text']);
>     return;
>   }
>   foreach((array)@$ROSPatterns as $pat=>$rep) 
>     $new['text'] = preg_replace($pat, $rep, $new['text']);
> }
> ===(snip)=== 
>
> I verified that this would, indeed, keep my ROE from being replaced on save
> as well.  Of course there is still the difficulty if you ever need to edit
> the template -- as soon as you edit it the replacement will occur and you
> will have to re-create your {ROE(...)} ... You could use a conditional in your
> config.php so that the EditMX.php was included only when you were *not*
> editing your template page.  
>
> Something like this:
>
> if (!in_array($page, array('MyGroup.Template', 'GroupB.TemplatePage')) {
>    include_once('cookbook/EditMX.php');
> }
>
>   
>> -----Original Message-----
>> From: Henrik Bechmann [mailto:henrik.bechmann at sympatico.ca] 
>> Sent: Sunday, May 04, 2008 9:33 PM
>> To: Peter & Melodye Bowers
>> Cc: SentN; Peter Gmail Bowers
>> Subject: Re: [pmwiki-users] New Recipe: EditMX
>>
>> Peter,
>>
>> Works well, with a caveat. See below.
>>
>> Set a template file in a group, such as Sandbox.php (placed 
>> in local/), 
>> and invoke the EditMX recipe:
>>
>> ===================start
>>
>> <?php
>> $EditTemplatesFmt = 'TestGroup.Template';
>> include_once('cookbook/EditMX.php');
>>
>> ===================end
>>
>> Create the a template file TestGroup.Template with the 
>> following wiki text
>>
>> ===================start
>>
>> Testgroup template
>>
>> The date is tomorrow: {ROE(ftime fmt="%Y-%m-%d" tomorrow)}
>>
>> ===================end
>>
>> Create a new page Sandbox.TestPage, and the wiki template appears as 
>> follows:
>>
>> ====================start
>>
>> Testgroup template
>>
>> The date is tomorrow: 2008-05-05
>>
>> ====================end
>>
>> Oddly, when I save a page containing an {ROE(... expression 
>> in scope of 
>> the EditMX recipe, the ROE conversion takes place on save (as 
>> verified 
>> by loading the saved page file in a text editor), as opposed 
>> to waiting 
>> for a user edit request. Put another way, ROE appears to 
>> behave as ROS 
>> in scope of the ROE pattern. This may be an anomaly of the 
>> ROEPatterns 
>> function.
>>
>> So IOW {ROE(function args)} works for the template as long as the 
>> template file is outside the scope of the {ROE(..)} MX recipe.
>>
>> Perhaps after you publish this (if you do), then I will raise this 
>> concern on pmwiki-devel.
>>
>>     
-- 

Henrik Bechmann
bechmann.ca
Webmaster, celos.ca webhosting services




More information about the pmwiki-devel mailing list