MediaWiki  REL1_23
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 
00100         return array(
00101             'id' => "ID of the block you want to unblock (obtained through list=blocks). " .
00102                 "Cannot be used together with {$p}user",
00103             'user' => "Username, IP address or IP range you want to unblock. " .
00104                 "Cannot be used together with {$p}id",
00105             'token' => "An unblock token previously obtained through prop=info",
00106             'reason' => 'Reason for unblock',
00107         );
00108     }
00109 
00110     public function getResultProperties() {
00111         return array(
00112             '' => array(
00113                 'id' => array(
00114                     ApiBase::PROP_TYPE => 'integer',
00115                     ApiBase::PROP_NULLABLE => true
00116                 ),
00117                 'user' => array(
00118                     ApiBase::PROP_TYPE => 'string',
00119                     ApiBase::PROP_NULLABLE => true
00120                 ),
00121                 'userid' => array(
00122                     ApiBase::PROP_TYPE => 'integer',
00123                     ApiBase::PROP_NULLABLE => true
00124                 ),
00125                 'reason' => array(
00126                     ApiBase::PROP_TYPE => 'string',
00127                     ApiBase::PROP_NULLABLE => true
00128                 )
00129             )
00130         );
00131     }
00132 
00133     public function getDescription() {
00134         return 'Unblock a user.';
00135     }
00136 
00137     public function getPossibleErrors() {
00138         return array_merge( parent::getPossibleErrors(), array(
00139             array( 'unblock-notarget' ),
00140             array( 'unblock-idanduser' ),
00141             array( 'cantunblock' ),
00142             array( 'ipbblocked' ),
00143             array( 'ipbnounblockself' ),
00144         ) );
00145     }
00146 
00147     public function needsToken() {
00148         return true;
00149     }
00150 
00151     public function getTokenSalt() {
00152         return '';
00153     }
00154 
00155     public function getExamples() {
00156         return array(
00157             'api.php?action=unblock&id=105',
00158             'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
00159         );
00160     }
00161 
00162     public function getHelpUrls() {
00163         return 'https://www.mediawiki.org/wiki/API:Block';
00164     }
00165 }