Interwiki cache

From mediawiki.org

MediaWiki has a database table (interwiki table) for interwiki prefixes. This is by default used directly, but two types of caching can be used for better performance.

Database and memcached[edit]

When memcached is enabled, the interwiki prefixes of the database table will be cached too. This can be controlled using the $wgInterwikiExpiry setting.

This cache can be cleared using the clearInterwikiCache.php script. It removes the caching based on the prefixes found in the database table.

Interwiki cache[edit]

The $wgInterwikiCache variable can be set to a static array that will be used instead of the database table, thus achieving even better performance by removing latencies to memcached and avoiding the database queries to populate a cache.

The array is typically storing in a PHP file containing <?php return array( .. ); and loaded by assinging it to $wgInterwikiCache with require.

MediaWiki does not currently provide a bulilt-in script to build such a cache file (bug 33395), however WikimediaMaintenance contains dumpInterwiki.php which is a WMF-specific script.

The $wgInterwikiScopes and $wgInterwikiFallbackSite settings are used when reading this cache.

Setting this up on your own wiki[edit]

See Interwiki cache/Setup for your own wiki for cheaper ways to do it, assuming you want interwiki links on your wiki to take readers to the Wikimedia Foundation projects. For the more painful but more correct approach, see below.

  • You will need a copy of extension/WikimediaMaintenance; place this in the extensions directory in the root of your MediaWiki installation.
  • Retrieve the files all.dblist, special.dblist, and langlist and put them someplace (e.g. in a subdir in the base of your MediaWiki installation) for convenience.
  • Edit extension/WikimediaMaintenance/dumpInterwikis.php and change the path /srv/mediawiki for those three files to the path to the directory where you just put them.
  • From the base of your MediaWiki installation, do
    echo 'print wfWikiID();' | php maintenance/eval.php
Add this value to all.dblist, assuming it's not already in there. If it does not start with a known language code (e.g. it is, say, 'wikitech-mw_ instead of something nice like frwiktionary), add it also to special.dblist. You can check the language codes in the langlist file you copied over.
  • From the base of your MediaWiki installation, do
    php extensions/WikimediaMaintenance/dumpInterwiki.php > cache/new-interwikis.php
  • From the base of your MediaWiki installation, make a copy of any existing cache/interwiki.db file you may have and then do
    cp cache/new-interwikis.php cache/interwiki.php
  • Edit LocalSettings.php and add
    $wgInterwikiCache = require "$IP/cache/interwiki.php";

Now shortcuts and all other iw links should work for your project. Note that if you added it to 'special.dblist', it will behave as though it is a 'wikipedia' with en as the default language.

Retrieving interwikis[edit]

To view the interwiki prefixes, you can use the API (action=query&meta=siteinfo&siprop=interwikimap) or install the Interwiki extension.