diff options
Diffstat (limited to 'includes/changes/RecentChange.php')
-rw-r--r-- | includes/changes/RecentChange.php | 113 |
1 files changed, 77 insertions, 36 deletions
diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index b430bab9..87871f49 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -89,6 +89,16 @@ class RecentChange { */ public $counter = -1; + /** + * @var array Array of change types + */ + private static $changeTypes = array( + 'edit' => RC_EDIT, + 'new' => RC_NEW, + 'log' => RC_LOG, + 'external' => RC_EXTERNAL, + ); + # Factory methods /** @@ -119,18 +129,10 @@ class RecentChange { return $retval; } - switch ( $type ) { - case 'edit': - return RC_EDIT; - case 'new': - return RC_NEW; - case 'log': - return RC_LOG; - case 'external': - return RC_EXTERNAL; - default: - throw new MWException( "Unknown type '$type'" ); + if ( !array_key_exists( $type, self::$changeTypes ) ) { + throw new MWException( "Unknown type '$type'" ); } + return self::$changeTypes[$type]; } /** @@ -140,31 +142,25 @@ class RecentChange { * @return string $type */ public static function parseFromRCType( $rcType ) { - switch ( $rcType ) { - case RC_EDIT: - $type = 'edit'; - break; - case RC_NEW: - $type = 'new'; - break; - case RC_LOG: - $type = 'log'; - break; - case RC_EXTERNAL: - $type = 'external'; - break; - default: - $type = "$rcType"; - } + return array_search( $rcType, self::$changeTypes, true ) ?: "$rcType"; + } - return $type; + /** + * Get an array of all change types + * + * @since 1.26 + * + * @return array + */ + public static function getChangeTypes() { + return array_keys( self::$changeTypes ); } /** * Obtain the recent change with a given rc_id value * * @param int $rcid The rc_id value to retrieve - * @return RecentChange + * @return RecentChange|null */ public static function newFromId( $rcid ) { return self::newFromConds( array( 'rc_id' => $rcid ), __METHOD__ ); @@ -176,7 +172,7 @@ class RecentChange { * @param array $conds Array of conditions * @param mixed $fname Override the method name in profiling/logs * @param array $options Query options - * @return RecentChange + * @return RecentChange|null */ public static function newFromConds( $conds, $fname = __METHOD__, $options = array() ) { $dbr = wfGetDB( DB_SLAVE ); @@ -332,6 +328,11 @@ class RecentChange { $this->mExtra['pageStatus'] ); } } + + // Update the cached list of active users + if ( $this->mAttribs['rc_user'] > 0 ) { + JobQueueGroup::singleton()->lazyPush( RecentChangesUpdateJob::newCacheUpdateJob() ); + } } /** @@ -377,6 +378,13 @@ class RecentChange { /** @var $formatter RCFeedFormatter */ $formatter = is_object( $feed['formatter'] ) ? $feed['formatter'] : new $feed['formatter'](); $line = $formatter->getLine( $feed, $this, $actionComment ); + if ( !$line ) { + // T109544 + // If a feed formatter returns null, this will otherwise cause an + // error in at least RedisPubSubFeedEngine. + // Not sure where/how this should best be handled. + continue; + } $engine->send( $feed, $line ); } @@ -512,8 +520,10 @@ class RecentChange { * @param int $patrol * @return RecentChange */ - public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId, - $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 ) { + public static function notifyEdit( + $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp, + $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 + ) { $rc = new RecentChange; $rc->mTitle = $title; $rc->mPerformer = $user; @@ -550,7 +560,13 @@ class RecentChange { 'newSize' => $newSize, 'pageStatus' => 'changed' ); - $rc->save(); + + DeferredUpdates::addCallableUpdate( function() use ( $rc ) { + $rc->save(); + if ( $rc->mAttribs['rc_patrolled'] ) { + PatrolLog::record( $rc, true, $rc->getPerformer() ); + } + } ); return $rc; } @@ -571,8 +587,10 @@ class RecentChange { * @param int $patrol * @return RecentChange */ - public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, - $ip = '', $size = 0, $newId = 0, $patrol = 0 ) { + public static function notifyNew( + $timestamp, &$title, $minor, &$user, $comment, $bot, + $ip = '', $size = 0, $newId = 0, $patrol = 0 + ) { $rc = new RecentChange; $rc->mTitle = $title; $rc->mPerformer = $user; @@ -609,7 +627,13 @@ class RecentChange { 'newSize' => $size, 'pageStatus' => 'created' ); - $rc->save(); + + DeferredUpdates::addCallableUpdate( function() use ( $rc ) { + $rc->save(); + if ( $rc->mAttribs['rc_patrolled'] ) { + PatrolLog::record( $rc, true, $rc->getPerformer() ); + } + } ); return $rc; } @@ -827,4 +851,21 @@ class RecentChange { return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge; } + + /** + * Parses and returns the rc_params attribute + * + * @since 1.26 + * + * @return array|null + */ + public function parseParams() { + $rcParams = $this->getAttribute( 'rc_params' ); + + MediaWiki\suppressWarnings(); + $unserializedParams = unserialize( $rcParams ); + MediaWiki\restoreWarnings(); + + return $unserializedParams; + } } |