MediaWiki  1.27.3
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() ) {
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  }
65 
66  // Check if user can add tags
67  if ( !is_null( $params['tags'] ) ) {
69  if ( !$ableToTag->isOK() ) {
70  $this->dieStatus( $ableToTag );
71  }
72  }
73 
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  }
84 
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  }
92 
93  public function mustBePosted() {
94  return true;
95  }
96 
97  public function isWriteMode() {
98  return true;
99  }
100 
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',
110  ApiBase::PARAM_ISMULTI => true,
111  ],
112  ];
113  }
114 
115  public function needsToken() {
116  return 'csrf';
117  }
118 
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  }
127 
128  public function getHelpUrls() {
129  return 'https://www.mediawiki.org/wiki/API:Block';
130  }
131 }
static checkUnblockSelf($user, User $performer)
bug 15810: blocked admins should not be able to block/unblock others, and probably shouldn't be able ...
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:88
getAllowedParams()
Definition: ApiUnblock.php:101
getResult()
Get the result object.
Definition: ApiBase.php:584
API module that facilitates the unblocking of users.
Definition: ApiUnblock.php:33
execute()
Unblocks the specified user or provides the reason the unblock failed.
Definition: ApiUnblock.php:38
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:685
getExamplesMessages()
Definition: ApiUnblock.php:119
static getBlockInfo(Block $block)
Get basic info about a given block.
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:1077
$res
Definition: database.txt:21
getContext()
Get the base IContextSource object.
$params
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:464
static processUnblock(array $data, IContextSource $context)
Process the form.
const TYPE_AUTO
Definition: Block.php:78
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:246
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
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:53
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:1526
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:1008
This abstract class implements many basic API functions, and is the base of all API classes...
Definition: ApiBase.php:39
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:378
parseMsg($error)
Return the error message related to a certain array.
Definition: ApiBase.php:2194
dieStatus($status)
Throw a UsageException based on the errors in the Status object.
Definition: ApiBase.php:1615
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:246
getUser()
Get the User object.
dieUsageMsg($error)
Output the error message related to a certain array.
Definition: ApiBase.php:2144