941fb5390c44683fa2a6de06415444ea56e098ee
[lhc/web/wiklou.git] / maintenance / language / checkDupeMessages.php
1 <?php
2 /**
3 * @todo document
4 * @file
5 * @ingroup MaintenanceLanguage
6 */
7
8 require_once( dirname(__FILE__).'/../commandLine.inc' );
9 $messagesDir = dirname(__FILE__).'/../../languages/messages/';
10 $runTest = false;
11 $run = false;
12 $runMode = 'text';
13
14 // Check parameters
15 if ( isset( $options['lang'] ) && isset( $options['clang'] )) {
16 if (!isset( $options['mode'] )) {
17 $runMode = 'text';
18 } else {
19 if (!strcmp($options['mode'],'wiki')) {
20 $runMode = 'wiki';
21 } else if (!strcmp($options['mode'],'raw')) {
22 $runMode = 'raw';
23 } else {
24 }
25 }
26 $runTest = true;
27 } else {
28 echo <<<END
29 Run this script to print out the duplicates against a message array.
30 Parameters:
31 * lang: Language code to be checked.
32 * clang: Language code to be compared.
33 Options:
34 * mode: Output format, can be either:
35 * text: Text output on the console (default)
36 * wiki: Wiki format, with * at beginning of each line
37 * raw: Raw output for duplicates
38 END;
39 }
40
41 // Check file exists
42 if ( $runTest ) {
43 $langCode = ucfirst(strtolower(preg_replace('/-/','_',$options['lang'])));
44 $langCodeC = ucfirst(strtolower(preg_replace('/-/','_',$options['clang'])));
45 $messagesFile = $messagesDir.'Messages'.$langCode.'.php';
46 $messagesFileC = $messagesDir.'Messages'.$langCodeC.'.php';
47 print("$messagesFile\n$messagesFileC\n");
48 if (file_exists($messagesFile) && file_exists($messagesFileC)) {
49 $run = true;
50 }
51 else {
52 echo "Languages file(s) could not found.\nMake sure both files are exists.\n";
53 }
54 }
55
56 // Run to check the dupes
57 if ( $run ) {
58 if (!strcmp($runMode,'wiki')) {
59 $runMode = 'wiki';
60 } else if (!strcmp($runMode,'raw')) {
61 $runMode = 'raw';
62 }
63 include( $messagesFile );
64 $wgMessages[$langCode] = $messages;
65 include( $messagesFileC );
66 $wgMessages[$langCodeC] = $messages;
67 $count = 0;
68
69 foreach ($wgMessages[$langCodeC] as $key => $value) {
70 foreach ($wgMessages[$langCode] as $ckey => $cvalue) {
71 if (!strcmp($key,$ckey)) {
72 if (!strcmp($value,$cvalue)) {
73 if (!strcmp($runMode,'raw')) {
74 print("$key\n");
75 } else if (!strcmp($runMode,'wiki')) {
76 $uKey = ucfirst($key);
77 print("* MediaWiki:$uKey/$langCode\n");
78 } else {
79 print("* $key\n");
80 }
81 $count++;
82 }
83 }
84 }
85 }
86 if (!strcmp($runMode,'text')) {
87 echo "\nThere are $count duplicates messages in ".$options['lang'].", against to ".$options['clang']."\n";
88 }
89 }