Allow patrolling pages by revision id
authorMarius Hoch <hoo@online.de>
Sun, 9 Jun 2013 00:44:01 +0000 (02:44 +0200)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 11 Jun 2013 00:54:43 +0000 (20:54 -0400)
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
includes/Revision.php
includes/api/ApiPatrol.php

index 0b1d88a..4f33548 100644 (file)
@@ -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===
 
index 47626a2..b3b971b 100644 (file)
@@ -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;
        }
 
        /**
index 4d4fbba..bd2fde2 100644 (file)
@@ -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'
                );
        }