MediaWiki  REL1_24
checkDupeMessages.php
Go to the documentation of this file.
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     } else {
00071         echo "Messages file(s) could not be found.\nMake sure both files are exists.\n";
00072     }
00073 }
00074 
00075 // Run to check the dupes
00076 if ( $run ) {
00077     if ( !strcmp( $runMode, 'wiki' ) ) {
00078         $runMode = 'wiki';
00079     } elseif ( !strcmp( $runMode, 'raw' ) ) {
00080         $runMode = 'raw';
00081     }
00082     include $messagesFile;
00083     $messageExist = isset( $messages );
00084     if ( $messageExist ) {
00085         $wgMessages[$langCode] = $messages;
00086     }
00087     include $messagesFileC;
00088     $messageCExist = isset( $messages );
00089     if ( $messageCExist ) {
00090         $wgMessages[$langCodeC] = $messages;
00091     }
00092     $count = 0;
00093 
00094     if ( ( $messageExist ) && ( $messageCExist ) ) {
00095 
00096         if ( !strcmp( $runMode, 'php' ) ) {
00097             print "<?php\n";
00098             print '$dupeMessages = array(' . "\n";
00099         }
00100         foreach ( $wgMessages[$langCodeC] as $key => $value ) {
00101             foreach ( $wgMessages[$langCode] as $ckey => $cvalue ) {
00102                 if ( !strcmp( $key, $ckey ) ) {
00103                     if ( ( !strcmp( $key, $ckey ) ) && ( !strcmp( $value, $cvalue ) ) ) {
00104                         if ( !strcmp( $runMode, 'raw' ) ) {
00105                             print "$key\n";
00106                         } elseif ( !strcmp( $runMode, 'php' ) ) {
00107                             print "'$key' => '',\n";
00108                         } elseif ( !strcmp( $runMode, 'wiki' ) ) {
00109                             $uKey = ucfirst( $key );
00110                             print "* MediaWiki:$uKey/$langCode\n";
00111                         } else {
00112                             print "* $key\n";
00113                         }
00114                         $count++;
00115                     }
00116                 }
00117             }
00118         }
00119         if ( !strcmp( $runMode, 'php' ) ) {
00120             print ");\n";
00121         }
00122         if ( !strcmp( $runMode, 'text' ) ) {
00123             if ( $count == 1 ) {
00124                 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n";
00125             } else {
00126                 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n";
00127             }
00128         }
00129     } else {
00130         if ( !$messageExist ) {
00131             echo "There are no messages defined in $langCode.\n";
00132         }
00133         if ( !$messageCExist ) {
00134             echo "There are no messages defined in $langCodeC.\n";
00135         }
00136     }
00137 }