]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiPatrol.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / api / ApiPatrol.php
index a6f25af29ebd18f1544d0c5125e94047900814c4..06e8ae28c2261f98b9bcee48c274e635025e15fa 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
-/*
- * Created on Sep 2, 2008
- *
+/**
  * API for MediaWiki 1.14+
  *
- * Copyright (C) 2008 Soxred93 soxred93@gmail.com,
+ * Created on Sep 2, 2008
+ *
+ * Copyright © 2008 Soxred93 soxred93@gmail.com,
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
-if (!defined('MEDIAWIKI')) {
-       require_once ('ApiBase.php');
-}
-
 /**
  * Allows user to patrol pages
  * @ingroup API
  */
 class ApiPatrol extends ApiBase {
 
-       public function __construct($main, $action) {
-               parent :: __construct($main, $action);
-       }
-
        /**
         * Patrols the article or provides the reason the patrol failed.
         */
        public function execute() {
-               global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
                $params = $this->extractRequestParams();
-               
-               if(!isset($params['token']))
-                       $this->dieUsageMsg(array('missingparam', 'token'));
-               if(!isset($params['rcid']))
-                       $this->dieUsageMsg(array('missingparam', 'rcid'));
-               if(!$wgUser->matchEditToken($params['token']))
-                       $this->dieUsageMsg(array('sessionfailure'));
+               $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
 
-               $rc = RecentChange::newFromID($params['rcid']);
-               if(!$rc instanceof RecentChange)
-                       $this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
-               $retval = RecentChange::markPatrolled($params['rcid']);
-                       
-               if($retval)
-                       $this->dieUsageMsg(reset($retval));
-               
-               $result = array('rcid' => intval($rc->getAttribute('rc_id')));
-               ApiQueryBase::addTitleInfo($result, $rc->getTitle());
-               $this->getResult()->addValue(null, $this->getModuleName(), $result);
+               if ( isset( $params['rcid'] ) ) {
+                       $rc = RecentChange::newFromId( $params['rcid'] );
+                       if ( !$rc ) {
+                               $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
+                       }
+               } else {
+                       $rev = Revision::newFromId( $params['revid'] );
+                       if ( !$rev ) {
+                               $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
+                       }
+                       $rc = $rev->getRecentChange();
+                       if ( !$rc ) {
+                               $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
+                       }
+               }
+
+               $user = $this->getUser();
+               $tags = $params['tags'];
+
+               // Check if user can add tags
+               if ( !is_null( $tags ) ) {
+                       $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $user );
+                       if ( !$ableToTag->isOK() ) {
+                               $this->dieStatus( $ableToTag );
+                       }
+               }
+
+               $retval = $rc->doMarkPatrolled( $user, false, $tags );
+
+               if ( $retval ) {
+                       $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
+               }
+
+               $result = [ 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ];
+               ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
+               $this->getResult()->addValue( null, $this->getModuleName(), $result );
        }
 
-       public function isWriteMode() {
+       public function mustBePosted() {
                return true;
        }
 
-       public function getAllowedParams() {
-               return array (
-                       'token' => null,
-                       'rcid' => array(
-                               ApiBase :: PARAM_TYPE => 'integer'
-                       ),
-               );
+       public function isWriteMode() {
+               return true;
        }
 
-       public function getParamDescription() {
-               return array (
-                       'token' => 'Patrol token obtained from list=recentchanges',
-                       'rcid' => 'Recentchanges ID to patrol',
-               );
+       public function getAllowedParams() {
+               return [
+                       'rcid' => [
+                               ApiBase::PARAM_TYPE => 'integer'
+                       ],
+                       'revid' => [
+                               ApiBase::PARAM_TYPE => 'integer'
+                       ],
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ],
+               ];
        }
 
-       public function getDescription() {
-               return array (
-                       'Patrol a page or revision. '
-               );
+       public function needsToken() {
+               return 'patrol';
        }
 
-       protected function getExamples() {
-               return array(
-                       'api.php?action=patrol&token=123abc&rcid=230672766'
-               );
+       protected function getExamplesMessages() {
+               return [
+                       'action=patrol&token=123ABC&rcid=230672766'
+                               => 'apihelp-patrol-example-rcid',
+                       'action=patrol&token=123ABC&revid=230672766'
+                               => 'apihelp-patrol-example-revid',
+               ];
        }
 
-       public function getVersion() {
-               return __CLASS__ . ': $Id: ApiPatrol.php 69579 2010-07-20 02:49:55Z tstarling $';
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol';
        }
 }