/**
* Write a messages array as a PHP text.
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
* @ingroup MaintenanceLanguage
*/
* @param $write Boolean: write to the messages file?
* @param $listUnknown Boolean: list the unknown messages?
* @param $removeUnknown Boolean: whether to remove unkown messages
+ * @param $messagesFolder String: path to a folder to store the MediaWiki messages. Defaults to the current install.
*/
- public static function writeMessagesToFile( $messages, $code, $write, $listUnknown, $removeUnknown ) {
+ public static function writeMessagesToFile( $messages, $code, $write, $listUnknown, $removeUnknown, $messagesFolder = false ) {
# Rewrite the messages array
$messages = self::writeMessagesArray( $messages, $code == 'en', false, $removeUnknown );
$messagesText = $messages[0];
$sortedMessages = $messages[1];
# Write to the file
- $filename = Language::getMessagesFileName( $code );
- $contents = file_get_contents( $filename );
+ if ( $messagesFolder )
+ $filename = Language::getFileName( "$messagesFolder/Messages", $code );
+ else
+ $filename = Language::getMessagesFileName( $code );
+
+ if ( file_exists( $filename ) )
+ $contents = file_get_contents( $filename );
+ else
+ $contents = '<?php
+$messages = array(
+);
+';
+
if( strpos( $contents, '$messages' ) !== false ) {
$contents = explode( '$messages', $contents );
if( $messagesText == '$messages' . $contents[1] ) {
*/
public static function writeMessagesArray( $messages, $ignoredComments = false, $prefix = false, $removeUnknown = false ) {
# Load messages
- $dir = $prefix ? $prefix : dirname( __FILE__ );
-
- global $wgMessageStructure, $wgBlockComments, $wgIgnoredMessages, $wgOptionalMessages;
+ $dir = $prefix ? $prefix : __DIR__;
require( $dir . '/messages.inc' );
self::$messageStructure = $wgMessageStructure;
# Sort messages to blocks
$sortedMessages['unknown'] = $messages;
foreach( self::$messageStructure as $blockName => $block ) {
+ /**
+ * @var $block array
+ */
foreach( $block as $key ) {
if( array_key_exists( $key, $sortedMessages['unknown'] ) ) {
$sortedMessages[$blockName][$key] = $sortedMessages['unknown'][$key];
* @param $messages Array: key of messages.
* @param $ignored Array: list of ingored message keys.
* @param $optional Array: list of optional message keys.
+ * @return array
*/
public static function makeComments( $messages, $ignored, $optional ) {
# Comment collector
* @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.
+ * @return string The block, formatted in PHP.
*/
public static function writeMessagesBlock( $blockComment, $messages,
$messageComments = array(), $prefix = '' ) {