MediaWiki
REL1_21
|
00001 <?php 00028 class ResourceLoaderLanguageDataModule extends ResourceLoaderModule { 00029 00030 protected $language; 00031 protected $targets = array( 'desktop', 'mobile' ); 00037 protected function getSiteLangGrammarForms() { 00038 return $this->language->getGrammarForms(); 00039 } 00040 00046 protected function getPluralRules() { 00047 return $this->language->getPluralRules(); 00048 } 00049 00055 protected function getDigitGroupingPattern() { 00056 return $this->language->digitGroupingPattern(); 00057 } 00058 00064 protected function getDigitTransformTable() { 00065 return $this->language->digitTransformTable(); 00066 } 00067 00074 protected function getSeparatorTransformTable() { 00075 return $this->language->separatorTransformTable(); 00076 } 00077 00078 00084 protected function getData() { 00085 return array( 00086 'digitTransformTable' => $this->getDigitTransformTable(), 00087 'separatorTransformTable' => $this->getSeparatorTransformTable(), 00088 'grammarForms' => $this->getSiteLangGrammarForms(), 00089 'pluralRules' => $this->getPluralRules(), 00090 'digitGroupingPattern' => $this->getDigitGroupingPattern(), 00091 ); 00092 } 00093 00098 public function getScript( ResourceLoaderContext $context ) { 00099 $this->language = Language::factory( $context->getLanguage() ); 00100 return Xml::encodeJsCall( 'mw.language.setData', array( 00101 $this->language->getCode(), 00102 $this->getData() 00103 ) ); 00104 } 00105 00110 public function getModifiedTime( ResourceLoaderContext $context ) { 00111 $this->language = Language::factory( $context ->getLanguage() ); 00112 $cache = wfGetCache( CACHE_ANYTHING ); 00113 $key = wfMemcKey( 'resourceloader', 'langdatamodule', 'changeinfo' ); 00114 00115 $data = $this->getData(); 00116 $hash = md5( serialize( $data ) ); 00117 00118 $result = $cache->get( $key ); 00119 if ( is_array( $result ) && $result['hash'] === $hash ) { 00120 return $result['timestamp']; 00121 } 00122 $timestamp = wfTimestamp(); 00123 $cache->set( $key, array( 00124 'hash' => $hash, 00125 'timestamp' => $timestamp, 00126 ) ); 00127 return $timestamp; 00128 } 00129 00133 public function getDependencies() { 00134 return array( 'mediawiki.language.init' ); 00135 } 00136 }