Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / resourceloader / ResourceLoaderLanguageDataModule.php
blobe840300d7267df3eb4dde041c8009745f9422c56
1 <?php
2 /**
3 * Resource loader module for populating language specific data.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Santhosh Thottingal
22 * @author Timo Tijhof
25 /**
26 * ResourceLoader module for populating language specific data.
28 class ResourceLoaderLanguageDataModule extends ResourceLoaderModule {
30 protected $language;
31 protected $targets = array( 'desktop', 'mobile' );
32 /**
33 * Get the grammar forms for the site content language.
35 * @return array
37 protected function getSiteLangGrammarForms() {
38 return $this->language->getGrammarForms();
41 /**
42 * Get the plural forms for the site content language.
44 * @return array
46 protected function getPluralRules() {
47 return $this->language->getPluralRules();
50 /**
51 * Get the digit groupin Pattern for the site content language.
53 * @return array
55 protected function getDigitGroupingPattern() {
56 return $this->language->digitGroupingPattern();
59 /**
60 * Get the digit transform table for the content language
62 * @return array
64 protected function getDigitTransformTable() {
65 return $this->language->digitTransformTable();
68 /**
69 * Get seperator transform table required for converting
70 * the . and , sign to appropriate forms in site content language.
72 * @return array
74 protected function getSeparatorTransformTable() {
75 return $this->language->separatorTransformTable();
79 /**
80 * Get all the dynamic data for the content language to an array
82 * @return array
84 protected function getData() {
85 return array(
86 'digitTransformTable' => $this->getDigitTransformTable(),
87 'separatorTransformTable' => $this->getSeparatorTransformTable(),
88 'grammarForms' => $this->getSiteLangGrammarForms(),
89 'pluralRules' => $this->getPluralRules(),
90 'digitGroupingPattern' => $this->getDigitGroupingPattern(),
94 /**
95 * @param $context ResourceLoaderContext
96 * @return string: JavaScript code
98 public function getScript( ResourceLoaderContext $context ) {
99 $this->language = Language::factory( $context->getLanguage() );
100 return Xml::encodeJsCall( 'mw.language.setData', array(
101 $this->language->getCode(),
102 $this->getData()
103 ) );
107 * @param $context ResourceLoaderContext
108 * @return array|int|Mixed
110 public function getModifiedTime( ResourceLoaderContext $context ) {
111 $this->language = Language::factory( $context->getLanguage() );
112 $cache = wfGetCache( CACHE_ANYTHING );
113 $key = wfMemcKey( 'resourceloader', 'langdatamodule', 'changeinfo' );
115 $data = $this->getData();
116 $hash = md5( serialize( $data ) );
118 $result = $cache->get( $key );
119 if ( is_array( $result ) && $result['hash'] === $hash ) {
120 return $result['timestamp'];
122 $timestamp = wfTimestamp();
123 $cache->set( $key, array(
124 'hash' => $hash,
125 'timestamp' => $timestamp,
126 ) );
127 return $timestamp;
131 * @return array
133 public function getDependencies() {
134 return array( 'mediawiki.language.init' );