MediaWiki
REL1_24
|
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 'rcid' => array( 00081 ApiBase::PARAM_TYPE => 'integer' 00082 ), 00083 'revid' => array( 00084 ApiBase::PARAM_TYPE => 'integer' 00085 ), 00086 ); 00087 } 00088 00089 public function getParamDescription() { 00090 return array( 00091 'rcid' => 'Recentchanges ID to patrol', 00092 'revid' => 'Revision ID to patrol', 00093 ); 00094 } 00095 00096 public function getDescription() { 00097 return 'Patrol a page or revision.'; 00098 } 00099 00100 public function needsToken() { 00101 return 'patrol'; 00102 } 00103 00104 public function getExamples() { 00105 return array( 00106 'api.php?action=patrol&token=123ABC&rcid=230672766', 00107 'api.php?action=patrol&token=123ABC&revid=230672766' 00108 ); 00109 } 00110 00111 public function getHelpUrls() { 00112 return 'https://www.mediawiki.org/wiki/API:Patrol'; 00113 } 00114 }