Action: Admin Replace

The {{admin_replace}} action allows administrators to do a global string find-and-replace on all the content pages of a wiki.

This is well suited to performing simple edits such as renaming a link, changing strings, adding templates, or correcting typos.

1. Usage

  1. search & replace form
  2. target matches selection form
  3. replace target text with replacement text

search & replace form

To replace one text string with another across all regular pages on this wiki, enter the two pieces of text here and then hit "Continue".

target matches selection form

You will then be shown a list of pages that contain the search text, and you can choose the ones in which you want to replace it.

After replacing the first batch of results, it reloads the selection form with the next batch of results.
It remembers all processed and not selected record ids via 'replace_unset' session array and excludes them in the next search query.

replace target text with replacement text

Your name will appear in page histories as the user responsible for any changes.

2. Configuration


Default is 50 matches, set max=100 in action for more.

  • average processing time may vary (on a local XAMPP stack 1 second per replaced match), it runs per match up to 12 queries (Change the max=NUMBER if it exceeds the max execution time.)
  • max is limited by get_list_count() -> range: 10 ... 100
  • options showing additional filters like language and categories
  • mute is on by default, else it will send notifications for every watched page it changes (you likely want avoid that)

3. Using regular expressions

If you click on the "Use regular expressions" checkbox, you can use regular expressions[1], within the search and replacement strings.

The set of regular expressions allowed is basically a small subset of the PHP and MariaDb/MySQL regular-expression[2] set.

The special characters that one can use in the search string are "( ) . * + ? [ ] |", and within the replacement string one can use values like $1, $2 etc. (To use these as regular characters, you just need to escape them by adding a "\" beforehand - which you would also need to do with the "/" character.)

Search string: a(.*)c
Replacement string: ac$1

This would look for pages containing the letter 'a', the letter 'c', and any text in between (signified by the ".*"). It would then put that middle text after the 'a' and 'c' - the "$1" in the replacement string refers to the first element of the search string contained within parentheses (in this case, there's only one).

For every page for which the replace is actually called, the replacement would happen for every occurrence of the search string, not just one - just as happens with regular, non-regular- expression search.

3.1. More complex regexps

Search string: hello([0-9]*)\.([0-9]*)
Replacement string: $1,$2

This would replace "hello222.555" with "222,555" and "hello2.55" with "2,55"

First the word "hello" is matched. In brackets follows an expression to search for any digits "0-9". The following asterisk finds multiple matches of the preceding element. The brackets and the asterisk get enclosed with parentheses, so we match the complete term and transfer it to $1. The "\." indicates that it's a true dot, and not a special character. The second expression within parentheses is matched and put into $2.

3.2. Replacements followed by numbers

Search string: 123(.*)456
Replacement string: {$1}123456

Enclose numbered values in curly brackets.

3.3. Case-insensitive search

To make your search case-insensitive, use regular expression and the case- insensitive modifier, (?i) [3]:

Search string: (?i)wackowiki
Replacement string: WackoWiki

The above will unify the casing of all mentions of Wackowiki/wackowiki/WACKOWIKI to WackoWiki.

3.4. Tips

3.4.1. Adding content to the top of the page

Detect any first character at the beginning of a page:

Search string: ^(.)

Prepend my content to the char found a the beginning of a page including a line break:

Replacement string:

3.4.2. Adding content at the end of the page

Detect any last character at the end of a page:

Search string: (.)$

Prepend my content to the char found a the ending of a page including a line break:

Replacement string:

4. ToDo

  • translate this page to all 6 main languages
  • test and improve it

5. See also

Show Files (4 files)