MediaWiki  1.23.15
SpecialUnblock.php
Go to the documentation of this file.
1 <?php
29 class SpecialUnblock extends SpecialPage {
30 
31  protected $target;
32  protected $type;
33  protected $block;
34 
35  public function __construct() {
36  parent::__construct( 'Unblock', 'block' );
37  }
38 
39  public function execute( $par ) {
40  $this->checkPermissions();
41  $this->checkReadOnly();
42 
43  list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $this->getRequest() );
44  $this->block = Block::newFromTarget( $this->target );
45  if ( $this->target instanceof User ) {
46  # Set the 'relevant user' in the skin, so it displays links like Contributions,
47  # User logs, UserRights, etc.
48  $this->getSkin()->setRelevantUser( $this->target );
49  }
50 
51  $this->setHeaders();
52  $this->outputHeader();
53 
54  $out = $this->getOutput();
55  $out->setPageTitle( $this->msg( 'unblockip' ) );
56  $out->addModules( 'mediawiki.special' );
57 
58  $form = new HTMLForm( $this->getFields(), $this->getContext() );
59  $form->setWrapperLegendMsg( 'unblockip' );
60  $form->setSubmitCallback( array( __CLASS__, 'processUIUnblock' ) );
61  $form->setSubmitTextMsg( 'ipusubmit' );
62  $form->addPreText( $this->msg( 'unblockiptext' )->parseAsBlock() );
63 
64  if ( $form->show() ) {
65  switch ( $this->type ) {
66  case Block::TYPE_USER:
67  case Block::TYPE_IP:
68  $out->addWikiMsg( 'unblocked', wfEscapeWikiText( $this->target ) );
69  break;
70  case Block::TYPE_RANGE:
71  $out->addWikiMsg( 'unblocked-range', wfEscapeWikiText( $this->target ) );
72  break;
73  case Block::TYPE_ID:
74  case Block::TYPE_AUTO:
75  $out->addWikiMsg( 'unblocked-id', wfEscapeWikiText( $this->target ) );
76  break;
77  }
78  }
79  }
80 
81  protected function getFields() {
82  $fields = array(
83  'Target' => array(
84  'type' => 'text',
85  'label-message' => 'ipadressorusername',
86  'tabindex' => '1',
87  'size' => '45',
88  'required' => true,
89  ),
90  'Name' => array(
91  'type' => 'info',
92  'label-message' => 'ipadressorusername',
93  ),
94  'Reason' => array(
95  'type' => 'text',
96  'label-message' => 'ipbreason',
97  )
98  );
99 
100  if ( $this->block instanceof Block ) {
101  list( $target, $type ) = $this->block->getTargetAndType();
102 
103  # Autoblocks are logged as "autoblock #123 because the IP was recently used by
104  # User:Foo, and we've just got any block, auto or not, that applies to a target
105  # the user has specified. Someone could be fishing to connect IPs to autoblocks,
106  # so don't show any distinction between unblocked IPs and autoblocked IPs
107  if ( $type == Block::TYPE_AUTO && $this->type == Block::TYPE_IP ) {
108  $fields['Target']['default'] = $this->target;
109  unset( $fields['Name'] );
110  } else {
111  $fields['Target']['default'] = $target;
112  $fields['Target']['type'] = 'hidden';
113  switch ( $type ) {
114  case Block::TYPE_USER:
115  case Block::TYPE_IP:
116  $fields['Name']['default'] = Linker::link(
117  $target->getUserPage(),
118  $target->getName()
119  );
120  $fields['Name']['raw'] = true;
121  break;
122 
123  case Block::TYPE_RANGE:
124  $fields['Name']['default'] = $target;
125  break;
126 
127  case Block::TYPE_AUTO:
128  $fields['Name']['default'] = $this->block->getRedactedName();
129  $fields['Name']['raw'] = true;
130  # Don't expose the real target of the autoblock
131  $fields['Target']['default'] = "#{$this->target}";
132  break;
133  }
134  }
135  } else {
136  $fields['Target']['default'] = $this->target;
137  unset( $fields['Name'] );
138  }
139 
140  return $fields;
141  }
142 
149  public static function processUIUnblock( array $data, HTMLForm $form ) {
150  return self::processUnblock( $data, $form->getContext() );
151  }
152 
161  public static function processUnblock( array $data, IContextSource $context ) {
162  $performer = $context->getUser();
163  $target = $data['Target'];
164  $block = Block::newFromTarget( $data['Target'] );
165 
166  if ( !$block instanceof Block ) {
167  return array( array( 'ipb_cant_unblock', $target ) );
168  }
169 
170  # bug 15810: blocked admins should have limited access here. This
171  # won't allow sysops to remove autoblocks on themselves, but they
172  # should have ipblock-exempt anyway
173  $status = SpecialBlock::checkUnblockSelf( $target, $performer );
174  if ( $status !== true ) {
175  throw new ErrorPageError( 'badaccess', $status );
176  }
177 
178  # If the specified IP is a single address, and the block is a range block, don't
179  # unblock the whole range.
181  if ( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) {
182  $range = $block->getTarget();
183 
184  return array( array( 'ipb_blocked_as_range', $target, $range ) );
185  }
186 
187  # If the name was hidden and the blocking user cannot hide
188  # names, then don't allow any block removals...
189  if ( !$performer->isAllowed( 'hideuser' ) && $block->mHideName ) {
190  return array( 'unblock-hideuser' );
191  }
192 
193  # Delete block
194  if ( !$block->delete() ) {
195  return array( 'ipb_cant_unblock', htmlspecialchars( $block->getTarget() ) );
196  }
197 
198  # Unset _deleted fields as needed
199  if ( $block->mHideName ) {
200  # Something is deeply FUBAR if this is not a User object, but who knows?
201  $id = $block->getTarget() instanceof User
202  ? $block->getTarget()->getID()
203  : User::idFromName( $block->getTarget() );
204 
205  RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
206  }
207 
208  # Redact the name (IP address) for autoblocks
209  if ( $block->getType() == Block::TYPE_AUTO ) {
210  $page = Title::makeTitle( NS_USER, '#' . $block->getId() );
211  } else {
212  $page = $block->getTarget() instanceof User
213  ? $block->getTarget()->getUserpage()
214  : Title::makeTitle( NS_USER, $block->getTarget() );
215  }
216 
217  # Make log entry
218  $log = new LogPage( 'block' );
219  $log->addEntry( 'unblock', $page, $data['Reason'], array(), $performer );
220 
221  return true;
222  }
223 
224  protected function getGroupName() {
225  return 'users';
226  }
227 }
SpecialUnblock\processUnblock
static processUnblock(array $data, IContextSource $context)
Process the form.
Definition: SpecialUnblock.php:161
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
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
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
Block\TYPE_IP
const TYPE_IP
Definition: Block.php:48
Block\TYPE_RANGE
const TYPE_RANGE
Definition: Block.php:49
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2584
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:287
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:987
SpecialUnblock\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialUnblock.php:224
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:555
RevisionDeleteUser\unsuppressUserName
static unsuppressUserName( $name, $userId, $dbw=null)
Definition: RevisionDeleteUser.php:133
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
$out
$out
Definition: UtfNormalGenerate.php:167
Block\TYPE_ID
const TYPE_ID
Definition: Block.php:51
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:32
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialUnblock\getFields
getFields()
Definition: SpecialUnblock.php:81
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
SpecialUnblock\$type
$type
Definition: SpecialUnblock.php:32
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:508
SpecialUnblock\processUIUnblock
static processUIUnblock(array $data, HTMLForm $form)
Submit callback for an HTMLForm object.
Definition: SpecialUnblock.php:149
SpecialUnblock\execute
execute( $par)
Default execute method Checks user permissions, calls the function given in mFunction.
Definition: SpecialUnblock.php:39
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:525
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:2124
SpecialUnblock\$block
$block
Definition: SpecialUnblock.php:33
IContextSource\getUser
getUser()
Get the User object.
Block\TYPE_AUTO
const TYPE_AUTO
Definition: Block.php:50
SpecialUnblock\$target
$target
Definition: SpecialUnblock.php:31
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
Block\TYPE_USER
const TYPE_USER
Definition: Block.php:47
SpecialUnblock\__construct
__construct()
Definition: SpecialUnblock.php:35
User\idFromName
static idFromName( $name)
Get database id given a user name.
Definition: User.php:503
type
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition: postgres.txt:22
Block
Definition: Block.php:22
block
this hook is for auditing only etc block
Definition: hooks.txt:1644
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
NS_USER
const NS_USER
Definition: Defines.php:81
SpecialBlock\getTargetAndType
static getTargetAndType( $par, WebRequest $request=null)
Determine the target of the block, and the type of target TODO: should be in Block....
Definition: SpecialBlock.php:455
SpecialPage\checkReadOnly
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
Definition: SpecialPage.php:300
SpecialUnblock
A special page for unblocking users.
Definition: SpecialUnblock.php:29
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:443
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:100