Merge "Drop -{webkit,moz}-box-shadow"
[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 protected $language;
31 protected $targets = array( 'desktop', 'mobile' );
32 /**
33 * Get the grammar forms for the site content language.
34 *
35 * @return array
36 */
37 protected function getSiteLangGrammarForms() {
38 return $this->language->getGrammarForms();
39 }
40
41 /**
42 * Get the plural forms for the site content language.
43 *
44 * @return array
45 */
46 protected function getPluralRules() {
47 return $this->language->getPluralRules();
48 }
49
50 /**
51 * Get the digit groupin Pattern for the site content language.
52 *
53 * @return array
54 */
55 protected function getDigitGroupingPattern() {
56 return $this->language->digitGroupingPattern();
57 }
58
59 /**
60 * Get the digit transform table for the content language
61 *
62 * @return array
63 */
64 protected function getDigitTransformTable() {
65 return $this->language->digitTransformTable();
66 }
67
68 /**
69 * Get seperator transform table required for converting
70 * the . and , sign to appropriate forms in site content language.
71 *
72 * @return array
73 */
74 protected function getSeparatorTransformTable() {
75 return $this->language->separatorTransformTable();
76 }
77
78 /**
79 * Get all the dynamic data for the content language to an array.
80 *
81 * NOTE: Before calling this you HAVE to make sure $this->language is set.
82 *
83 * @return array
84 */
85 protected function getData() {
86 return array(
87 'digitTransformTable' => $this->getDigitTransformTable(),
88 'separatorTransformTable' => $this->getSeparatorTransformTable(),
89 'grammarForms' => $this->getSiteLangGrammarForms(),
90 'pluralRules' => $this->getPluralRules(),
91 'digitGroupingPattern' => $this->getDigitGroupingPattern(),
92 );
93 }
94
95 /**
96 * @param ResourceLoaderContext $context
97 * @return string JavaScript code
98 */
99 public function getScript( ResourceLoaderContext $context ) {
100 $this->language = Language::factory( $context->getLanguage() );
101 return Xml::encodeJsCall( 'mw.language.setData', array(
102 $this->language->getCode(),
103 $this->getData()
104 ) );
105 }
106
107 /**
108 * @param ResourceLoaderContext $context
109 * @return int UNIX timestamp
110 */
111 public function getModifiedTime( ResourceLoaderContext $context ) {
112 return max( 1, $this->getHashMtime( $context ) );
113 }
114
115 /**
116 * @param ResourceLoaderContext $context
117 * @return string Hash
118 */
119 public function getModifiedHash( ResourceLoaderContext $context ) {
120 $this->language = Language::factory( $context->getLanguage() );
121
122 return md5( serialize( $this->getData() ) );
123 }
124
125 /**
126 * @return array
127 */
128 public function getDependencies() {
129 return array( 'mediawiki.language.init' );
130 }
131 }