How to update all external links after migrating a MediaWiki

情到浓时终转凉″ 提交于 2019-12-12 04:56:37

问题


I have migrated a MediaWiki from one environment to another. Everything works fine, except for the fact that a few users have hard-coded external links (which actually link to other pages within the same wiki). For example, the old wiki was on ://foo/wiki and the new is at ://foo.com. On pages of the migrated wiki there are external links on the page text like ://foo/wiki/somepage. So when they click the link on the migrated wiki they get taken back to the old wiki and are directed to ://foo/wiki/somepage -- which is not the correct behavior (it should go to ://foo.com/somepage). In the "externallinks" table in MySQL I have run the two statements on a single link to see if the change would update the link:

UPDATE `foowiki`.`externallinks`
SET el_to = REPLACE(el_to, '://foo/wiki', '://www.foo.com')
WHERE el_to LIKE '%://foo/wiki/somepage%';

UPDATE `foowiki`.`externallinks`
SET el_index = REPLACE(el_index, '://foo./wiki', '://com.foo.www.')
WHERE el_index LIKE '%://foo./wiki/somepage%';

When I restart the site and go to the page with the sample link I'm trying to update, the link is still the same (i.e., it links to the old wiki environment).

Is there a quick and easy way to replace all external links (in the text) with the correct prefix (i.e. go from ://foo/wiki/somerandompage to ://foo.com/somerandompage)? Maybe there is an even cleaner way to do it, instead of updating all the records in a MySQL table, such as intercepting the HTTP requests in LocalSettings.php and doing a single substring replace there?


回答1:


Solution A (no code):

  1. Dump the table:
    mysqldump -u user -p database table > dump.sql
  2. Open it with notepad++
  3. Do a search and replace:
    ctrl+h
  4. Re-import the table:
    mysqlimport -u user -p database table < dump.sql

Solution B, use sed:

  1. Dump the table:
    mysqldump -u user -p database table > dump.sql
  2. Find and replace using sed:
    find /path/to/dump.sql -type f -exec sed -i 's/:\/\/foo\/wiki\//:\/\/foo.com\//g' {} \;
  3. Re-import the table:
    mysqlimport -u user -p database table < dump.sql

PS: always backup.




回答2:


Rather than trying to alter the database (the layout is quite complex), I would try the extension Replace_Text. It is stable, well tested, and made just for situations like these.

BTW, you have a colon prepending you protocol relative URLs. You probably mean to write //www.foo.com.

If you still want to hack the DB, I believe it is the archive and text tables you want to look at. After doing your work there, you will have to rebuild the external links table based on that.



来源:https://stackoverflow.com/questions/29659394/how-to-update-all-external-links-after-migrating-a-mediawiki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!