MediaWiki  REL1_21
ApiUnblock.php
Go to the documentation of this file.
00001 <?php
00033 class ApiUnblock extends ApiBase {
00034 
00038         public function execute() {
00039                 $user = $this->getUser();
00040                 $params = $this->extractRequestParams();
00041 
00042                 if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
00043                         $this->dieUsageMsg( 'unblock-notarget' );
00044                 }
00045                 if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
00046                         $this->dieUsageMsg( 'unblock-idanduser' );
00047                 }
00048 
00049                 if ( !$user->isAllowed( 'block' ) ) {
00050                         $this->dieUsageMsg( 'cantunblock' );
00051                 }
00052                 # bug 15810: blocked admins should have limited access here
00053                 if ( $user->isBlocked() ) {
00054                         $status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
00055                         if ( $status !== true ) {
00056                                 $this->dieUsageMsg( $status );
00057                         }
00058                 }
00059 
00060                 $data = array(
00061                         'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}",
00062                         'Reason' => $params['reason']
00063                 );
00064                 $block = Block::newFromTarget( $data['Target'] );
00065                 $retval = SpecialUnblock::processUnblock( $data, $this->getContext() );
00066                 if ( $retval !== true ) {
00067                         $this->dieUsageMsg( $retval[0] );
00068                 }
00069 
00070                 $res['id'] = $block->getId();
00071                 $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
00072                 $res['user'] = $target instanceof User ? $target->getName() : $target;
00073                 $res['userid'] = $target instanceof User ? $target->getId() : 0;
00074                 $res['reason'] = $params['reason'];
00075                 $this->getResult()->addValue( null, $this->getModuleName(), $res );
00076         }
00077 
00078         public function mustBePosted() {
00079                 return true;
00080         }
00081 
00082         public function isWriteMode() {
00083                 return true;
00084         }
00085 
00086         public function getAllowedParams() {
00087                 return array(
00088                         'id' => array(
00089                                 ApiBase::PARAM_TYPE => 'integer',
00090                         ),
00091                         'user' => null,
00092                         'token' => null,
00093                         'reason' => '',
00094                 );
00095         }
00096 
00097         public function getParamDescription() {
00098                 $p = $this->getModulePrefix();
00099                 return array(
00100                         'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
00101                         'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
00102                         'token' => "An unblock token previously obtained through prop=info",
00103                         'reason' => 'Reason for unblock',
00104                 );
00105         }
00106 
00107         public function getResultProperties() {
00108                 return array(
00109                         '' => array(
00110                                 'id' => array(
00111                                         ApiBase::PROP_TYPE => 'integer',
00112                                         ApiBase::PROP_NULLABLE => true
00113                                 ),
00114                                 'user' => array(
00115                                         ApiBase::PROP_TYPE => 'string',
00116                                         ApiBase::PROP_NULLABLE => true
00117                                 ),
00118                                 'userid' => array(
00119                                         ApiBase::PROP_TYPE => 'integer',
00120                                         ApiBase::PROP_NULLABLE => true
00121                                 ),
00122                                 'reason' => array(
00123                                         ApiBase::PROP_TYPE => 'string',
00124                                         ApiBase::PROP_NULLABLE => true
00125                                 )
00126                         )
00127                 );
00128         }
00129 
00130         public function getDescription() {
00131                 return 'Unblock a user';
00132         }
00133 
00134         public function getPossibleErrors() {
00135                 return array_merge( parent::getPossibleErrors(), array(
00136                         array( 'unblock-notarget' ),
00137                         array( 'unblock-idanduser' ),
00138                         array( 'cantunblock' ),
00139                         array( 'ipbblocked' ),
00140                         array( 'ipbnounblockself' ),
00141                 ) );
00142         }
00143 
00144         public function needsToken() {
00145                 return true;
00146         }
00147 
00148         public function getTokenSalt() {
00149                 return '';
00150         }
00151 
00152         public function getExamples() {
00153                 return array(
00154                         'api.php?action=unblock&id=105',
00155                         'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
00156                 );
00157         }
00158 
00159         public function getHelpUrls() {
00160                 return 'https://www.mediawiki.org/wiki/API:Block';
00161         }
00162 }