* @file
*/
+use Cdb\Exception as CdbException;
+use Cdb\Reader as CdbReader;
+use Cdb\Writer as CdbWriter;
+
/**
* Class for caching the contents of localisation files, Messages*.php
* and *.i18n.php.
* as grammatical transformation, is done by the caller.
*/
class LocalisationCache {
- const VERSION = 2;
+ const VERSION = 3;
/** Configuration associative array */
private $conf;
* @param string $fileName
*/
protected function loadPluralFile( $fileName ) {
+ // Use file_get_contents instead of DOMDocument::load (T58439)
+ $xml = file_get_contents( $fileName );
+ if ( !$xml ) {
+ throw new MWException( "Unable to read plurals file $fileName" );
+ }
$doc = new DOMDocument;
- $doc->load( $fileName );
+ $doc->loadXML( $xml );
$rulesets = $doc->getElementsByTagName( "pluralRules" );
foreach ( $rulesets as $ruleset ) {
$codes = $ruleset->getAttribute( 'locales' );
return $used;
}
+ /**
+ * Gets the combined list of messages dirs from
+ * core and extensions
+ *
+ * @since 1.25
+ * @return array
+ */
+ public 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 );
# Allow extensions an opportunity to adjust the data for this
# fallback
- wfRunHooks( 'LocalisationCacheRecacheFallback', array( $this, $csCode, &$csData ) );
+ Hooks::run( 'LocalisationCacheRecacheFallback', array( $this, $csCode, &$csData ) );
# Merge the data for this fallback into the final array
if ( $csCode === $code ) {
# 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' );
}
# Run hooks
$purgeBlobs = true;
- wfRunHooks( 'LocalisationCacheRecache', array( $this, $code, &$allData, &$purgeBlobs ) );
+ Hooks::run( 'LocalisationCacheRecache', array( $this, $code, &$allData, &$purgeBlobs ) );
if ( is_null( $allData['namespaceNames'] ) ) {
wfProfileOut( __METHOD__ );