MediaWiki  REL1_24
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             'reason' => '',
00093         );
00094     }
00095 
00096     public function getParamDescription() {
00097         $p = $this->getModulePrefix();
00098 
00099         return array(
00100             'id' => "ID of the block you want to unblock (obtained through list=blocks). " .
00101                 "Cannot be used together with {$p}user",
00102             'user' => "Username, IP address or IP range you want to unblock. " .
00103                 "Cannot be used together with {$p}id",
00104             'reason' => 'Reason for unblock',
00105         );
00106     }
00107 
00108     public function getDescription() {
00109         return 'Unblock a user.';
00110     }
00111 
00112     public function needsToken() {
00113         return 'csrf';
00114     }
00115 
00116     public function getExamples() {
00117         return array(
00118             'api.php?action=unblock&id=105',
00119             'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
00120         );
00121     }
00122 
00123     public function getHelpUrls() {
00124         return 'https://www.mediawiki.org/wiki/API:Block';
00125     }
00126 }