Extension:ReplaceSet

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
ReplaceSet

Release status: beta

Implementation Parser function
Description Allows for multiple patterns of text, either plain or RegExp based to be replaced using a parser function.
Author(s) Daniel Friesen (DantmanTalk)
Last version 1.1
License GPL2+
Download
Hooks used
ParserFirstCallInit

Check usage (experimental)

ReplaceSet allows for patterns of text, either plain or RegExp based to be replaced. The idea is to allow many patterns to be replaced simply without overloading the Parser with dozens of ParserFunctions and allow for simple replace based syntaxes to be built such as linking certain words in a Card lore.

ReplaceSet is coded to make full use of pcre's performance. All the replacement patterns are passed together at once to pcre instead of looping over each one and doing replacements separate, this avoids shuffling between pcre and php.

Contents

[edit] Beta

The extension was complete but only missing one minor feature. It was planned to allow use of /=/ and \= in the way that = inside of regex will not end the pattern and a backslash escape \= in strings will allow a = to be used inside of the pattern. (Also need to make sure that \\ will work for that case)

[edit] Usage

{{#replaceset: text to replace | regex pattern or string to be replaced = replacement | ... }}

Regex patterns are wrapped in !pattern! #pattern# (pattern) [pattern] or {pattern}, and may be followed with any of the flags "imsxADU" (see php's documentation on pcre modifiers for what they individually do). Patterns that do not use any of those will be considered plaintext replacements such as "|A=B|" (replace all occurrences of "A" with "B").

[edit] Example

{{#replaceset:Text to replace|/(\w+)/i="\1"|to=2}}

Would produce "Text" "2" "replace".

[edit] Installation

  1. Download a snapshot and extract it to your extensions directory. Choose the version that matches your version of MediaWiki.
  2. Add
    require_once( "$IP/extensions/ReplaceSet/ReplaceSet.php" );
    to the bottom of LocalSettings.php.
  3. Installation can now be verified through Special:Version of your wiki.

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox