<?php
-# Script to initialise the MediaWiki namespace
+/**
+ * Script to initialise the MediaWiki namespace
+ *
+ * This script is included from update.php and install.php. Do not run it
+ * by itself.
+ *
+ * @deprecated
+ * @package MediaWiki
+ * @subpackage Maintenance
+ */
+
+/** */
+function initialiseMessages( $overwrite = false, $messageArray = false ) {
+ global $wgContLang, $wgContLanguageCode;
+ global $wgContLangClass, $wgAllMessagesEn;
+ global $wgDisableLangConversion;
+ global $wgForceUIMsgAsContentMsg;
+ global $wgLanguageNames;
+ global $IP;
-# This script is included from update.php and install.php. Do not run it
-# by itself.
+ # overwrite language conversion option so that all variants
+ # of the messages are initialised
+ $wgDisableLangConversion = false;
-function initialiseMessages( $overwrite = false, $messageArray = false ) {
- global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
+ if ( $messageArray ) {
+ $sortedArray = $messageArray;
+ } else {
+ $sortedArray = $wgAllMessagesEn;
+ }
+
+ ksort( $sortedArray );
+ $messages=array();
+
+ $variants = $wgContLang->getVariants();
+ if(!in_array($wgContLanguageCode, $variants))
+ $variants[]=$wgContLanguageCode;
+
+ foreach ($variants as $v) {
+ $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
+ if( !class_exists($langclass) ) {
+ wfDie( "class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?" );
+ }
+ $lang = new $langclass;
+
+ if($v==$wgContLanguageCode)
+ $suffix='';
+ else
+ $suffix="/$v";
+ foreach ($sortedArray as $key => $msg) {
+ $messages[$key.$suffix] = $lang->getMessage($key);
+ }
+ }
+
+ require_once('languages/Names.php');
+
+ /*
+ initialize all messages in $wgForceUIMsgAsContentMsg for all
+ languages in Names.php
+ */
+ if( is_array( $wgForceUIMsgAsContentMsg ) ) {
+ foreach( $wgForceUIMsgAsContentMsg as $uikey ) {
+ foreach( $wgLanguageNames as $code => $name) {
+ if( $code == $wgContLanguageCode )
+ continue;
+ $msg = $wgContLang->getMessage( $uikey );
+ if( $msg )
+ $messages[$uikey. '/' . $code] = $msg;
+ }
+ }
+ }
+ initialiseMessagesReal( $overwrite, $messages );
+}
+
+/** */
+function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
+ global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
global $wgOut, $wgArticle, $wgUser;
global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
+ # Initialise $wgOut and $wgUser for a command line script
+ $wgOut->disable();
+
+ $wgUser = new User;
+ $wgUser->setLoaded( true ); # Don't load from DB
+ $wgUser->setName( 'MediaWiki default' );
+
# Don't try to draw messages from the database we're initialising
$wgMessageCache->disable();
+ $wgMessageCache->disableTransform();
- $fname = "initialiseMessages";
+ $fname = 'initialiseMessages';
$ns = NS_MEDIAWIKI;
# cur_user_text responsible for the modifications
- # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
+ # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
# default messages won't be overwritte
- $username = "MediaWiki default";
+ $username = 'MediaWiki default';
+
- $timestamp = wfTimestampNow();
- $invTimestamp = wfInvertTimestamp( $timestamp );
- $mwMsg =& MagicWord::get( MAG_MSG );
- $navText = str_replace( "$1", "allmessagestext", $mwMsg->getSynonym( 0 ) );
- $navText .= "
-
-<table border=1 width=100%><tr><td>
- '''Name'''
-</td><td>
- '''Default text'''
-</td><td>
- '''Current text'''
-</td></tr>";
-
print "Initialising \"MediaWiki\" namespace...\n";
- $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM cur WHERE cur_namespace=$ns AND cur_title IN(";
+
+ $dbr =& wfGetDB( DB_SLAVE );
+ $dbw =& wfGetDB( DB_MASTER );
+ $page = $dbr->tableName( 'page' );
+ $revision = $dbr->tableName( 'revision' );
+
+ $timestamp = wfTimestampNow();
+
+ #$sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
# Get keys from $wgAllMessagesEn, which is more complete than the local language
$first = true;
if ( $messageArray ) {
- $sortedArray = $wgAllMessagesEn;
+ $sortedArray = $messageArray;
} else {
$sortedArray = $wgAllMessagesEn;
}
-
+
ksort( $sortedArray );
-
+
# SELECT all existing messages
- foreach ( $sortedArray as $key => $enMsg ) {
- if ( $key == "" ) {
- continue; // Skip odd members
- }
- if ( $first ) {
- $first = false;
- } else {
- $sql .= ",";
+ # Can't afford to be locking all rows for update, this script can take quite a long time to complete
+ $rows = array();
+ $nitems = count($sortedArray);
+ $maxitems = $dbr->maxListLen();
+ $pos = 0;
+ if ($maxitems)
+ $chunks = array_chunk($sortedArray, $maxitems);
+ else
+ $chunks = array($sortedArray);
+
+ foreach ($chunks as $chunk) {
+ $first = true;
+ $sql = "SELECT page_title,page_is_new,rev_user_text FROM $page, $revision WHERE
+ page_namespace=$ns AND rev_page=page_id AND page_title IN(";
+
+ foreach ( $chunk as $key => $enMsg ) {
+ if ( $key == '' ) {
+ continue; // Skip odd members
+ }
+ if ( $first ) {
+ $first = false;
+ } else {
+ $sql .= ',';
+ }
+ $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
+ $enctitle = $dbr->strencode($titleObj->getDBkey());
+ $sql .= "'$enctitle'";
}
- $titleObj = Title::newFromText( $key );
- $enctitle = wfStrencode($titleObj->getDBkey());
- $sql .= "'$enctitle'";
+
+ $sql .= ')';
+ $res = $dbr->query( $sql );
+ while ($row = $dbr->fetchObject($res))
+ $rows[] = $row;
}
- $sql .= ")";
- $res = wfQuery( $sql, DB_READ );
- $row = wfFetchObject( $res );
# Read the results into an array
# Decide whether or not each one needs to be overwritten
$existingTitles = array();
- while ( $row ) {
- if ( !$row->cur_is_new || $row->cur_user_text != $username ) {
- $existingTitles[$row->cur_title] = "keep";
+ foreach ($rows as $row) {
+ if ( $row->rev_user_text != $username && $row->rev_user_text != 'Template namespace initialisation script' ) {
+ $existingTitles[$row->page_title] = 'keep';
} else {
- $existingTitles[$row->cur_title] = "chuck";
+ $existingTitles[$row->page_title] = 'chuck';
}
-
- $row = wfFetchObject( $res );
}
# Insert queries are done in one multi-row insert
# Here's the start of it:
- $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
- cur_user_text, cur_timestamp, cur_restrictions,
- cur_is_new, inverse_timestamp, cur_touched) VALUES ";
- $first = true;
- $mwObj =& MagicWord::get( MAG_MSGNW );
- $msgnw = $mwObj->getSynonym( 0 );
- $talk = $wgLang->getNsText( NS_TALK );
- $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
-
+ $arr = array();
+ $talk = $wgContLang->getNsText( NS_TALK );
+ $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
+
+ # Merge these into a single transaction for speed
+ $dbw->begin();
+
# Process each message
foreach ( $sortedArray as $key => $enMsg ) {
- if ( $key == "" ) {
+ if ( $key == '' ) {
continue; // Skip odd members
}
# Get message text
if ( $messageArray ) {
$message = $enMsg;
} else {
- $message = wfMsgNoDB( $key );
+ $message = wfMsgNoDBForContent( $key );
}
- $titleObj = Title::newFromText( $key );
+ $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ), NS_MEDIAWIKI );
$title = $titleObj->getDBkey();
- $dbencMsg = wfStrencode( $message );
# Update messages which already exist
- # Note: UPDATE is now used instead of DELETE/INSERT to avoid wiping cur_restrictions
if ( array_key_exists( $title, $existingTitles ) ) {
- if ( $existingTitles[$title] == "chuck" || $overwrite) {
- wfQuery( "UPDATE cur
- SET
- cur_text='$dbencMsg',
- cur_user=0,
- cur_user_text='$username',
- cur_timestamp='$timestamp',
- cur_touched='$timestamp',
- inverse_timestamp='$invTimestamp'
- WHERE cur_namespace=8 and cur_title='$title'", DB_WRITE
- );
+ if ( $existingTitles[$title] == 'chuck' || $overwrite) {
+ # Don't bother writing a new revision if we're the same
+ # as the current text!
+ $revision = Revision::newFromTitle( $titleObj );
+ if( is_null( $revision ) || $revision->getText() != $message ) {
+ $article = new Article( $titleObj );
+ $article->quickEdit( $message );
+ }
}
- $doInsert = false;
} else {
- # Queue for insertion
- if ( $first ) {
- $first = false;
- } else {
- $sql .= ",";
- }
- $sql .=
- "($ns,
- '$title',
- '$dbencMsg',
- '$username',
- '$timestamp',
- 'sysop',
- 1,
- '$invTimestamp',
- '$timestamp')";
+ $article = new Article( $titleObj );
+ $newid = $article->insertOn( $dbw, 'sysop' );
+ # FIXME: set restrictions
+ $revision = new Revision( array(
+ 'page' => $newid,
+ 'text' => $message,
+ 'user' => 0,
+ 'user_text' => $username,
+ 'comment' => '',
+ ) );
+ $revid = $revision->insertOn( $dbw );
+ $article->updateRevisionOn( $dbw, $revision );
}
-
- # Make table row for navigation page
- $mw = str_replace( "$1", $key, $msgnw );
-
- $message = wfEscapeWikiText( $message );
- $navText .=
-"<tr><td>
- [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]<br>
- [[$mwtalk:$title|$talk]]
-</td><td>
- $message
-</td><td>
- $mw
-</td></tr>";
- }
-
- # Perform the insert query
- if ( !$first ) {
- wfQuery( $sql, DB_WRITE, $fname );
}
+ $dbw->commit();
- # Write the navigation page
-
- $navText .= "</table>";
- $title = wfMsgNoDB( "allmessages" );
- $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
- $wgArticle = new Article( $titleObj );
- $wgOut->disable();
- $wgUser = User::newFromName( 'MediaWiki default' );
- if ( $titleObj->getArticleID() ) {
- $wgArticle->updateArticle( $navText, '', 0, 0 );
- } else {
- $wgArticle->insertNewArticle( $navText, '', 0, 0 );
- }
-
# Clear the relevant memcached key
- if( $wgUseMemCached ) {
- print "Clearing message cache...";
- $wgMemc->delete( "$wgDBname:messages" );
- print "Done.\n";
- }
+ print 'Clearing message cache...';
+ $wgMessageCache->clear();
+ print "Done.\n";
}
-function loadArrayFromFile( $filename )
-{
+/** */
+function loadLanguageFile( $filename ) {
$contents = file_get_contents( $filename );
+ # Remove header line
+ $p = strpos( $contents, "\n" ) + 1;
+ $contents = substr( $contents, $p );
+ # Unserialize
return unserialize( $contents );
}
+/** */
+function doUpdates() {
+ global $wgDeferredUpdateList;
+ foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
+}
?>