Revert r72959
[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'], 'php' ) ) {
22 $runMode = 'php';
23 } else if ( !strcmp( $options['mode'], 'raw' ) ) {
24 $runMode = 'raw';
25 } else {
26 }
27 }
28 $runTest = true;
29 } else {
30 echo <<<TEXT
31 Run this script to print out the duplicates against a message array.
32 Parameters:
33 * lang: Language code to be checked.
34 * clang: Language code to be compared.
35 Options:
36 * mode: Output format, can be either:
37 * text: Text output on the console (default)
38 * wiki: Wiki format, with * at beginning of each line
39 * php: Output text as PHP syntax in a array $dupeMessages
40 * raw: Raw output for duplicates
41 TEXT;
42 }
43
44 // Check file exists
45 if ( $runTest ) {
46 $langCode = $options['lang'];
47 $langCodeC = $options['clang'];
48 $langCodeF = ucfirst( strtolower( preg_replace( '/-/', '_', $langCode ) ) );
49 $langCodeFC = ucfirst( strtolower( preg_replace( '/-/', '_', $langCodeC ) ) );
50 $messagesFile = $messagesDir . 'Messages' . $langCodeF . '.php';
51 $messagesFileC = $messagesDir . 'Messages' . $langCodeFC . '.php';
52 if ( file_exists( $messagesFile ) && file_exists( $messagesFileC ) ) {
53 $run = true;
54 }
55 else {
56 echo "Messages file(s) could not be found.\nMake sure both files are exists.\n";
57 }
58 }
59
60 // Run to check the dupes
61 if ( $run ) {
62 if ( !strcmp( $runMode, 'wiki' ) ) {
63 $runMode = 'wiki';
64 } else if ( !strcmp( $runMode, 'raw' ) ) {
65 $runMode = 'raw';
66 }
67 include( $messagesFile );
68 $messageExist = isset( $messages );
69 if ( $messageExist )
70 $wgMessages[$langCode] = $messages;
71 include( $messagesFileC );
72 $messageCExist = isset( $messages );
73 if ( $messageCExist )
74 $wgMessages[$langCodeC] = $messages;
75 $count = 0;
76
77 if ( ( $messageExist ) && ( $messageCExist ) ) {
78
79 if ( !strcmp( $runMode, 'php' ) ) {
80 print( "<?php\n" );
81 print( '$dupeMessages = array(' . "\n" );
82 }
83 foreach ( $wgMessages[$langCodeC] as $key => $value ) {
84 foreach ( $wgMessages[$langCode] as $ckey => $cvalue ) {
85 if ( !strcmp( $key, $ckey ) ) {
86 if ( ( !strcmp( $key, $ckey ) ) && ( !strcmp( $value, $cvalue ) ) ) {
87 if ( !strcmp( $runMode, 'raw' ) ) {
88 print( "$key\n" );
89 } else if ( !strcmp( $runMode, 'php' ) ) {
90 print( "'$key' => '',\n" );
91 } else if ( !strcmp( $runMode, 'wiki' ) ) {
92 $uKey = ucfirst( $key );
93 print( "* MediaWiki:$uKey/$langCode\n" );
94 } else {
95 print( "* $key\n" );
96 }
97 $count++;
98 }
99 }
100 }
101 }
102 if ( !strcmp( $runMode, 'php' ) ) {
103 print( ");\n" );
104 }
105 if ( !strcmp( $runMode, 'text' ) ) {
106 if ( $count == 1 ) {
107 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n";
108 } else {
109 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n";
110 }
111 }
112 } else {
113 if ( !$messageExist )
114 echo "There are no messages defined in $langCode.\n";
115 if ( !$messageCExist )
116 echo "There are no messages defined in $langCodeC.\n";
117 }
118 }