MediaWiki  1.23.2
ApiUnblock.php
Go to the documentation of this file.
1 <?php
33 class ApiUnblock extends ApiBase {
34 
38  public function execute() {
39  $user = $this->getUser();
40  $params = $this->extractRequestParams();
41 
42  if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
43  $this->dieUsageMsg( 'unblock-notarget' );
44  }
45  if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
46  $this->dieUsageMsg( 'unblock-idanduser' );
47  }
48 
49  if ( !$user->isAllowed( 'block' ) ) {
50  $this->dieUsageMsg( 'cantunblock' );
51  }
52  # bug 15810: blocked admins should have limited access here
53  if ( $user->isBlocked() ) {
54  $status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
55  if ( $status !== true ) {
56  $this->dieUsageMsg( $status );
57  }
58  }
59 
60  $data = array(
61  'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}",
62  'Reason' => $params['reason']
63  );
64  $block = Block::newFromTarget( $data['Target'] );
66  if ( $retval !== true ) {
67  $this->dieUsageMsg( $retval[0] );
68  }
69 
70  $res['id'] = $block->getId();
71  $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
72  $res['user'] = $target instanceof User ? $target->getName() : $target;
73  $res['userid'] = $target instanceof User ? $target->getId() : 0;
74  $res['reason'] = $params['reason'];
75  $this->getResult()->addValue( null, $this->getModuleName(), $res );
76  }
77 
78  public function mustBePosted() {
79  return true;
80  }
81 
82  public function isWriteMode() {
83  return true;
84  }
85 
86  public function getAllowedParams() {
87  return array(
88  'id' => array(
89  ApiBase::PARAM_TYPE => 'integer',
90  ),
91  'user' => null,
92  'token' => null,
93  'reason' => '',
94  );
95  }
96 
97  public function getParamDescription() {
98  $p = $this->getModulePrefix();
99 
100  return array(
101  'id' => "ID of the block you want to unblock (obtained through list=blocks). " .
102  "Cannot be used together with {$p}user",
103  'user' => "Username, IP address or IP range you want to unblock. " .
104  "Cannot be used together with {$p}id",
105  'token' => "An unblock token previously obtained through prop=info",
106  'reason' => 'Reason for unblock',
107  );
108  }
109 
110  public function getResultProperties() {
111  return array(
112  '' => array(
113  'id' => array(
114  ApiBase::PROP_TYPE => 'integer',
115  ApiBase::PROP_NULLABLE => true
116  ),
117  'user' => array(
118  ApiBase::PROP_TYPE => 'string',
119  ApiBase::PROP_NULLABLE => true
120  ),
121  'userid' => array(
122  ApiBase::PROP_TYPE => 'integer',
123  ApiBase::PROP_NULLABLE => true
124  ),
125  'reason' => array(
126  ApiBase::PROP_TYPE => 'string',
127  ApiBase::PROP_NULLABLE => true
128  )
129  )
130  );
131  }
132 
133  public function getDescription() {
134  return 'Unblock a user.';
135  }
136 
137  public function getPossibleErrors() {
138  return array_merge( parent::getPossibleErrors(), array(
139  array( 'unblock-notarget' ),
140  array( 'unblock-idanduser' ),
141  array( 'cantunblock' ),
142  array( 'ipbblocked' ),
143  array( 'ipbnounblockself' ),
144  ) );
145  }
146 
147  public function needsToken() {
148  return true;
149  }
150 
151  public function getTokenSalt() {
152  return '';
153  }
154 
155  public function getExamples() {
156  return array(
157  'api.php?action=unblock&id=105',
158  'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
159  );
160  }
161 
162  public function getHelpUrls() {
163  return 'https://www.mediawiki.org/wiki/API:Block';
164  }
165 }
SpecialUnblock\processUnblock
static processUnblock(array $data, IContextSource $context)
Process the form.
Definition: SpecialUnblock.php:161
ContextSource\getContext
getContext()
Get the RequestContext object.
Definition: ContextSource.php:40
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
User\getId
getId()
Get the user's ID.
Definition: User.php:1852
ApiUnblock\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiUnblock.php:86
ApiBase\dieUsageMsg
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition: ApiBase.php:1929
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
$params
$params
Definition: styleTest.css.php:40
Block\newFromTarget
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
Definition: Block.php:970
ApiUnblock\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiUnblock.php:133
ApiUnblock\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiUnblock.php:82
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:132
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
ApiUnblock\execute
execute()
Unblocks the specified user or provides the reason the unblock failed.
Definition: ApiUnblock.php:38
ApiUnblock\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiUnblock.php:110
ApiUnblock
API module that facilitates the unblocking of users.
Definition: ApiUnblock.php:33
ApiUnblock\getPossibleErrors
getPossibleErrors()
Returns a list of all possible errors returned by the module.
Definition: ApiUnblock.php:137
ApiUnblock\getHelpUrls
getHelpUrls()
Definition: ApiUnblock.php:162
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiBase\PROP_TYPE
const PROP_TYPE
Definition: ApiBase.php:74
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:165
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
ApiUnblock\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiUnblock.php:97
ApiUnblock\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiUnblock.php:155
ApiBase\PROP_NULLABLE
const PROP_NULLABLE
Definition: ApiBase.php:76
ApiUnblock\getTokenSalt
getTokenSalt()
Returns the token salt if there is one, '' if the module doesn't require a salt, else false if the mo...
Definition: ApiUnblock.php:151
Block\TYPE_AUTO
const TYPE_AUTO
Definition: Block.php:50
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
ApiUnblock\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition: ApiUnblock.php:78
ApiUnblock\needsToken
needsToken()
Returns whether this module requires a token to execute It is used to show possible errors in action=...
Definition: ApiUnblock.php:147
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
SpecialBlock\checkUnblockSelf
static checkUnblockSelf( $user, User $performer)
bug 15810: blocked admins should not be able to block/unblock others, and probably shouldn't be able ...
Definition: SpecialBlock.php:869
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
$res
$res
Definition: database.txt:21
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:1876
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237