/**
* Script to initialise the MediaWiki namespace
*
- * This script is included from update.php and install.php. Do not run it
+ * This script is included from update.php and install.php. Do not run it
* by itself.
*
* @deprecated
*/
/** */
-function initialiseMessages( $overwrite = false, $messageArray = false ) {
+function initialiseMessages( $overwrite = false, $messageArray = false, $outputCallback = false ) {
global $wgContLang, $wgContLanguageCode;
- global $wgContLangClass, $wgAllMessagesEn;
+ global $wgContLangClass;
global $wgDisableLangConversion;
global $wgForceUIMsgAsContentMsg;
global $wgLanguageNames;
global $IP;
- # overwrite language conversion option so that all variants
+ # overwrite language conversion option so that all variants
# of the messages are initialised
$wgDisableLangConversion = false;
if ( $messageArray ) {
$sortedArray = $messageArray;
} else {
- $sortedArray = $wgAllMessagesEn;
+ $sortedArray = Language::getMessagesFor( 'en' );
}
-
+
ksort( $sortedArray );
$messages=array();
$variants[]=$wgContLanguageCode;
foreach ($variants as $v) {
- $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
- if( !class_exists($langclass) ) {
- die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
- }
- $lang = new $langclass;
+ $lang = Language::factory( $v );
if($v==$wgContLanguageCode)
$suffix='';
}
}
}
- initialiseMessagesReal( $overwrite, $messages );
+ initialiseMessagesReal( $overwrite, $messages, $outputCallback );
}
/** */
-function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
- global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
+function initialiseMessagesReal( $overwrite = false, $messageArray = false, $outputCallback = false ) {
+ global $wgContLang, $wgScript, $wgServer, $wgLanguageCode;
global $wgOut, $wgArticle, $wgUser;
- global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
+ global $wgMessageCache, $wgMemc, $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';
$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
- # default messages won't be overwritte
+ # username responsible for the modifications
+ # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
+ # default messages won't be overwritten
$username = 'MediaWiki default';
-
- print "Initialising \"MediaWiki\" namespace...\n";
+ if ( !$outputCallback ) {
+ # Print is not a function, and there doesn't appear to be any built-in
+ # workalikes, so let's just make our own anonymous function to do the
+ # same thing.
+ $outputCallback = create_function( '$s', 'print $s;' );
+ }
+
+ $outputCallback( "Initialising \"MediaWiki\" namespace for language code $wgLanguageCode...\n" );
+
+ # Check that the serialized data files are OK
+ if ( Language::isLocalisationOutOfDate( $wgLanguageCode ) ) {
+ $outputCallback( "Warning: serialized data file may be out of date.\n" );
+ }
-
$dbr =& wfGetDB( DB_SLAVE );
$dbw =& wfGetDB( DB_MASTER );
$page = $dbr->tableName( 'page' );
$revision = $dbr->tableName( 'revision' );
$timestamp = wfTimestampNow();
- $invTimestamp = wfInvertTimestamp( $timestamp );
-
- #$sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
- $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(";
- # Get keys from $wgAllMessagesEn, which is more complete than the local language
$first = true;
if ( $messageArray ) {
$sortedArray = $messageArray;
} else {
- $sortedArray = $wgAllMessagesEn;
+ $sortedArray = $wgContLang->getAllMessages();
}
-
+
ksort( $sortedArray );
# SELECT all existing messages
# Can't afford to be locking all rows for update, this script can take quite a long time to complete
- foreach ( $sortedArray as $key => $enMsg ) {
- if ( $key == '' ) {
- continue; // Skip odd members
- }
- if ( $first ) {
- $first = false;
- } else {
- $sql .= ',';
+ $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_id=page_latest 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( $wgContLang->ucfirst( $key ) );
- $enctitle = $dbr->strencode($titleObj->getDBkey());
- $sql .= "'$enctitle'";
+
+ $sql .= ')';
+ $res = $dbr->query( $sql );
+ while ($row = $dbr->fetchObject($res))
+ $rows[] = $row;
}
- $sql .= ')';
- $res = $dbr->query( $sql );
- $row = $dbr->fetchObject( $res );
# Read the results into an array
# Decide whether or not each one needs to be overwritten
$existingTitles = array();
- while ( $row ) {
- if ( $row->rev_user_text != $username ) {
+ 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->page_title] = 'chuck';
}
-
- $row = $dbr->fetchObject( $res );
}
# Insert queries are done in one multi-row insert
$arr = array();
$talk = $wgContLang->getNsText( NS_TALK );
$mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
+
+ $numUpdated = 0;
+ $numKept = 0;
+ $numInserted = 0;
+ # Merge these into a single transaction for speed
+ $dbw->begin();
+
# Process each message
- foreach ( $sortedArray as $key => $enMsg ) {
+ foreach ( $sortedArray as $key => $message ) {
if ( $key == '' ) {
continue; // Skip odd members
}
# Get message text
- if ( $messageArray ) {
- $message = $enMsg;
- } else {
+ if ( !$messageArray ) {
$message = wfMsgNoDBForContent( $key );
}
- $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
+ if ( is_null( $message ) ) {
+ # This happens sometimes with out of date serialized data files
+ $outputCallback( "Warning: Skipping null message $key\n" );
+ continue;
+ }
+
+ $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ), NS_MEDIAWIKI );
$title = $titleObj->getDBkey();
# Update messages which already exist
if ( array_key_exists( $title, $existingTitles ) ) {
if ( $existingTitles[$title] == 'chuck' || $overwrite) {
- # print "$title\n";
- $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
- $article = new Article( $mwTitleObj );
- $article->quickEdit( $message );
+ # 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 );
+ ++$numUpdated;
+ } else {
+ ++$numKept;
+ }
+ } else {
+ ++$numKept;
}
} else {
- extract( $dbw->tableNames( 'text', 'page', 'revision' ) );
- $sql = "INSERT INTO $text (old_text, old_flags) VALUES ('" .
- wfStrencode( $message ) .
- "', '')";
- $dbw->query( $sql, $fname );
- $text_id = $dbw->insertID();
-
- $sql = "INSERT INTO $page (page_namespace, page_title, page_restrictions, page_counter, page_is_redirect,
- page_is_new, page_random, page_touched, page_latest) VALUES (
- {$ns}, '{$title}', 'sysop', 0, 0, 1, 0.5, '{$timestamp}', {$text_id} )";
- $dbw->query( $sql, $fname );
- $page_id = $dbw->insertID();
-
- $sql = "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text,
- rev_timestamp, rev_minor_edit)
- VALUES ({$text_id}, {$page_id}, '', 0, '{$username}', '{$timestamp}', 0)";
- $dbw->query( $sql, $fname );
-
+ $article = new Article( $titleObj );
+ $newid = $article->insertOn( $dbw );
+ # 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 );
+ ++$numInserted;
}
}
+ $dbw->commit();
# Clear the relevant memcached key
- print 'Clearing message cache...';
$wgMessageCache->clear();
- print "Done.\n";
+ $outputCallback( "Done. Updated: $numUpdated, inserted: $numInserted, kept: $numKept.\n" );
}
/** */