MediaWiki  1.29.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  $this->requireOnlyOneParameter( $params, 'id', 'user', 'userid' );
43 
44  if ( !$user->isAllowed( 'block' ) ) {
45  $this->dieWithError( 'apierror-permissiondenied-unblock', 'permissiondenied' );
46  }
47  # T17810: blocked admins should have limited access here
48  if ( $user->isBlocked() ) {
50  if ( $status !== true ) {
51  $this->dieWithError(
52  $status,
53  null,
54  [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
55  );
56  }
57  }
58 
59  // Check if user can add tags
60  if ( !is_null( $params['tags'] ) ) {
62  if ( !$ableToTag->isOK() ) {
63  $this->dieStatus( $ableToTag );
64  }
65  }
66 
67  if ( $params['userid'] !== null ) {
68  $username = User::whoIs( $params['userid'] );
69 
70  if ( $username === false ) {
71  $this->dieWithError( [ 'apierror-nosuchuserid', $params['userid'] ], 'nosuchuserid' );
72  } else {
73  $params['user'] = $username;
74  }
75  }
76 
77  $data = [
78  'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}",
79  'Reason' => $params['reason'],
80  'Tags' => $params['tags']
81  ];
82  $block = Block::newFromTarget( $data['Target'] );
84  if ( $retval !== true ) {
85  $this->dieStatus( $this->errorArrayToStatus( $retval ) );
86  }
87 
88  $res['id'] = $block->getId();
89  $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
90  $res['user'] = $target instanceof User ? $target->getName() : $target;
91  $res['userid'] = $target instanceof User ? $target->getId() : 0;
92  $res['reason'] = $params['reason'];
93  $this->getResult()->addValue( null, $this->getModuleName(), $res );
94  }
95 
96  public function mustBePosted() {
97  return true;
98  }
99 
100  public function isWriteMode() {
101  return true;
102  }
103 
104  public function getAllowedParams() {
105  return [
106  'id' => [
107  ApiBase::PARAM_TYPE => 'integer',
108  ],
109  'user' => null,
110  'userid' => [
111  ApiBase::PARAM_TYPE => 'integer'
112  ],
113  'reason' => '',
114  'tags' => [
115  ApiBase::PARAM_TYPE => 'tags',
116  ApiBase::PARAM_ISMULTI => true,
117  ],
118  ];
119  }
120 
121  public function needsToken() {
122  return 'csrf';
123  }
124 
125  protected function getExamplesMessages() {
126  return [
127  'action=unblock&id=105'
128  => 'apihelp-unblock-example-id',
129  'action=unblock&user=Bob&reason=Sorry%20Bob'
130  => 'apihelp-unblock-example-user',
131  ];
132  }
133 
134  public function getHelpUrls() {
135  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
136  }
137 }
SpecialUnblock\processUnblock
static processUnblock(array $data, IContextSource $context)
Process the form.
Definition: SpecialUnblock.php:180
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
User\getId
getId()
Get the user's ID.
Definition: User.php:2200
ApiUnblock\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiUnblock.php:104
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1796
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:91
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:610
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
$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:246
$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:1113
$res
$res
Definition: database.txt:21
ApiUnblock\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiUnblock.php:100
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
ApiUnblock\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiUnblock.php:125
php
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:35
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:41
ApiUnblock\execute
execute()
Unblocks the specified user or provides the reason the unblock failed.
Definition: ApiUnblock.php:38
ApiUnblock
API module that facilitates the unblocking of users.
Definition: ApiUnblock.php:33
ApiUnblock\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiUnblock.php:134
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:718
User\whoIs
static whoIs( $id)
Get the username corresponding to a given user ID.
Definition: User.php:739
$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:246
ApiBase\requireOnlyOneParameter
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:754
Block\TYPE_AUTO
const TYPE_AUTO
Definition: Block.php:86
ApiUnblock\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition: ApiUnblock.php:96
ChangeTags\canAddTagsAccompanyingChange
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...
Definition: ChangeTags.php:395
ApiUnblock\needsToken
needsToken()
Returns the token type this module requires in order to execute.
Definition: ApiUnblock.php:121
ApiBase\dieStatus
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition: ApiBase.php:1861
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:490
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:55
SpecialBlock\checkUnblockSelf
static checkUnblockSelf( $user, User $performer)
T17810: blocked admins should not be able to block/unblock others, and probably shouldn't be able to ...
Definition: SpecialBlock.php:912
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:50
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:783
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2225
ApiBase\errorArrayToStatus
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.
Definition: ApiBase.php:1667
ApiQueryUserInfo\getBlockInfo
static getBlockInfo(Block $block)
Get basic info about a given block.
Definition: ApiQueryUserInfo.php:69