*/
class ApiQueryWatchlist extends ApiQueryGeneratorBase {
- public function __construct( $query, $moduleName ) {
+ public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'wl' );
}
$fld_loginfo = false;
/**
- * @param $resultPageSet ApiPageSet
+ * @param ApiPageSet $resultPageSet
* @return void
*/
private function run( $resultPageSet = null ) {
}
$this->addFields( array(
+ 'rc_id',
'rc_namespace',
'rc_title',
'rc_timestamp',
$this->addTimestampWhereRange( 'rc_timestamp', $params['dir'],
$params['start'], $params['end'] );
+ // Include in ORDER BY for uniqueness
+ $this->addWhereRange( 'rc_id', $params['dir'], null, null );
+
+ if ( !is_null( $params['continue'] ) ) {
+ $cont = explode( '|', $params['continue'] );
+ $this->dieContinueUsageIf( count( $cont ) != 2 );
+ $op = ( $params['dir'] === 'newer' ? '>' : '<' );
+ $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
+ $continueId = (int)$cont[1];
+ $this->dieContinueUsageIf( $continueId != $cont[1] );
+ $this->addWhere( "rc_timestamp $op $continueTimestamp OR " .
+ "(rc_timestamp = $continueTimestamp AND " .
+ "rc_id $op= $continueId)"
+ );
+ }
+
$this->addWhereFld( 'wl_namespace', $params['namespace'] );
if ( !$params['allrev'] ) {
|| ( isset( $show['bot'] ) && isset( $show['!bot'] ) )
|| ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
|| ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
+ || ( isset( $show['unread'] ) && isset( $show['!unread'] ) )
) {
$this->dieUsageMsg( 'show' );
}
$this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) );
$this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
$this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
+ $this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['unread'] ) );
+ $this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!unread'] ) );
}
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['user'] ) && !is_null( $params['excludeuser'] ) ) {
if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
if ( !$user->isAllowed( 'deletedhistory' ) ) {
$bitmask = Revision::DELETED_USER;
- } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
+ } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
$bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
} else {
$bitmask = 0;
// entirely from the watchlist, or someone could guess the title.
if ( !$user->isAllowed( 'deletedhistory' ) ) {
$bitmask = LogPage::DELETED_ACTION;
- } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
+ } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
$bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
} else {
$bitmask = 0;
if ( ++$count > $params['limit'] ) {
// We've reached the one extra which shows that there are
// additional pages to be had. Stop here...
- $this->setContinueEnumParameter(
- 'start',
- wfTimestamp( TS_ISO_8601, $row->rc_timestamp )
- );
+ $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
break;
}
$vals = $this->extractRowInfo( $row );
$fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
if ( !$fit ) {
- $this->setContinueEnumParameter( 'start',
- wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
+ $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
break;
}
} else {
/* Our output data. */
$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;
/* Create a new entry in the result for the title. */
return $vals;
}
- /** Copied from ApiQueryRecentChanges.
- *
- * @param string $type
- * @return string
- */
- 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 getAllowedParams() {
return array(
'allrev' => false,
'!anon',
'patrolled',
'!patrolled',
+ 'unread',
+ '!unread',
)
),
'type' => array(
'token' => array(
ApiBase::PARAM_TYPE => 'string'
),
+ 'continue' => null,
);
}
'owner' => 'The name of the user whose watchlist you\'d like to access',
'token' => 'Give a security token (settable in preferences) to ' .
'allow access to another user\'s watchlist',
- );
- }
-
- public function getResultProperties() {
- global $wgLogTypes;
-
- return array(
- '' => array(
- 'type' => array(
- ApiBase::PROP_TYPE => array(
- 'edit',
- 'new',
- 'move',
- 'log',
- 'move over redirect'
- )
- )
- ),
- 'ids' => array(
- 'pageid' => 'integer',
- 'revid' => 'integer',
- 'old_revid' => 'integer'
- ),
- 'title' => array(
- 'ns' => 'namespace',
- 'title' => 'string'
- ),
- 'user' => array(
- 'user' => 'string',
- 'anon' => 'boolean'
- ),
- 'userid' => array(
- 'userid' => 'integer',
- 'anon' => 'boolean'
- ),
- 'flags' => array(
- 'new' => 'boolean',
- 'minor' => 'boolean',
- 'bot' => 'boolean'
- ),
- 'patrol' => array(
- 'patrolled' => 'boolean'
- ),
- 'timestamp' => array(
- 'timestamp' => 'timestamp'
- ),
- 'sizes' => array(
- 'oldlen' => 'integer',
- 'newlen' => 'integer'
- ),
- 'notificationtimestamp' => array(
- 'notificationtimestamp' => array(
- ApiBase::PROP_TYPE => 'timestamp',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'comment' => array(
- 'comment' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'parsedcomment' => array(
- 'parsedcomment' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'loginfo' => array(
- 'logid' => array(
- ApiBase::PROP_TYPE => 'integer',
- ApiBase::PROP_NULLABLE => true
- ),
- 'logtype' => array(
- ApiBase::PROP_TYPE => $wgLogTypes,
- ApiBase::PROP_NULLABLE => true
- ),
- 'logaction' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- )
+ 'continue' => 'When more results are available, use this to continue',
);
}
return "Get all recent changes to pages in the logged in user's watchlist.";
}
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(), array(
- array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ),
- array(
- 'code' => 'bad_wltoken',
- 'info' => 'Incorrect watchlist token provided -- ' .
- 'please set a correct token in Special:Preferences'
- ),
- array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
- array( 'code' => 'patrol', 'info' => 'patrol property is not available' ),
- array( 'show' ),
- array(
- 'code' => 'permissiondenied',
- 'info' => 'You need the patrol right to request the patrolled flag'
- ),
- array( 'code' => 'user-excludeuser', 'info' => 'user and excludeuser cannot be used together' ),
- ) );
- }
-
public function getExamples() {
return array(
'api.php?action=query&list=watchlist',