dd5ed521bb2d62ff441bd232b2d03d0c59fa59df
3 * Copyright (C) 2007 Ashar Voultoiz <hashar@altern.org>
6 * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
8 * http://www.mediawiki.org
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @addtogroup SpecialPage
29 # Lacking documentation. Examples:
30 # php checkExtensioni18n.php /opt/mw/extensions/CentralAuth/CentralAuth.i18n.php wgCentralAuthMessages
31 # php checkExtensioni18n.php --extdir /opt/mw/extensions/
33 # BUGS: cant guess registered extensions :)
34 # TODO: let users set parameters to configure checklanguage.inc (it uses globals)
36 // Filename for the extension i18n files database:
37 define( 'EXT_I18N_DB', 'i18n.db' );
39 // Global parameters for checkLanguage.inc
41 $wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
43 $optionsWithArgs = array( 'extdir' );
45 require_once( dirname(__FILE__
).'/../commandLine.inc' );
46 require_once( 'languages.inc' );
47 require_once( 'checkLanguage.inc' );
50 class extensionLanguages
extends languages
{
51 private $mExt18nFilename, $mExtArrayName ;
54 function __construct( $ext18nFilename, $extArrayName ) {
55 $this->mExt18nFilename
= $ext18nFilename;
56 $this->mExtArrayName
= $extArrayName;
58 $this->mIgnoredMessages
= array();
59 $this->mOptionalMessages
= array();
61 if ( file_exists( $this->mExt18nFilename
) ) {
62 require_once( $this->mExt18nFilename
);
65 if( isset( $
{$this->mExtArrayName
} ) ) {
66 // File provided in the db file
67 $foundarray = $
{$this->mExtArrayName
};
70 /* For extensions included elsewhere. For some reason other extensions
71 * break with the global statement, so recheck here.
73 global $
{$this->mExtArrayName
};
74 if( isset( $
{$this->mExtArrayName
} ) ) {
75 $foundarray = $
{$this->mExtArrayName
};
79 // Provided array could not be found we try to guess it.
81 # Using the extension path ($m[1]) and filename ($m[2]):
83 preg_match( '%.*/(.*)/(.*).i18n\.php%', $this->mExt18nFilename
, $m);
84 $arPathCandidate = 'wg' . $m[1].'Messages';
85 $arFileCandidate = 'wg' . $m[2].'Messages';
86 $funcCandidate = "ef{$m[2]}Messages";
89 if( isset($
$arPathCandidate) && is_array( $
$arPathCandidate ) ) {
90 print "warning> messages from guessed path array \$$arPathCandidate.\n";
91 $foundarray = $
$arPathCandidate;
92 } elseif( isset($
$arFileCandidate) && is_array( $
$arFileCandidate ) ) {
93 print "warning> messages from guessed file array \$$arFileCandidate.\n";
94 $foundarray = $
$arFileCandidate;
95 } elseif( function_exists( $funcCandidate ) ) {
96 print "warning> messages build from guessed function {$funcCandidate}().\n";
97 $foundarray = $funcCandidate();
101 # We are unlucky, return empty stuff
103 print "ERROR> failed to guess an array to use.\n";
104 $this->mExtArray
= null;
105 $this->mLanguages
= null;
110 $this->mExtArray
= $foundarray ;
111 $this->mLanguages
= array_keys( $this->mExtArray
);
113 wfDie( "File $this->mExt18nFilename not found\n" );
117 protected function loadRawMessages( $code ) {
118 if ( isset( $this->mRawMessages
[$code] ) ) {
121 if( isset( $this->mExtArray
[$code] ) ) {
122 $this->mRawMessages
[$code] = $this->mExtArray
[$code] ;
124 $this->mRawMessages
[$code] = array();
128 public function getLanguages() {
129 return $this->mLanguages
;
134 function checkExtensionLanguage( $filename, $arrayname ) {
135 global $wgGeneralMessages, $wgRequiredMessagesNumber;
137 $extLanguages = new extensionLanguages($filename, $arrayname);
139 // Stuff needed by the checkLanguage routine (globals)
140 $wgGeneralMessages = $extLanguages->getGeneralMessages();
141 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
143 $langs = $extLanguages->getLanguages();
145 print "ERROR> \$$arrayname array does not exist.\n";
149 print "Found ". count($langs) . " languages : " . implode(' ', $langs) ."\n";
150 foreach( $langs as $lang ) {
151 if( $lang == 'en' ) {
152 #print "Skipped english language\n";
156 checkLanguage( $extLanguages, $lang );
160 function checkExtensionRepository( $extdir, $db ) {
161 $fh = fopen( $extdir. '/' . $db, 'r' );
164 while( $line = fgets( $fh ) ) {
168 if( preg_match( '/^#/', $line ) ) {
172 // Load data from i18n database
173 $data = split( ' ', chop($line) );
174 $i18n_file = @$data[0];
175 $arrayname = @$data[1];
177 print "------------------------------------------------------\n";
178 print "Checking $i18n_file (\$$arrayname).\n";
181 if( !file_exists( $extdir . '/' . $i18n_file ) ) {
182 print "ERROR> $i18n_file not found ($db:$line_number).\n";
185 # if( $arrayname == '' ) {
186 # print "warning> no array name for $i18n_file ($db:$line_number).\n";
189 $i18n_file = $extdir . '/' . $i18n_file ;
191 checkExtensionLanguage( $i18n_file, $arrayname );
202 php checkExtensioni18n.php <filename> <arrayname>
203 php checkExtensioni18n.php --extdir <exstention repository>
210 // Play with options and arguments
211 if( isset( $options['extdir'] ) ) {
212 $extdb = $options['extdir'] . '/' . EXT_I18N_DB
;
214 if( file_exists( $extdb ) ) {
215 checkExtensionRepository( $options['extdir'], EXT_I18N_DB
);
217 print "$extdb does not exist\n";
222 if ( isset( $argv[0] ) ) {
224 if (file_exists( $argv[0] ) ) {
225 $filename = $argv[0];
227 print "Unable to open file '{$argv[0]}'\n";
231 if ( isset( $argv[1] ) ) {
232 $arrayname = $argv[1];
234 print "You must give an array name to be checked\n";
238 checkExtensionLanguage( $filename, $arrayname );