X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FInitialiseMessages.inc;h=12522466c1aaec5d12ebdefe31c1e5cc5c4d6dcf;hb=9c1bb5a9ad1441029b70ea0f7b33da0bcfde511b;hp=4f59afd0b00d6eddf69158d4f49a028a4b4d6cca;hpb=b53762cf69f3958e7d85498987daa41657e2f3a3;p=lhc%2Fweb%2Fwiklou.git
diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc
index 4f59afd0b0..12522466c1 100755
--- a/maintenance/InitialiseMessages.inc
+++ b/maintenance/InitialiseMessages.inc
@@ -1,132 +1,189 @@
-
+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 );
- $navText = wfMsgNoDB( "allmessagestext" );
+ $mwMsg =& MagicWord::get( MAG_MSG );
+ $navText = str_replace( "$1", "allmessagestext", $mwMsg->getSynonym( 0 ) );
$navText .= "
- '''Name'''
+'''Name'''
|
- '''Default text'''
+'''Default text'''
|
- '''Current text'''
+'''Current text'''
|
";
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 = ksort( $wgAllMessagesEn );
-
+ if ( $messageArray ) {
+ $sortedArray = $wgAllMessagesEn;
+ } 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 .= ",";
}
-
- $message = wfMsgNoDB( $key );
$titleObj = Title::newFromText( $key );
$enctitle = wfStrencode($titleObj->getDBkey());
$sql .= "'$enctitle'";
}
$sql .= ")";
- print "Reading...";
$res = wfQuery( $sql, DB_READ );
- print ".";
$row = wfFetchObject( $res );
- print "done\n";
- print "Setting up...";
- $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 );
}
- print ".";
+
+ # 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 );
- print "Done\n";
-
- print "Processing...";
+ $talk = $wgLang->getNsText( NS_TALK );
+ $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
+ # Process each message
foreach ( $sortedArray as $key => $enMsg ) {
- $message = wfMsgNoDB( $key );
+ if ( $key == "" ) {
+ continue; // Skip odd members
+ }
+ # 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 ) {
- $sql = "DELETE FROM cur WHERE cur_namespace=$ns AND cur_title='$title'";
- wfQuery( $sql, 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 );
$navText .=
"
- [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]
+[$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]
+[[$mwtalk:$title|$talk]]
|
- $message
+$message
|
- $mw
+$mw
|
";
}
- print "Done\n";
- print "Writing...";
- wfQuery( $sql, DB_WRITE, $fname );
- print "Done\n";
- $navText .= "
";
+ # Perform the insert query
+ if ( !$first ) {
+ wfQuery( $sql, DB_WRITE, $fname );
+ }
+ # Write the navigation page
+
+ $navText .= "";
$title = wfMsgNoDB( "allmessages" );
$titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
$wgArticle = new Article( $titleObj );
$wgOut->disable();
$wgUser = User::newFromName( 'MediaWiki default' );
- print "Writing to " . $titleObj->getPrefixedDBkey() . "\n";
if ( $titleObj->getArticleID() ) {
$wgArticle->updateArticle( $navText, '', 0, 0 );
} else {
$wgArticle->insertNewArticle( $navText, '', 0, 0 );
}
- print "Finished\n";
+
+ # 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 );
}
+?>