b823f1d25b81fb10af21953a86c05a805a859557
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderLanguageDataModule.php
1 <?php
2 /**
3 * Resource loader module for populating language specific data.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Santhosh Thottingal
22 * @author Timo Tijhof
23 */
24
25 /**
26 * ResourceLoader module for populating language specific data.
27 */
28 class ResourceLoaderLanguageDataModule extends ResourceLoaderModule {
29
30 /**
31 * Get the grammer forms for the site content language.
32 *
33 * @return array
34 */
35 protected function getSiteLangGrammarForms() {
36 global $wgContLang;
37 return $wgContLang->getGrammarForms();
38 }
39
40 /**
41 * @param $context ResourceLoaderContext
42 * @return string: Javascript code
43 */
44 public function getScript( ResourceLoaderContext $context ) {
45 global $wgContLang;
46
47 return Xml::encodeJsCall( 'mw.language.setData', array(
48 $wgContLang->getCode(),
49 array(
50 'grammarForms' => $this->getSiteLangGrammarForms()
51 )
52 ) );
53 }
54
55 /**
56 * @param $context ResourceLoaderContext
57 * @return array|int|Mixed
58 */
59 public function getModifiedTime( ResourceLoaderContext $context ) {
60 $cache = wfGetCache( CACHE_ANYTHING );
61 $key = wfMemcKey( 'resourceloader', 'langdatamodule', 'changeinfo' );
62
63 $forms = $this->getSiteLangGrammarForms();
64 $hash = md5( serialize( $forms ) );
65
66 $result = $cache->get( $key );
67 if ( is_array( $result ) && $result['hash'] === $hash ) {
68 return $result['timestamp'];
69 }
70 $timestamp = wfTimestamp();
71 $cache->set( $key, array(
72 'hash' => $hash,
73 'timestamp' => $timestamp,
74 ) );
75 return $timestamp;
76 }
77
78 /**
79 * @return array
80 */
81 public function getDependencies() {
82 return array( 'mediawiki.language.init' );
83 }
84 }