r50959 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50958‎ | r50959 | r50960 >
Date:14:21, 24 May 2009
Author:shinjiman
Status:deferred
Tags:
Comment:
added functionality to removing a array key specified on a source file in the rebuildLanguage.php, to incorporate the functionality of the checkDupeMessages.php file.
Modified paths:
  • /trunk/phase3/maintenance/language/rebuildLanguage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/rebuildLanguage.php
@@ -18,14 +18,46 @@
1919 * @param $write Write to the messages file?
2020 * @param $listUnknown List the unknown messages?
2121 * @param $removeUnKnown Remove the unknown messages?
 22+ * @param $removeDupes Remove the duplicated messages?
 23+ * @param $dupeMsgSource The source file intended to remove from the array.
2224 */
23 -function rebuildLanguage( $code, $write, $listUnknown, $removeUnknown ) {
 25+function rebuildLanguage( $code, $write, $listUnknown, $removeUnknown, $removeDupes, $dupeMsgSource ) {
2426 global $wgLanguages;
2527 $messages = $wgLanguages->getMessages( $code );
2628 $messages = $messages['all'];
 29+ if ($removeDupes) {
 30+ $messages = removeDupes( $messages, $dupeMsgSource );
 31+ }
2732 MessageWriter::writeMessagesToFile( $messages, $code, $write, $listUnknown, $removeUnknown );
2833 }
2934
 35+/**
 36+ * Remove duplicates from a message array.
 37+ *
 38+ * @param $oldMsgArray The input message array.
 39+ * @param $dupeMsgSource The source file path for duplicates.
 40+ * @return $newMsgArray The output message array, with duplicates removed.
 41+ */
 42+function removeDupes( $oldMsgArray, $dupeMsgSource ) {
 43+ if (file_exists($dupeMsgSource)) {
 44+ include($dupeMsgSource);
 45+ if (!isset($dupeMessages)) {
 46+ echo("There are no duplicated messages in the source file provided.");
 47+ exit(1);
 48+ }
 49+ } else {
 50+ echo ("The specified file $dupeMsgSource cannot be found.");
 51+ exit(1);
 52+ }
 53+ $newMsgArray = $oldMsgArray;
 54+ foreach ($oldMsgArray as $key => $value) {
 55+ if ( array_key_exists( $key, $dupeMessages ) ) {
 56+ unset($newMsgArray[$key]);
 57+ }
 58+ }
 59+ return $newMsgArray;
 60+}
 61+
3062 # Show help
3163 if ( isset( $options['help'] ) ) {
3264 echo <<<END
@@ -37,6 +69,7 @@
3870 * dry-run: Do not write the array to the file.
3971 * no-unknown: Do not list the unknown messages.
4072 * remove-unknown: Remove unknown messages.
 73+ * remove-duplicates: Remove duplicated messages based on a PHP source file.
4174
4275 END;
4376 exit(1);
@@ -49,10 +82,18 @@
5083 $wgCode = $wgContLang->getCode();
5184 }
5285
 86+# Get the duplicate message source
 87+if ( isset( $options['remove-duplicates'] ) && ( strcmp( $options['remove-duplicates'], '' ) ) ) {
 88+ $wgDupeMessageSource = $options['remove-duplicates'];
 89+} else {
 90+ $wgDupeMessageSource = '';
 91+}
 92+
5393 # Get the options
5494 $wgWriteToFile = !isset( $options['dry-run'] );
5595 $wgListUnknownMessages = !isset( $options['no-unknown'] );
5696 $wgRemoveUnknownMessages = isset( $options['remove-unknown'] );
 97+$wgRemoveDuplicateMessages = isset( $options['remove-duplicates'] );
5798
5899 # Get language objects
59100 $wgLanguages = new languages();
@@ -60,8 +101,8 @@
61102 # Write all the language
62103 if ( $wgCode == 'all' ) {
63104 foreach ( $wgLanguages->getLanguages() as $language ) {
64 - rebuildLanguage( $language, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages );
 105+ rebuildLanguage( $language, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages, $wgRemoveDuplicateMessages, $wgDupeMessageSource );
65106 }
66107 } else {
67 - rebuildLanguage( $wgCode, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages );
 108+ rebuildLanguage( $wgCode, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages, $wgRemoveDuplicateMessages, $wgDupeMessageSource );
68109 }

Status & tagging log