From 277cfd5a5515752a3f5e2b8bc787158d0a915a9d Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 30 Apr 2014 23:45:13 +0200 Subject: [PATCH] ResourceLoaderLanguageDataModule: Clean up useless methods and fragile state ResourceLoaderModule methods that need context should use context. Setting a temporary property and then calling a bunch of methods seems a bit fragile. Though the actual instance could be passed around instead, in this case the methods don't seem very useful. They're one-liner wrappers that can just as well be done directly. It's not like we need the abstraction for anything. Follows-up f47dfe9. Change-Id: I2f2f57896002fba87dc581dca61f5760ea5db31e --- .../ResourceLoaderLanguageDataModule.php | 71 +++---------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderLanguageDataModule.php b/includes/resourceloader/ResourceLoaderLanguageDataModule.php index 77dcdf9e03..a1c8ac9dd5 100644 --- a/includes/resourceloader/ResourceLoaderLanguageDataModule.php +++ b/includes/resourceloader/ResourceLoaderLanguageDataModule.php @@ -27,68 +27,22 @@ */ 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. - * - * @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. * - * NOTE: Before calling this you HAVE to make sure $this->language is set. - * + * @param ResourceLoaderContext $context * @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(), ); } @@ -97,10 +51,9 @@ class ResourceLoaderLanguageDataModule extends ResourceLoaderModule { * @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 ) ) ); } @@ -117,9 +70,7 @@ class ResourceLoaderLanguageDataModule extends ResourceLoaderModule { * @return string Hash */ public function getModifiedHash( ResourceLoaderContext $context ) { - $this->language = Language::factory( $context->getLanguage() ); - - return md5( serialize( $this->getData() ) ); + return md5( serialize( $this->getData( $context ) ) ); } /** -- 2.20.1