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' ) );
101 $form->setSubmitDestructive();
103 $msg = $this->alreadyBlocked ?
'ipb-change-block' : 'ipbsubmit';
104 $form->setSubmitTextMsg( $msg );
106 $this->getOutput()->addHelpLink( 'Help:Blocking users' );
108 # Don't need to do anything if the form has been posted
109 if ( !$this->getRequest()->wasPosted() && $this->preErrors
) {
110 $s = $form->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' => 'ipaddressorusername',
136 'id' => 'mw-bi-target',
140 'validation-callback' => array( __CLASS__
, 'validateTargetField' ),
141 'cssclass' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
144 'type' => !count( $suggestedDurations ) ?
'text' : 'selectorother',
145 'label-message' => 'ipbexpiry',
147 'options' => $suggestedDurations,
148 'other' => $this->msg( 'ipbother' )->text(),
149 'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(),
152 '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 Hooks
::run( '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
;
241 if ( $this->target
) {
242 $status = self
::validateTarget( $this->target
, $this->getUser() );
243 if ( !$status->isOK() ) {
244 $errors = $status->getErrorsArray();
245 $this->preErrors
= array_merge( $this->preErrors
, $errors );
250 $fields['PreviousTarget']['default'] = (string)$this->target
;
252 $block = Block
::newFromTarget( $this->target
);
254 if ( $block instanceof Block
&& !$block->mAuto
# The block exists and isn't an autoblock
255 && ( $this->type
!= Block
::TYPE_RANGE
# The block isn't a rangeblock
256 ||
$block->getTarget() == $this->target
) # or if it is, the range is what we're about to block
258 $fields['HardBlock']['default'] = $block->isHardblock();
259 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
260 $fields['AutoBlock']['default'] = $block->isAutoblocking();
262 if ( isset( $fields['DisableEmail'] ) ) {
263 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
266 if ( isset( $fields['HideUser'] ) ) {
267 $fields['HideUser']['default'] = $block->mHideName
;
270 if ( isset( $fields['DisableUTEdit'] ) ) {
271 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
274 // If the username was hidden (ipb_deleted == 1), don't show the reason
275 // unless this user also has rights to hideuser: Bug 35839
276 if ( !$block->mHideName ||
$this->getUser()->isAllowed( 'hideuser' ) ) {
277 $fields['Reason']['default'] = $block->mReason
;
279 $fields['Reason']['default'] = '';
282 if ( $this->getRequest()->wasPosted() ) {
283 # Ok, so we got a POST submission asking us to reblock a user. So show the
284 # confirm checkbox; the user will only see it if they haven't previously
285 $fields['Confirm']['type'] = 'check';
287 # We got a target, but it wasn't a POST request, so the user must have gone
288 # to a link like [[Special:Block/User]]. We don't need to show the checkbox
289 # as long as they go ahead and block *that* user
290 $fields['Confirm']['default'] = 1;
293 if ( $block->mExpiry
== 'infinity' ) {
294 $fields['Expiry']['default'] = 'infinite';
296 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822
, $block->mExpiry
);
299 $this->alreadyBlocked
= true;
300 $this->preErrors
[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) );
303 # We always need confirmation to do HideUser
304 if ( $this->requestedHideUser
) {
305 $fields['Confirm']['type'] = 'check';
306 unset( $fields['Confirm']['default'] );
307 $this->preErrors
[] = array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
310 # Or if the user is trying to block themselves
311 if ( (string)$this->target
=== $this->getUser()->getName() ) {
312 $fields['Confirm']['type'] = 'check';
313 unset( $fields['Confirm']['default'] );
314 $this->preErrors
[] = array( 'ipb-blockingself', 'ipb-confirmaction' );
319 * Add header elements like block log entries, etc.
322 protected function preText() {
323 $this->getOutput()->addModules( array( 'mediawiki.special.block', 'mediawiki.userSuggest' ) );
325 $text = $this->msg( 'blockiptext' )->parse();
327 $otherBlockMessages = array();
328 if ( $this->target
!== null ) {
329 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
330 Hooks
::run( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target
) );
332 if ( count( $otherBlockMessages ) ) {
333 $s = Html
::rawElement(
336 $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
341 foreach ( $otherBlockMessages as $link ) {
342 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
345 $s .= Html
::rawElement(
347 array( 'class' => 'mw-blockip-alreadyblocked' ),
359 * Add footer elements to the form
362 protected function postText() {
365 # Link to the user's contributions, if applicable
366 if ( $this->target
instanceof User
) {
367 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->target
->getName() );
368 $links[] = Linker
::link(
370 $this->msg( 'ipb-blocklist-contribs', $this->target
->getName() )->escaped()
374 # Link to unblock the specified user, or to a blank unblock form
375 if ( $this->target
instanceof User
) {
376 $message = $this->msg(
378 wfEscapeWikiText( $this->target
->getName() )
380 $list = SpecialPage
::getTitleFor( 'Unblock', $this->target
->getName() );
382 $message = $this->msg( 'ipb-unblock' )->parse();
383 $list = SpecialPage
::getTitleFor( 'Unblock' );
385 $links[] = Linker
::linkKnown( $list, $message, array() );
387 # Link to the block list
388 $links[] = Linker
::linkKnown(
389 SpecialPage
::getTitleFor( 'BlockList' ),
390 $this->msg( 'ipb-blocklist' )->escaped()
393 $user = $this->getUser();
395 # Link to edit the block dropdown reasons, if applicable
396 if ( $user->isAllowed( 'editinterface' ) ) {
397 $links[] = Linker
::link(
398 Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' ),
399 $this->msg( 'ipb-edit-dropdown' )->escaped(),
401 array( 'action' => 'edit' )
405 $text = Html
::rawElement(
407 array( 'class' => 'mw-ipb-conveniencelinks' ),
408 $this->getLanguage()->pipeList( $links )
411 $userTitle = self
::getTargetUserTitle( $this->target
);
413 # Get relevant extracts from the block and suppression logs, if possible
416 LogEventsList
::showLogExtract(
423 'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
424 'showIfEmpty' => false
429 # Add suppression block entries if allowed
430 if ( $user->isAllowed( 'suppressionlog' ) ) {
431 LogEventsList
::showLogExtract(
438 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
439 'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
440 'showIfEmpty' => false
452 * Get a user page target for things like logs.
453 * This handles account and IP range targets.
454 * @param User|string $target
457 protected static function getTargetUserTitle( $target ) {
458 if ( $target instanceof User
) {
459 return $target->getUserPage();
460 } elseif ( IP
::isIPAddress( $target ) ) {
461 return Title
::makeTitleSafe( NS_USER
, $target );
468 * Determine the target of the block, and the type of target
469 * @todo Should be in Block.php?
470 * @param string $par Subpage parameter passed to setup, or data value from
472 * @param WebRequest $request Optionally try and get data from a request too
473 * @return array( User|string|null, Block::TYPE_ constant|null )
475 public static function getTargetAndType( $par, WebRequest
$request = null ) {
482 # The HTMLForm will check wpTarget first and only if it doesn't get
483 # a value use the default, which will be generated from the options
484 # below; so this has to have a higher precedence here than $par, or
485 # we could end up with different values in $this->target and the HTMLForm!
486 if ( $request instanceof WebRequest
) {
487 $target = $request->getText( 'wpTarget', null );
494 if ( $request instanceof WebRequest
) {
495 $target = $request->getText( 'ip', null );
500 if ( $request instanceof WebRequest
) {
501 $target = $request->getText( 'wpBlockAddress', null );
508 list( $target, $type ) = Block
::parseTarget( $target );
510 if ( $type !== null ) {
511 return array( $target, $type );
515 return array( null, null );
519 * HTMLForm field validation-callback for Target field.
521 * @param string $value
522 * @param array $alldata
523 * @param HTMLForm $form
526 public static function validateTargetField( $value, $alldata, $form ) {
527 $status = self
::validateTarget( $value, $form->getUser() );
528 if ( !$status->isOK() ) {
529 $errors = $status->getErrorsArray();
531 return call_user_func_array( array( $form, 'msg' ), $errors[0] );
538 * Validate a block target.
541 * @param string $value Block target to check
542 * @param User $user Performer of the block
545 public static function validateTarget( $value, User
$user ) {
546 global $wgBlockCIDRLimit;
548 /** @var User $target */
549 list( $target, $type ) = self
::getTargetAndType( $value );
550 $status = Status
::newGood( $target );
552 if ( $type == Block
::TYPE_USER
) {
553 if ( $target->isAnon() ) {
556 wfEscapeWikiText( $target->getName() )
560 $unblockStatus = self
::checkUnblockSelf( $target, $user );
561 if ( $unblockStatus !== true ) {
562 $status->fatal( 'badaccess', $unblockStatus );
564 } elseif ( $type == Block
::TYPE_RANGE
) {
565 list( $ip, $range ) = explode( '/', $target, 2 );
568 ( IP
::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
569 ( IP
::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
571 // Range block effectively disabled
572 $status->fatal( 'range_block_disabled' );
576 ( IP
::isIPv4( $ip ) && $range > 32 ) ||
577 ( IP
::isIPv6( $ip ) && $range > 128 )
580 $status->fatal( 'ip_range_invalid' );
583 if ( IP
::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
584 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
587 if ( IP
::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
588 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
590 } elseif ( $type == Block
::TYPE_IP
) {
593 $status->fatal( 'badipaddress' );
600 * Submit callback for an HTMLForm object, will simply pass
602 * @param HTMLForm $form
603 * @return bool|string
605 public static function processUIForm( array $data, HTMLForm
$form ) {
606 return self
::processForm( $data, $form->getContext() );
610 * Given the form data, actually implement a block
612 * @param IContextSource $context
613 * @return bool|string
615 public static function processForm( array $data, IContextSource
$context ) {
616 global $wgBlockAllowsUTEdit, $wgHideUserContribLimit, $wgContLang;
618 $performer = $context->getUser();
620 // Handled by field validator callback
621 // self::validateTargetField( $data['Target'] );
623 # This might have been a hidden field or a checkbox, so interesting data
625 $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true );
627 /** @var User $target */
628 list( $target, $type ) = self
::getTargetAndType( $data['Target'] );
629 if ( $type == Block
::TYPE_USER
) {
631 $target = $user->getName();
632 $userId = $user->getId();
634 # Give admins a heads-up before they go and block themselves. Much messier
635 # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
636 # permission anyway, although the code does allow for it.
637 # Note: Important to use $target instead of $data['Target']
638 # since both $data['PreviousTarget'] and $target are normalized
639 # but $data['target'] gets overridden by (non-normalized) request variable
640 # from previous request.
641 if ( $target === $performer->getName() &&
642 ( $data['PreviousTarget'] !== $target ||
!$data['Confirm'] )
644 return array( 'ipb-blockingself', 'ipb-confirmaction' );
646 } elseif ( $type == Block
::TYPE_RANGE
) {
648 } elseif ( $type == Block
::TYPE_IP
) {
649 $target = $target->getName();
652 # This should have been caught in the form field validation
653 return array( 'badipaddress' );
656 if ( ( strlen( $data['Expiry'] ) == 0 ) ||
( strlen( $data['Expiry'] ) > 50 )
657 ||
!self
::parseExpiryInput( $data['Expiry'] )
659 return array( 'ipb_expiry_invalid' );
662 if ( !isset( $data['DisableEmail'] ) ) {
663 $data['DisableEmail'] = false;
666 # If the user has done the form 'properly', they won't even have been given the
667 # option to suppress-block unless they have the 'hideuser' permission
668 if ( !isset( $data['HideUser'] ) ) {
669 $data['HideUser'] = false;
672 if ( $data['HideUser'] ) {
673 if ( !$performer->isAllowed( 'hideuser' ) ) {
674 # this codepath is unreachable except by a malicious user spoofing forms,
675 # or by race conditions (user has oversight and sysop, loads block form,
676 # and is de-oversighted before submission); so need to fail completely
677 # rather than just silently disable hiding
678 return array( 'badaccess-group0' );
681 # Recheck params here...
682 if ( $type != Block
::TYPE_USER
) {
683 $data['HideUser'] = false; # IP users should not be hidden
684 } elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
686 return array( 'ipb_expiry_temp' );
687 } elseif ( $wgHideUserContribLimit !== false
688 && $user->getEditCount() > $wgHideUserContribLimit
690 # Typically, the user should have a handful of edits.
691 # Disallow hiding users with many edits for performance.
692 return array( array( 'ipb_hide_invalid',
693 Message
::numParam( $wgHideUserContribLimit ) ) );
694 } elseif ( !$data['Confirm'] ) {
695 return array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
699 # Create block object.
700 $block = new Block();
701 $block->setTarget( $target );
702 $block->setBlocker( $performer );
703 # Truncate reason for whole multibyte characters
704 $block->mReason
= $wgContLang->truncate( $data['Reason'][0], 255 );
705 $block->mExpiry
= self
::parseExpiryInput( $data['Expiry'] );
706 $block->prevents( 'createaccount', $data['CreateAccount'] );
707 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit ||
$data['DisableUTEdit'] ) );
708 $block->prevents( 'sendemail', $data['DisableEmail'] );
709 $block->isHardblock( $data['HardBlock'] );
710 $block->isAutoblocking( $data['AutoBlock'] );
711 $block->mHideName
= $data['HideUser'];
713 $reason = array( 'hookaborted' );
714 if ( !Hooks
::run( 'BlockIp', array( &$block, &$performer, &$reason ) ) ) {
718 # Try to insert block. Is there a conflicting block?
719 $status = $block->insert();
721 # Indicates whether the user is confirming the block and is aware of
722 # the conflict (did not change the block target in the meantime)
723 $blockNotConfirmed = !$data['Confirm'] ||
( array_key_exists( 'PreviousTarget', $data )
724 && $data['PreviousTarget'] !== $target );
726 # Special case for API - bug 32434
727 $reblockNotAllowed = ( array_key_exists( 'Reblock', $data ) && !$data['Reblock'] );
729 # Show form unless the user is already aware of this...
730 if ( $blockNotConfirmed ||
$reblockNotAllowed ) {
731 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
732 # Otherwise, try to update the block...
734 # This returns direct blocks before autoblocks/rangeblocks, since we should
735 # be sure the user is blocked by now it should work for our purposes
736 $currentBlock = Block
::newFromTarget( $target );
738 if ( $block->equals( $currentBlock ) ) {
739 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
742 # If the name was hidden and the blocking user cannot hide
743 # names, then don't allow any block changes...
744 if ( $currentBlock->mHideName
&& !$performer->isAllowed( 'hideuser' ) ) {
745 return array( 'cant-see-hidden-user' );
748 $currentBlock->isHardblock( $block->isHardblock() );
749 $currentBlock->prevents( 'createaccount', $block->prevents( 'createaccount' ) );
750 $currentBlock->mExpiry
= $block->mExpiry
;
751 $currentBlock->isAutoblocking( $block->isAutoblocking() );
752 $currentBlock->mHideName
= $block->mHideName
;
753 $currentBlock->prevents( 'sendemail', $block->prevents( 'sendemail' ) );
754 $currentBlock->prevents( 'editownusertalk', $block->prevents( 'editownusertalk' ) );
755 $currentBlock->mReason
= $block->mReason
;
757 $status = $currentBlock->update();
759 $logaction = 'reblock';
761 # Unset _deleted fields if requested
762 if ( $currentBlock->mHideName
&& !$data['HideUser'] ) {
763 RevisionDeleteUser
::unsuppressUserName( $target, $userId );
766 # If hiding/unhiding a name, this should go in the private logs
767 if ( (bool)$currentBlock->mHideName
) {
768 $data['HideUser'] = true;
772 $logaction = 'block';
775 Hooks
::run( 'BlockIpComplete', array( $block, $performer ) );
777 # Set *_deleted fields if requested
778 if ( $data['HideUser'] ) {
779 RevisionDeleteUser
::suppressUserName( $target, $userId );
782 # Can't watch a rangeblock
783 if ( $type != Block
::TYPE_RANGE
&& $data['Watch'] ) {
784 WatchAction
::doWatch(
785 Title
::makeTitle( NS_USER
, $target ),
787 WatchedItem
::IGNORE_USER_RIGHTS
791 # Block constructor sanitizes certain block options on insert
792 $data['BlockEmail'] = $block->prevents( 'sendemail' );
793 $data['AutoBlock'] = $block->isAutoblocking();
795 # Prepare log parameters
796 $logParams = array();
797 $logParams['5::duration'] = $data['Expiry'];
798 $logParams['6::flags'] = self
::blockLogFlags( $data, $type );
800 # Make log entry, if the name is hidden, put it in the oversight log
801 $log_type = $data['HideUser'] ?
'suppress' : 'block';
802 $logEntry = new ManualLogEntry( $log_type, $logaction );
803 $logEntry->setTarget( Title
::makeTitle( NS_USER
, $target ) );
804 $logEntry->setComment( $data['Reason'][0] );
805 $logEntry->setPerformer( $performer );
806 $logEntry->setParameters( $logParams );
807 # Relate log ID to block IDs (bug 25763)
808 $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] );
809 $logEntry->setRelations( array( 'ipb_id' => $blockIds ) );
810 $logId = $logEntry->insert();
811 $logEntry->publish( $logId );
818 * Get an array of suggested block durations from MediaWiki:Ipboptions
819 * @todo FIXME: This uses a rather odd syntax for the options, should it be converted
820 * to the standard "**<duration>|<displayname>" format?
821 * @param Language|null $lang The language to get the durations in, or null to use
822 * the wiki's content language
825 public static function getSuggestedDurations( $lang = null ) {
827 $msg = $lang === null
828 ?
wfMessage( 'ipboptions' )->inContentLanguage()->text()
829 : wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
835 foreach ( explode( ',', $msg ) as $option ) {
836 if ( strpos( $option, ':' ) === false ) {
837 $option = "$option:$option";
840 list( $show, $value ) = explode( ':', $option );
848 * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
849 * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
850 * @param string $expiry Whatever was typed into the form
851 * @return string Timestamp or "infinity" string for the DB implementation
853 public static function parseExpiryInput( $expiry ) {
855 if ( $infinity == null ) {
856 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
859 if ( $expiry == 'infinite' ||
$expiry == 'indefinite' ) {
862 $expiry = strtotime( $expiry );
864 if ( $expiry < 0 ||
$expiry === false ) {
868 $expiry = wfTimestamp( TS_MW
, $expiry );
875 * Can we do an email block?
876 * @param User $user The sysop wanting to make a block
879 public static function canBlockEmail( $user ) {
880 global $wgEnableUserEmail, $wgSysopEmailBans;
882 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
886 * bug 15810: blocked admins should not be able to block/unblock
887 * others, and probably shouldn't be able to unblock themselves
889 * @param User|int|string $user
890 * @param User $performer User doing the request
891 * @return bool|string True or error message key
893 public static function checkUnblockSelf( $user, User
$performer ) {
894 if ( is_int( $user ) ) {
895 $user = User
::newFromId( $user );
896 } elseif ( is_string( $user ) ) {
897 $user = User
::newFromName( $user );
900 if ( $performer->isBlocked() ) {
901 if ( $user instanceof User
&& $user->getId() == $performer->getId() ) {
902 # User is trying to unblock themselves
903 if ( $performer->isAllowed( 'unblockself' ) ) {
905 # User blocked themselves and is now trying to reverse it
906 } elseif ( $performer->blockedBy() === $performer->getName() ) {
909 return 'ipbnounblockself';
912 # User is trying to block/unblock someone else
921 * Return a comma-delimited list of "flags" to be passed to the log
922 * reader for this block, to provide more information in the logs
923 * @param array $data From HTMLForm data
924 * @param int $type Block::TYPE_ constant (USER, RANGE, or IP)
927 protected static function blockLogFlags( array $data, $type ) {
928 global $wgBlockAllowsUTEdit;
931 # when blocking a user the option 'anononly' is not available/has no effect
932 # -> do not write this into log
933 if ( !$data['HardBlock'] && $type != Block
::TYPE_USER
) {
934 // For grepping: message block-log-flags-anononly
935 $flags[] = 'anononly';
938 if ( $data['CreateAccount'] ) {
939 // For grepping: message block-log-flags-nocreate
940 $flags[] = 'nocreate';
943 # Same as anononly, this is not displayed when blocking an IP address
944 if ( !$data['AutoBlock'] && $type == Block
::TYPE_USER
) {
945 // For grepping: message block-log-flags-noautoblock
946 $flags[] = 'noautoblock';
949 if ( $data['DisableEmail'] ) {
950 // For grepping: message block-log-flags-noemail
951 $flags[] = 'noemail';
954 if ( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ) {
955 // For grepping: message block-log-flags-nousertalk
956 $flags[] = 'nousertalk';
959 if ( $data['HideUser'] ) {
960 // For grepping: message block-log-flags-hiddenname
961 $flags[] = 'hiddenname';
964 return implode( ',', $flags );
968 * Process the form on POST submission.
970 * @return bool|array True for success, false for didn't-try, array of errors on failure
972 public function onSubmit( array $data ) {
973 // This isn't used since we need that HTMLForm that's passed in the
974 // second parameter. See alterForm for the real function
978 * Do something exciting on successful processing of the form, most likely to show a
979 * confirmation message
981 public function onSuccess() {
982 $out = $this->getOutput();
983 $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
984 $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target
) );
987 protected function getGroupName() {