MediaWiki
REL1_22
|
00001 <?php 00024 require_once __DIR__ . '/../commandLine.inc'; 00025 $messagesDir = __DIR__ . '/../../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 an array named \$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 } 00088 include $messagesFileC; 00089 $messageCExist = isset( $messages ); 00090 if ( $messageCExist ) { 00091 $wgMessages[$langCodeC] = $messages; 00092 } 00093 $count = 0; 00094 00095 if ( ( $messageExist ) && ( $messageCExist ) ) { 00096 00097 if ( !strcmp( $runMode, 'php' ) ) { 00098 print "<?php\n"; 00099 print '$dupeMessages = array(' . "\n"; 00100 } 00101 foreach ( $wgMessages[$langCodeC] as $key => $value ) { 00102 foreach ( $wgMessages[$langCode] as $ckey => $cvalue ) { 00103 if ( !strcmp( $key, $ckey ) ) { 00104 if ( ( !strcmp( $key, $ckey ) ) && ( !strcmp( $value, $cvalue ) ) ) { 00105 if ( !strcmp( $runMode, 'raw' ) ) { 00106 print "$key\n"; 00107 } elseif ( !strcmp( $runMode, 'php' ) ) { 00108 print "'$key' => '',\n"; 00109 } elseif ( !strcmp( $runMode, 'wiki' ) ) { 00110 $uKey = ucfirst( $key ); 00111 print "* MediaWiki:$uKey/$langCode\n"; 00112 } else { 00113 print "* $key\n"; 00114 } 00115 $count++; 00116 } 00117 } 00118 } 00119 } 00120 if ( !strcmp( $runMode, 'php' ) ) { 00121 print ");\n"; 00122 } 00123 if ( !strcmp( $runMode, 'text' ) ) { 00124 if ( $count == 1 ) { 00125 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n"; 00126 } else { 00127 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n"; 00128 } 00129 } 00130 } else { 00131 if ( !$messageExist ) { 00132 echo "There are no messages defined in $langCode.\n"; 00133 } 00134 if ( !$messageCExist ) { 00135 echo "There are no messages defined in $langCodeC.\n"; 00136 } 00137 } 00138 }