Extension:Replace Text

Replace Text is an extension to MediaWiki that provides a special page to allow administrators to do a global string find-and-replace on both the text and titles of the wiki's content pages.

Description
An administrator submits a search string and its replacement, as well as choosing whether or not to also replace the text within page titles. They are then shown a list of all the pages that contain that search string, and possibly a list of pages whose titles contain the search string, with a checkbox for each, so that they can uncheck whichever pages they don't want replaced. The user then can hit "Replace" to do the actual replacement. Once a text replace is done, it is not directly undoable; though you can always run a "reverse" replace, replacing the new string with the original string. For that reason, if the replacement string is blank or is a string that already exists in the wiki, the user is first asked to confirm their action before being shown the list of possible pages, since this action may not be easily undoable.

If the search string is contained multiple times on a page, every such instance is replaced. Every page's replacements shows up as a (minor) wiki edit, with the administrator who performed the text replacement as the user who made the edit and an edit summary that looks like "Text replace: ' search string ' to ' replacement string '".

A page's title cannot be moved to a title that already exists in the wiki. Pages that cannot be moved will be simply listed on the "select" page as being unmoveable, without a checkbox near them.

The search is case-sensitive, and does not currently allow regular expressions. The text of talk pages and "MediaWiki:" pages are not modified (though their titles can be modified). Talk pages in namespaces other than the main one (like "Template talk") can have their text modified; this is a known bug.

Note: the replacement actions themselves are structured as MediaWiki "jobs", to ensure that the system is not overloaded if the user wants to do many at the same time. This means that a large set of replacements will not be done immediately, and may take minutes, hours or even longer to complete.

Code and download
You can download the Replace Text code in either one of these two compressed files:


 * replace_text_0.3.tar.gz
 * replace_text_0.3.zip

You can also download the code directly via SVN from the MediaWiki source code repository, at http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/ReplaceText/. From a command line, you can call the following:

To view the code online, including version history for each file, you can go here.

Installation
After you've obtained a 'ReplaceText' directory (either by extracting a compressed file or downloading via SVN), place this directory within the main MediaWiki 'extensions' directory. Then, anywhere in the file 'LocalSettings.php' in the main MediaWiki directory, add the following lines:

Author
Replace Text was written by Yaron Koren, reachable at yaron57 -at- gmail.com.

Version
Replace Text is currently at version 0.3.

The version history is:


 * 0.1 - April 29, 2008 - Initial version
 * 0.1.1 - May 7, 2008 - Language support added for Arabic, Dutch, French, Javanese, Malayalam, Norwegian Bokmål, Occitan, Portuguese, Serbian Cyrillic, Slovak, Swedish and Thai
 * 0.2 - May 12, 2008 - Replacement turned into two-step process, asking user to select among list of pages; actual replacement implemented as MediaWiki jobs; language support added for Traditional Chinese, Esperanto, Farsi, German, Khmer and Marathi
 * 0.2.1 - May 14, 2008 - Retrieval of matching pages done through SQL call, instead of manually; language support added for Bulgarian, Taiwanese Chinese and Luxembourgish
 * 0.2.2 - May 27, 2008 - Fixed handling of strings containing single quotation marks and target strings at the beginning of the page; set all replacements to be minor edits; pages are displayed in alphabetical order; language support added for Telugu
 * 0.2.3 - June 24, 2008 - Fixed handling of regular quotation marks; language support added for Czech, Galician, Polish and Vietnamese
 * 0.2.4 - August 6, 2008 - Updated initialization to use autoloading of classes and language values; bug fix so that replacement job does not override identity of logged-in user; title of page added as hidden field in forms; new 'replacetext' permission type added; "invert selections" link added to let user invert checkboxes in form; language support added for Brazilian Portuguese
 * 0.2.5 - September 2, 2008 - Fixed handling of strings containing backslashes; "invert selections" link only shown if there are more than five items
 * 0.2.6 - September 5, 2008 - Language aliases added
 * 0.2.7 - September 18, 2008 - Access control improved; language support added for Egyptian Arabic
 * 0.2.8 - October 1, 2008 - Handling of apostrophes re-fixed; language support added for Interlingua and Ripuarian
 * 0.3 - November 5, 2008 - Added handling for moving pages; language support added for Croatian and Russian

Screenshots
Below are images of the workflow of Replace Text. First, the initial page in which "George F. Will" and "George Will" are entered for the target string and replacement string, respectively, and replacing text in page titles is specified as well, on Discourse DB:



And here is what the page looks like after the user hits "Continue":



Hitting "Replace" would replace this value in all of the listed pages, as well as moving the page at the end to its new value.

Code structure
The following are the files in the Replace Text extension:


 * README - description of the extension
 * ReplaceText.php - main file
 * ReplaceTextJob.php - class for the MediaWiki job that does the text replacement
 * ReplaceText.i18n.php - language file
 * SpecialReplaceText.php - the "Special" page that provides the interface for the replacement

Languages supported
Replace Text supports Arabic, Egyptian Arabic, Bulgarian, Taiwanese Chinese, Traditional Chinese, Croatian, Czech, Dutch, English, Esperanto, French, Galician, German, Interlingua, Javanese, Khmer, Luxembourgish, Malayalam, Marathi, Norwegian Bokmål, Occitan, Persian, Polish, Portuguese, Brazilian Portuguese, Ripuarian, Russian, Serbian Cyrillic, Slovak, Swedish, Telugu, Thai and Vietnamese.

Bugs and feature requests
Send any bug reports and requests to Yaron Koren, at yaron57 -at- gmail.com.

Contributing patches to the project
If you found some bug and fixed it, please create a patch by going to the "ReplaceText" directory, and typing:

svn diff >descriptivename.patch

Then send this patch, with a description, to Yaron Koren.

Translating
Translation of Replace Text is done through Betawiki. The translation for this extension can be found here. To add language values or change existing ones, you should create an account on Betawiki, then request permission from the administrators to translate a certain language or languages on this page (this is a very simple process). Once you have permission for a given language, you can log in and add or edit whatever messages you want to in that language.