MediaWiki  REL1_22
rebuildLanguage.php
Go to the documentation of this file.
00001 <?php
00025 require_once __DIR__ . '/../commandLine.inc';
00026 require_once 'languages.inc';
00027 require_once 'writeMessagesArray.inc';
00028 
00041 function rebuildLanguage( $languages, $code, $write, $listUnknown, $removeUnknown, $removeDupes, $dupeMsgSource, $messagesFolder ) {
00042     $messages = $languages->getMessages( $code );
00043     $messages = $messages['all'];
00044     if ( $removeDupes ) {
00045         $messages = removeDupes( $messages, $dupeMsgSource );
00046     }
00047     MessageWriter::writeMessagesToFile( $messages, $code, $write, $listUnknown, $removeUnknown, $messagesFolder );
00048 }
00049 
00057 function removeDupes( $oldMsgArray, $dupeMsgSource ) {
00058     if ( file_exists( $dupeMsgSource ) ) {
00059         include $dupeMsgSource;
00060         if ( !isset( $dupeMessages ) ) {
00061             echo "There are no duplicated messages in the source file provided.";
00062             exit( 1 );
00063         }
00064     } else {
00065         echo "The specified file $dupeMsgSource cannot be found.";
00066         exit( 1 );
00067     }
00068     $newMsgArray = $oldMsgArray;
00069     foreach ( $oldMsgArray as $key => $value ) {
00070         if ( array_key_exists( $key, $dupeMessages ) ) {
00071             unset( $newMsgArray[$key] );
00072         }
00073     }
00074     return $newMsgArray;
00075 }
00076 
00077 # Show help
00078 if ( isset( $options['help'] ) ) {
00079     echo <<<TEXT
00080 Run this script to rewrite the messages array in the files languages/messages/MessagesXX.php.
00081 Parameters:
00082     * lang: Language code (default: the installation default language). You can also specify "all" to check all the languages.
00083     * help: Show this help.
00084 Options:
00085     * dry-run: Do not write the array to the file.
00086     * no-unknown: Do not list the unknown messages.
00087     * remove-unknown: Remove unknown messages.
00088     * remove-duplicates: Remove duplicated messages based on a PHP source file.
00089     * messages-folder: An alternative folder with MediaWiki messages.
00090 
00091 TEXT;
00092     exit( 1 );
00093 }
00094 
00095 # Get the language code
00096 if ( isset( $options['lang'] ) ) {
00097     $wgCode = $options['lang'];
00098 } else {
00099     $wgCode = $wgContLang->getCode();
00100 }
00101 
00102 # Get the duplicate message source
00103 if ( isset( $options['remove-duplicates'] ) && ( strcmp( $options['remove-duplicates'], '' ) ) ) {
00104     $wgDupeMessageSource = $options['remove-duplicates'];
00105 } else {
00106     $wgDupeMessageSource = '';
00107 }
00108 
00109 # Get the options
00110 $wgWriteToFile = !isset( $options['dry-run'] );
00111 $wgListUnknownMessages = !isset( $options['no-unknown'] );
00112 $wgRemoveUnknownMessages = isset( $options['remove-unknown'] );
00113 $wgRemoveDuplicateMessages = isset( $options['remove-duplicates'] );
00114 $messagesFolder = isset( $options['messages-folder'] ) ? $options['messages-folder'] : false;
00115 
00116 # Get language objects
00117 $languages = new languages();
00118 
00119 # Write all the language
00120 if ( $wgCode == 'all' ) {
00121     foreach ( $languages->getLanguages() as $languageCode ) {
00122         rebuildLanguage( $languages, $languageCode, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages, $wgRemoveDuplicateMessages, $wgDupeMessageSource, $messagesFolder );
00123     }
00124 } else {
00125     rebuildLanguage( $languages, $wgCode, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages, $wgRemoveDuplicateMessages, $wgDupeMessageSource, $messagesFolder );
00126 }