Fixed use of X-Newest in Swift backend
[lhc/web/wiklou.git] / includes / changes / RecentChange.php
index 48a8d03..f1f2578 100644 (file)
@@ -64,7 +64,6 @@
  * @todo document functions and variables
  */
 class RecentChange {
-
        // Constants for the rc_source field.  Extensions may also have
        // their own source constants.
        const SRC_EDIT = 'mw.edit';
@@ -72,24 +71,26 @@ class RecentChange {
        const SRC_LOG = 'mw.log';
        const SRC_EXTERNAL = 'mw.external'; // obsolete
 
-       var $mAttribs = array(), $mExtra = array();
+       public $mAttribs = array();
+       public $mExtra = array();
 
        /**
         * @var Title
         */
-       var $mTitle = false;
+       public $mTitle = false;
 
        /**
         * @var User
         */
        private $mPerformer = false;
 
+       public $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentChangesLinked
+       public $notificationtimestamp;
+
        /**
-        * @var Title
+        * @var int Line number of recent change. Default -1.
         */
-       var $mMovedToTitle = false;
-       var $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentchangeslinked
-       var $notificationtimestamp;
+       public $counter = -1;
 
        # Factory methods
 
@@ -100,10 +101,12 @@ class RecentChange {
        public static function newFromRow( $row ) {
                $rc = new RecentChange;
                $rc->loadFromRow( $row );
+
                return $rc;
        }
 
        /**
+        * No uses left in Gerrit on 2013-11-19.
         * @deprecated in 1.22
         * @param $row
         * @return RecentChange
@@ -114,6 +117,7 @@ class RecentChange {
                $rc->loadFromCurRow( $row );
                $rc->notificationtimestamp = false;
                $rc->numberofWatchingusers = false;
+
                return $rc;
        }
 
@@ -203,6 +207,7 @@ class RecentChange {
                if ( $this->mTitle === false ) {
                        $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
                }
+
                return $this->mTitle;
        }
 
@@ -219,6 +224,7 @@ class RecentChange {
                                $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false );
                        }
                }
+
                return $this->mPerformer;
        }
 
@@ -320,7 +326,7 @@ class RecentChange {
                        'add_interwiki_prefix' => $wgRC2UDPInterwikiPrefix,
                );
 
-               return $engine->send( $feed, $line );
+               $engine->send( $feed, $line );
        }
 
        /**
@@ -347,6 +353,7 @@ class RecentChange {
                                continue;
                        }
 
+                       /** @var $formatter RCFeedFormatter */
                        $formatter = new $feed['formatter']();
                        $line = $formatter->getLine( $feed, $this, $actionComment );
 
@@ -357,7 +364,8 @@ class RecentChange {
        /**
         * Gets the stream engine object for a given URI from $wgRCEngines
         *
-        * @param $uri string URI to get the engine object for
+        * @param string $uri URI to get the engine object for
+        * @throws MWException
         * @return object The engine object
         */
        private static function getEngine( $uri ) {
@@ -380,6 +388,7 @@ class RecentChange {
         */
        public static function cleanupForIRC( $text ) {
                wfDeprecated( __METHOD__, '1.22' );
+
                return IRCColourfulRCFeedFormatter::cleanupForIRC( $text );
        }
 
@@ -400,13 +409,15 @@ class RecentChange {
                if ( !$change instanceof RecentChange ) {
                        return null;
                }
+
                return $change->doMarkPatrolled( $wgUser, $auto );
        }
 
        /**
         * Mark this RecentChange as patrolled
         *
-        * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
+        * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and
+        * 'markedaspatrollederror-noautopatrol' as errors
         * @param $user User object doing the action
         * @param $auto Boolean: for automatic patrol
         * @return array of permissions errors, see Title::getUserPermissionsErrors()
@@ -427,7 +438,9 @@ class RecentChange {
                }
                // Users without the 'autopatrol' right can't patrol their
                // own revisions
-               if ( $user->getName() == $this->getAttribute( 'rc_user_text' ) && !$user->isAllowed( 'autopatrol' ) ) {
+               if ( $user->getName() == $this->getAttribute( 'rc_user_text' )
+                       && !$user->isAllowed( 'autopatrol' )
+               ) {
                        $errors[] = array( 'markedaspatrollederror-noautopatrol' );
                }
                if ( $errors ) {
@@ -442,6 +455,7 @@ class RecentChange {
                // Log this patrol event
                PatrolLog::record( $this, $auto, $user );
                wfRunHooks( 'MarkPatrolledComplete', array( $this->getAttribute( 'rc_id' ), &$user, false ) );
+
                return array();
        }
 
@@ -464,6 +478,7 @@ class RecentChange {
                // Invalidate the page cache after the page has been patrolled
                // to make sure that the Patrol link isn't visible any longer!
                $this->getTitle()->invalidateCache();
+
                return $dbw->affectedRows();
        }
 
@@ -491,39 +506,40 @@ class RecentChange {
                $rc->mTitle = $title;
                $rc->mPerformer = $user;
                $rc->mAttribs = array(
-                       'rc_timestamp'  => $timestamp,
-                       'rc_namespace'  => $title->getNamespace(),
-                       'rc_title'      => $title->getDBkey(),
-                       'rc_type'       => RC_EDIT,
-                       'rc_source'     => self::SRC_EDIT,
-                       'rc_minor'      => $minor ? 1 : 0,
-                       'rc_cur_id'     => $title->getArticleID(),
-                       'rc_user'       => $user->getId(),
-                       'rc_user_text'  => $user->getName(),
-                       'rc_comment'    => $comment,
+                       'rc_timestamp' => $timestamp,
+                       'rc_namespace' => $title->getNamespace(),
+                       'rc_title' => $title->getDBkey(),
+                       'rc_type' => RC_EDIT,
+                       'rc_source' => self::SRC_EDIT,
+                       'rc_minor' => $minor ? 1 : 0,
+                       'rc_cur_id' => $title->getArticleID(),
+                       'rc_user' => $user->getId(),
+                       'rc_user_text' => $user->getName(),
+                       'rc_comment' => $comment,
                        'rc_this_oldid' => $newId,
                        'rc_last_oldid' => $oldId,
-                       'rc_bot'        => $bot ? 1 : 0,
-                       'rc_ip'         => self::checkIPAddress( $ip ),
-                       'rc_patrolled'  => intval( $patrol ),
-                       'rc_new'        => 0,  # obsolete
-                       'rc_old_len'    => $oldSize,
-                       'rc_new_len'    => $newSize,
-                       'rc_deleted'    => 0,
-                       'rc_logid'      => 0,
-                       'rc_log_type'   => null,
+                       'rc_bot' => $bot ? 1 : 0,
+                       'rc_ip' => self::checkIPAddress( $ip ),
+                       'rc_patrolled' => intval( $patrol ),
+                       'rc_new' => 0, # obsolete
+                       'rc_old_len' => $oldSize,
+                       'rc_new_len' => $newSize,
+                       'rc_deleted' => 0,
+                       'rc_logid' => 0,
+                       'rc_log_type' => null,
                        'rc_log_action' => '',
-                       'rc_params'     => ''
+                       'rc_params' => ''
                );
 
                $rc->mExtra = array(
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
                        'lastTimestamp' => $lastTimestamp,
-                       'oldSize'       => $oldSize,
-                       'newSize'       => $newSize,
-                       'pageStatus'   => 'changed'
+                       'oldSize' => $oldSize,
+                       'newSize' => $newSize,
+                       'pageStatus' => 'changed'
                );
                $rc->save();
+
                return $rc;
        }
 
@@ -550,29 +566,29 @@ class RecentChange {
                $rc->mTitle = $title;
                $rc->mPerformer = $user;
                $rc->mAttribs = array(
-                       'rc_timestamp'      => $timestamp,
-                       'rc_namespace'      => $title->getNamespace(),
-                       'rc_title'          => $title->getDBkey(),
-                       'rc_type'           => RC_NEW,
-                       'rc_source'         => self::SRC_NEW,
-                       'rc_minor'          => $minor ? 1 : 0,
-                       'rc_cur_id'         => $title->getArticleID(),
-                       'rc_user'           => $user->getId(),
-                       'rc_user_text'      => $user->getName(),
-                       'rc_comment'        => $comment,
-                       'rc_this_oldid'     => $newId,
-                       'rc_last_oldid'     => 0,
-                       'rc_bot'            => $bot ? 1 : 0,
-                       'rc_ip'             => self::checkIPAddress( $ip ),
-                       'rc_patrolled'      => intval( $patrol ),
-                       'rc_new'            => 1, # obsolete
-                       'rc_old_len'        => 0,
-                       'rc_new_len'        => $size,
-                       'rc_deleted'        => 0,
-                       'rc_logid'          => 0,
-                       'rc_log_type'       => null,
-                       'rc_log_action'     => '',
-                       'rc_params'         => ''
+                       'rc_timestamp' => $timestamp,
+                       'rc_namespace' => $title->getNamespace(),
+                       'rc_title' => $title->getDBkey(),
+                       'rc_type' => RC_NEW,
+                       'rc_source' => self::SRC_NEW,
+                       'rc_minor' => $minor ? 1 : 0,
+                       'rc_cur_id' => $title->getArticleID(),
+                       'rc_user' => $user->getId(),
+                       'rc_user_text' => $user->getName(),
+                       'rc_comment' => $comment,
+                       'rc_this_oldid' => $newId,
+                       'rc_last_oldid' => 0,
+                       'rc_bot' => $bot ? 1 : 0,
+                       'rc_ip' => self::checkIPAddress( $ip ),
+                       'rc_patrolled' => intval( $patrol ),
+                       'rc_new' => 1, # obsolete
+                       'rc_old_len' => 0,
+                       'rc_new_len' => $size,
+                       'rc_deleted' => 0,
+                       'rc_logid' => 0,
+                       'rc_log_type' => null,
+                       'rc_log_action' => '',
+                       'rc_params' => ''
                );
 
                $rc->mExtra = array(
@@ -583,6 +599,7 @@ class RecentChange {
                        'pageStatus' => 'created'
                );
                $rc->save();
+
                return $rc;
        }
 
@@ -602,9 +619,10 @@ class RecentChange {
         * @return bool
         */
        public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
-               $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' )
-       {
+               $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
+       {
                global $wgLogRestrictions;
+
                # Don't add private logs to RC!
                if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
                        return false;
@@ -612,6 +630,7 @@ class RecentChange {
                $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
                        $target, $logComment, $params, $newId, $actionCommentIRC );
                $rc->save();
+
                return true;
        }
 
@@ -659,38 +678,39 @@ class RecentChange {
                $rc->mTitle = $target;
                $rc->mPerformer = $user;
                $rc->mAttribs = array(
-                       'rc_timestamp'  => $timestamp,
-                       'rc_namespace'  => $target->getNamespace(),
-                       'rc_title'      => $target->getDBkey(),
-                       'rc_type'       => RC_LOG,
-                       'rc_source'     => self::SRC_LOG,
-                       'rc_minor'      => 0,
-                       'rc_cur_id'     => $target->getArticleID(),
-                       'rc_user'       => $user->getId(),
-                       'rc_user_text'  => $user->getName(),
-                       'rc_comment'    => $logComment,
+                       'rc_timestamp' => $timestamp,
+                       'rc_namespace' => $target->getNamespace(),
+                       'rc_title' => $target->getDBkey(),
+                       'rc_type' => RC_LOG,
+                       'rc_source' => self::SRC_LOG,
+                       'rc_minor' => 0,
+                       'rc_cur_id' => $target->getArticleID(),
+                       'rc_user' => $user->getId(),
+                       'rc_user_text' => $user->getName(),
+                       'rc_comment' => $logComment,
                        'rc_this_oldid' => 0,
                        'rc_last_oldid' => 0,
-                       'rc_bot'        => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
-                       'rc_ip'         => self::checkIPAddress( $ip ),
-                       'rc_patrolled'  => 1,
-                       'rc_new'        => 0, # obsolete
-                       'rc_old_len'    => null,
-                       'rc_new_len'    => null,
-                       'rc_deleted'    => 0,
-                       'rc_logid'      => $newId,
-                       'rc_log_type'   => $type,
+                       'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
+                       'rc_ip' => self::checkIPAddress( $ip ),
+                       'rc_patrolled' => 1,
+                       'rc_new' => 0, # obsolete
+                       'rc_old_len' => null,
+                       'rc_new_len' => null,
+                       'rc_deleted' => 0,
+                       'rc_logid' => $newId,
+                       'rc_log_type' => $type,
                        'rc_log_action' => $action,
-                       'rc_params'     => $params
+                       'rc_params' => $params
                );
 
                $rc->mExtra = array(
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
                        'lastTimestamp' => 0,
                        'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
-                       'pageStatus'    => $pageStatus,
+                       'pageStatus' => $pageStatus,
                        'actionCommentIRC' => $actionCommentIRC
                );
+
                return $rc;
        }
 
@@ -776,6 +796,7 @@ class RecentChange {
                } else {
                        $trail = '';
                }
+
                return $trail;
        }
 
@@ -796,6 +817,7 @@ class RecentChange {
                if ( $old === null || $new === null ) {
                        return '';
                }
+
                return ChangesList::showCharacterDifference( $old, $new );
        }
 
@@ -810,7 +832,7 @@ class RecentChange {
 
                $method = __METHOD__;
                $dbw = wfGetDB( DB_MASTER );
-               $dbw->onTransactionIdle( function() use ( $dbw, $method ) {
+               $dbw->onTransactionIdle( function () use ( $dbw, $method ) {
                        global $wgRCMaxAge;
 
                        $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
@@ -826,7 +848,8 @@ class RecentChange {
                global $wgRequest;
                if ( $ip ) {
                        if ( !IP::isIPAddress( $ip ) ) {
-                               throw new MWException( "Attempt to write \"" . $ip . "\" as an IP address into recent changes" );
+                               throw new MWException( "Attempt to write \"" . $ip .
+                                       "\" as an IP address into recent changes" );
                        }
                } else {
                        $ip = $wgRequest->getIP();
@@ -834,6 +857,7 @@ class RecentChange {
                                $ip = '';
                        }
                }
+
                return $ip;
        }
 
@@ -848,6 +872,7 @@ class RecentChange {
         */
        public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
                global $wgRCMaxAge;
+
                return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
        }
 }