ROEPatterns

Summary: Replace On Edit
Version: 1.2
Prerequisites: none
Status: Working
Maintainer:
Categories: Markup

NOTE: This recipe (below the examples) is not needed if you are using pmwiki-2.2.0-beta45 or later versions. Instead use $ROEPatterns (very similar to $ROSPatterns). See $ROEPatterns for comments/examples of how to use that variable.

Questions answered by this recipe

  • Is there a replace on edit like there is a replace on save?

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

Description

ROEPatterns (Replace On Edit) works just like ROSPatterns except that it is executed before a page is edited.

Can this page be refactored as an example page for ROEPatterns, similar to ROSPatterns? HansB May 06, 2007, at 05:24 AM

The $ROEPatterns are enabled by placing them in the local/config.php file.

Example:
$ROEPatterns ["text to search for"] = "text to replace with";

The "text to search for" is searched and replaced using the PHP preg_replace function, thus the pattern has to use the preg_replace syntax.

Recipe Example:

A config/php or recipe could setup a new action, then setup $ROEPatterns and then go to the editor

<?php
    if ($action == 'convert') {
        global $ROEPatterns;
        $ROEPatterns ['/\\|\\|/'] = '(:cell:)';
        # ... MORE $ROEPatterns could go here
        $action='edit';
}

Installation

Copy ReplaceOnEdit.phpΔ to your cookbook directory.

In your config.php enter:

include_once("cookbook/ReplaceOnEdit.php");

or in your farmconfig.php enter:

include_once("$FarmD/cookbook/ReplaceOnEdit.php");

Notes

This recipe is intended for wiki administrators. It could be useful for a recipe that might want to modify text on a page just before displaying it in the editor.

Release Notes

  • Version: 1.1 - added RecipeInfo
  • Version: 10 12 2006 05:40 am CST - Initial release

Comments

Usage of $ROEPatterns for pmwiki-2.2.0-beta45 and after

As of pmwiki-2.2.0-beta45 the recipe above became incorporated into the core as a $ROEPatterns array. Here are some comments and examples on how to use $ROEPatterns:

  • Typically one significant reason for $ROEPatterns is for template pages. You create the template with certain patterns and then when a new page is created from that template the $ROEPatterns are automatically substituted and your page has the desired values.
  • The difficulty with template substitutions is that they have a tendency to get substituted while you are editing the template page itself -- thus the search-pattern (in the KEY of $ROEPatterns) is never found when the new page is created because it was already substituted in the template page. Here's how to get around that in your config.php:
if (!in_array($pagename, array('GroupA.Template', 'GroupB.Template'))) {
   $ROEPatterns['/searchpat/'] = 'ReplaceString';
   ...
}

That way the $ROEPatterns are not "active" for the template pages themselves (assuming you have listed all your template pages in the array) and so you can place the search patterns in the template and they will not be replaced until a new page is created from the template.

See Also

Contributors

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.