From 50faf2138cb80a74db03abc3b02b5506dda2d310 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Sun, 9 Jun 2013 02:44:01 +0200 Subject: [PATCH] Allow patrolling pages by revision id This became necessary as it's quite hard to get the rc id of a change from the html after I1e24733c. Bug: 49259 Change-Id: Ia7d3960cf11bf8ae0fc06ae1a0f7fcfb3c080f21 --- RELEASE-NOTES-1.22 | 1 + includes/Revision.php | 27 ++++++++++++++++------ includes/api/ApiPatrol.php | 46 ++++++++++++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 0b1d88a89a..4f33548aa1 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -170,6 +170,7 @@ production. * New upload log entries will now contain information on the relavent image (sha1 and timestamp). * (bug 49239) action=parse now can parse in preview mode. +* (bug 49259) action=patrol now accepts revision ids. === Languages updated in 1.22=== diff --git a/includes/Revision.php b/includes/Revision.php index 47626a22b3..b3b971b17a 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -867,24 +867,37 @@ class Revision implements IDBAccessObject { } /** - * @return Integer rcid of the unpatrolled row, zero if there isn't one + * @return integer rcid of the unpatrolled row, zero if there isn't one */ public function isUnpatrolled() { if ( $this->mUnpatrolled !== null ) { return $this->mUnpatrolled; } + $rc = $this->getRecentChange(); + if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == 0 ) { + $this->mUnpatrolled = $rc->getAttribute( 'rc_id' ); + } else { + $this->mUnpatrolled = 0; + } + return $this->mUnpatrolled; + } + + /** + * Get the RC object belonging to the current revision, if there's one + * + * @since 1.22 + * @return RecentChange|null + */ + public function getRecentChange() { $dbr = wfGetDB( DB_SLAVE ); - $this->mUnpatrolled = $dbr->selectField( 'recentchanges', - 'rc_id', - array( // Add redundant user,timestamp condition so we can use the existing index + return RecentChange::newFromConds( + array( 'rc_user_text' => $this->getRawUserText(), 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ), - 'rc_this_oldid' => $this->getId(), - 'rc_patrolled' => 0 + 'rc_this_oldid' => $this->getId() ), __METHOD__ ); - return (int)$this->mUnpatrolled; } /** diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php index 4d4fbba987..bd2fde2b39 100644 --- a/includes/api/ApiPatrol.php +++ b/includes/api/ApiPatrol.php @@ -35,11 +35,27 @@ class ApiPatrol extends ApiBase { */ public function execute() { $params = $this->extractRequestParams(); - - $rc = RecentChange::newFromID( $params['rcid'] ); - if ( !$rc instanceof RecentChange ) { - $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) ); + $this->requireOnlyOneParameter( $params, 'rcid', 'revid' ); + + if ( isset( $params['rcid'] ) ) { + $rc = RecentChange::newFromID( $params['rcid'] ); + if ( !$rc ) { + $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) ); + } + } else { + $rev = Revision::newFromId( $params['revid'] ); + if ( !$rev ) { + $this->dieUsageMsg( array( 'nosuchrevid', $params['revid'] ) ); + } + $rc = $rev->getRecentChange(); + if ( !$rc ) { + $this->dieUsage( + 'The revision ' . $params['revid'] . " can't be patrolled as it's too old", + 'notpatrollable' + ); + } } + $retval = $rc->doMarkPatrolled( $this->getUser() ); if ( $retval ) { @@ -66,8 +82,10 @@ class ApiPatrol extends ApiBase { ApiBase::PARAM_REQUIRED => true ), 'rcid' => array( - ApiBase::PARAM_TYPE => 'integer', - ApiBase::PARAM_REQUIRED => true + ApiBase::PARAM_TYPE => 'integer' + ), + 'revid' => array( + ApiBase::PARAM_TYPE => 'integer' ), ); } @@ -76,6 +94,7 @@ class ApiPatrol extends ApiBase { return array( 'token' => 'Patrol token obtained from list=recentchanges', 'rcid' => 'Recentchanges ID to patrol', + 'revid' => 'Revision ID to patrol', ); } @@ -94,8 +113,16 @@ class ApiPatrol extends ApiBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'nosuchrcid', 'rcid' ), + return array_merge( + parent::getPossibleErrors(), + parent::getRequireOnlyOneParameterErrorMessages( array( 'rcid', 'revid' ) ), + array( + array( 'nosuchrcid', 'rcid' ), + array( 'nosuchrevid', 'revid' ), + array( + 'code' => 'notpatrollable', + 'info' => "The revision can't be patrolled as it's too old" + ) ) ); } @@ -109,7 +136,8 @@ class ApiPatrol extends ApiBase { public function getExamples() { return array( - 'api.php?action=patrol&token=123abc&rcid=230672766' + 'api.php?action=patrol&token=123abc&rcid=230672766', + 'api.php?action=patrol&token=123abc&revid=230672766' ); } -- 2.20.1