From 4addfef96958e271b3580ca9ef23c0da7060e4f1 Mon Sep 17 00:00:00 2001 From: Rotem Liss Date: Mon, 6 Nov 2006 18:48:14 +0000 Subject: [PATCH] Adding the block of unknown messages for messages which are not defined in messages.inc, for future fixing, instead of just removing them. --- maintenance/language/writeMessagesArray.inc | 120 ++++++++++++-------- 1 file changed, 73 insertions(+), 47 deletions(-) diff --git a/maintenance/language/writeMessagesArray.inc b/maintenance/language/writeMessagesArray.inc index 8fc6b389d0..7596a49cf0 100644 --- a/maintenance/language/writeMessagesArray.inc +++ b/maintenance/language/writeMessagesArray.inc @@ -12,6 +12,8 @@ require_once( 'messages.inc' ); * Write a messages array as a PHP text. * * @param $messages The messages array. + * + * @return The PHP text. */ function writeMessagesArray( $messages ) { global $wgMessageStrucutre, $wgBlockComments, $wgMessageComments; @@ -30,69 +32,93 @@ function writeMessagesArray( $messages ) { # Write all the messages $messagesText = "\$messages = array(\n"; - foreach( $sortedMessages as $blockName => $block ) { - # Continue if it's the block of unknown messages, or the block is empty - if ( $blockName == 'unknown' || empty( $block ) ) { + foreach( $sortedMessages as $block => $messages ) { + # Skip if it's the block of unknown messages - handle that in the end of file + if ( $block == 'unknown' ) { continue; } - # Get the block comment and format it (if exist); check for multiple lines comments - $comment = $wgBlockComments[$blockName]; - if ( !empty( $comment ) ) { - if ( strpos( $comment, "\n" ) === false ) { - $messagesText .= "# $comment\n"; - } else { - $messagesText .= "/*\n$comment\n*/\n"; - } - } + # Write the block + $messagesText .= writeMessagesBlock( $block, $wgBlockComments[$block], $messages ); + } + $messagesText .= writeMessagesBlock( 'unknown', 'Unknown messages', $sortedMessages['unknown'] ); + $messagesText .= ");\n"; - # Get max key length - $maxKeyLength = 0; - foreach( array_keys( $block ) as $key ) { - if ( strlen( $key ) > $maxKeyLength ) { - $maxKeyLength = strlen( $key ); - } + return $messagesText; +} + +/** + * Write a block of messages to PHP. + * + * @param $name The block name. + * @param $comment The block comment. + * @param $messages The block messages. + * + * @return The block, formatted in PHP. + */ +function writeMessagesBlock( $name, $comment, $messages ) { + global $wgMessageComments; + $blockText = ''; + + # Skip the block if it includes no messages + if ( empty( $messages ) ) { + return ''; + } + + # Format the block comment (if exists); check for multiple lines comments + if ( !empty( $comment ) ) { + if ( strpos( $comment, "\n" ) === false ) { + $blockText .= "# $comment\n"; + } else { + $blockText .= "/*\n$comment\n*/\n"; } + } - # Format the messages - foreach( $block as $key => $value ) { - # Add the key name - $messagesText .= "'$key'"; + # Get max key length + $maxKeyLength = 0; + foreach( array_keys( $messages ) as $key ) { + if ( strlen( $key ) > $maxKeyLength ) { + $maxKeyLength = strlen( $key ); + } + } - # Add the appropriate block whitespace - for ( $i = 1; $i <= ( $maxKeyLength - strlen( $key ) ); $i++ ) { - $messagesText .= ' '; - } + # Format the messages + foreach( $messages as $key => $value ) { + # Add the key name + $blockText .= "'$key'"; - # Refer to the value - $messagesText .= ' => '; + # Add the appropriate block whitespace + for ( $i = 1; $i <= ( $maxKeyLength - strlen( $key ) ); $i++ ) { + $blockText .= ' '; + } - # Check for the appropriate apostrophe and add the value - if ( strpos( $value, "'" ) === false ) { - $messagesText .= "'$value'"; - } elseif ( strpos( $value, '"' ) === false ) { - $messagesText .= "\"$value\""; - } else { - $messagesText .= "'" . str_replace( "'", "\'", $value ) . "'"; - } + # Refer to the value + $blockText .= ' => '; - # Comma - $messagesText .= ','; + # Check for the appropriate apostrophe and add the value + if ( strpos( $value, "'" ) === false ) { + $blockText .= "'$value'"; + } elseif ( strpos( $value, '"' ) === false ) { + $blockText .= "\"$value\""; + } else { + $blockText .= "'" . str_replace( "'", "\'", $value ) . "'"; + } - if ( array_key_exists( $key, $wgMessageComments ) ) { - $messagesText .= ' # ' . $wgMessageComments[$key]; - } + # Comma + $blockText .= ','; - # Newline - $messagesText .= "\n"; + if ( array_key_exists( $key, $wgMessageComments ) ) { + $blockText .= ' # ' . $wgMessageComments[$key]; } - # Newline to end the block - $messagesText .= "\n"; + # Newline + $blockText .= "\n"; } - $messagesText .= ");\n"; - return $messagesText; + # Newline to end the block + $blockText .= "\n"; + + return $blockText; } ?> -- 2.20.1