MediaWiki  REL1_19
checkDupeMessages.php
Go to the documentation of this file.
00001 <?php
00024 require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
00025 $messagesDir = dirname( __FILE__ ) . '/../../languages/messages/';
00026 $runTest = false;
00027 $run = false;
00028 $runMode = 'text';
00029 
00030 // Check parameters
00031 if ( isset( $options['lang'] ) && isset( $options['clang'] ) ) {
00032         if ( !isset( $options['mode'] ) ) {
00033                 $runMode = 'text';
00034         } else {
00035                 if ( !strcmp( $options['mode'], 'wiki' ) ) {
00036                         $runMode = 'wiki';
00037                 } elseif ( !strcmp( $options['mode'], 'php' ) ) {
00038                         $runMode = 'php';
00039                 } elseif ( !strcmp( $options['mode'], 'raw' ) ) {
00040                         $runMode = 'raw';
00041                 } else {
00042                 }
00043         }
00044         $runTest = true;
00045 } else {
00046         echo <<<TEXT
00047 Run this script to print out the duplicates against a message array.
00048 Parameters:
00049         * lang:  Language code to be checked.
00050         * clang: Language code to be compared.
00051 Options:
00052         * mode:  Output format, can be either:
00053                 * text:   Text output on the console (default)
00054                 * wiki:   Wiki format, with * at beginning of each line
00055                 * php:    Output text as PHP syntax in a array $dupeMessages
00056                 * raw:    Raw output for duplicates
00057 TEXT;
00058 }
00059 
00060 // Check file exists
00061 if ( $runTest ) {
00062         $langCode = $options['lang'];
00063         $langCodeC = $options['clang'];
00064         $langCodeF = ucfirst( strtolower( preg_replace( '/-/', '_', $langCode ) ) );
00065         $langCodeFC = ucfirst( strtolower( preg_replace( '/-/', '_', $langCodeC ) ) );
00066         $messagesFile = $messagesDir . 'Messages' . $langCodeF . '.php';
00067         $messagesFileC = $messagesDir . 'Messages' . $langCodeFC . '.php';
00068         if ( file_exists( $messagesFile ) && file_exists( $messagesFileC ) ) {
00069                 $run = true;
00070         }
00071         else {
00072                 echo "Messages file(s) could not be found.\nMake sure both files are exists.\n";
00073         }
00074 }
00075 
00076 // Run to check the dupes
00077 if ( $run ) {
00078         if ( !strcmp( $runMode, 'wiki' ) ) {
00079                 $runMode = 'wiki';
00080         } elseif ( !strcmp( $runMode, 'raw' ) ) {
00081                 $runMode = 'raw';
00082         }
00083         include( $messagesFile );
00084         $messageExist = isset( $messages );
00085         if ( $messageExist )
00086                 $wgMessages[$langCode] = $messages;
00087         include( $messagesFileC );
00088         $messageCExist = isset( $messages );
00089         if ( $messageCExist )
00090                 $wgMessages[$langCodeC] = $messages;
00091         $count = 0;
00092 
00093         if ( ( $messageExist ) && ( $messageCExist ) ) {
00094 
00095                 if ( !strcmp( $runMode, 'php' ) ) {
00096                         print( "<?php\n" );
00097                         print( '$dupeMessages = array(' . "\n" );
00098                 }
00099                 foreach ( $wgMessages[$langCodeC] as $key => $value ) {
00100                         foreach ( $wgMessages[$langCode] as $ckey => $cvalue ) {
00101                                 if ( !strcmp( $key, $ckey ) ) {
00102                                         if ( ( !strcmp( $key, $ckey ) ) && ( !strcmp( $value, $cvalue ) ) ) {
00103                                                 if ( !strcmp( $runMode, 'raw' ) ) {
00104                                                         print( "$key\n" );
00105                                                 } elseif ( !strcmp( $runMode, 'php' ) ) {
00106                                                         print( "'$key' => '',\n" );
00107                                                 } elseif ( !strcmp( $runMode, 'wiki' ) ) {
00108                                                         $uKey = ucfirst( $key );
00109                                                         print( "* MediaWiki:$uKey/$langCode\n" );
00110                                                 } else {
00111                                                         print( "* $key\n" );
00112                                                 }
00113                                                 $count++;
00114                                         }
00115                                 }
00116                         }
00117                 }
00118                 if ( !strcmp( $runMode, 'php' ) ) {
00119                         print( ");\n" );
00120                 }
00121                 if ( !strcmp( $runMode, 'text' ) ) {
00122                         if ( $count == 1 ) {
00123                                 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n";
00124                         } else {
00125                                 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n";
00126                         }
00127                 }
00128         } else {
00129                 if ( !$messageExist )
00130                         echo "There are no messages defined in $langCode.\n";
00131                 if ( !$messageCExist )
00132                         echo "There are no messages defined in $langCodeC.\n";
00133         }
00134 }