MediaWiki  REL1_22
ApiPatrol.php
Go to the documentation of this file.
00001 <?php
00031 class ApiPatrol extends ApiBase {
00032 
00036     public function execute() {
00037         $params = $this->extractRequestParams();
00038         $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
00039 
00040         if ( isset( $params['rcid'] ) ) {
00041             $rc = RecentChange::newFromID( $params['rcid'] );
00042             if ( !$rc ) {
00043                 $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
00044             }
00045         } else {
00046             $rev = Revision::newFromId( $params['revid'] );
00047             if ( !$rev ) {
00048                 $this->dieUsageMsg( array( 'nosuchrevid', $params['revid'] ) );
00049             }
00050             $rc = $rev->getRecentChange();
00051             if ( !$rc ) {
00052                 $this->dieUsage(
00053                     'The revision ' . $params['revid'] . " can't be patrolled as it's too old",
00054                     'notpatrollable'
00055                 );
00056             }
00057         }
00058 
00059         $retval = $rc->doMarkPatrolled( $this->getUser() );
00060 
00061         if ( $retval ) {
00062             $this->dieUsageMsg( reset( $retval ) );
00063         }
00064 
00065         $result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) );
00066         ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
00067         $this->getResult()->addValue( null, $this->getModuleName(), $result );
00068     }
00069 
00070     public function mustBePosted() {
00071         return true;
00072     }
00073 
00074     public function isWriteMode() {
00075         return true;
00076     }
00077 
00078     public function getAllowedParams() {
00079         return array(
00080             'token' => array(
00081                 ApiBase::PARAM_TYPE => 'string',
00082                 ApiBase::PARAM_REQUIRED => true
00083             ),
00084             'rcid' => array(
00085                 ApiBase::PARAM_TYPE => 'integer'
00086             ),
00087             'revid' => array(
00088                 ApiBase::PARAM_TYPE => 'integer'
00089             ),
00090         );
00091     }
00092 
00093     public function getParamDescription() {
00094         return array(
00095             'token' => 'Patrol token obtained from list=recentchanges',
00096             'rcid' => 'Recentchanges ID to patrol',
00097             'revid' => 'Revision ID to patrol',
00098         );
00099     }
00100 
00101     public function getResultProperties() {
00102         return array(
00103             '' => array(
00104                 'rcid' => 'integer',
00105                 'ns' => 'namespace',
00106                 'title' => 'string'
00107             )
00108         );
00109     }
00110 
00111     public function getDescription() {
00112         return 'Patrol a page or revision';
00113     }
00114 
00115     public function getPossibleErrors() {
00116         return array_merge(
00117             parent::getPossibleErrors(),
00118             parent::getRequireOnlyOneParameterErrorMessages( array( 'rcid', 'revid' ) ),
00119             array(
00120                 array( 'nosuchrcid', 'rcid' ),
00121                 array( 'nosuchrevid', 'revid' ),
00122                 array(
00123                     'code' => 'notpatrollable',
00124                     'info' => "The revision can't be patrolled as it's too old"
00125                 )
00126         ) );
00127     }
00128 
00129     public function needsToken() {
00130         return true;
00131     }
00132 
00133     public function getTokenSalt() {
00134         return 'patrol';
00135     }
00136 
00137     public function getExamples() {
00138         return array(
00139             'api.php?action=patrol&token=123abc&rcid=230672766',
00140             'api.php?action=patrol&token=123abc&revid=230672766'
00141         );
00142     }
00143 
00144     public function getHelpUrls() {
00145         return 'https://www.mediawiki.org/wiki/API:Patrol';
00146     }
00147 }