X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderLanguageDataModule.php;h=a1c8ac9dd5b4bb414543844258a64d82791f3d63;hb=0acddf0b416da9fb0ed5b11da743789dfa3e5526;hp=e840300d7267df3eb4dde041c8009745f9422c56;hpb=9bb4218be4311bc403e9ab348d80d79ad86977be;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderLanguageDataModule.php b/includes/resourceloader/ResourceLoaderLanguageDataModule.php index e840300d72..a1c8ac9dd5 100644 --- a/includes/resourceloader/ResourceLoaderLanguageDataModule.php +++ b/includes/resourceloader/ResourceLoaderLanguageDataModule.php @@ -27,104 +27,50 @@ */ class ResourceLoaderLanguageDataModule extends ResourceLoaderModule { - protected $language; protected $targets = array( 'desktop', 'mobile' ); - /** - * Get the grammar forms for the site content language. - * - * @return array - */ - protected function getSiteLangGrammarForms() { - return $this->language->getGrammarForms(); - } - - /** - * Get the plural forms for the site content language. - * - * @return array - */ - protected function getPluralRules() { - return $this->language->getPluralRules(); - } /** - * Get the digit groupin Pattern for the site content language. + * Get all the dynamic data for the content language to an array. * + * @param ResourceLoaderContext $context * @return array */ - protected function getDigitGroupingPattern() { - return $this->language->digitGroupingPattern(); - } - - /** - * Get the digit transform table for the content language - * - * @return array - */ - protected function getDigitTransformTable() { - return $this->language->digitTransformTable(); - } - - /** - * Get seperator transform table required for converting - * the . and , sign to appropriate forms in site content language. - * - * @return array - */ - protected function getSeparatorTransformTable() { - return $this->language->separatorTransformTable(); - } - - - /** - * Get all the dynamic data for the content language to an array - * - * @return array - */ - protected function getData() { + protected function getData( ResourceLoaderContext $context ) { + $language = Language::factory( $context->getLanguage() ); return array( - 'digitTransformTable' => $this->getDigitTransformTable(), - 'separatorTransformTable' => $this->getSeparatorTransformTable(), - 'grammarForms' => $this->getSiteLangGrammarForms(), - 'pluralRules' => $this->getPluralRules(), - 'digitGroupingPattern' => $this->getDigitGroupingPattern(), + 'digitTransformTable' => $language->digitTransformTable(), + 'separatorTransformTable' => $language->separatorTransformTable(), + 'grammarForms' => $language->getGrammarForms(), + 'pluralRules' => $language->getPluralRules(), + 'digitGroupingPattern' => $language->digitGroupingPattern(), ); } /** - * @param $context ResourceLoaderContext - * @return string: JavaScript code + * @param ResourceLoaderContext $context + * @return string JavaScript code */ public function getScript( ResourceLoaderContext $context ) { - $this->language = Language::factory( $context->getLanguage() ); return Xml::encodeJsCall( 'mw.language.setData', array( - $this->language->getCode(), - $this->getData() + $context->getLanguage(), + $this->getData( $context ) ) ); } /** - * @param $context ResourceLoaderContext - * @return array|int|Mixed + * @param ResourceLoaderContext $context + * @return int UNIX timestamp */ public function getModifiedTime( ResourceLoaderContext $context ) { - $this->language = Language::factory( $context->getLanguage() ); - $cache = wfGetCache( CACHE_ANYTHING ); - $key = wfMemcKey( 'resourceloader', 'langdatamodule', 'changeinfo' ); - - $data = $this->getData(); - $hash = md5( serialize( $data ) ); + return max( 1, $this->getHashMtime( $context ) ); + } - $result = $cache->get( $key ); - if ( is_array( $result ) && $result['hash'] === $hash ) { - return $result['timestamp']; - } - $timestamp = wfTimestamp(); - $cache->set( $key, array( - 'hash' => $hash, - 'timestamp' => $timestamp, - ) ); - return $timestamp; + /** + * @param ResourceLoaderContext $context + * @return string Hash + */ + public function getModifiedHash( ResourceLoaderContext $context ) { + return md5( serialize( $this->getData( $context ) ) ); } /**