Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67624


Change subject: Allow patrolling pages by revision id
......................................................................

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
---
M includes/Revision.php
M includes/api/ApiPatrol.php
2 files changed, 48 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/24/67624/1

diff --git a/includes/Revision.php b/includes/Revision.php
index 47626a2..623f656 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -867,24 +867,35 @@
        }
 
        /**
-        * @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;
                }
-               $dbr = wfGetDB( DB_SLAVE );
-               $this->mUnpatrolled = $dbr->selectField( 'recentchanges',
-                       'rc_id',
-                       array( // Add redundant user,timestamp condition so we 
can use the existing index
+               $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
+        *
+        * @return RecentChange|null
+        */
+       public function getRecentChange() {
+               return RecentChange::newFromConds(
+                       array(
                                'rc_user_text' => $this->getRawUserText(),
-                               'rc_timestamp' => $dbr->timestamp( 
$this->getTimestamp() ),
-                               'rc_this_oldid' => $this->getId(),
-                               'rc_patrolled' => 0
+                               'rc_timestamp' => $this->getTimestamp(),
+                               'rc_this_oldid' => $this->getId()
                        ),
                        __METHOD__
                );
-               return (int)$this->mUnpatrolled;
        }
 
        /**
diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php
index 4d4fbba..f35f7b8 100644
--- a/includes/api/ApiPatrol.php
+++ b/includes/api/ApiPatrol.php
@@ -35,11 +35,27 @@
         */
        public function execute() {
                $params = $this->extractRequestParams();
+               $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
 
-               $rc = RecentChange::newFromID( $params['rcid'] );
-               if ( !$rc instanceof RecentChange ) {
-                       $this->dieUsageMsg( array( 'nosuchrcid', 
$params['rcid'] ) );
+               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 to old",
+                                       'patrolerror'
+                               );
+                       }
                }
+
                $retval = $rc->doMarkPatrolled( $this->getUser() );
 
                if ( $retval ) {
@@ -66,8 +82,10 @@
                                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 @@
                return array(
                        'token' => 'Patrol token obtained from 
list=recentchanges',
                        'rcid' => 'Recentchanges ID to patrol',
+                       'revid' => 'Revision ID to patrol',
                );
        }
 
@@ -96,6 +115,8 @@
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'nosuchrcid', 'rcid' ),
+                       array( 'nosuchrevid', 'revid' ),
+                       array( 'notpatrollable', 'revid' ),
                ) );
        }
 
@@ -109,7 +130,8 @@
 
        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'
                );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/67624
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia7d3960cf11bf8ae0fc06ae1a0f7fcfb3c080f21
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to