*/
class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
- public function __construct( $query, $moduleName ) {
+ public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rc' );
}
}
/**
- * @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 ) {
/**
* 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();
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 " .
$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'] ) ) {
/* Add the fields we're concerned with to our query. */
$this->addFields( array(
+ 'rc_id',
'rc_timestamp',
'rc_namespace',
'rc_title',
);
}
- $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 );
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;
}
}
$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 {
$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;
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 ) {