SpecialVersion: Handle Closures in $wgHooks nicer
[lhc/web/wiklou.git] / includes / changes / RecentChange.php
index b430bab..77bf5df 100644 (file)
@@ -164,7 +164,7 @@ class RecentChange {
         * 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 +176,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 +332,11 @@ class RecentChange {
                                        $this->mExtra['pageStatus'] );
                        }
                }
+
+               // Update the cached list of active users
+               if ( $this->mAttribs['rc_user'] > 0 ) {
+                       JobQueueGroup::singleton()->lazyPush( RecentChangesUpdateJob::newCacheUpdateJob() );
+               }
        }
 
        /**
@@ -512,8 +517,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 +557,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 +584,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 +624,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 +848,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;
+       }
 }