3 * Implements Special:Block
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page that allows users with 'block' right to block users from
26 * editing pages and other actions
28 * @ingroup SpecialPage
30 class SpecialBlock
extends FormSpecialPage
{
31 /** The maximum number of edits a user can have and still be hidden
32 * TODO: config setting? */
33 const HIDEUSER_CONTRIBLIMIT
= 1000;
35 /** @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
36 * or as subpage (Special:Block/Foo) */
39 /// @var Block::TYPE_ constant
42 /// @var User|String the previous block target
43 protected $previousTarget;
45 /// @var Bool whether the previous submission of the form asked for HideUser
46 protected $requestedHideUser;
49 protected $alreadyBlocked;
52 protected $preErrors = array();
54 public function __construct() {
55 parent
::__construct( 'Block', 'block' );
59 * Checks that the user can unblock themselves if they are trying to do so
62 * @throws ErrorPageError
64 protected function checkExecutePermissions( User
$user ) {
65 parent
::checkExecutePermissions( $user );
67 # bug 15810: blocked admins should have limited access here
68 $status = self
::checkUnblockSelf( $this->target
, $user );
69 if ( $status !== true ) {
70 throw new ErrorPageError( 'badaccess', $status );
75 * Handle some magic here
79 protected function setParameter( $par ) {
80 # Extract variables from the request. Try not to get into a situation where we
81 # need to extract *every* variable from the form just for processing here, but
82 # there are legitimate uses for some variables
83 $request = $this->getRequest();
84 list( $this->target
, $this->type
) = self
::getTargetAndType( $par, $request );
85 if ( $this->target
instanceof User
) {
86 # Set the 'relevant user' in the skin, so it displays links like Contributions,
87 # User logs, UserRights, etc.
88 $this->getSkin()->setRelevantUser( $this->target
);
91 list( $this->previousTarget
, /*...*/ ) = Block
::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
92 $this->requestedHideUser
= $request->getBool( 'wpHideUser' );
96 * Customizes the HTMLForm a bit
98 * @param $form HTMLForm
100 protected function alterForm( HTMLForm
$form ) {
101 $form->setWrapperLegendMsg( 'blockip-legend' );
102 $form->setHeaderText( '' );
103 $form->setSubmitCallback( array( __CLASS__
, 'processUIForm' ) );
105 $msg = $this->alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit';
106 $form->setSubmitTextMsg( $msg );
108 # Don't need to do anything if the form has been posted
109 if ( !$this->getRequest()->wasPosted() && $this->preErrors
) {
110 $s = HTMLForm
::formatErrors( $this->preErrors
);
112 $form->addHeaderText( Html
::rawElement(
114 array( 'class' => 'error' ),
122 * Get the HTMLForm descriptor array for the block form
125 protected function getFormFields() {
126 global $wgBlockAllowsUTEdit;
128 $user = $this->getUser();
130 $suggestedDurations = self
::getSuggestedDurations();
135 'label-message' => 'ipadressorusername',
137 'id' => 'mw-bi-target',
141 'validation-callback' => array( __CLASS__
, 'validateTargetField' ),
144 'type' => !count( $suggestedDurations ) ?
'text' : 'selectorother',
145 'label-message' => 'ipbexpiry',
148 'options' => $suggestedDurations,
149 'other' => $this->msg( 'ipbother' )->text(),
150 'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(),
153 'type' => 'selectandother',
154 'label-message' => 'ipbreason',
155 'options-message' => 'ipbreason-dropdown',
157 'CreateAccount' => array(
159 'label-message' => 'ipbcreateaccount',
164 if ( self
::canBlockEmail( $user ) ) {
165 $a['DisableEmail'] = array(
167 'label-message' => 'ipbemailban',
171 if ( $wgBlockAllowsUTEdit ) {
172 $a['DisableUTEdit'] = array(
174 'label-message' => 'ipb-disableusertalk',
179 $a['AutoBlock'] = array(
181 'label-message' => 'ipbenableautoblock',
185 # Allow some users to hide name from block log, blocklist and listusers
186 if ( $user->isAllowed( 'hideuser' ) ) {
187 $a['HideUser'] = array(
189 'label-message' => 'ipbhidename',
190 'cssclass' => 'mw-block-hideuser',
194 # Watchlist their user page? (Only if user is logged in)
195 if ( $user->isLoggedIn() ) {
198 'label-message' => 'ipbwatchuser',
202 $a['HardBlock'] = array(
204 'label-message' => 'ipb-hardblock',
208 # This is basically a copy of the Target field, but the user can't change it, so we
209 # can see if the warnings we maybe showed to the user before still apply
210 $a['PreviousTarget'] = array(
215 # We'll turn this into a checkbox if we need to
216 $a['Confirm'] = array(
219 'label-message' => 'ipb-confirm',
222 $this->maybeAlterFormDefaults( $a );
224 // Allow extensions to add more fields
225 wfRunHooks( 'SpecialBlockModifyFormFields', array( $this, &$a ) );
231 * If the user has already been blocked with similar settings, load that block
232 * and change the defaults for the form fields to match the existing settings.
233 * @param array $fields HTMLForm descriptor array
234 * @return Bool whether fields were altered (that is, whether the target is
237 protected function maybeAlterFormDefaults( &$fields ) {
238 # This will be overwritten by request data
239 $fields['Target']['default'] = (string)$this->target
;
242 $fields['PreviousTarget']['default'] = (string)$this->target
;
244 $block = Block
::newFromTarget( $this->target
);
246 if ( $block instanceof Block
&& !$block->mAuto
# The block exists and isn't an autoblock
247 && ( $this->type
!= Block
::TYPE_RANGE
# The block isn't a rangeblock
248 ||
$block->getTarget() == $this->target
) # or if it is, the range is what we're about to block
250 $fields['HardBlock']['default'] = $block->isHardblock();
251 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
252 $fields['AutoBlock']['default'] = $block->isAutoblocking();
254 if ( isset( $fields['DisableEmail'] ) ) {
255 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
258 if ( isset( $fields['HideUser'] ) ) {
259 $fields['HideUser']['default'] = $block->mHideName
;
262 if ( isset( $fields['DisableUTEdit'] ) ) {
263 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
266 // If the username was hidden (ipb_deleted == 1), don't show the reason
267 // unless this user also has rights to hideuser: Bug 35839
268 if ( !$block->mHideName ||
$this->getUser()->isAllowed( 'hideuser' ) ) {
269 $fields['Reason']['default'] = $block->mReason
;
271 $fields['Reason']['default'] = '';
274 if ( $this->getRequest()->wasPosted() ) {
275 # Ok, so we got a POST submission asking us to reblock a user. So show the
276 # confirm checkbox; the user will only see it if they haven't previously
277 $fields['Confirm']['type'] = 'check';
279 # We got a target, but it wasn't a POST request, so the user must have gone
280 # to a link like [[Special:Block/User]]. We don't need to show the checkbox
281 # as long as they go ahead and block *that* user
282 $fields['Confirm']['default'] = 1;
285 if ( $block->mExpiry
== 'infinity' ) {
286 $fields['Expiry']['default'] = 'infinite';
288 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822
, $block->mExpiry
);
291 $this->alreadyBlocked
= true;
292 $this->preErrors
[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) );
295 # We always need confirmation to do HideUser
296 if ( $this->requestedHideUser
) {
297 $fields['Confirm']['type'] = 'check';
298 unset( $fields['Confirm']['default'] );
299 $this->preErrors
[] = array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
302 # Or if the user is trying to block themselves
303 if ( (string)$this->target
=== $this->getUser()->getName() ) {
304 $fields['Confirm']['type'] = 'check';
305 unset( $fields['Confirm']['default'] );
306 $this->preErrors
[] = array( 'ipb-blockingself', 'ipb-confirmaction' );
311 * Add header elements like block log entries, etc.
314 protected function preText() {
315 $this->getOutput()->addModules( 'mediawiki.special.block' );
317 $text = $this->msg( 'blockiptext' )->parse();
319 $otherBlockMessages = array();
320 if ( $this->target
!== null ) {
321 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
322 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target
) );
324 if ( count( $otherBlockMessages ) ) {
325 $s = Html
::rawElement(
328 $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
333 foreach ( $otherBlockMessages as $link ) {
334 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
337 $s .= Html
::rawElement(
339 array( 'class' => 'mw-blockip-alreadyblocked' ),
351 * Add footer elements to the form
354 protected function postText() {
357 # Link to the user's contributions, if applicable
358 if ( $this->target
instanceof User
) {
359 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->target
->getName() );
360 $links[] = Linker
::link(
362 $this->msg( 'ipb-blocklist-contribs', $this->target
->getName() )->escaped()
366 # Link to unblock the specified user, or to a blank unblock form
367 if ( $this->target
instanceof User
) {
368 $message = $this->msg( 'ipb-unblock-addr', wfEscapeWikiText( $this->target
->getName() ) )->parse();
369 $list = SpecialPage
::getTitleFor( 'Unblock', $this->target
->getName() );
371 $message = $this->msg( 'ipb-unblock' )->parse();
372 $list = SpecialPage
::getTitleFor( 'Unblock' );
374 $links[] = Linker
::linkKnown( $list, $message, array() );
376 # Link to the block list
377 $links[] = Linker
::linkKnown(
378 SpecialPage
::getTitleFor( 'BlockList' ),
379 $this->msg( 'ipb-blocklist' )->escaped()
382 $user = $this->getUser();
384 # Link to edit the block dropdown reasons, if applicable
385 if ( $user->isAllowed( 'editinterface' ) ) {
386 $links[] = Linker
::link(
387 Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' ),
388 $this->msg( 'ipb-edit-dropdown' )->escaped(),
390 array( 'action' => 'edit' )
394 $text = Html
::rawElement(
396 array( 'class' => 'mw-ipb-conveniencelinks' ),
397 $this->getLanguage()->pipeList( $links )
400 $userTitle = self
::getTargetUserTitle( $this->target
);
402 # Get relevant extracts from the block and suppression logs, if possible
405 LogEventsList
::showLogExtract(
412 'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
413 'showIfEmpty' => false
418 # Add suppression block entries if allowed
419 if ( $user->isAllowed( 'suppressionlog' ) ) {
420 LogEventsList
::showLogExtract(
427 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
428 'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
429 'showIfEmpty' => false
441 * Get a user page target for things like logs.
442 * This handles account and IP range targets.
443 * @param $target User|string
446 protected static function getTargetUserTitle( $target ) {
447 if ( $target instanceof User
) {
448 return $target->getUserPage();
449 } elseif ( IP
::isIPAddress( $target ) ) {
450 return Title
::makeTitleSafe( NS_USER
, $target );
457 * Determine the target of the block, and the type of target
458 * TODO: should be in Block.php?
459 * @param string $par subpage parameter passed to setup, or data value from
461 * @param $request WebRequest optionally try and get data from a request too
462 * @return array( User|string|null, Block::TYPE_ constant|null )
464 public static function getTargetAndType( $par, WebRequest
$request = null ) {
471 # The HTMLForm will check wpTarget first and only if it doesn't get
472 # a value use the default, which will be generated from the options
473 # below; so this has to have a higher precedence here than $par, or
474 # we could end up with different values in $this->target and the HTMLForm!
475 if ( $request instanceof WebRequest
) {
476 $target = $request->getText( 'wpTarget', null );
483 if ( $request instanceof WebRequest
) {
484 $target = $request->getText( 'ip', null );
489 if ( $request instanceof WebRequest
) {
490 $target = $request->getText( 'wpBlockAddress', null );
497 list( $target, $type ) = Block
::parseTarget( $target );
499 if ( $type !== null ) {
500 return array( $target, $type );
504 return array( null, null );
508 * HTMLForm field validation-callback for Target field.
510 * @param $value String
511 * @param $alldata Array
512 * @param $form HTMLForm
515 public static function validateTargetField( $value, $alldata, $form ) {
516 $status = self
::validateTarget( $value, $form->getUser() );
517 if ( !$status->isOK() ) {
518 $errors = $status->getErrorsArray();
520 return call_user_func_array( array( $form, 'msg' ), $errors[0] );
527 * Validate a block target.
530 * @param string $value Block target to check
531 * @param User $user Performer of the block
534 public static function validateTarget( $value, User
$user ) {
535 global $wgBlockCIDRLimit;
537 /** @var User $target */
538 list( $target, $type ) = self
::getTargetAndType( $value );
539 $status = Status
::newGood( $target );
541 if ( $type == Block
::TYPE_USER
) {
542 if ( $target->isAnon() ) {
545 wfEscapeWikiText( $target->getName() )
549 $unblockStatus = self
::checkUnblockSelf( $target, $user );
550 if ( $unblockStatus !== true ) {
551 $status->fatal( 'badaccess', $unblockStatus );
553 } elseif ( $type == Block
::TYPE_RANGE
) {
554 list( $ip, $range ) = explode( '/', $target, 2 );
557 ( IP
::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
558 ( IP
::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
560 // Range block effectively disabled
561 $status->fatal( 'range_block_disabled' );
565 ( IP
::isIPv4( $ip ) && $range > 32 ) ||
566 ( IP
::isIPv6( $ip ) && $range > 128 )
569 $status->fatal( 'ip_range_invalid' );
572 if ( IP
::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
573 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
576 if ( IP
::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
577 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
579 } elseif ( $type == Block
::TYPE_IP
) {
582 $status->fatal( 'badipaddress' );
589 * Submit callback for an HTMLForm object, will simply pass
591 * @param $form HTMLForm
592 * @return Bool|String
594 public static function processUIForm( array $data, HTMLForm
$form ) {
595 return self
::processForm( $data, $form->getContext() );
599 * Given the form data, actually implement a block
601 * @param $context IContextSource
602 * @return Bool|String
604 public static function processForm( array $data, IContextSource
$context ) {
605 global $wgBlockAllowsUTEdit;
607 $performer = $context->getUser();
609 // Handled by field validator callback
610 // self::validateTargetField( $data['Target'] );
612 # This might have been a hidden field or a checkbox, so interesting data
614 $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true );
616 /** @var User $target */
617 list( $target, $type ) = self
::getTargetAndType( $data['Target'] );
618 if ( $type == Block
::TYPE_USER
) {
620 $target = $user->getName();
621 $userId = $user->getId();
623 # Give admins a heads-up before they go and block themselves. Much messier
624 # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
625 # permission anyway, although the code does allow for it.
626 # Note: Important to use $target instead of $data['Target']
627 # since both $data['PreviousTarget'] and $target are normalized
628 # but $data['target'] gets overriden by (non-normalized) request variable
629 # from previous request.
630 if ( $target === $performer->getName() &&
631 ( $data['PreviousTarget'] !== $target ||
!$data['Confirm'] )
633 return array( 'ipb-blockingself', 'ipb-confirmaction' );
635 } elseif ( $type == Block
::TYPE_RANGE
) {
637 } elseif ( $type == Block
::TYPE_IP
) {
638 $target = $target->getName();
641 # This should have been caught in the form field validation
642 return array( 'badipaddress' );
645 if ( ( strlen( $data['Expiry'] ) == 0 ) ||
( strlen( $data['Expiry'] ) > 50 )
646 ||
!self
::parseExpiryInput( $data['Expiry'] )
648 return array( 'ipb_expiry_invalid' );
651 if ( !isset( $data['DisableEmail'] ) ) {
652 $data['DisableEmail'] = false;
655 # If the user has done the form 'properly', they won't even have been given the
656 # option to suppress-block unless they have the 'hideuser' permission
657 if ( !isset( $data['HideUser'] ) ) {
658 $data['HideUser'] = false;
661 if ( $data['HideUser'] ) {
662 if ( !$performer->isAllowed( 'hideuser' ) ) {
663 # this codepath is unreachable except by a malicious user spoofing forms,
664 # or by race conditions (user has oversight and sysop, loads block form,
665 # and is de-oversighted before submission); so need to fail completely
666 # rather than just silently disable hiding
667 return array( 'badaccess-group0' );
670 # Recheck params here...
671 if ( $type != Block
::TYPE_USER
) {
672 $data['HideUser'] = false; # IP users should not be hidden
673 } elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
675 return array( 'ipb_expiry_temp' );
676 } elseif ( $user->getEditCount() > self
::HIDEUSER_CONTRIBLIMIT
) {
677 # Typically, the user should have a handful of edits.
678 # Disallow hiding users with many edits for performance.
679 return array( 'ipb_hide_invalid' );
680 } elseif ( !$data['Confirm'] ) {
681 return array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
685 # Create block object.
686 $block = new Block();
687 $block->setTarget( $target );
688 $block->setBlocker( $performer );
689 $block->mReason
= $data['Reason'][0];
690 $block->mExpiry
= self
::parseExpiryInput( $data['Expiry'] );
691 $block->prevents( 'createaccount', $data['CreateAccount'] );
692 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit ||
$data['DisableUTEdit'] ) );
693 $block->prevents( 'sendemail', $data['DisableEmail'] );
694 $block->isHardblock( $data['HardBlock'] );
695 $block->isAutoblocking( $data['AutoBlock'] );
696 $block->mHideName
= $data['HideUser'];
698 if ( !wfRunHooks( 'BlockIp', array( &$block, &$performer ) ) ) {
699 return array( 'hookaborted' );
702 # Try to insert block. Is there a conflicting block?
703 $status = $block->insert();
705 # Indicates whether the user is confirming the block and is aware of
706 # the conflict (did not change the block target in the meantime)
707 $blockNotConfirmed = !$data['Confirm'] ||
( array_key_exists( 'PreviousTarget', $data )
708 && $data['PreviousTarget'] !== $target );
710 # Special case for API - bug 32434
711 $reblockNotAllowed = ( array_key_exists( 'Reblock', $data ) && !$data['Reblock'] );
713 # Show form unless the user is already aware of this...
714 if ( $blockNotConfirmed ||
$reblockNotAllowed ) {
715 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
716 # Otherwise, try to update the block...
718 # This returns direct blocks before autoblocks/rangeblocks, since we should
719 # be sure the user is blocked by now it should work for our purposes
720 $currentBlock = Block
::newFromTarget( $target );
722 if ( $block->equals( $currentBlock ) ) {
723 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
726 # If the name was hidden and the blocking user cannot hide
727 # names, then don't allow any block changes...
728 if ( $currentBlock->mHideName
&& !$performer->isAllowed( 'hideuser' ) ) {
729 return array( 'cant-see-hidden-user' );
732 $currentBlock->delete();
733 $status = $block->insert();
734 $logaction = 'reblock';
736 # Unset _deleted fields if requested
737 if ( $currentBlock->mHideName
&& !$data['HideUser'] ) {
738 RevisionDeleteUser
::unsuppressUserName( $target, $userId );
741 # If hiding/unhiding a name, this should go in the private logs
742 if ( (bool)$currentBlock->mHideName
) {
743 $data['HideUser'] = true;
747 $logaction = 'block';
750 wfRunHooks( 'BlockIpComplete', array( $block, $performer ) );
752 # Set *_deleted fields if requested
753 if ( $data['HideUser'] ) {
754 RevisionDeleteUser
::suppressUserName( $target, $userId );
757 # Can't watch a rangeblock
758 if ( $type != Block
::TYPE_RANGE
&& $data['Watch'] ) {
759 WatchAction
::doWatch( Title
::makeTitle( NS_USER
, $target ), $performer, WatchedItem
::IGNORE_USER_RIGHTS
);
762 # Block constructor sanitizes certain block options on insert
763 $data['BlockEmail'] = $block->prevents( 'sendemail' );
764 $data['AutoBlock'] = $block->isAutoblocking();
766 # Prepare log parameters
767 $logParams = array();
768 $logParams[] = $data['Expiry'];
769 $logParams[] = self
::blockLogFlags( $data, $type );
771 # Make log entry, if the name is hidden, put it in the oversight log
772 $log_type = $data['HideUser'] ?
'suppress' : 'block';
773 $log = new LogPage( $log_type );
774 $log_id = $log->addEntry(
776 Title
::makeTitle( NS_USER
, $target ),
781 # Relate log ID to block IDs (bug 25763)
782 $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] );
783 $log->addRelations( 'ipb_id', $blockIds, $log_id );
790 * Get an array of suggested block durations from MediaWiki:Ipboptions
791 * @todo FIXME: This uses a rather odd syntax for the options, should it be converted
792 * to the standard "**<duration>|<displayname>" format?
793 * @param $lang Language|null the language to get the durations in, or null to use
794 * the wiki's content language
797 public static function getSuggestedDurations( $lang = null ) {
799 $msg = $lang === null
800 ?
wfMessage( 'ipboptions' )->inContentLanguage()->text()
801 : wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
807 foreach ( explode( ',', $msg ) as $option ) {
808 if ( strpos( $option, ':' ) === false ) {
809 $option = "$option:$option";
812 list( $show, $value ) = explode( ':', $option );
813 $a[htmlspecialchars( $show )] = htmlspecialchars( $value );
820 * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
821 * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
822 * @param string $expiry whatever was typed into the form
823 * @return String: timestamp or "infinity" string for the DB implementation
825 public static function parseExpiryInput( $expiry ) {
827 if ( $infinity == null ) {
828 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
831 if ( $expiry == 'infinite' ||
$expiry == 'indefinite' ) {
834 $expiry = strtotime( $expiry );
836 if ( $expiry < 0 ||
$expiry === false ) {
840 $expiry = wfTimestamp( TS_MW
, $expiry );
847 * Can we do an email block?
848 * @param $user User: the sysop wanting to make a block
851 public static function canBlockEmail( $user ) {
852 global $wgEnableUserEmail, $wgSysopEmailBans;
854 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
858 * bug 15810: blocked admins should not be able to block/unblock
859 * others, and probably shouldn't be able to unblock themselves
861 * @param $user User|Int|String
862 * @param $performer User user doing the request
863 * @return Bool|String true or error message key
865 public static function checkUnblockSelf( $user, User
$performer ) {
866 if ( is_int( $user ) ) {
867 $user = User
::newFromId( $user );
868 } elseif ( is_string( $user ) ) {
869 $user = User
::newFromName( $user );
872 if ( $performer->isBlocked() ) {
873 if ( $user instanceof User
&& $user->getId() == $performer->getId() ) {
874 # User is trying to unblock themselves
875 if ( $performer->isAllowed( 'unblockself' ) ) {
877 # User blocked themselves and is now trying to reverse it
878 } elseif ( $performer->blockedBy() === $performer->getName() ) {
881 return 'ipbnounblockself';
884 # User is trying to block/unblock someone else
893 * Return a comma-delimited list of "flags" to be passed to the log
894 * reader for this block, to provide more information in the logs
895 * @param array $data from HTMLForm data
896 * @param $type Block::TYPE_ constant (USER, RANGE, or IP)
899 protected static function blockLogFlags( array $data, $type ) {
900 global $wgBlockAllowsUTEdit;
903 # when blocking a user the option 'anononly' is not available/has no effect
904 # -> do not write this into log
905 if ( !$data['HardBlock'] && $type != Block
::TYPE_USER
) {
906 // For grepping: message block-log-flags-anononly
907 $flags[] = 'anononly';
910 if ( $data['CreateAccount'] ) {
911 // For grepping: message block-log-flags-nocreate
912 $flags[] = 'nocreate';
915 # Same as anononly, this is not displayed when blocking an IP address
916 if ( !$data['AutoBlock'] && $type == Block
::TYPE_USER
) {
917 // For grepping: message block-log-flags-noautoblock
918 $flags[] = 'noautoblock';
921 if ( $data['DisableEmail'] ) {
922 // For grepping: message block-log-flags-noemail
923 $flags[] = 'noemail';
926 if ( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ) {
927 // For grepping: message block-log-flags-nousertalk
928 $flags[] = 'nousertalk';
931 if ( $data['HideUser'] ) {
932 // For grepping: message block-log-flags-hiddenname
933 $flags[] = 'hiddenname';
936 return implode( ',', $flags );
940 * Process the form on POST submission.
942 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
944 public function onSubmit( array $data ) {
945 // This isn't used since we need that HTMLForm that's passed in the
946 // second parameter. See alterForm for the real function
950 * Do something exciting on successful processing of the form, most likely to show a
951 * confirmation message
953 public function onSuccess() {
954 $out = $this->getOutput();
955 $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
956 $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target
) );
959 protected function getGroupName() {
965 class IPBlockForm
extends SpecialBlock
{