Removing the unused message 'linktrail' from the ignored messages.
[lhc/web/wiklou.git] / maintenance / languages.inc
1 <?php
2 /**
3 * Handle messages in the language files.
4 *
5 * @package MediaWiki
6 * @subpackage Maintenance
7 */
8
9 class languages {
10 private $mList = array();
11 private $mMessages = array();
12 private $mIgnoredMessages = array(
13 'sidebar',
14 'addsection',
15 'anonnotice',
16 'catseparator',
17 'googlesearch',
18 'exif-make-value',
19 'exif-model-value',
20 'exif-software-value',
21 'history_copyright',
22 'licenses',
23 'linkprefix',
24 'loginend',
25 'loginlanguagelinks',
26 'markaspatrolledlink',
27 'metadata-fields', // Objection, contains help
28 'newarticletextanon',
29 'noarticletextanon',
30 'number_of_watching_users_RCview',
31 'pubmedurl',
32 'randompage-url',
33 'recentchanges-url',
34 'rfcurl',
35 'shareddescriptionfollows',
36 'signupend',
37 'sitenotice',
38 'sitesubtitle',
39 'sitetitle',
40 'talkpagetext',
41 'trackback',
42 'trackbackexcerpt',
43 'widthheight',
44 );
45
46 /**
47 * Load the list of languages: all the Messages*.php
48 * files in the languages directory.
49 */
50 function __construct() {
51 global $IP;
52 $dir = opendir("$IP/languages");
53 while ( $file = readdir( $dir ) ) {
54 if ( preg_match( "/Messages([^.]*?)\.php$/", $file, $matches ) ) {
55 $this->mList[] = $matches[1];
56 }
57 }
58 sort($this->mList);
59 }
60
61 /**
62 * Get the language list.
63 *
64 * @return the language list
65 */
66 public function getList() {
67 return $this->mList;
68 }
69
70 /**
71 * Load the messages for a specific langauge from the messages file.
72 *
73 * @param $code The langauge code.
74 */
75 private function loadMessages( $code ) {
76 if ( !isset( $this->mMessages[$code] ) ) {
77 global $IP;
78 $filename = Language::getFileName( "$IP/languages/Messages", $code, '.php' );
79 if ( file_exists( $filename ) ) {
80 require( $filename );
81 if ( isset( $messages ) ) {
82 $this->mMessages[$code] = $messages;
83 } else {
84 $this->mMessages[$code] = array();
85 }
86 } else {
87 $this->mMessages[$code] = array();
88 }
89 }
90 }
91
92 /**
93 * Get all the messages for a specific langauge, without the fallback
94 * language messages.
95 *
96 * @param $code The langauge code.
97 *
98 * @return The messages in this language.
99 */
100 public function getMessagesFor( $code ) {
101 $this->loadMessages( $code );
102 return $this->mMessages[$code];
103 }
104
105 /**
106 * Get all the messages of all the languages.
107 */
108 public function getAllMessages() {
109 foreach ( $this->mList as $code ) {
110 $this->getMessages( $code );
111 }
112 }
113
114 /**
115 * Get the untranslated messages for a specific language.
116 *
117 * @param $code The langauge code.
118 *
119 * @return The untranslated messages for this language.
120 */
121 public function getUntranslatedMessages( $code ) {
122 $this->loadMessages( 'en' );
123 $this->loadMessages( $code );
124 $untranslatedMessages = array();
125 foreach ( $this->mMessages['en'] as $key => $value ) {
126 if ( !isset( $this->mMessages[$code][$key] ) && !in_array( $key, $this->mIgnoredMessages ) ) {
127 $untranslatedMessages[$key] = $value;
128 }
129 }
130 return $untranslatedMessages;
131 }
132
133 /**
134 * Get the duplicate messages for a specific language.
135 *
136 * @param $code The langauge code.
137 *
138 * @return The duplicate messages for this language.
139 */
140 public function getDuplicateMessages( $code ) {
141 $this->loadMessages( 'en' );
142 $this->loadMessages( $code );
143 $duplicateMessages = array();
144 foreach ( $this->mMessages[$code] as $key => $value ) {
145 if ( @$this->mMessages['en'][$key] == $value ) {
146 $duplicateMessages[$key] = $value;
147 }
148 }
149 return $duplicateMessages;
150 }
151
152 /**
153 * Get the obsolete messages for a specific language.
154 *
155 * @param $code The langauge code.
156 *
157 * @return The obsolete messages for this language.
158 */
159 public function getObsoleteMessages( $code ) {
160 $this->loadMessages( 'en' );
161 $this->loadMessages( $code );
162 $obsoleteMessages = array();
163 foreach ( $this->mMessages[$code] as $key => $value ) {
164 if ( !isset( $this->mMessages['en'][$key] ) ) {
165 $obsoleteMessages[$key] = $value;
166 }
167 }
168 return $obsoleteMessages;
169 }
170
171 /**
172 * Get the messages which do not use some variables.
173 *
174 * @param $code The langauge code.
175 *
176 * @return The messages which do not use some variables in this language.
177 */
178 public function getMessagesWithoutVariables( $code ) {
179 $this->loadMessages( 'en' );
180 $this->loadMessages( $code );
181 $variables = array( '\$1', '\$2', '\$3', '\$4', '\$5', '\$6', '\$7', '\$8', '\$9' );
182 $messagesWithoutVariables = array();
183 foreach ( $this->mMessages[$code] as $key => $value ) {
184 if ( isset( $this->mMessages['en'][$key] ) ) {
185 $missing = array();
186 foreach ( $variables as $var ) {
187 if ( preg_match( "/$var/sU", $this->mMessages['en'][$key] ) &&
188 !preg_match( "/$var/sU", $value ) ) {
189 $missing[] = str_replace( '\$', '$', $var );
190 }
191 }
192 if ( count( $missing ) > 0 ) {
193 $messagesWithoutVariables[$key] = implode( ', ', $missing );
194 }
195 }
196 }
197 return $messagesWithoutVariables;
198 }
199
200 /**
201 * Get the empty messages.
202 *
203 * @param $code The langauge code.
204 *
205 * @return The empty messages for this language.
206 */
207 public function getEmptyMessages( $code ) {
208 $this->loadMessages( 'en' );
209 $this->loadMessages( $code );
210 $emptyMessages = array();
211 foreach ( $this->mMessages[$code] as $key => $value ) {
212 if ( isset( $this->mMessages['en'][$key] ) &&
213 ( $this->mMessages[$code][$key] === '' || $this->mMessages[$code][$key] === '-' ) ) {
214 $emptyMessages[$key] = $value;
215 }
216 }
217 return $emptyMessages;
218 }
219
220 /**
221 * Get the messages with trailing whitespace.
222 *
223 * @param $code The langauge code.
224 *
225 * @return The messages with trailing whitespace in this language.
226 */
227 public function getMessagesWithWhitespace( $code ) {
228 $this->loadMessages( 'en' );
229 $this->loadMessages( $code );
230 $messagesWithWhitespace = array();
231 foreach ( $this->mMessages[$code] as $key => $value ) {
232 if ( isset( $this->mMessages['en'][$key] ) && $this->mMessages['en'][$key] !== '' &&
233 $value !== rtrim( $value ) ) {
234 $messagesWithWhitespace[$key] = $value;
235 }
236 }
237 return $messagesWithWhitespace;
238 }
239
240 /**
241 * Get the non-XHTML messages.
242 *
243 * @param $code The langauge code.
244 *
245 * @return The non-XHTML messages for this language.
246 */
247 public function getNonXHTMLMessages( $code ) {
248 $this->loadMessages( 'en' );
249 $this->loadMessages( $code );
250 $wrongPhrases = array(
251 '<hr *\\?>',
252 '<br *\\?>',
253 '<hr/>',
254 '<br/>',
255 );
256 $wrongPhrases = '~(' . implode( '|', $wrongPhrases ) . ')~sDu';
257 $nonXHTMLMessages = array();
258 foreach ( $this->mMessages[$code] as $key => $value ) {
259 if ( isset( $this->mMessages['en'][$key] ) && preg_match( $wrongPhrases, $value ) ) {
260 $nonXHTMLMessages[$key] = $value;
261 }
262 }
263 return $nonXHTMLMessages;
264 }
265
266 /**
267 * Output a messages list.
268 *
269 * @param $messages The messages list.
270 * @param $text The text to show before the list (optional).
271 * @param $hideMessages Hide the real messages if specified.
272 */
273 public function outputMessagesList( $messages, $text = '', $hideMessages = false ) {
274 if ( count( $messages ) > 0 ) {
275 if ( $text ) {
276 echo "$text\n";
277 }
278 if ( $hideMessages ) {
279 echo "[messages are hidden]\n";
280 } else {
281 foreach ( $messages as $key => $value ) {
282 echo "* '$key': $value\n";
283 }
284 }
285 }
286 }
287 }
288
289 ?>