Followup r69961. Remove now unused global.
[lhc/web/wiklou.git] / maintenance / language / writeMessagesArray.inc
index ac4a3d9..e3a48ab 100644 (file)
@@ -15,21 +15,21 @@ class MessageWriter {
 
        static $messageStructure;
        static $blockComments;
-       static $messageComments;
        static $ignoredMessages;
        static $optionalMessages;
 
        /**
         * Write a messages array as a PHP text and write it to the messages file.
         *
-        * @param $messages The messages array.
-        * @param $code The language code.
-        * @param $write Write to the messages file?
-        * @param $listUnknown List the unknown messages?
+        * @param $messages Array: the messages array.
+        * @param $code String: the language code.
+        * @param $write Boolean: write to the messages file?
+        * @param $listUnknown Boolean: list the unknown messages?
+        * @param $removeUnknown Boolean: whether to remove unkown messages
         */
-       public static function writeMessagesToFile( $messages, $code, $write, $listUnknown ) {
+       public static function writeMessagesToFile( $messages, $code, $write, $listUnknown, $removeUnknown ) {
                # Rewrite the messages array
-               $messages = self::writeMessagesArray( $messages, $code == 'en' );
+               $messages = self::writeMessagesArray( $messages, $code == 'en', false, $removeUnknown );
                $messagesText = $messages[0];
                $sortedMessages = $messages[1];
 
@@ -51,7 +51,10 @@ class MessageWriter {
                                }
                        }
                        if( $listUnknown && isset( $sortedMessages['unknown'] ) && !empty( $sortedMessages['unknown'] ) ) {
-                               echo "\nThere are " . count( $sortedMessages['unknown'] ) . " unknown messages, please check them:\n";
+                               if ( $removeUnknown )
+                                       echo "\nThe following " . count( $sortedMessages['unknown'] ) . " unknown messages have been removed:\n";
+                               else
+                                       echo "\nThere are " . count( $sortedMessages['unknown'] ) . " unknown messages, please check them:\n";
                                foreach( $sortedMessages['unknown'] as $key => $value ) {
                                        echo "* " . $key . "\n";
                                }
@@ -64,25 +67,27 @@ class MessageWriter {
        /**
         * Write a messages array as a PHP text.
         *
-        * @param $messages The messages array.
-        * @param $ignoredComments Show comments about ignored and optional messages? (For English.)
+        * @param $messages Array: the messages array.
+        * @param $ignoredComments Boolean: show comments about ignored and optional
+        *                         messages? (For English.)
+        * @param $prefix String: base path for messages.inc and messageTypes.inc files
+        *                or false for default path (this directory)
+        * @param $removeUnknown Boolean: whether to remove unkown messages
         *
         * @return Array of the PHP text and the sorted messages array.
         */
-       public static function writeMessagesArray( $messages, $ignoredComments = false, $prefix = false ) {
+       public static function writeMessagesArray( $messages, $ignoredComments = false, $prefix = false, $removeUnknown = false ) {
                # Load messages
                $dir = $prefix ? $prefix : dirname( __FILE__ );
-               
+
                require( $dir . '/messages.inc' );
                self::$messageStructure = $wgMessageStructure;
                self::$blockComments = $wgBlockComments;
-               self::$messageComments = $wgMessageComments;
 
                require( $dir . '/messageTypes.inc' );
                self::$ignoredMessages = $wgIgnoredMessages;
                self::$optionalMessages = $wgOptionalMessages;
 
-
                # Sort messages to blocks
                $sortedMessages['unknown'] = $messages;
                foreach( self::$messageStructure as $blockName => $block ) {
@@ -110,53 +115,40 @@ class MessageWriter {
                                $ignored = array();
                                $optional = array();
                        }
-                       $comments = self::makeComments( array_keys($messages), self::$messageComments, $ignored, $optional );
+                       $comments = self::makeComments( array_keys( $messages ), $ignored, $optional );
 
                        # Write the block
                        $messagesText .= self::writeMessagesBlock( self::$blockComments[$block], $messages, $comments );
                }
 
                # Write the unknown messages, alphabetically sorted.
-               # Of course, we don't have any comments for them, because the are unknown.
-               ksort( $sortedMessages['unknown'] );
-               $messagesText .= self::writeMessagesBlock( 'Unknown messages', $sortedMessages['unknown'] );
+               # Of course, we don't have any comments for them, because they are unknown.
+               if ( !$removeUnknown ) {
+                       ksort( $sortedMessages['unknown'] );
+                       $messagesText .= self::writeMessagesBlock( 'Unknown messages', $sortedMessages['unknown'] );
+               }
                $messagesText .= ");
 ";
-
                return array( $messagesText, $sortedMessages );
        }
 
        /**
         * Generates an array of comments for messages.
         *
-        * @param $messages Key of messages.
-        * @param $comments Comments for messages, indexed by key.
-        * @param $ignored List of ingored message keys.
-        * @param $optional List of optional message keys.
+        * @param $messages Array: key of messages.
+        * @param $ignored Array: list of ingored message keys.
+        * @param $optional Array: list of optional message keys.
         */
-       public static function makeComments( $messages, $comments, $ignored, $optional ) {
+       public static function makeComments( $messages, $ignored, $optional ) {
                # Comment collector
                $commentArray = array();
 
                # List of keys only
                foreach( $messages as $key ) {
-                       $commentsForKey = array();
-
-                       # Add descriptive comment for this message if there is one
-                       if( array_key_exists( $key, $comments ) ) {
-                               $commentsForKey[] = $comments[$key];
-                       }
-
-                       # For translator information only
                        if( in_array( $key, $ignored ) ) {
-                               $commentsForKey[] = self::$ignoredComment;
+                               $commentArray[$key] = ' # ' . self::$ignoredComment;
                        } elseif( in_array( $key, $optional ) ) {
-                               $commentsForKey[] = self::$optionalComment;
-                       }
-
-                       # Format one or more comments nicely and store in array
-                       if( count( $commentsForKey ) ) {
-                               $commentArray[$key] = ' # ' . implode( '; ', $commentsForKey );
+                               $commentArray[$key] = ' # ' . self::$optionalComment;
                        }
                }
 
@@ -166,10 +158,10 @@ class MessageWriter {
        /**
         * Write a block of messages to PHP.
         *
-        * @param $blockComment The comment of whole block.
-        * @param $messages The block messages.
-        * @param $messageComments Optional comments for messages in this block.
-        * @param $prefix Prefix for every line, for indenting purposes.
+        * @param $blockComment String: the comment of whole block.
+        * @param $messages Array: the block messages.
+        * @param $messageComments Array: optional comments for messages in this block.
+        * @param $prefix String: prefix for every line, for indenting purposes.
         *
         * @return The block, formatted in PHP.
         */