I need to rename all pages matching a certain pattern in MediaWiki. For any page containing XXXXX, it must be renamed to YYYYY. This includes page content as well as page names. For example, the wiki URL http://wiki.example.org/TfrmXXX_Rates should be renamed to http://wiki.example.org/TfrmYYY_Rates, and any text containing XXXXX should be replaced with YYYYY.
The Replace Text extension cannot be used for this, because it can only modify page content. I also need to rename the pages, and all references to them (including interwiki links).
What I have tried is this: dump the MySQL database, replace all occurrences of XXXX to YYYY, then drop and recreate the wiki database with the modified SQL script, and finally run the maintenance/rebuildall.php script (provided by MediaWiki).
The problem is that it does not work. When I search for a keyword, MediaWiki shows some hits with related page content. But when I open the URL, it shows "no content yet". I suspect that the reason for this is that some of the data is stored in PHP serialized form, and that cannot be replaced easily with a text search/replace.
So the question is: how do I rename all references in a MediaWiki database, including content and page names?
I could finish the task. Here are the steps:
Backup your database
Execute this to export all page names:
select page_title into outfile '/tmp/pagenames.txt' from page;
I have used a program to replace all occurences that needs to be replaced, and construct another text file with the format
oldXXXname|newXXXname
miken's solution is equally good, if you need to replace just a single word. If you need to replace XXX_1
, XXX_2 XXX
, and other words that are prefixes of each other, then you need to write a program for this, and carefully select the order of replacements so they don't conflict with each other.
Then run
php maintenance/moveBatch.php --noredirects /tmp/constructed.txt
Then use this kind of SQL to replace all other text references:
use wiki_db;
begin;
update text set old_text =
replace(
replace(
replace(
convert(old_text using utf8), 'XXX_1', 'YYYY'
-- and so on…
), 'XXX_2', 'YYYY'
), 'XXX_3', 'YYYY'
), 'XXXX_2', 'YYYY_or_whatever'
);
Finally, run
php maintenance/rebuildall.php
I did not accept miken's answer only because it was just half of the solution.