Invalid magic words


· MediaWiki ·

Recently I've been getting annoying intermittent errors about invalid magic words, but usually only after updating MediaWiki core:

  • UnexpectedValueException: Error: invalid magic word 'if'
  • "" is not a valid magic word for "if"

(In this case the {{#if:}} parser function comes from the ParserFunctions extension, but the errors happen usually with whichever magic-word-using extension is loaded first in LocalSettings.php.)

It seems that these stem from the $wgLocalisationCacheConf['store'] = 'array' in DevelopmentSettings.php, which means that the localisation cache is stored serialized in text files in the cache directory.

The problem is that DevelopmentSettings.php also defines $wgCacheDirectory as follows:

$wgCacheDirectory = TempFSFile::getUsableTempDirectory() .
	rawurlencode( MediaWiki\WikiMap\WikiMap::getCurrentWikiId() );

Which uses the wiki ID in the directory name. This would be fine, but for the fact that I have a weird set-up and define the wiki ID myself (based on various things that I'll go into in a separate post).

So the fix is to make sure I define $wgCacheDirectory after including DevelopmentSettings.php:

$wgCacheDirectory = __DIR__ . '/cache-' . $wikiId . '/';