Index: trunk/phase3/maintenance/language/checkExtensioni18n.php |
— | — | @@ -1,269 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Copyright (C) 2007 Ashar Voultoiz <hashar@altern.org> |
5 | | - * |
6 | | - * Based on dumpBackup: |
7 | | - * Copyright (C) 2005 Brion Vibber <brion@pobox.com> |
8 | | - * |
9 | | - * http://www.mediawiki.org |
10 | | - * |
11 | | - * This program is free software; you can redistribute it and/or modify |
12 | | - * it under the terms of the GNU General Public License as published by |
13 | | - * the Free Software Foundation; either version 2 of the License, or |
14 | | - * (at your option) any later version. |
15 | | - * |
16 | | - * This program is distributed in the hope that it will be useful, |
17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | | - * GNU General Public License for more details. |
20 | | - * |
21 | | - * You should have received a copy of the GNU General Public License along |
22 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
23 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 | | - * http://www.gnu.org/copyleft/gpl.html |
25 | | - * |
26 | | - * @addtogroup SpecialPage |
27 | | - */ |
28 | | - |
29 | | -# |
30 | | -# Lacking documentation. Examples: |
31 | | -# php checkExtensioni18n.php /opt/mw/extensions/CentralAuth/CentralAuth.i18n.php wgCentralAuthMessages |
32 | | -# php checkExtensioni18n.php --extdir /opt/mw/extensions/ |
33 | | -# |
34 | | -# BUGS: cant guess registered extensions :) |
35 | | -# TODO: let users set parameters to configure checklanguage.inc (it uses globals) |
36 | | - |
37 | | -// Filename for the extension i18n files database: |
38 | | -define( 'EXT_I18N_DB', 'i18n.db' ); |
39 | | - |
40 | | -$optionsWithArgs = array( 'extdir', 'lang' ); |
41 | | - |
42 | | -require_once( dirname(__FILE__).'/../commandLine.inc' ); |
43 | | -require_once( 'languages.inc' ); |
44 | | -require_once( 'checkLanguage.inc' ); |
45 | | - |
46 | | - |
47 | | -class extensionLanguages extends languages { |
48 | | - private $mExt18nFilename, $mExtArrayName ; |
49 | | - private $mExtArray; |
50 | | - |
51 | | - function __construct( $ext18nFilename, $extArrayName ) { |
52 | | - $this->mExt18nFilename = $ext18nFilename; |
53 | | - $this->mExtArrayName = $extArrayName; |
54 | | - |
55 | | - $this->mIgnoredMessages = array(); |
56 | | - $this->mOptionalMessages = array(); |
57 | | - |
58 | | - if ( file_exists( $this->mExt18nFilename ) ) { |
59 | | - require_once( $this->mExt18nFilename ); |
60 | | - |
61 | | - $foundarray = false; |
62 | | - if( isset( ${$this->mExtArrayName} ) ) { |
63 | | - // File provided in the db file |
64 | | - $foundarray = ${$this->mExtArrayName}; |
65 | | - } else { |
66 | | - |
67 | | - /* For extensions included elsewhere. For some reason other extensions |
68 | | - * break with the global statement, so recheck here. |
69 | | - */ |
70 | | - global ${$this->mExtArrayName}; |
71 | | - if( is_array( ${$this->mExtArrayName} ) ) { |
72 | | - $foundarray = ${$this->mExtArrayName}; |
73 | | - } |
74 | | - |
75 | | - /* we might have been given a function name, test it too */ |
76 | | - if( function_exists( $this->mExtArrayName ) ) { |
77 | | - // Load data |
78 | | - $funcName = $this->mExtArrayName ; |
79 | | - $foundarray = $funcName(); |
80 | | - } |
81 | | - |
82 | | - if(!$foundarray) { |
83 | | - // Provided array could not be found we try to guess it. |
84 | | - |
85 | | - # Using the extension path ($m[1]) and filename ($m[2]): |
86 | | - $m = array(); |
87 | | - preg_match( '%.*/(.*)/(.*).i18n\.php%', $this->mExt18nFilename, $m); |
88 | | - $arPathCandidate = 'wg' . $m[1].'Messages'; |
89 | | - $arFileCandidate = 'wg' . $m[2].'Messages'; |
90 | | - $funcCandidate = "ef{$m[2]}Messages"; |
91 | | - |
92 | | - // Try them: |
93 | | - if( isset($$arPathCandidate) && is_array( $$arPathCandidate ) ) { |
94 | | - print "warning> messages from guessed path array \$$arPathCandidate.\n"; |
95 | | - $foundarray = $$arPathCandidate; |
96 | | - } elseif( isset($$arFileCandidate) && is_array( $$arFileCandidate ) ) { |
97 | | - print "warning> messages from guessed file array \$$arFileCandidate.\n"; |
98 | | - $foundarray = $$arFileCandidate; |
99 | | - } elseif( function_exists( $funcCandidate ) ) { |
100 | | - print "warning> messages build from guessed function {$funcCandidate}().\n"; |
101 | | - $foundarray = $funcCandidate(); |
102 | | - } |
103 | | - } |
104 | | - |
105 | | - # We are unlucky, return empty stuff |
106 | | - if(!$foundarray) { |
107 | | - print "ERROR> failed to guess an array to use.\n"; |
108 | | - $this->mExtArray = null; |
109 | | - $this->mLanguages = null; |
110 | | - return; |
111 | | - } |
112 | | - } |
113 | | - |
114 | | - $this->mExtArray = $foundarray ; |
115 | | - $this->mLanguages = array_keys( $this->mExtArray ); |
116 | | - } else { |
117 | | - wfDie( "File $this->mExt18nFilename not found\n" ); |
118 | | - } |
119 | | - } |
120 | | - |
121 | | - protected function loadRawMessages( $code ) { |
122 | | - if ( isset( $this->mRawMessages[$code] ) ) { |
123 | | - return; |
124 | | - } |
125 | | - if( isset( $this->mExtArray[$code] ) ) { |
126 | | - $this->mRawMessages[$code] = $this->mExtArray[$code] ; |
127 | | - } else { |
128 | | - $this->mRawMessages[$code] = array(); |
129 | | - } |
130 | | - } |
131 | | - |
132 | | - public function getLanguages() { |
133 | | - return $this->mLanguages; |
134 | | - } |
135 | | -} |
136 | | - |
137 | | -/** |
138 | | - * @param $filename Filename containing the extension i18n |
139 | | - * @param $arrayname The name of the array in the filename |
140 | | - * @param $filter Optional, restrict check to a given language code (default; null) |
141 | | - */ |
142 | | -function checkExtensionLanguage( $filename, $arrayname, $filter = null ) { |
143 | | - $extLanguages = new extensionLanguages($filename, $arrayname); |
144 | | - |
145 | | - $langs = $extLanguages->getLanguages(); |
146 | | - if( !$langs ) { |
147 | | - print "ERROR> \$$arrayname array does not exist.\n"; |
148 | | - return false; |
149 | | - } |
150 | | - |
151 | | - $nErrors = 0; |
152 | | - if( $filter ) { |
153 | | - $nErrors += checkLanguage( $extLanguages, $filter ); |
154 | | - } else { |
155 | | - print "Will check ". count($langs) . " languages : " . implode(' ', $langs) .".\n"; |
156 | | - foreach( $langs as $lang ) { |
157 | | - if( $lang == 'en' ) { |
158 | | - #print "Skipped english language\n"; |
159 | | - continue; |
160 | | - } |
161 | | - |
162 | | - $nErrors += checkLanguage( $extLanguages, $lang ); |
163 | | - } |
164 | | - } |
165 | | - |
166 | | - return $nErrors; |
167 | | -} |
168 | | - |
169 | | -/** |
170 | | - * Read the db file, parse it, start the check. |
171 | | - */ |
172 | | -function checkExtensionRepository( $extdir, $db ) { |
173 | | - $fh = fopen( $extdir. '/' . $db, 'r' ); |
174 | | - |
175 | | - $line_number = 0; |
176 | | - while( $line = fgets( $fh ) ) { |
177 | | - $line_number++; |
178 | | - |
179 | | - // Ignore comments |
180 | | - if( preg_match( '/^#/', $line ) ) { |
181 | | - continue; |
182 | | - } |
183 | | - |
184 | | - // Load data from i18n database |
185 | | - $data = split( ' ', chop($line) ); |
186 | | - $i18n_file = @$data[0]; |
187 | | - $arrayname = @$data[1]; |
188 | | - |
189 | | - print "------------------------------------------------------\n"; |
190 | | - print "Checking $i18n_file (\$$arrayname).\n"; |
191 | | - |
192 | | - // Check data |
193 | | - if( !file_exists( $extdir . '/' . $i18n_file ) ) { |
194 | | - print "ERROR> $i18n_file not found ($db:$line_number).\n"; |
195 | | - continue; |
196 | | - } |
197 | | -# if( $arrayname == '' ) { |
198 | | -# print "warning> no array name for $i18n_file ($db:$line_number).\n"; |
199 | | -# } |
200 | | - |
201 | | - $i18n_file = $extdir . '/' . $i18n_file ; |
202 | | - |
203 | | - global $myLang; |
204 | | - $nErrors = checkExtensionLanguage( $i18n_file, $arrayname, $myLang ); |
205 | | - if($nErrors == 1 ) { |
206 | | - print "\nFound $nErrors error for this extension.\n"; |
207 | | - } elseif($nErrors) { |
208 | | - print "\nFound $nErrors errors for this extension.\n"; |
209 | | - } else { |
210 | | - print "Looks OK.\n"; |
211 | | - } |
212 | | - |
213 | | - print "\n"; |
214 | | - } |
215 | | -} |
216 | | - |
217 | | - |
218 | | -function usage() { |
219 | | -// Usage |
220 | | -print <<<END |
221 | | -Usage: |
222 | | - php checkExtensioni18n.php <filename> <arrayname> |
223 | | - php checkExtensioni18n.php --extdir <extension repository> |
224 | | - |
225 | | -Common option: |
226 | | - --lang <language code> : only check the given language. |
227 | | - |
228 | | - |
229 | | -END; |
230 | | -die; |
231 | | -} |
232 | | - |
233 | | -// Play with options and arguments |
234 | | -$myLang = isset($options['lang']) ? $options['lang'] : null; |
235 | | - |
236 | | -if( isset( $options['extdir'] ) ) { |
237 | | - $extdb = $options['extdir'] . '/' . EXT_I18N_DB ; |
238 | | - |
239 | | - if( file_exists( $extdb ) ) { |
240 | | - checkExtensionRepository( $options['extdir'], EXT_I18N_DB ); |
241 | | - } else { |
242 | | - print "$extdb does not exist\n"; |
243 | | - } |
244 | | - |
245 | | -} else { |
246 | | - // Check arguments |
247 | | - if ( isset( $argv[0] ) ) { |
248 | | - |
249 | | - if (file_exists( $argv[0] ) ) { |
250 | | - $filename = $argv[0]; |
251 | | - } else { |
252 | | - print "Unable to open file '{$argv[0]}'\n"; |
253 | | - usage(); |
254 | | - } |
255 | | - |
256 | | - if ( isset( $argv[1] ) ) { |
257 | | - $arrayname = $argv[1]; |
258 | | - } else { |
259 | | - print "You must give an array name to be checked\n"; |
260 | | - usage(); |
261 | | - } |
262 | | - |
263 | | - global $myLang; |
264 | | - checkExtensionLanguage( $filename, $arrayname, $myLang ); |
265 | | - } else { |
266 | | - usage(); |
267 | | - } |
268 | | -} |
269 | | - |
270 | | - |
Index: trunk/phase3/maintenance/language/checkExtensions.php |
— | — | @@ -0,0 +1,269 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Copyright (C) 2007 Ashar Voultoiz <hashar@altern.org> |
| 5 | + * |
| 6 | + * Based on dumpBackup: |
| 7 | + * Copyright (C) 2005 Brion Vibber <brion@pobox.com> |
| 8 | + * |
| 9 | + * http://www.mediawiki.org |
| 10 | + * |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License along |
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | + * http://www.gnu.org/copyleft/gpl.html |
| 25 | + * |
| 26 | + * @addtogroup Maintenance |
| 27 | + */ |
| 28 | + |
| 29 | +# |
| 30 | +# Lacking documentation. Examples: |
| 31 | +# php checkExtensions.php /opt/mw/extensions/CentralAuth/CentralAuth.i18n.php wgCentralAuthMessages |
| 32 | +# php checkExtensions.php --extdir /opt/mw/extensions/ |
| 33 | +# |
| 34 | +# BUGS: cant guess registered extensions :) |
| 35 | +# TODO: let users set parameters to configure checklanguage.inc |
| 36 | + |
| 37 | +// Filename for the extension i18n files database: |
| 38 | +define( 'EXT_I18N_DB', 'i18n.db' ); |
| 39 | + |
| 40 | +$optionsWithArgs = array( 'extdir', 'lang' ); |
| 41 | + |
| 42 | +require_once( dirname(__FILE__).'/../commandLine.inc' ); |
| 43 | +require_once( 'languages.inc' ); |
| 44 | +require_once( 'checkLanguage.inc' ); |
| 45 | + |
| 46 | + |
| 47 | +class extensionLanguages extends languages { |
| 48 | + private $mExt18nFilename, $mExtArrayName ; |
| 49 | + private $mExtArray; |
| 50 | + |
| 51 | + function __construct( $ext18nFilename, $extArrayName ) { |
| 52 | + $this->mExt18nFilename = $ext18nFilename; |
| 53 | + $this->mExtArrayName = $extArrayName; |
| 54 | + |
| 55 | + $this->mIgnoredMessages = array(); |
| 56 | + $this->mOptionalMessages = array(); |
| 57 | + |
| 58 | + if ( file_exists( $this->mExt18nFilename ) ) { |
| 59 | + require_once( $this->mExt18nFilename ); |
| 60 | + |
| 61 | + $foundarray = false; |
| 62 | + if( isset( ${$this->mExtArrayName} ) ) { |
| 63 | + // File provided in the db file |
| 64 | + $foundarray = ${$this->mExtArrayName}; |
| 65 | + } else { |
| 66 | + |
| 67 | + /* For extensions included elsewhere. For some reason other extensions |
| 68 | + * break with the global statement, so recheck here. |
| 69 | + */ |
| 70 | + global ${$this->mExtArrayName}; |
| 71 | + if( is_array( ${$this->mExtArrayName} ) ) { |
| 72 | + $foundarray = ${$this->mExtArrayName}; |
| 73 | + } |
| 74 | + |
| 75 | + /* we might have been given a function name, test it too */ |
| 76 | + if( function_exists( $this->mExtArrayName ) ) { |
| 77 | + // Load data |
| 78 | + $funcName = $this->mExtArrayName ; |
| 79 | + $foundarray = $funcName(); |
| 80 | + } |
| 81 | + |
| 82 | + if(!$foundarray) { |
| 83 | + // Provided array could not be found we try to guess it. |
| 84 | + |
| 85 | + # Using the extension path ($m[1]) and filename ($m[2]): |
| 86 | + $m = array(); |
| 87 | + preg_match( '%.*/(.*)/(.*).i18n\.php%', $this->mExt18nFilename, $m); |
| 88 | + $arPathCandidate = 'wg' . $m[1].'Messages'; |
| 89 | + $arFileCandidate = 'wg' . $m[2].'Messages'; |
| 90 | + $funcCandidate = "ef{$m[2]}Messages"; |
| 91 | + |
| 92 | + // Try them: |
| 93 | + if( isset($$arPathCandidate) && is_array( $$arPathCandidate ) ) { |
| 94 | + print "warning> messages from guessed path array \$$arPathCandidate.\n"; |
| 95 | + $foundarray = $$arPathCandidate; |
| 96 | + } elseif( isset($$arFileCandidate) && is_array( $$arFileCandidate ) ) { |
| 97 | + print "warning> messages from guessed file array \$$arFileCandidate.\n"; |
| 98 | + $foundarray = $$arFileCandidate; |
| 99 | + } elseif( function_exists( $funcCandidate ) ) { |
| 100 | + print "warning> messages build from guessed function {$funcCandidate}().\n"; |
| 101 | + $foundarray = $funcCandidate(); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + # We are unlucky, return empty stuff |
| 106 | + if(!$foundarray) { |
| 107 | + print "ERROR> failed to guess an array to use.\n"; |
| 108 | + $this->mExtArray = null; |
| 109 | + $this->mLanguages = null; |
| 110 | + return; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + $this->mExtArray = $foundarray ; |
| 115 | + $this->mLanguages = array_keys( $this->mExtArray ); |
| 116 | + } else { |
| 117 | + wfDie( "File $this->mExt18nFilename not found\n" ); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + protected function loadRawMessages( $code ) { |
| 122 | + if ( isset( $this->mRawMessages[$code] ) ) { |
| 123 | + return; |
| 124 | + } |
| 125 | + if( isset( $this->mExtArray[$code] ) ) { |
| 126 | + $this->mRawMessages[$code] = $this->mExtArray[$code] ; |
| 127 | + } else { |
| 128 | + $this->mRawMessages[$code] = array(); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + public function getLanguages() { |
| 133 | + return $this->mLanguages; |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +/** |
| 138 | + * @param $filename Filename containing the extension i18n |
| 139 | + * @param $arrayname The name of the array in the filename |
| 140 | + * @param $filter Optional, restrict check to a given language code (default; null) |
| 141 | + */ |
| 142 | +function checkExtensionLanguage( $filename, $arrayname, $filter = null ) { |
| 143 | + $extLanguages = new extensionLanguages($filename, $arrayname); |
| 144 | + |
| 145 | + $langs = $extLanguages->getLanguages(); |
| 146 | + if( !$langs ) { |
| 147 | + print "ERROR> \$$arrayname array does not exist.\n"; |
| 148 | + return false; |
| 149 | + } |
| 150 | + |
| 151 | + $nErrors = 0; |
| 152 | + if( $filter ) { |
| 153 | + $nErrors += checkLanguage( $extLanguages, $filter ); |
| 154 | + } else { |
| 155 | + print "Will check ". count($langs) . " languages : " . implode(' ', $langs) .".\n"; |
| 156 | + foreach( $langs as $lang ) { |
| 157 | + if( $lang == 'en' ) { |
| 158 | + #print "Skipped english language\n"; |
| 159 | + continue; |
| 160 | + } |
| 161 | + |
| 162 | + $nErrors += checkLanguage( $extLanguages, $lang ); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + return $nErrors; |
| 167 | +} |
| 168 | + |
| 169 | +/** |
| 170 | + * Read the db file, parse it, start the check. |
| 171 | + */ |
| 172 | +function checkExtensionRepository( $extdir, $db ) { |
| 173 | + $fh = fopen( $extdir. '/' . $db, 'r' ); |
| 174 | + |
| 175 | + $line_number = 0; |
| 176 | + while( $line = fgets( $fh ) ) { |
| 177 | + $line_number++; |
| 178 | + |
| 179 | + // Ignore comments |
| 180 | + if( preg_match( '/^#/', $line ) ) { |
| 181 | + continue; |
| 182 | + } |
| 183 | + |
| 184 | + // Load data from i18n database |
| 185 | + $data = split( ' ', chop($line) ); |
| 186 | + $i18n_file = @$data[0]; |
| 187 | + $arrayname = @$data[1]; |
| 188 | + |
| 189 | + print "------------------------------------------------------\n"; |
| 190 | + print "Checking $i18n_file (\$$arrayname).\n"; |
| 191 | + |
| 192 | + // Check data |
| 193 | + if( !file_exists( $extdir . '/' . $i18n_file ) ) { |
| 194 | + print "ERROR> $i18n_file not found ($db:$line_number).\n"; |
| 195 | + continue; |
| 196 | + } |
| 197 | +# if( $arrayname == '' ) { |
| 198 | +# print "warning> no array name for $i18n_file ($db:$line_number).\n"; |
| 199 | +# } |
| 200 | + |
| 201 | + $i18n_file = $extdir . '/' . $i18n_file ; |
| 202 | + |
| 203 | + global $myLang; |
| 204 | + $nErrors = checkExtensionLanguage( $i18n_file, $arrayname, $myLang ); |
| 205 | + if($nErrors == 1 ) { |
| 206 | + print "\nFound $nErrors error for this extension.\n"; |
| 207 | + } elseif($nErrors) { |
| 208 | + print "\nFound $nErrors errors for this extension.\n"; |
| 209 | + } else { |
| 210 | + print "Looks OK.\n"; |
| 211 | + } |
| 212 | + |
| 213 | + print "\n"; |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | + |
| 218 | +function usage() { |
| 219 | +// Usage |
| 220 | +print <<<END |
| 221 | +Usage: |
| 222 | + php checkExtensioni18n.php <filename> <arrayname> |
| 223 | + php checkExtensioni18n.php --extdir <extension repository> |
| 224 | + |
| 225 | +Common option: |
| 226 | + --lang <language code> : only check the given language. |
| 227 | + |
| 228 | + |
| 229 | +END; |
| 230 | +die; |
| 231 | +} |
| 232 | + |
| 233 | +// Play with options and arguments |
| 234 | +$myLang = isset($options['lang']) ? $options['lang'] : null; |
| 235 | + |
| 236 | +if( isset( $options['extdir'] ) ) { |
| 237 | + $extdb = $options['extdir'] . '/' . EXT_I18N_DB ; |
| 238 | + |
| 239 | + if( file_exists( $extdb ) ) { |
| 240 | + checkExtensionRepository( $options['extdir'], EXT_I18N_DB ); |
| 241 | + } else { |
| 242 | + print "$extdb does not exist\n"; |
| 243 | + } |
| 244 | + |
| 245 | +} else { |
| 246 | + // Check arguments |
| 247 | + if ( isset( $argv[0] ) ) { |
| 248 | + |
| 249 | + if (file_exists( $argv[0] ) ) { |
| 250 | + $filename = $argv[0]; |
| 251 | + } else { |
| 252 | + print "Unable to open file '{$argv[0]}'\n"; |
| 253 | + usage(); |
| 254 | + } |
| 255 | + |
| 256 | + if ( isset( $argv[1] ) ) { |
| 257 | + $arrayname = $argv[1]; |
| 258 | + } else { |
| 259 | + print "You must give an array name to be checked\n"; |
| 260 | + usage(); |
| 261 | + } |
| 262 | + |
| 263 | + global $myLang; |
| 264 | + checkExtensionLanguage( $filename, $arrayname, $myLang ); |
| 265 | + } else { |
| 266 | + usage(); |
| 267 | + } |
| 268 | +} |
| 269 | + |
| 270 | + |
Property changes on: trunk/phase3/maintenance/language/checkExtensions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 271 | + native |