3 * Print out duplicates in message array
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup MaintenanceLanguage
24 require_once __DIR__
. '/../commandLine.inc';
25 $messagesDir = __DIR__
. '/../../languages/messages/';
31 if ( isset( $options['lang'] ) && isset( $options['clang'] ) ) {
32 if ( !isset( $options['mode'] ) ) {
35 if ( !strcmp( $options['mode'], 'wiki' ) ) {
37 } elseif ( !strcmp( $options['mode'], 'php' ) ) {
39 } elseif ( !strcmp( $options['mode'], 'raw' ) ) {
47 Run this script to print out the duplicates against a message array.
49 * lang: Language code to be checked.
50 * clang: Language code to be compared.
52 * mode: Output format, can be either:
53 * text: Text output on the console (default)
54 * wiki: Wiki format, with * at beginning of each line
55 * php: Output text as PHP syntax in an array named \$dupeMessages
56 * raw: Raw output for duplicates
62 $langCode = $options['lang'];
63 $langCodeC = $options['clang'];
64 $langCodeF = ucfirst( strtolower( preg_replace( '/-/', '_', $langCode ) ) );
65 $langCodeFC = ucfirst( strtolower( preg_replace( '/-/', '_', $langCodeC ) ) );
66 $messagesFile = $messagesDir . 'Messages' . $langCodeF . '.php';
67 $messagesFileC = $messagesDir . 'Messages' . $langCodeFC . '.php';
68 if ( file_exists( $messagesFile ) && file_exists( $messagesFileC ) ) {
71 echo "Messages file(s) could not be found.\nMake sure both files are exists.\n";
75 // Run to check the dupes
77 if ( !strcmp( $runMode, 'wiki' ) ) {
79 } elseif ( !strcmp( $runMode, 'raw' ) ) {
82 include $messagesFile;
83 $messageExist = isset( $messages );
84 if ( $messageExist ) {
85 $wgMessages[$langCode] = $messages;
87 include $messagesFileC;
88 $messageCExist = isset( $messages );
89 if ( $messageCExist ) {
90 $wgMessages[$langCodeC] = $messages;
94 if ( ( $messageExist ) && ( $messageCExist ) ) {
96 if ( !strcmp( $runMode, 'php' ) ) {
98 print '$dupeMessages = array(' . "\n";
100 foreach ( $wgMessages[$langCodeC] as $key => $value ) {
101 foreach ( $wgMessages[$langCode] as $ckey => $cvalue ) {
102 if ( !strcmp( $key, $ckey ) ) {
103 if ( ( !strcmp( $key, $ckey ) ) && ( !strcmp( $value, $cvalue ) ) ) {
104 if ( !strcmp( $runMode, 'raw' ) ) {
106 } elseif ( !strcmp( $runMode, 'php' ) ) {
107 print "'$key' => '',\n";
108 } elseif ( !strcmp( $runMode, 'wiki' ) ) {
109 $uKey = ucfirst( $key );
110 print "* MediaWiki:$uKey/$langCode\n";
119 if ( !strcmp( $runMode, 'php' ) ) {
122 if ( !strcmp( $runMode, 'text' ) ) {
124 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n";
126 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n";
130 if ( !$messageExist ) {
131 echo "There are no messages defined in $langCode.\n";
133 if ( !$messageCExist ) {
134 echo "There are no messages defined in $langCodeC.\n";