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