$this->showArticle( $text, wfMsg( "newarticle" ) );
}
- function updateArticle( $text, $summary, $minor, $watchthis, $section = "")
+ function updateArticle( $text, $summary, $minor, $watchthis, $section = "", $forceBot = false )
{
global $wgOut, $wgUser, $wgLinkCache;
global $wgDBtransactions, $wgMwRedir;
$res = wfQuery( $sql, DB_WRITE, $fname );
$oldid = wfInsertID( $res );
+ $bot = (int)($wgUser->isBot() || $forceBot);
+
$sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
"rc_namespace,rc_title,rc_new,rc_minor,rc_bot,rc_cur_id,rc_user," .
"rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid) VALUES (" .
"'{$now}','{$now}'," . $this->mTitle->getNamespace() . ",'" .
wfStrencode( $this->mTitle->getDBkey() ) . "',0,{$me2}," .
- ( $wgUser->isBot() ? 1 : 0 ) . "," .
- $this->getID() . "," . $wgUser->getID() . ",'" .
+ "$bot," . $this->getID() . "," . $wgUser->getID() . ",'" .
wfStrencode( $wgUser->getName() ) . "','" .
wfStrencode( $summary ) . "',0,{$oldid})";
wfQuery( $sql, DB_WRITE, $fname );
function delete()
{
- global $wgUser, $wgOut;
+ global $wgUser, $wgOut, $wgMessageCache;
global $wpConfirm, $wpReason, $image, $oldimage;
# This code desperately needs to be totally rewritten
return;
}
+ # Can't delete cached MediaWiki namespace (i.e. vital messages)
+ if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && $wgMessageCache->isCacheable( $this->mTitle->getDBkey() ) ) {
+ $wgOut->fatalError( wfMsg( "cannotdelete" ) );
+ return;
+ }
+
# Better double-check that it hasn't been deleted yet!
$wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
if ( ( "" == trim( $this->mTitle->getText() ) )
$wgOut->readOnlyPage( $this->getContent() );
return;
}
-
+
+ # Secret enhanced rollback, marks edits rc_bot=1
+ $bot = !!$_REQUEST['bot'];
+
# Replace all this user's current edits with the next one down
$tt = wfStrencode( $this->mTitle->getDBKey() );
$n = $this->mTitle->getNamespace();
}
# Get the last edit not by this guy
- $sql = "SELECT old_text,old_user,old_user_text
+ $sql = "SELECT old_text,old_user,old_user_text,old_timestamp
FROM old USE INDEX (name_title_timestamp)
WHERE old_namespace={$n} AND old_title='{$tt}'
AND (old_user <> {$uid} OR old_user_text <> '{$ut}')
return;
}
$s = wfFetchObject( $res );
-
+
+ if ( $bot ) {
+ # Mark all reverted edits as bot
+ $sql = "UPDATE recentchanges SET rc_bot=1 WHERE
+ rc_cur_id=$pid AND rc_user=$uid AND rc_timestamp > '{$s->old_timestamp}'";
+ wfQuery( $sql, DB_WRITE, $fname );
+ }
+
# Save it!
$newcomment = wfMsg( "revertpage", $s->old_user_text );
$wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
$wgOut->setRobotpolicy( "noindex,nofollow" );
$wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
- $this->updateArticle( $s->old_text, $newcomment, 1, $this->mTitle->userIsWatching() );
+ $this->updateArticle( $s->old_text, $newcomment, 1, $this->mTitle->userIsWatching(), "", $bot );
global $wgEnablePersistentLC;
if ( $wgEnablePersistentLC ) {
wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
}
-
+
+
$wgOut->returnToMain( false );
}
/* private */ function editUpdates( $text )
{
global $wgDeferredUpdateList, $wgDBname, $wgMemc;
+ global $wgMessageCache;
wfSeedRandom();
if ( 0 == mt_rand( 0, 999 ) ) {
}
$id = $this->getID();
$title = $this->mTitle->getPrefixedDBkey();
+ $shortTitle = $this->mTitle->getDBkey();
+
$adj = $this->mCountAdjustment;
if ( 0 != $id ) {
$u = new SearchUpdate( $id, $title, $text );
array_push( $wgDeferredUpdateList, $u );
- $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(),
- $this->mTitle->getDBkey() );
+ $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
array_push( $wgDeferredUpdateList, $u );
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- $messageCache = $wgMemc->get( "$wgDBname:messages" );
-
- # If another thread is loading, poll
- for ( $i=0; $i<70 && $messageCache == 'loading'; $i++ ) {
- sleep(1);
- $messageCache = $wgMemc->get( "$wgDBname:messages" );
- }
-
- if ( !$messageCache || $messageCache == 'loading' ) {
- $messageCache = wfLoadAllMessages();
- }
- $messageCache[$this->mTitle->getDBkey()] = $text;
- $wgMemc->set( "$wgDBname:messages", $messageCache, 86400 );
+ $wgMessageCache->replace( $shortTitle, $text );
}
}
}
# Really get a message
function wfMsgReal( $key, $args, $useDB ) {
- global $wgLang, $wgReplacementKeys, $wgMemc, $wgDBname;
- global $wgUseDatabaseMessages, $wgUseMemCached, $wgOut;
- global $wgAllMessagesEn, $wgLanguageCode;
+ global $wgReplacementKeys, $wgMessageCache, $wgLang;
$fname = "wfMsg";
wfProfileIn( $fname );
-
- static $messageCache = false;
- $memcKey = "$wgDBname:messages";
- $fname = "wfMsg";
- $message = false;
-
- # newFromText is too slow!
- $title = ucfirst( $key );
- if ( $messageCache ) {
- $message = $messageCache[$title];
- } elseif ( !$wgUseDatabaseMessages || !$useDB ) {
+ if ( $wgMessageCache ) {
+ $message = $wgMessageCache->get( $key, $useDB );
+ } elseif ( $wgLang ) {
$message = $wgLang->getMessage( $key );
+ } else {
+ wfDebug( "No language object when getting $key\n" );
+ $message = "<$key>";
}
- if ( !$message && $wgUseMemCached ) {
- # Try memcached
- if ( !$messageCache ) {
- $messageCache = $wgMemc->get( $memcKey );
- }
-
- # If there's nothing in memcached, load all the messages from the database
- # This should only happen on server reset -- ordinary changes should update
- # memcached in editUpdates()
- if ( !$messageCache ) {
- # Other threads don't need to load the messages if another thread is doing it.
- $wgMemc->set( $memcKey, "loading", time() + 60 );
- $messageCache = wfLoadAllMessages();
- # Save in memcached
- $wgMemc->set( $memcKey, $messageCache, time() + 3600 );
-
-
- }
- if ( is_array( $messageCache ) && array_key_exists( $title, $messageCache ) ) {
- $message = $messageCache[$title];
- } elseif ( $messageCache == "loading" ) {
- $messageCache = false;
- }
- }
-
- # If there was no MemCached, load each message from the DB individually
- if ( !$message ) {
- if ( $useDB ) {
- $sql = "SELECT cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI .
- " AND cur_title='$title'";
- $res = wfQuery( $sql, DB_READ, $fname );
-
- if ( wfNumRows( $res ) ) {
- $obj = wfFetchObject( $res );
- $message = $obj->cur_text;
- wfFreeResult( $res );
- }
- }
- }
-
- # Try the array in $wgLang
- if ( !$message ) {
- $message = $wgLang->getMessage( $key );
- }
-
- # Try the English array
- if ( !$message && $wgLanguageCode != "en" ) {
- $message = Language::getMessage( $key );
- }
-
# Replace arguments
if( count( $args ) ) {
$message = str_replace( $wgReplacementKeys, $args, $message );
}
wfProfileOut( $fname );
- if ( !$message ) {
- # Failed, message does not exist
- return "<$key>";
- }
return $message;
}
return $text;
}
-# Loads the entire MediaWiki namespace, returns the array
-function wfLoadAllMessages()
-{
- $sql = "SELECT cur_title,cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI;
- $res = wfQuery( $sql, DB_READ, $fname );
-
- $messages = array();
- for ( $row = wfFetchObject( $res ); $row; $row = wfFetchObject( $res ) ) {
- $messages[$row->cur_title] = $row->cur_text;
- }
- wfFreeResult( $res );
- return $messages;
-}
-
function wfQuotedPrintable( $string, $charset = "" )
{
# Probably incomplete; see RFC 2045
global $wgUseDynamicDates;
wfProfileIn( "$fname-includes" );
-# Only files which are used on every invocation should be included here
-# Otherwise, include them conditionally [TS]
include_once( "GlobalFunctions.php" );
include_once( "Namespace.php" );
include_once( "Skin.php" );
include_once( "Block.php" );
include_once( "SearchEngine.php" );
include_once( "DifferenceEngine.php" );
+include_once( "MessageCache.php" );
wfProfileOut( "$fname-includes" );
wfProfileIn( "$fname-memcached" );
global $wgUser, $wgLang, $wgOut, $wgTitle;
global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
+global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
+global $wgMsgCacheExpiry, $wgDBname;
class MemCachedClientforWiki extends MemCachedClient {
function _debug( $text ) {
include_once( "Language.php" );
+$wgMessageCache = new MessageCache( $wgUseMemCached, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname );
+
$wgOut = new OutputPage();
wfDebug( "\n\n" );