MediaWiki
REL1_23
|
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, 00042 $removeDupes, $dupeMsgSource, $messagesFolder 00043 ) { 00044 $messages = $languages->getMessages( $code ); 00045 $messages = $messages['all']; 00046 if ( $removeDupes ) { 00047 $messages = removeDupes( $messages, $dupeMsgSource ); 00048 } 00049 MessageWriter::writeMessagesToFile( 00050 $messages, 00051 $code, 00052 $write, 00053 $listUnknown, 00054 $removeUnknown, 00055 $messagesFolder 00056 ); 00057 } 00058 00066 function removeDupes( $oldMsgArray, $dupeMsgSource ) { 00067 if ( file_exists( $dupeMsgSource ) ) { 00068 include $dupeMsgSource; 00069 if ( !isset( $dupeMessages ) ) { 00070 echo "There are no duplicated messages in the source file provided."; 00071 exit( 1 ); 00072 } 00073 } else { 00074 echo "The specified file $dupeMsgSource cannot be found."; 00075 exit( 1 ); 00076 } 00077 $newMsgArray = $oldMsgArray; 00078 foreach ( $oldMsgArray as $key => $value ) { 00079 if ( array_key_exists( $key, $dupeMessages ) ) { 00080 unset( $newMsgArray[$key] ); 00081 } 00082 } 00083 00084 return $newMsgArray; 00085 } 00086 00087 # Show help 00088 if ( isset( $options['help'] ) ) { 00089 echo <<<TEXT 00090 Run this script to rewrite the messages array in the files 00091 languages/messages/MessagesXX.php. 00092 Parameters: 00093 * lang: Language code (default: the installation default language). 00094 You can also specify "all" to check all the languages. 00095 * help: Show this help. 00096 Options: 00097 * dry-run: Do not write the array to the file. 00098 * no-unknown: Do not list the unknown messages. 00099 * remove-unknown: Remove unknown messages. 00100 * remove-duplicates: Remove duplicated messages based on a PHP source file. 00101 * messages-folder: An alternative folder with MediaWiki messages. 00102 00103 TEXT; 00104 exit( 1 ); 00105 } 00106 00107 # Get the language code 00108 if ( isset( $options['lang'] ) ) { 00109 $wgCode = $options['lang']; 00110 } else { 00111 $wgCode = $wgContLang->getCode(); 00112 } 00113 00114 # Get the duplicate message source 00115 if ( isset( $options['remove-duplicates'] ) && ( strcmp( $options['remove-duplicates'], '' ) ) ) { 00116 $wgDupeMessageSource = $options['remove-duplicates']; 00117 } else { 00118 $wgDupeMessageSource = ''; 00119 } 00120 00121 # Get the options 00122 $wgWriteToFile = !isset( $options['dry-run'] ); 00123 $wgListUnknownMessages = !isset( $options['no-unknown'] ); 00124 $wgRemoveUnknownMessages = isset( $options['remove-unknown'] ); 00125 $wgRemoveDuplicateMessages = isset( $options['remove-duplicates'] ); 00126 $messagesFolder = isset( $options['messages-folder'] ) ? $options['messages-folder'] : false; 00127 00128 # Get language objects 00129 $languages = new Languages(); 00130 00131 # Write all the language 00132 if ( $wgCode == 'all' ) { 00133 foreach ( $languages->getLanguages() as $languageCode ) { 00134 rebuildLanguage( 00135 $languages, 00136 $languageCode, 00137 $wgWriteToFile, 00138 $wgListUnknownMessages, 00139 $wgRemoveUnknownMessages, 00140 $wgRemoveDuplicateMessages, 00141 $wgDupeMessageSource, 00142 $messagesFolder 00143 ); 00144 } 00145 } else { 00146 rebuildLanguage( 00147 $languages, 00148 $wgCode, 00149 $wgWriteToFile, 00150 $wgListUnknownMessages, 00151 $wgRemoveUnknownMessages, 00152 $wgRemoveDuplicateMessages, 00153 $wgDupeMessageSource, 00154 $messagesFolder 00155 ); 00156 }