<?php
+# Script to initialise the MediaWiki namespace
# This script is included from update.php and install.php. Do not run it
# by itself.
-function initialiseMessages( $overwrite = false) {
+function initialiseMessages( $overwrite = false, $messageArray = false ) {
global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
global $wgOut, $wgArticle, $wgUser;
- global $wgMessageCache, $wgMemc, $wgDBname, $wgDatabaseMessages;
+ global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
+
+ # Don't try to draw messages from the database we're initialising
$wgMessageCache->disable();
$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 = "MediaWiki default";
$timestamp = wfTimestampNow();
$invTimestamp = wfInvertTimestamp( $timestamp );
</td></tr>";
print "Initialising \"MediaWiki\" namespace...\n";
- $sql = "SELECT cur_title FROM cur WHERE cur_namespace=$ns AND cur_title IN(";
+ $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;
- $sortedArray = $wgAllMessagesEn;
+ if ( $messageArray ) {
+ $sortedArray = $wgAllMessagesEn;
+ } else {
+ $sortedArray = $wgAllMessagesEn;
+ }
+
ksort( $sortedArray );
+ # SELECT all existing messages
foreach ( $sortedArray as $key => $enMsg ) {
if ( $first ) {
$first = false;
} else {
$sql .= ",";
}
-
- $message = wfMsgNoDB( $key );
$titleObj = Title::newFromText( $key );
$enctitle = wfStrencode($titleObj->getDBkey());
$sql .= "'$enctitle'";
$res = wfQuery( $sql, DB_READ );
$row = wfFetchObject( $res );
- $exists = array();
+ # Read the results into an array
+ # Decide whether or not each one needs to be overwritten
+ $existingTitles = array();
while ( $row ) {
- $exists[$row->cur_title] = 1;
+ if ( !$row->cur_is_new || $row->cur_user_text != $username ) {
+ $existingTitles[$row->cur_title] = "keep";
+ } else {
+ $existingTitles[$row->cur_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 ";
$talk = $wgLang->getNsText( NS_TALK );
$mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
+ # Process each message
foreach ( $sortedArray as $key => $enMsg ) {
- $message = wfMsgNoDB( $key );
+ # Get message text
+ if ( $messageArray ) {
+ $message = $enMsg;
+ } else {
+ $message = wfMsgNoDB( $key );
+ }
$titleObj = Title::newFromText( $key );
$title = $titleObj->getDBkey();
$dbencMsg = wfStrencode( $message );
- $doInsert = true;
- if ( $overwrite ) {
- wfQuery( "DELETE FROM cur WHERE cur_namespace=$ns AND cur_title='$title'", DB_WRITE, $fname );
- } else {
- if (array_key_exists($title, $exists)) {
- $doInsert = false;
+ # 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 ( $doInsert ) {
+ $doInsert = false;
+ } else {
+ # Queue for insertion
if ( $first ) {
$first = false;
} else {
$sql .= ",";
}
$sql .=
- "($ns,
- '$title',
- '$dbencMsg',
- 'MediaWiki default',
- '$timestamp',
- 'sysop',
- 1,
- '$invTimestamp',
- '$timestamp')";
+ "($ns,
+ '$title',
+ '$dbencMsg',
+ '$username',
+ '$timestamp',
+ 'sysop',
+ 1,
+ '$invTimestamp',
+ '$timestamp')";
}
+
+ # Make table row for navigation page
$mw = str_replace( "$1", $key, $msgnw );
$message = wfEscapeWikiText( $message );
</td></tr>";
}
+ # Perform the insert query
if ( !$first ) {
wfQuery( $sql, DB_WRITE, $fname );
}
+ # Write the navigation page
$navText .= "</table>";
-
$title = wfMsgNoDB( "allmessages" );
$titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
$wgArticle = new Article( $titleObj );
$wgArticle->insertNewArticle( $navText, '', 0, 0 );
}
- if( $wgDatabaseMessages ) {
+ # Clear the relevant memcached key
+ if( $wgUseMemCached ) {
print "Clearing message cache...";
$wgMemc->delete( "$wgDBname:messages" );
print "Done.\n";
}
+}
+function loadArrayFromFile( $filename )
+{
+ $contents = file_get_contents( $filename );
+ return unserialize( $contents );
}
-?>
\ No newline at end of file
+?>