00001 <?php
00002 # MediaWiki web-based config/installation
00003 # Copyright (C) 2004 Ashar Voultoiz <thoane@altern.org> and others
00004 # http://www.mediawiki.org/
00005 #
00006 # This program is free software; you can redistribute it and/or modify
00007 # it under the terms of the GNU General Public License as published by
00008 # the Free Software Foundation; either version 2 of the License, or
00009 # (at your option) any later version.
00010 #
00011 # This program is distributed in the hope that it will be useful,
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014 # GNU General Public License for more details.
00015 #
00016 # You should have received a copy of the GNU General Public License along
00017 # with this program; if not, write to the Free Software Foundation, Inc.,
00018 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 # http://www.gnu.org/copyleft/gpl.html
00020
00043 require_once( dirname(__FILE__).'/../parserTests.inc' );
00044 require_once( dirname(__FILE__).'/../commandLine.inc' );
00045
00046 if( isset($options['help']) ) { usage(); wfDie(); }
00047
00048 $wgLanguageCode = ucfirstlcrest($wgLanguageCode);
00050 $referenceMessages = $wgAllMessagesEn;
00051 $referenceLanguage = 'En';
00052 $referenceFilename = 'Language'.$referenceLanguage.'.php';
00054 $testMessages = array();
00055 $testLanguage = '';
00057 $externalRef = false;
00058
00059 # FUNCTIONS
00060
00061 function usage() {
00062 echo 'php DiffLanguage.php [lang [file]] [--color=(yes|no|light)]'."\n";
00063 }
00064
00066 function ucfirstlcrest($string) {
00067 return strtoupper(substr($string,0,1)).strtolower(substr($string,1));
00068 }
00069
00075 function getMediawikiMessages($languageCode = 'En') {
00076
00077 $foo = "wgAllMessages$languageCode";
00078 global $$foo;
00079 global $wgSkinNamesEn;
00080
00081
00082 if(!isset($$foo)) {
00083 global $IP;
00084 $langFile = $IP.'/languages/classes/Language'.$languageCode.'.php';
00085 if (file_exists( $langFile ) ) {
00086 print "Including $langFile\n";
00087 include($langFile);
00088 } else wfDie("ERROR: The file $langFile does not exist !\n");
00089 }
00090 return $$foo;
00091 }
00092
00100 function getExternalMessages($filename, $languageCode) {
00101 print "Including external file $filename.\n";
00102 include($filename);
00103 $foo = "wgAllMessages$languageCode";
00104 return $$foo;
00105 }
00106
00107 # MAIN ENTRY
00108 if ( isset($args[0]) ) {
00109 $lang = ucfirstlcrest($args[0],1);
00110
00111
00112
00113 if( isset($args[1])) {
00114
00115
00116 $referenceMessages = getExternalMessages( $args[1], $lang );
00117 $referenceLanguage = $lang;
00118 $referenceFilename = $args[1];
00119 $externalRef = true;
00120 }
00121
00122
00123 $testMessages = getMediawikiMessages($lang);
00124 $testLanguage = $lang;
00125 } else {
00126 usage();
00127 wfDie();
00128 }
00129
00131 $myParserTest = new ParserTest();
00132
00133 # Get all references messages and check if they exist in the tested language
00134 $i = 0;
00135
00136 $msg = "MW Language{$testLanguage}.php against ";
00137 if($externalRef) { $msg .= 'external file '; }
00138 else { $msg .= 'internal file '; }
00139 $msg .= $referenceFilename.' ('.$referenceLanguage."):\n----\n";
00140 echo $msg;
00141
00142
00143 foreach($referenceMessages as $index => $ref)
00144 {
00145
00146 if(!(isset($testMessages[$index]))) {
00147 $i++;
00148 print "'$index' => \"$ref\",\n";
00149
00150 } elseif( ($lang == $referenceLanguage) AND ($testMessages[$index] != $ref)) {
00151 print "\n$index differs:\n";
00152 print $myParserTest->quickDiff($testMessages[$index],$ref,'tested','reference');
00153 }
00154 }
00155
00156 echo "\n----\n".$msg;
00157 echo "$referenceLanguage language is complete at ".number_format((100 - $i/count($wgAllMessagesEn) * 100),2)."%\n";
00158 echo "$i unlocalised messages of the ".count($wgAllMessagesEn)." messages available.\n";
00159