dqqyp90576 2016-04-11 10:18
浏览 271
已采纳

MediaWiki批量页面重命名

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?

  • 写回答

2条回答 默认 最新

  • dongyanju0945 2016-04-22 10:35
    关注

    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 mediawiki/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' ), 'XXX_2', 'YYYY' ), 'XXX_3', 'YYYY' ... ), 'XXXX_2', 'YYYY_or_whatever' );

    • Finally, run

      php mediawiki/maintenance/rebuildall.php

    I did not accept miken's answer only because it was just half of the solution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题