WackoWiki: Action: Admin Replace

https://wackowiki.org/doc     Version: 46 (11/13/2026 22:07)

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.

This action is reserved for administrators. For non-administrators it produces no output at all.

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".

The form also offers the following options:

Notes on the scope of the search:

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. When regular expressions are used, the pages just processed are added to this list as well, so that they cannot match a second time. The "Cancel" button resets the form and the session data.

replace target text with replacement text

Your name will appear in page histories as the user responsible for any changes, together with the automatically generated edit note (search string and replacement string).

2. Configuration

{{admin_replace
	[page="PageName"]
	[options=1]
	[lang="en"]
	[mute=1]
	[max=NUMBER]
}}		


These are the parameters of the action; all of them are optional:



To display the built-in help of this action use {{admin_replace help=1}}.

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.

Please note: the search is performed by the database, the replacement by PHP.

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.

Further details worth knowing:

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 at the beginning of a page including a line break:
Replacement string:
MyContent
$1		

Paste only the text between the markers into the replacement field of the form (the %% are just wiki code markers). The form converts Windows line breaks (\r\n) into Unix line breaks (\n).

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 at the ending of a page including a line break:
Replacement string:
\$1
MyContent		

Caveat: in both the database and in PHP, the "\$" may match the position before a final newline; if a page ends with a line break, the last matched character can therefore be that line break. Check the result on a test page first.

4. ToDo


5. See also



Footnotes:

[1]
https://en.wikipedia.org/wiki/Regular_expression
[2]
MySQL: https://dev.mysql.com/doc/refm[...]html#operator_regexp[link3]
MariaDB: https://mariadb.com/docs/serve[...]expressions-overview[link4]
[3]
http://www.regular-expressions.info/modifiers.html