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 /** @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
32 * or as subpage (Special:Block/Foo) */
35 /** @var int Block::TYPE_ constant */
38 /** @var User|string The previous block target */
39 protected $previousTarget;
41 /** @var bool Whether the previous submission of the form asked for HideUser */
42 protected $requestedHideUser;
45 protected $alreadyBlocked;
48 protected $preErrors = array();
50 public function __construct() {
51 parent
::__construct( 'Block', 'block' );
55 * Checks that the user can unblock themselves if they are trying to do so
58 * @throws ErrorPageError
60 protected function checkExecutePermissions( User
$user ) {
61 parent
::checkExecutePermissions( $user );
63 # bug 15810: blocked admins should have limited access here
64 $status = self
::checkUnblockSelf( $this->target
, $user );
65 if ( $status !== true ) {
66 throw new ErrorPageError( 'badaccess', $status );
71 * Handle some magic here
75 protected function setParameter( $par ) {
76 # Extract variables from the request. Try not to get into a situation where we
77 # need to extract *every* variable from the form just for processing here, but
78 # there are legitimate uses for some variables
79 $request = $this->getRequest();
80 list( $this->target
, $this->type
) = self
::getTargetAndType( $par, $request );
81 if ( $this->target
instanceof User
) {
82 # Set the 'relevant user' in the skin, so it displays links like Contributions,
83 # User logs, UserRights, etc.
84 $this->getSkin()->setRelevantUser( $this->target
);
87 list( $this->previousTarget
, /*...*/ ) =
88 Block
::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
89 $this->requestedHideUser
= $request->getBool( 'wpHideUser' );
93 * Customizes the HTMLForm a bit
95 * @param HTMLForm $form
97 protected function alterForm( HTMLForm
$form ) {
98 $form->setWrapperLegendMsg( 'blockip-legend' );
99 $form->setHeaderText( '' );
100 $form->setSubmitCallback( array( __CLASS__
, 'processUIForm' ) );
102 $msg = $this->alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit';
103 $form->setSubmitTextMsg( $msg );
105 # Don't need to do anything if the form has been posted
106 if ( !$this->getRequest()->wasPosted() && $this->preErrors
) {
107 $s = HTMLForm
::formatErrors( $this->preErrors
);
109 $form->addHeaderText( Html
::rawElement(
111 array( 'class' => 'error' ),
119 * Get the HTMLForm descriptor array for the block form
122 protected function getFormFields() {
123 global $wgBlockAllowsUTEdit;
125 $user = $this->getUser();
127 $suggestedDurations = self
::getSuggestedDurations();
132 'label-message' => 'ipaddressorusername',
133 'id' => 'mw-bi-target',
137 'validation-callback' => array( __CLASS__
, 'validateTargetField' ),
140 'type' => !count( $suggestedDurations ) ?
'text' : 'selectorother',
141 'label-message' => 'ipbexpiry',
143 'options' => $suggestedDurations,
144 'other' => $this->msg( 'ipbother' )->text(),
145 'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(),
148 'type' => 'selectandother',
149 'label-message' => 'ipbreason',
150 'options-message' => 'ipbreason-dropdown',
152 'CreateAccount' => array(
154 'label-message' => 'ipbcreateaccount',
159 if ( self
::canBlockEmail( $user ) ) {
160 $a['DisableEmail'] = array(
162 'label-message' => 'ipbemailban',
166 if ( $wgBlockAllowsUTEdit ) {
167 $a['DisableUTEdit'] = array(
169 'label-message' => 'ipb-disableusertalk',
174 $a['AutoBlock'] = array(
176 'label-message' => 'ipbenableautoblock',
180 # Allow some users to hide name from block log, blocklist and listusers
181 if ( $user->isAllowed( 'hideuser' ) ) {
182 $a['HideUser'] = array(
184 'label-message' => 'ipbhidename',
185 'cssclass' => 'mw-block-hideuser',
189 # Watchlist their user page? (Only if user is logged in)
190 if ( $user->isLoggedIn() ) {
193 'label-message' => 'ipbwatchuser',
197 $a['HardBlock'] = array(
199 'label-message' => 'ipb-hardblock',
203 # This is basically a copy of the Target field, but the user can't change it, so we
204 # can see if the warnings we maybe showed to the user before still apply
205 $a['PreviousTarget'] = array(
210 # We'll turn this into a checkbox if we need to
211 $a['Confirm'] = array(
214 'label-message' => 'ipb-confirm',
217 $this->maybeAlterFormDefaults( $a );
219 // Allow extensions to add more fields
220 wfRunHooks( 'SpecialBlockModifyFormFields', array( $this, &$a ) );
226 * If the user has already been blocked with similar settings, load that block
227 * and change the defaults for the form fields to match the existing settings.
228 * @param array $fields HTMLForm descriptor array
229 * @return bool Whether fields were altered (that is, whether the target is
232 protected function maybeAlterFormDefaults( &$fields ) {
233 # This will be overwritten by request data
234 $fields['Target']['default'] = (string)$this->target
;
237 $fields['PreviousTarget']['default'] = (string)$this->target
;
239 $block = Block
::newFromTarget( $this->target
);
241 if ( $block instanceof Block
&& !$block->mAuto
# The block exists and isn't an autoblock
242 && ( $this->type
!= Block
::TYPE_RANGE
# The block isn't a rangeblock
243 ||
$block->getTarget() == $this->target
) # or if it is, the range is what we're about to block
245 $fields['HardBlock']['default'] = $block->isHardblock();
246 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
247 $fields['AutoBlock']['default'] = $block->isAutoblocking();
249 if ( isset( $fields['DisableEmail'] ) ) {
250 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
253 if ( isset( $fields['HideUser'] ) ) {
254 $fields['HideUser']['default'] = $block->mHideName
;
257 if ( isset( $fields['DisableUTEdit'] ) ) {
258 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
261 // If the username was hidden (ipb_deleted == 1), don't show the reason
262 // unless this user also has rights to hideuser: Bug 35839
263 if ( !$block->mHideName ||
$this->getUser()->isAllowed( 'hideuser' ) ) {
264 $fields['Reason']['default'] = $block->mReason
;
266 $fields['Reason']['default'] = '';
269 if ( $this->getRequest()->wasPosted() ) {
270 # Ok, so we got a POST submission asking us to reblock a user. So show the
271 # confirm checkbox; the user will only see it if they haven't previously
272 $fields['Confirm']['type'] = 'check';
274 # We got a target, but it wasn't a POST request, so the user must have gone
275 # to a link like [[Special:Block/User]]. We don't need to show the checkbox
276 # as long as they go ahead and block *that* user
277 $fields['Confirm']['default'] = 1;
280 if ( $block->mExpiry
== 'infinity' ) {
281 $fields['Expiry']['default'] = 'infinite';
283 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822
, $block->mExpiry
);
286 $this->alreadyBlocked
= true;
287 $this->preErrors
[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) );
290 # We always need confirmation to do HideUser
291 if ( $this->requestedHideUser
) {
292 $fields['Confirm']['type'] = 'check';
293 unset( $fields['Confirm']['default'] );
294 $this->preErrors
[] = array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
297 # Or if the user is trying to block themselves
298 if ( (string)$this->target
=== $this->getUser()->getName() ) {
299 $fields['Confirm']['type'] = 'check';
300 unset( $fields['Confirm']['default'] );
301 $this->preErrors
[] = array( 'ipb-blockingself', 'ipb-confirmaction' );
306 * Add header elements like block log entries, etc.
309 protected function preText() {
310 $this->getOutput()->addModules( 'mediawiki.special.block' );
312 $text = $this->msg( 'blockiptext' )->parse();
314 $otherBlockMessages = array();
315 if ( $this->target
!== null ) {
316 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
317 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target
) );
319 if ( count( $otherBlockMessages ) ) {
320 $s = Html
::rawElement(
323 $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
328 foreach ( $otherBlockMessages as $link ) {
329 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
332 $s .= Html
::rawElement(
334 array( 'class' => 'mw-blockip-alreadyblocked' ),
346 * Add footer elements to the form
349 protected function postText() {
352 # Link to the user's contributions, if applicable
353 if ( $this->target
instanceof User
) {
354 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->target
->getName() );
355 $links[] = Linker
::link(
357 $this->msg( 'ipb-blocklist-contribs', $this->target
->getName() )->escaped()
361 # Link to unblock the specified user, or to a blank unblock form
362 if ( $this->target
instanceof User
) {
363 $message = $this->msg(
365 wfEscapeWikiText( $this->target
->getName() )
367 $list = SpecialPage
::getTitleFor( 'Unblock', $this->target
->getName() );
369 $message = $this->msg( 'ipb-unblock' )->parse();
370 $list = SpecialPage
::getTitleFor( 'Unblock' );
372 $links[] = Linker
::linkKnown( $list, $message, array() );
374 # Link to the block list
375 $links[] = Linker
::linkKnown(
376 SpecialPage
::getTitleFor( 'BlockList' ),
377 $this->msg( 'ipb-blocklist' )->escaped()
380 $user = $this->getUser();
382 # Link to edit the block dropdown reasons, if applicable
383 if ( $user->isAllowed( 'editinterface' ) ) {
384 $links[] = Linker
::link(
385 Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' ),
386 $this->msg( 'ipb-edit-dropdown' )->escaped(),
388 array( 'action' => 'edit' )
392 $text = Html
::rawElement(
394 array( 'class' => 'mw-ipb-conveniencelinks' ),
395 $this->getLanguage()->pipeList( $links )
398 $userTitle = self
::getTargetUserTitle( $this->target
);
400 # Get relevant extracts from the block and suppression logs, if possible
403 LogEventsList
::showLogExtract(
410 'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
411 'showIfEmpty' => false
416 # Add suppression block entries if allowed
417 if ( $user->isAllowed( 'suppressionlog' ) ) {
418 LogEventsList
::showLogExtract(
425 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
426 'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
427 'showIfEmpty' => false
439 * Get a user page target for things like logs.
440 * This handles account and IP range targets.
441 * @param User|string $target
444 protected static function getTargetUserTitle( $target ) {
445 if ( $target instanceof User
) {
446 return $target->getUserPage();
447 } elseif ( IP
::isIPAddress( $target ) ) {
448 return Title
::makeTitleSafe( NS_USER
, $target );
455 * Determine the target of the block, and the type of target
456 * @todo Should be in Block.php?
457 * @param string $par subpage parameter passed to setup, or data value from
459 * @param WebRequest $request Optionally try and get data from a request too
460 * @return array( User|string|null, Block::TYPE_ constant|null )
462 public static function getTargetAndType( $par, WebRequest
$request = null ) {
469 # The HTMLForm will check wpTarget first and only if it doesn't get
470 # a value use the default, which will be generated from the options
471 # below; so this has to have a higher precedence here than $par, or
472 # we could end up with different values in $this->target and the HTMLForm!
473 if ( $request instanceof WebRequest
) {
474 $target = $request->getText( 'wpTarget', null );
481 if ( $request instanceof WebRequest
) {
482 $target = $request->getText( 'ip', null );
487 if ( $request instanceof WebRequest
) {
488 $target = $request->getText( 'wpBlockAddress', null );
495 list( $target, $type ) = Block
::parseTarget( $target );
497 if ( $type !== null ) {
498 return array( $target, $type );
502 return array( null, null );
506 * HTMLForm field validation-callback for Target field.
508 * @param string $value
509 * @param array $alldata
510 * @param HTMLForm $form
513 public static function validateTargetField( $value, $alldata, $form ) {
514 $status = self
::validateTarget( $value, $form->getUser() );
515 if ( !$status->isOK() ) {
516 $errors = $status->getErrorsArray();
518 return call_user_func_array( array( $form, 'msg' ), $errors[0] );
525 * Validate a block target.
528 * @param string $value Block target to check
529 * @param User $user Performer of the block
532 public static function validateTarget( $value, User
$user ) {
533 global $wgBlockCIDRLimit;
535 /** @var User $target */
536 list( $target, $type ) = self
::getTargetAndType( $value );
537 $status = Status
::newGood( $target );
539 if ( $type == Block
::TYPE_USER
) {
540 if ( $target->isAnon() ) {
543 wfEscapeWikiText( $target->getName() )
547 $unblockStatus = self
::checkUnblockSelf( $target, $user );
548 if ( $unblockStatus !== true ) {
549 $status->fatal( 'badaccess', $unblockStatus );
551 } elseif ( $type == Block
::TYPE_RANGE
) {
552 list( $ip, $range ) = explode( '/', $target, 2 );
555 ( IP
::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
556 ( IP
::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
558 // Range block effectively disabled
559 $status->fatal( 'range_block_disabled' );
563 ( IP
::isIPv4( $ip ) && $range > 32 ) ||
564 ( IP
::isIPv6( $ip ) && $range > 128 )
567 $status->fatal( 'ip_range_invalid' );
570 if ( IP
::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
571 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
574 if ( IP
::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
575 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
577 } elseif ( $type == Block
::TYPE_IP
) {
580 $status->fatal( 'badipaddress' );
587 * Submit callback for an HTMLForm object, will simply pass
589 * @param HTMLForm $form
590 * @return bool|string
592 public static function processUIForm( array $data, HTMLForm
$form ) {
593 return self
::processForm( $data, $form->getContext() );
597 * Given the form data, actually implement a block
599 * @param IContextSource $context
600 * @return bool|string
602 public static function processForm( array $data, IContextSource
$context ) {
603 global $wgBlockAllowsUTEdit, $wgHideUserContribLimit;
605 $performer = $context->getUser();
607 // Handled by field validator callback
608 // self::validateTargetField( $data['Target'] );
610 # This might have been a hidden field or a checkbox, so interesting data
612 $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true );
614 /** @var User $target */
615 list( $target, $type ) = self
::getTargetAndType( $data['Target'] );
616 if ( $type == Block
::TYPE_USER
) {
618 $target = $user->getName();
619 $userId = $user->getId();
621 # Give admins a heads-up before they go and block themselves. Much messier
622 # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
623 # permission anyway, although the code does allow for it.
624 # Note: Important to use $target instead of $data['Target']
625 # since both $data['PreviousTarget'] and $target are normalized
626 # but $data['target'] gets overriden by (non-normalized) request variable
627 # from previous request.
628 if ( $target === $performer->getName() &&
629 ( $data['PreviousTarget'] !== $target ||
!$data['Confirm'] )
631 return array( 'ipb-blockingself', 'ipb-confirmaction' );
633 } elseif ( $type == Block
::TYPE_RANGE
) {
635 } elseif ( $type == Block
::TYPE_IP
) {
636 $target = $target->getName();
639 # This should have been caught in the form field validation
640 return array( 'badipaddress' );
643 if ( ( strlen( $data['Expiry'] ) == 0 ) ||
( strlen( $data['Expiry'] ) > 50 )
644 ||
!self
::parseExpiryInput( $data['Expiry'] )
646 return array( 'ipb_expiry_invalid' );
649 if ( !isset( $data['DisableEmail'] ) ) {
650 $data['DisableEmail'] = false;
653 # If the user has done the form 'properly', they won't even have been given the
654 # option to suppress-block unless they have the 'hideuser' permission
655 if ( !isset( $data['HideUser'] ) ) {
656 $data['HideUser'] = false;
659 if ( $data['HideUser'] ) {
660 if ( !$performer->isAllowed( 'hideuser' ) ) {
661 # this codepath is unreachable except by a malicious user spoofing forms,
662 # or by race conditions (user has oversight and sysop, loads block form,
663 # and is de-oversighted before submission); so need to fail completely
664 # rather than just silently disable hiding
665 return array( 'badaccess-group0' );
668 # Recheck params here...
669 if ( $type != Block
::TYPE_USER
) {
670 $data['HideUser'] = false; # IP users should not be hidden
671 } elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
673 return array( 'ipb_expiry_temp' );
674 } elseif ( $wgHideUserContribLimit !== false
675 && $user->getEditCount() > $wgHideUserContribLimit
677 # Typically, the user should have a handful of edits.
678 # Disallow hiding users with many edits for performance.
679 return array( array( 'ipb_hide_invalid',
680 Message
::numParam( $wgHideUserContribLimit ) ) );
681 } elseif ( !$data['Confirm'] ) {
682 return array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
686 # Create block object.
687 $block = new Block();
688 $block->setTarget( $target );
689 $block->setBlocker( $performer );
690 $block->mReason
= $data['Reason'][0];
691 $block->mExpiry
= self
::parseExpiryInput( $data['Expiry'] );
692 $block->prevents( 'createaccount', $data['CreateAccount'] );
693 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit ||
$data['DisableUTEdit'] ) );
694 $block->prevents( 'sendemail', $data['DisableEmail'] );
695 $block->isHardblock( $data['HardBlock'] );
696 $block->isAutoblocking( $data['AutoBlock'] );
697 $block->mHideName
= $data['HideUser'];
699 $reason = array( 'hookaborted' );
700 if ( !wfRunHooks( 'BlockIp', array( &$block, &$performer, &$reason ) ) ) {
704 # Try to insert block. Is there a conflicting block?
705 $status = $block->insert();
707 # Indicates whether the user is confirming the block and is aware of
708 # the conflict (did not change the block target in the meantime)
709 $blockNotConfirmed = !$data['Confirm'] ||
( array_key_exists( 'PreviousTarget', $data )
710 && $data['PreviousTarget'] !== $target );
712 # Special case for API - bug 32434
713 $reblockNotAllowed = ( array_key_exists( 'Reblock', $data ) && !$data['Reblock'] );
715 # Show form unless the user is already aware of this...
716 if ( $blockNotConfirmed ||
$reblockNotAllowed ) {
717 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
718 # Otherwise, try to update the block...
720 # This returns direct blocks before autoblocks/rangeblocks, since we should
721 # be sure the user is blocked by now it should work for our purposes
722 $currentBlock = Block
::newFromTarget( $target );
724 if ( $block->equals( $currentBlock ) ) {
725 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
728 # If the name was hidden and the blocking user cannot hide
729 # names, then don't allow any block changes...
730 if ( $currentBlock->mHideName
&& !$performer->isAllowed( 'hideuser' ) ) {
731 return array( 'cant-see-hidden-user' );
734 $currentBlock->isHardblock( $block->isHardblock() );
735 $currentBlock->prevents( 'createaccount', $block->prevents( 'createaccount' ) );
736 $currentBlock->mExpiry
= $block->mExpiry
;
737 $currentBlock->isAutoblocking( $block->isAutoblocking() );
738 $currentBlock->mHideName
= $block->mHideName
;
739 $currentBlock->prevents( 'sendemail', $block->prevents( 'sendemail' ) );
740 $currentBlock->prevents( 'editownusertalk', $block->prevents( 'editownusertalk' ) );
741 $currentBlock->mReason
= $block->mReason
;
743 $status = $currentBlock->update();
745 $logaction = 'reblock';
747 # Unset _deleted fields if requested
748 if ( $currentBlock->mHideName
&& !$data['HideUser'] ) {
749 RevisionDeleteUser
::unsuppressUserName( $target, $userId );
752 # If hiding/unhiding a name, this should go in the private logs
753 if ( (bool)$currentBlock->mHideName
) {
754 $data['HideUser'] = true;
758 $logaction = 'block';
761 wfRunHooks( 'BlockIpComplete', array( $block, $performer ) );
763 # Set *_deleted fields if requested
764 if ( $data['HideUser'] ) {
765 RevisionDeleteUser
::suppressUserName( $target, $userId );
768 # Can't watch a rangeblock
769 if ( $type != Block
::TYPE_RANGE
&& $data['Watch'] ) {
770 WatchAction
::doWatch(
771 Title
::makeTitle( NS_USER
, $target ),
773 WatchedItem
::IGNORE_USER_RIGHTS
777 # Block constructor sanitizes certain block options on insert
778 $data['BlockEmail'] = $block->prevents( 'sendemail' );
779 $data['AutoBlock'] = $block->isAutoblocking();
781 # Prepare log parameters
782 $logParams = array();
783 $logParams[] = $data['Expiry'];
784 $logParams[] = self
::blockLogFlags( $data, $type );
786 # Make log entry, if the name is hidden, put it in the oversight log
787 $log_type = $data['HideUser'] ?
'suppress' : 'block';
788 $log = new LogPage( $log_type );
789 $log_id = $log->addEntry(
791 Title
::makeTitle( NS_USER
, $target ),
796 # Relate log ID to block IDs (bug 25763)
797 $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] );
798 $log->addRelations( 'ipb_id', $blockIds, $log_id );
805 * Get an array of suggested block durations from MediaWiki:Ipboptions
806 * @todo FIXME: This uses a rather odd syntax for the options, should it be converted
807 * to the standard "**<duration>|<displayname>" format?
808 * @param Language|null $lang The language to get the durations in, or null to use
809 * the wiki's content language
812 public static function getSuggestedDurations( $lang = null ) {
814 $msg = $lang === null
815 ?
wfMessage( 'ipboptions' )->inContentLanguage()->text()
816 : wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
822 foreach ( explode( ',', $msg ) as $option ) {
823 if ( strpos( $option, ':' ) === false ) {
824 $option = "$option:$option";
827 list( $show, $value ) = explode( ':', $option );
828 $a[htmlspecialchars( $show )] = htmlspecialchars( $value );
835 * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
836 * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
837 * @param string $expiry Whatever was typed into the form
838 * @return string Timestamp or "infinity" string for the DB implementation
840 public static function parseExpiryInput( $expiry ) {
842 if ( $infinity == null ) {
843 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
846 if ( $expiry == 'infinite' ||
$expiry == 'indefinite' ) {
849 $expiry = strtotime( $expiry );
851 if ( $expiry < 0 ||
$expiry === false ) {
855 $expiry = wfTimestamp( TS_MW
, $expiry );
862 * Can we do an email block?
863 * @param User $user The sysop wanting to make a block
866 public static function canBlockEmail( $user ) {
867 global $wgEnableUserEmail, $wgSysopEmailBans;
869 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
873 * bug 15810: blocked admins should not be able to block/unblock
874 * others, and probably shouldn't be able to unblock themselves
876 * @param User|int|string $user
877 * @param User $performer User doing the request
878 * @return bool|string True or error message key
880 public static function checkUnblockSelf( $user, User
$performer ) {
881 if ( is_int( $user ) ) {
882 $user = User
::newFromId( $user );
883 } elseif ( is_string( $user ) ) {
884 $user = User
::newFromName( $user );
887 if ( $performer->isBlocked() ) {
888 if ( $user instanceof User
&& $user->getId() == $performer->getId() ) {
889 # User is trying to unblock themselves
890 if ( $performer->isAllowed( 'unblockself' ) ) {
892 # User blocked themselves and is now trying to reverse it
893 } elseif ( $performer->blockedBy() === $performer->getName() ) {
896 return 'ipbnounblockself';
899 # User is trying to block/unblock someone else
908 * Return a comma-delimited list of "flags" to be passed to the log
909 * reader for this block, to provide more information in the logs
910 * @param array $data From HTMLForm data
911 * @param int $type Block::TYPE_ constant (USER, RANGE, or IP)
914 protected static function blockLogFlags( array $data, $type ) {
915 global $wgBlockAllowsUTEdit;
918 # when blocking a user the option 'anononly' is not available/has no effect
919 # -> do not write this into log
920 if ( !$data['HardBlock'] && $type != Block
::TYPE_USER
) {
921 // For grepping: message block-log-flags-anononly
922 $flags[] = 'anononly';
925 if ( $data['CreateAccount'] ) {
926 // For grepping: message block-log-flags-nocreate
927 $flags[] = 'nocreate';
930 # Same as anononly, this is not displayed when blocking an IP address
931 if ( !$data['AutoBlock'] && $type == Block
::TYPE_USER
) {
932 // For grepping: message block-log-flags-noautoblock
933 $flags[] = 'noautoblock';
936 if ( $data['DisableEmail'] ) {
937 // For grepping: message block-log-flags-noemail
938 $flags[] = 'noemail';
941 if ( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ) {
942 // For grepping: message block-log-flags-nousertalk
943 $flags[] = 'nousertalk';
946 if ( $data['HideUser'] ) {
947 // For grepping: message block-log-flags-hiddenname
948 $flags[] = 'hiddenname';
951 return implode( ',', $flags );
955 * Process the form on POST submission.
957 * @return bool|array True for success, false for didn't-try, array of errors on failure
959 public function onSubmit( array $data ) {
960 // This isn't used since we need that HTMLForm that's passed in the
961 // second parameter. See alterForm for the real function
965 * Do something exciting on successful processing of the form, most likely to show a
966 * confirmation message
968 public function onSuccess() {
969 $out = $this->getOutput();
970 $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
971 $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target
) );
974 protected function getGroupName() {