Merge "User::pingLimiter() profiles per action as well"
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
index 0284916..1fb2a69 100644 (file)
@@ -32,7 +32,7 @@
  */
 class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
-       public function __construct( $query, $moduleName ) {
+       public function __construct( ApiQuery $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'rc' );
        }
 
@@ -69,9 +69,9 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
        }
 
        /**
-        * @param  $pageid
-        * @param  $title
-        * @param $rc RecentChange (optional)
+        * @param int $pageid
+        * @param Title $title
+        * @param RecentChange|null $rc
         * @return bool|string
         */
        public static function getPatrolToken( $pageid, $title, $rc = null ) {
@@ -135,7 +135,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
        /**
         * Generates and outputs the result of this query based upon the provided parameters.
         *
-        * @param $resultPageSet ApiPageSet
+        * @param ApiPageSet $resultPageSet
         */
        public function run( $resultPageSet = null ) {
                $user = $this->getUser();
@@ -152,15 +152,12 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
                if ( !is_null( $params['continue'] ) ) {
                        $cont = explode( '|', $params['continue'] );
-                       if ( count( $cont ) != 2 ) {
-                               $this->dieUsage( 'Invalid continue param. You should pass the ' .
-                                       'original value returned by the previous query', '_badcontinue' );
-                       }
-
-                       $timestamp = $this->getDB()->addQuotes( wfTimestamp( TS_MW, $cont[0] ) );
+                       $this->dieContinueUsageIf( count( $cont ) != 2 );
+                       $db = $this->getDB();
+                       $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
                        $id = intval( $cont[1] );
+                       $this->dieContinueUsageIf( $id != $cont[1] );
                        $op = $params['dir'] === 'older' ? '<' : '>';
-
                        $this->addWhere(
                                "rc_timestamp $op $timestamp OR " .
                                "(rc_timestamp = $timestamp AND " .
@@ -177,7 +174,11 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                $this->addWhereFld( 'rc_namespace', $params['namespace'] );
 
                if ( !is_null( $params['type'] ) ) {
-                       $this->addWhereFld( 'rc_type', $this->parseRCType( $params['type'] ) );
+                       try {
+                               $this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
+                       } catch ( MWException $e ) {
+                               ApiBase::dieDebug( __METHOD__, $e->getMessage() );
+                       }
                }
 
                if ( !is_null( $params['show'] ) ) {
@@ -254,6 +255,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
                /* Add the fields we're concerned with to our query. */
                $this->addFields( array(
+                       'rc_id',
                        'rc_timestamp',
                        'rc_namespace',
                        'rc_title',
@@ -277,7 +279,6 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                );
                        }
 
-                       $this->addFields( 'rc_id' );
                        /* Add fields to our query if they are specified as a needed parameter. */
                        $this->addFieldsIf( array( 'rc_this_oldid', 'rc_last_oldid' ), $this->fld_ids );
                        $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
@@ -371,10 +372,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        if ( ++$count > $params['limit'] ) {
                                // We've reached the one extra which shows that there are
                                // additional pages to be had. Stop here...
-                               $this->setContinueEnumParameter(
-                                       'continue',
-                                       wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) . '|' . $row->rc_id
-                               );
+                               $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
                                break;
                        }
 
@@ -388,10 +386,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                }
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                                if ( !$fit ) {
-                                       $this->setContinueEnumParameter(
-                                               'continue',
-                                               wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) . '|' . $row->rc_id
-                                       );
+                                       $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
                                        break;
                                }
                        } else {
@@ -423,30 +418,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                $vals = array();
 
                $type = intval( $row->rc_type );
-
-               /* Determine what kind of change this was. */
-               switch ( $type ) {
-                       case RC_EDIT:
-                               $vals['type'] = 'edit';
-                               break;
-                       case RC_NEW:
-                               $vals['type'] = 'new';
-                               break;
-                       case RC_MOVE:
-                               $vals['type'] = 'move';
-                               break;
-                       case RC_LOG:
-                               $vals['type'] = 'log';
-                               break;
-                       case RC_EXTERNAL:
-                               $vals['type'] = 'external';
-                               break;
-                       case RC_MOVE_OVER_REDIRECT:
-                               $vals['type'] = 'move over redirect';
-                               break;
-                       default:
-                               $vals['type'] = $type;
-               }
+               $vals['type'] = RecentChange::parseFromRCType( $type );
 
                $anyHidden = false;
 
@@ -616,30 +588,6 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                return $vals;
        }
 
-       private function parseRCType( $type ) {
-               if ( is_array( $type ) ) {
-                       $retval = array();
-                       foreach ( $type as $t ) {
-                               $retval[] = $this->parseRCType( $t );
-                       }
-
-                       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:
-                               ApiBase::dieDebug( __METHOD__, "Unknown type '$type'" );
-               }
-       }
-
        public function getCacheMode( $params ) {
                if ( isset( $params['show'] ) ) {
                        foreach ( $params['show'] as $show ) {