Extension:ReplaceSet

Category:Unmaintained extensions#ReplaceSet Category:Extensions without an imageCategory:Extensions without a compatibility policyCategory:GPL licensed extensions
MediaWiki extensions manual
ReplaceSet
Release status: unmaintainedCategory:Unmaintained extensions
Implementation Parser function Category:Parser function extensions
Description Allows for multiple patterns of text, either plain or RegExp based to be replaced using a parser function.
Author(s) Daniel Friesen (Dantmantalk)
Latest version 1.6.0 (2018-03-09)
MediaWiki 1.25+Category:Extensions with manual MediaWiki version
PHP 5.4+
Database changes No
License GNU General Public License 2.0 or later
Download Category:Extensions in Wikimedia version control
Example sandbox.semantic-mediawiki.org
  • $egReplaceSetPregLimit
  • $egReplaceSetCallLimit
Quarterly downloads 2 (Ranked 94th)
Translate the ReplaceSet extension if it is available at translatewiki.net
Category:All extensions

The ReplaceSet extension 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.

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 documentation on PCRE Pattern 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").

If you need to use an = or an | within the pattern or text you want to replace you can wrap the pattern inside of a nowiki. ie: {{#replaceset:A=B|<nowiki>=</nowiki>=&}}

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

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

Installation

  • Download and move the extracted ReplaceSet folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceSet
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'ReplaceSet' );
    
  • Configure as required.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration

Two configurable limitations are set for the {{#replaceset}} parser function:

$egReplaceSetCallLimit
A limit to the number of times #replaceset may be used in a page. This is set to 25 by default.
$egReplaceSetPregLimit
A limit passed to preg limiting the number of replacements within the text to replace that will be made. This is set to 50 by default.

See also


Category:Extensions migrated from Wiki-Tools#ReplaceSet Category:Languages pages
Category:All extensions Category:Extensions in Wikimedia version control Category:Extensions migrated from Wiki-Tools Category:Extensions with manual MediaWiki version Category:Extensions without a compatibility policy Category:Extensions without an image Category:GPL licensed extensions Category:Languages pages Category:ParserFirstCallInit extensions Category:Parser function extensions Category:Unmaintained extensions