jenkins-bot has submitted this change and it was merged.
Change subject: Move core message dirs from $wgMessagesDirs to
LocalisationCache::getMessagesDirs()
......................................................................
Move core message dirs from $wgMessagesDirs to
LocalisationCache::getMessagesDirs()
If $wgMessagesDirs is initially empty, we can optimize when batch loading
extensions:
if ( !$wgMessagesDirs ) {
$wgMessagesDirs = $cache['MessagesDirs'];
}
With APC, this should be O(1) CPU time.
This was suggested by Tim in the code review of I7074b65d07c5.
Change-Id: I66fa907cdaafe18b74b5b9afaa8b6b1db069bea3
---
M includes/DefaultSettings.php
M includes/cache/LocalisationCache.php
M tests/phpunit/includes/cache/LocalisationCacheTest.php
3 files changed, 45 insertions(+), 13 deletions(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index ca41088..be79e0b 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6229,6 +6229,8 @@
* 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';
@@ -6244,11 +6246,7 @@
* @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
diff --git a/includes/cache/LocalisationCache.php
b/includes/cache/LocalisationCache.php
index 2a3cd38..2c908af 100644
--- a/includes/cache/LocalisationCache.php
+++ b/includes/cache/LocalisationCache.php
@@ -36,7 +36,7 @@
* as grammatical transformation, is done by the caller.
*/
class LocalisationCache {
- const VERSION = 2;
+ const VERSION = 3;
/** Configuration associative array */
private $conf;
@@ -793,13 +793,29 @@
}
/**
+ * 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
* @param string $code
* @throws MWException
*/
public function recache( $code ) {
- global $wgExtensionMessagesFiles, $wgMessagesDirs;
+ global $wgExtensionMessagesFiles;
wfProfileIn( __METHOD__ );
if ( !$code ) {
@@ -846,6 +862,7 @@
}
$codeSequence = array_merge( array( $code ),
$coreData['fallbackSequence'] );
+ $messageDirs = $this->getMessagesDirs();
wfProfileIn( __METHOD__ . '-fallbacks' );
@@ -854,7 +871,7 @@
$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;
}
@@ -882,7 +899,7 @@
$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
);
@@ -949,6 +966,7 @@
# 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' );
diff --git a/tests/phpunit/includes/cache/LocalisationCacheTest.php
b/tests/phpunit/includes/cache/LocalisationCacheTest.php
index 35ff919..24b5186 100644
--- a/tests/phpunit/includes/cache/LocalisationCacheTest.php
+++ b/tests/phpunit/includes/cache/LocalisationCacheTest.php
@@ -11,14 +11,30 @@
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' ),
@@ -46,7 +62,7 @@
}
public function testRecacheFallbacks() {
- $lc = new LocalisationCache( array( 'store' => 'detect' ) );
+ $lc = $this->getMockLocalisationCache();
$lc->recache( 'uk' );
$this->assertEquals(
array(
@@ -78,7 +94,7 @@
)
) );
- $lc = new LocalisationCache( array( 'store' => 'detect' ) );
+ $lc = $this->getMockLocalisationCache();
$lc->recache( 'uk' );
$this->assertEquals(
array(
--
To view, visit https://gerrit.wikimedia.org/r/177385
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I66fa907cdaafe18b74b5b9afaa8b6b1db069bea3
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits