* en.json, de.json, etc. Extensions with messages in multiple places may specify an array of
* message directories.
*
+ * Message directories in core should be added to LocalisationCache::getMessagesDirs()
+ *
* @par Simple example:
* @code
* $wgMessagesDirs['Example'] = __DIR__ . '/i18n';
* @endcode
* @since 1.23
*/
-$wgMessagesDirs = array(
- 'core' => "$IP/languages/i18n",
- 'api' => "$IP/includes/api/i18n",
- 'oojs-ui' => "$IP/resources/lib/oojs-ui/i18n",
-);
+$wgMessagesDirs = array();
/**
* Array of files with list(s) of extension entry points to be used in
* as grammatical transformation, is done by the caller.
*/
class LocalisationCache {
- const VERSION = 2;
+ const VERSION = 3;
/** Configuration associative array */
private $conf;
return $used;
}
+ /**
+ * Gets the combined list of messages dirs from
+ * core and extensions
+ *
+ * @since 1.25
+ * @return array
+ */
+ protected function getMessagesDirs() {
+ global $wgMessagesDirs, $IP;
+ return array(
+ 'core' => "$IP/languages/i18n",
+ 'api' => "$IP/includes/api/i18n",
+ 'oojs-ui' => "$IP/resources/lib/oojs-ui/i18n",
+ ) + $wgMessagesDirs;
+ }
+
/**
* Load localisation data for a given language for both core and extensions
* and save it to the persistent cache store and the process cache
* @throws MWException
*/
public function recache( $code ) {
- global $wgExtensionMessagesFiles, $wgMessagesDirs;
+ global $wgExtensionMessagesFiles;
wfProfileIn( __METHOD__ );
if ( !$code ) {
}
$codeSequence = array_merge( array( $code ), $coreData['fallbackSequence'] );
+ $messageDirs = $this->getMessagesDirs();
wfProfileIn( __METHOD__ . '-fallbacks' );
$codeSequence,
array_fill( 0, count( $codeSequence ), $initialData ) );
foreach ( $wgExtensionMessagesFiles as $extension => $fileName ) {
- if ( isset( $wgMessagesDirs[$extension] ) ) {
+ if ( isset( $messageDirs[$extension] ) ) {
# This extension has JSON message data; skip the PHP shim
continue;
}
$csData = $initialData;
# Load core messages and the extension localisations.
- foreach ( $wgMessagesDirs as $dirs ) {
+ foreach ( $messageDirs as $dirs ) {
foreach ( (array)$dirs as $dir ) {
$fileName = "$dir/$csCode.json";
$data = $this->readJSONFile( $fileName );
# Add cache dependencies for any referenced globals
$deps['wgExtensionMessagesFiles'] = new GlobalDependency( 'wgExtensionMessagesFiles' );
+ // $wgMessagesDirs is used in LocalisationCache::getMessagesDirs()
$deps['wgMessagesDirs'] = new GlobalDependency( 'wgMessagesDirs' );
$deps['version'] = new ConstantDependency( 'LocalisationCache::VERSION' );
parent::setUp();
$this->setMwGlobals( array(
- 'wgMessagesDirs' => array( "$IP/tests/phpunit/data/localisationcache" ),
'wgExtensionMessagesFiles' => array(),
'wgHooks' => array(),
) );
}
+ /**
+ * @return PHPUnit_Framework_MockObject_MockObject|LocalisationCache
+ */
+ protected function getMockLocalisationCache() {
+ global $IP;
+ $lc = $this->getMockBuilder( 'LocalisationCache' )
+ ->setConstructorArgs( array( array( 'store' => 'detect' ) ) )
+ ->setMethods( array( 'getMessagesDirs' ) )
+ ->getMock();
+ $lc->expects( $this->any() )->method( 'getMessagesDirs' )
+ ->will( $this->returnValue(
+ array( "$IP/tests/phpunit/data/localisationcache" )
+ ) );
+
+ return $lc;
+ }
+
public function testPuralRulesFallback() {
- $cache = new LocalisationCache( array( 'store' => 'detect' ) );
+ $cache = $this->getMockLocalisationCache();
$this->assertEquals(
$cache->getItem( 'ar', 'pluralRules' ),
}
public function testRecacheFallbacks() {
- $lc = new LocalisationCache( array( 'store' => 'detect' ) );
+ $lc = $this->getMockLocalisationCache();
$lc->recache( 'uk' );
$this->assertEquals(
array(
)
) );
- $lc = new LocalisationCache( array( 'store' => 'detect' ) );
+ $lc = $this->getMockLocalisationCache();
$lc->recache( 'uk' );
$this->assertEquals(
array(