MediaWiki REL1_28
Go to the documentation of this file.
33class ApiUnblock extends ApiBase {
38 public function execute() {
39 $user = $this->getUser();
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 }
49 if ( !$user->isAllowed( 'block' ) ) {
50 $this->dieUsageMsg( 'cantunblock' );
51 }
52 # bug 15810: blocked admins should have limited access here
53 if ( $user->isBlocked() ) {
55 if ( $status !== true ) {
56 $msg = $this->parseMsg( $status );
57 $this->dieUsage(
58 $msg['info'],
59 $msg['code'],
60 0,
61 [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
62 );
63 }
64 }
66 // Check if user can add tags
67 if ( !is_null( $params['tags'] ) ) {
69 if ( !$ableToTag->isOK() ) {
70 $this->dieStatus( $ableToTag );
71 }
72 }
74 $data = [
75 'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}",
76 'Reason' => $params['reason'],
77 'Tags' => $params['tags']
78 ];
79 $block = Block::newFromTarget( $data['Target'] );
81 if ( $retval !== true ) {
82 $this->dieUsageMsg( $retval[0] );
83 }
85 $res['id'] = $block->getId();
86 $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
87 $res['user'] = $target instanceof User ? $target->getName() : $target;
88 $res['userid'] = $target instanceof User ? $target->getId() : 0;
89 $res['reason'] = $params['reason'];
90 $this->getResult()->addValue( null, $this->getModuleName(), $res );
91 }
93 public function mustBePosted() {
94 return true;
95 }
97 public function isWriteMode() {
98 return true;
99 }
101 public function getAllowedParams() {
102 return [
103 'id' => [
104 ApiBase::PARAM_TYPE => 'integer',
105 ],
106 'user' => null,
107 'reason' => '',
108 'tags' => [
109 ApiBase::PARAM_TYPE => 'tags',
111 ],
112 ];
113 }
115 public function needsToken() {
116 return 'csrf';
117 }
119 protected function getExamplesMessages() {
120 return [
121 'action=unblock&id=105'
122 => 'apihelp-unblock-example-id',
123 'action=unblock&user=Bob&reason=Sorry%20Bob'
124 => 'apihelp-unblock-example-user',
125 ];
126 }
128 public function getHelpUrls() {
129 return '';
130 }
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:39
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:88
parseMsg( $error)
Return the error message related to a certain array.
Definition ApiBase.php:2253
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:685
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition ApiBase.php:2203
Get the result object.
Definition ApiBase.php:584
Get the name of the module being executed by this instance.
Definition ApiBase.php:464
dieStatus( $status)
Throw a UsageException based on the errors in the Status object.
Definition ApiBase.php:1674
dieUsage( $description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
Definition ApiBase.php:1585
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:53
static getBlockInfo(Block $block)
Get basic info about a given block.
API module that facilitates the unblocking of users.
Indicates whether this module requires write mode.
Returns the token type this module requires in order to execute.
Unblocks the specified user or provides the reason the unblock failed.
Return links to more detailed help pages about the module.
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Indicates whether this module must be called with a POST request.
Returns usage examples for this module.
Definition Block.php:81
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:1082
static canAddTagsAccompanyingChange(array $tags, User $user=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
Get the User object.
Get the base IContextSource object.
static checkUnblockSelf( $user, User $performer)
bug 15810: blocked admins should not be able to block/unblock others, and probably shouldn't be able ...
static processUnblock(array $data, IContextSource $context)
Process the form.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
Get the user name, or the IP of an anonymous user.
Definition User.php:2108
Get the user's ID.
Definition User.php:2083
Definition database.txt:21
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
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 local account $user
Definition hooks.txt:249
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 local account incomplete not yet checked for validity & $retval
Definition hooks.txt:268
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37