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 # Don't need to do anything if the form has been posted
107 if ( !$this->getRequest()->wasPosted() && $this->preErrors
) {
108 $s = $form->formatErrors( $this->preErrors
);
110 $form->addHeaderText( Html
::rawElement(
112 array( 'class' => 'error' ),
120 * Get the HTMLForm descriptor array for the block form
123 protected function getFormFields() {
124 global $wgBlockAllowsUTEdit;
126 $user = $this->getUser();
128 $suggestedDurations = self
::getSuggestedDurations();
133 'label-message' => 'ipaddressorusername',
134 'id' => 'mw-bi-target',
138 'validation-callback' => array( __CLASS__
, 'validateTargetField' ),
139 'cssclass' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
142 'type' => !count( $suggestedDurations ) ?
'text' : 'selectorother',
143 'label-message' => 'ipbexpiry',
145 'options' => $suggestedDurations,
146 'other' => $this->msg( 'ipbother' )->text(),
147 'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(),
150 'type' => 'selectandother',
152 'label-message' => 'ipbreason',
153 'options-message' => 'ipbreason-dropdown',
155 'CreateAccount' => array(
157 'label-message' => 'ipbcreateaccount',
162 if ( self
::canBlockEmail( $user ) ) {
163 $a['DisableEmail'] = array(
165 'label-message' => 'ipbemailban',
169 if ( $wgBlockAllowsUTEdit ) {
170 $a['DisableUTEdit'] = array(
172 'label-message' => 'ipb-disableusertalk',
177 $a['AutoBlock'] = array(
179 'label-message' => 'ipbenableautoblock',
183 # Allow some users to hide name from block log, blocklist and listusers
184 if ( $user->isAllowed( 'hideuser' ) ) {
185 $a['HideUser'] = array(
187 'label-message' => 'ipbhidename',
188 'cssclass' => 'mw-block-hideuser',
192 # Watchlist their user page? (Only if user is logged in)
193 if ( $user->isLoggedIn() ) {
196 'label-message' => 'ipbwatchuser',
200 $a['HardBlock'] = array(
202 'label-message' => 'ipb-hardblock',
206 # This is basically a copy of the Target field, but the user can't change it, so we
207 # can see if the warnings we maybe showed to the user before still apply
208 $a['PreviousTarget'] = array(
213 # We'll turn this into a checkbox if we need to
214 $a['Confirm'] = array(
217 'label-message' => 'ipb-confirm',
220 $this->maybeAlterFormDefaults( $a );
222 // Allow extensions to add more fields
223 Hooks
::run( 'SpecialBlockModifyFormFields', array( $this, &$a ) );
229 * If the user has already been blocked with similar settings, load that block
230 * and change the defaults for the form fields to match the existing settings.
231 * @param array $fields HTMLForm descriptor array
232 * @return bool Whether fields were altered (that is, whether the target is
235 protected function maybeAlterFormDefaults( &$fields ) {
236 # This will be overwritten by request data
237 $fields['Target']['default'] = (string)$this->target
;
239 if ( $this->target
) {
240 $status = self
::validateTarget( $this->target
, $this->getUser() );
241 if ( !$status->isOK() ) {
242 $errors = $status->getErrorsArray();
243 $this->preErrors
= array_merge( $this->preErrors
, $errors );
248 $fields['PreviousTarget']['default'] = (string)$this->target
;
250 $block = Block
::newFromTarget( $this->target
);
252 if ( $block instanceof Block
&& !$block->mAuto
# The block exists and isn't an autoblock
253 && ( $this->type
!= Block
::TYPE_RANGE
# The block isn't a rangeblock
254 ||
$block->getTarget() == $this->target
) # or if it is, the range is what we're about to block
256 $fields['HardBlock']['default'] = $block->isHardblock();
257 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
258 $fields['AutoBlock']['default'] = $block->isAutoblocking();
260 if ( isset( $fields['DisableEmail'] ) ) {
261 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
264 if ( isset( $fields['HideUser'] ) ) {
265 $fields['HideUser']['default'] = $block->mHideName
;
268 if ( isset( $fields['DisableUTEdit'] ) ) {
269 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
272 // If the username was hidden (ipb_deleted == 1), don't show the reason
273 // unless this user also has rights to hideuser: Bug 35839
274 if ( !$block->mHideName ||
$this->getUser()->isAllowed( 'hideuser' ) ) {
275 $fields['Reason']['default'] = $block->mReason
;
277 $fields['Reason']['default'] = '';
280 if ( $this->getRequest()->wasPosted() ) {
281 # Ok, so we got a POST submission asking us to reblock a user. So show the
282 # confirm checkbox; the user will only see it if they haven't previously
283 $fields['Confirm']['type'] = 'check';
285 # We got a target, but it wasn't a POST request, so the user must have gone
286 # to a link like [[Special:Block/User]]. We don't need to show the checkbox
287 # as long as they go ahead and block *that* user
288 $fields['Confirm']['default'] = 1;
291 if ( $block->mExpiry
== 'infinity' ) {
292 $fields['Expiry']['default'] = 'infinite';
294 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822
, $block->mExpiry
);
297 $this->alreadyBlocked
= true;
298 $this->preErrors
[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) );
301 # We always need confirmation to do HideUser
302 if ( $this->requestedHideUser
) {
303 $fields['Confirm']['type'] = 'check';
304 unset( $fields['Confirm']['default'] );
305 $this->preErrors
[] = array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
308 # Or if the user is trying to block themselves
309 if ( (string)$this->target
=== $this->getUser()->getName() ) {
310 $fields['Confirm']['type'] = 'check';
311 unset( $fields['Confirm']['default'] );
312 $this->preErrors
[] = array( 'ipb-blockingself', 'ipb-confirmaction' );
317 * Add header elements like block log entries, etc.
320 protected function preText() {
321 $this->getOutput()->addModules( array( 'mediawiki.special.block', 'mediawiki.userSuggest' ) );
323 $text = $this->msg( 'blockiptext' )->parse();
325 $otherBlockMessages = array();
326 if ( $this->target
!== null ) {
327 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
328 Hooks
::run( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target
) );
330 if ( count( $otherBlockMessages ) ) {
331 $s = Html
::rawElement(
334 $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
339 foreach ( $otherBlockMessages as $link ) {
340 $list .= Html
::rawElement( 'li', array(), $link ) . "\n";
343 $s .= Html
::rawElement(
345 array( 'class' => 'mw-blockip-alreadyblocked' ),
357 * Add footer elements to the form
360 protected function postText() {
363 # Link to the user's contributions, if applicable
364 if ( $this->target
instanceof User
) {
365 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $this->target
->getName() );
366 $links[] = Linker
::link(
368 $this->msg( 'ipb-blocklist-contribs', $this->target
->getName() )->escaped()
372 # Link to unblock the specified user, or to a blank unblock form
373 if ( $this->target
instanceof User
) {
374 $message = $this->msg(
376 wfEscapeWikiText( $this->target
->getName() )
378 $list = SpecialPage
::getTitleFor( 'Unblock', $this->target
->getName() );
380 $message = $this->msg( 'ipb-unblock' )->parse();
381 $list = SpecialPage
::getTitleFor( 'Unblock' );
383 $links[] = Linker
::linkKnown( $list, $message, array() );
385 # Link to the block list
386 $links[] = Linker
::linkKnown(
387 SpecialPage
::getTitleFor( 'BlockList' ),
388 $this->msg( 'ipb-blocklist' )->escaped()
391 $user = $this->getUser();
393 # Link to edit the block dropdown reasons, if applicable
394 if ( $user->isAllowed( 'editinterface' ) ) {
395 $links[] = Linker
::link(
396 Title
::makeTitle( NS_MEDIAWIKI
, 'Ipbreason-dropdown' ),
397 $this->msg( 'ipb-edit-dropdown' )->escaped(),
399 array( 'action' => 'edit' )
403 $text = Html
::rawElement(
405 array( 'class' => 'mw-ipb-conveniencelinks' ),
406 $this->getLanguage()->pipeList( $links )
409 $userTitle = self
::getTargetUserTitle( $this->target
);
411 # Get relevant extracts from the block and suppression logs, if possible
414 LogEventsList
::showLogExtract(
421 'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
422 'showIfEmpty' => false
427 # Add suppression block entries if allowed
428 if ( $user->isAllowed( 'suppressionlog' ) ) {
429 LogEventsList
::showLogExtract(
436 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
437 'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
438 'showIfEmpty' => false
450 * Get a user page target for things like logs.
451 * This handles account and IP range targets.
452 * @param User|string $target
455 protected static function getTargetUserTitle( $target ) {
456 if ( $target instanceof User
) {
457 return $target->getUserPage();
458 } elseif ( IP
::isIPAddress( $target ) ) {
459 return Title
::makeTitleSafe( NS_USER
, $target );
466 * Determine the target of the block, and the type of target
467 * @todo Should be in Block.php?
468 * @param string $par Subpage parameter passed to setup, or data value from
470 * @param WebRequest $request Optionally try and get data from a request too
471 * @return array( User|string|null, Block::TYPE_ constant|null )
473 public static function getTargetAndType( $par, WebRequest
$request = null ) {
480 # The HTMLForm will check wpTarget first and only if it doesn't get
481 # a value use the default, which will be generated from the options
482 # below; so this has to have a higher precedence here than $par, or
483 # we could end up with different values in $this->target and the HTMLForm!
484 if ( $request instanceof WebRequest
) {
485 $target = $request->getText( 'wpTarget', null );
492 if ( $request instanceof WebRequest
) {
493 $target = $request->getText( 'ip', null );
498 if ( $request instanceof WebRequest
) {
499 $target = $request->getText( 'wpBlockAddress', null );
506 list( $target, $type ) = Block
::parseTarget( $target );
508 if ( $type !== null ) {
509 return array( $target, $type );
513 return array( null, null );
517 * HTMLForm field validation-callback for Target field.
519 * @param string $value
520 * @param array $alldata
521 * @param HTMLForm $form
524 public static function validateTargetField( $value, $alldata, $form ) {
525 $status = self
::validateTarget( $value, $form->getUser() );
526 if ( !$status->isOK() ) {
527 $errors = $status->getErrorsArray();
529 return call_user_func_array( array( $form, 'msg' ), $errors[0] );
536 * Validate a block target.
539 * @param string $value Block target to check
540 * @param User $user Performer of the block
543 public static function validateTarget( $value, User
$user ) {
544 global $wgBlockCIDRLimit;
546 /** @var User $target */
547 list( $target, $type ) = self
::getTargetAndType( $value );
548 $status = Status
::newGood( $target );
550 if ( $type == Block
::TYPE_USER
) {
551 if ( $target->isAnon() ) {
554 wfEscapeWikiText( $target->getName() )
558 $unblockStatus = self
::checkUnblockSelf( $target, $user );
559 if ( $unblockStatus !== true ) {
560 $status->fatal( 'badaccess', $unblockStatus );
562 } elseif ( $type == Block
::TYPE_RANGE
) {
563 list( $ip, $range ) = explode( '/', $target, 2 );
566 ( IP
::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
567 ( IP
::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
569 // Range block effectively disabled
570 $status->fatal( 'range_block_disabled' );
574 ( IP
::isIPv4( $ip ) && $range > 32 ) ||
575 ( IP
::isIPv6( $ip ) && $range > 128 )
578 $status->fatal( 'ip_range_invalid' );
581 if ( IP
::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
582 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
585 if ( IP
::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
586 $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
588 } elseif ( $type == Block
::TYPE_IP
) {
591 $status->fatal( 'badipaddress' );
598 * Submit callback for an HTMLForm object, will simply pass
600 * @param HTMLForm $form
601 * @return bool|string
603 public static function processUIForm( array $data, HTMLForm
$form ) {
604 return self
::processForm( $data, $form->getContext() );
608 * Given the form data, actually implement a block
610 * @param IContextSource $context
611 * @return bool|string
613 public static function processForm( array $data, IContextSource
$context ) {
614 global $wgBlockAllowsUTEdit, $wgHideUserContribLimit, $wgContLang;
616 $performer = $context->getUser();
618 // Handled by field validator callback
619 // self::validateTargetField( $data['Target'] );
621 # This might have been a hidden field or a checkbox, so interesting data
623 $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true );
625 /** @var User $target */
626 list( $target, $type ) = self
::getTargetAndType( $data['Target'] );
627 if ( $type == Block
::TYPE_USER
) {
629 $target = $user->getName();
630 $userId = $user->getId();
632 # Give admins a heads-up before they go and block themselves. Much messier
633 # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
634 # permission anyway, although the code does allow for it.
635 # Note: Important to use $target instead of $data['Target']
636 # since both $data['PreviousTarget'] and $target are normalized
637 # but $data['target'] gets overridden by (non-normalized) request variable
638 # from previous request.
639 if ( $target === $performer->getName() &&
640 ( $data['PreviousTarget'] !== $target ||
!$data['Confirm'] )
642 return array( 'ipb-blockingself', 'ipb-confirmaction' );
644 } elseif ( $type == Block
::TYPE_RANGE
) {
646 } elseif ( $type == Block
::TYPE_IP
) {
647 $target = $target->getName();
650 # This should have been caught in the form field validation
651 return array( 'badipaddress' );
654 if ( ( strlen( $data['Expiry'] ) == 0 ) ||
( strlen( $data['Expiry'] ) > 50 )
655 ||
!self
::parseExpiryInput( $data['Expiry'] )
657 return array( 'ipb_expiry_invalid' );
660 if ( !isset( $data['DisableEmail'] ) ) {
661 $data['DisableEmail'] = false;
664 # If the user has done the form 'properly', they won't even have been given the
665 # option to suppress-block unless they have the 'hideuser' permission
666 if ( !isset( $data['HideUser'] ) ) {
667 $data['HideUser'] = false;
670 if ( $data['HideUser'] ) {
671 if ( !$performer->isAllowed( 'hideuser' ) ) {
672 # this codepath is unreachable except by a malicious user spoofing forms,
673 # or by race conditions (user has oversight and sysop, loads block form,
674 # and is de-oversighted before submission); so need to fail completely
675 # rather than just silently disable hiding
676 return array( 'badaccess-group0' );
679 # Recheck params here...
680 if ( $type != Block
::TYPE_USER
) {
681 $data['HideUser'] = false; # IP users should not be hidden
682 } elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
684 return array( 'ipb_expiry_temp' );
685 } elseif ( $wgHideUserContribLimit !== false
686 && $user->getEditCount() > $wgHideUserContribLimit
688 # Typically, the user should have a handful of edits.
689 # Disallow hiding users with many edits for performance.
690 return array( array( 'ipb_hide_invalid',
691 Message
::numParam( $wgHideUserContribLimit ) ) );
692 } elseif ( !$data['Confirm'] ) {
693 return array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
697 # Create block object.
698 $block = new Block();
699 $block->setTarget( $target );
700 $block->setBlocker( $performer );
701 # Truncate reason for whole multibyte characters
702 $block->mReason
= $wgContLang->truncate( $data['Reason'][0], 255 );
703 $block->mExpiry
= self
::parseExpiryInput( $data['Expiry'] );
704 $block->prevents( 'createaccount', $data['CreateAccount'] );
705 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit ||
$data['DisableUTEdit'] ) );
706 $block->prevents( 'sendemail', $data['DisableEmail'] );
707 $block->isHardblock( $data['HardBlock'] );
708 $block->isAutoblocking( $data['AutoBlock'] );
709 $block->mHideName
= $data['HideUser'];
711 $reason = array( 'hookaborted' );
712 if ( !Hooks
::run( 'BlockIp', array( &$block, &$performer, &$reason ) ) ) {
716 # Try to insert block. Is there a conflicting block?
717 $status = $block->insert();
719 # Indicates whether the user is confirming the block and is aware of
720 # the conflict (did not change the block target in the meantime)
721 $blockNotConfirmed = !$data['Confirm'] ||
( array_key_exists( 'PreviousTarget', $data )
722 && $data['PreviousTarget'] !== $target );
724 # Special case for API - bug 32434
725 $reblockNotAllowed = ( array_key_exists( 'Reblock', $data ) && !$data['Reblock'] );
727 # Show form unless the user is already aware of this...
728 if ( $blockNotConfirmed ||
$reblockNotAllowed ) {
729 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
730 # Otherwise, try to update the block...
732 # This returns direct blocks before autoblocks/rangeblocks, since we should
733 # be sure the user is blocked by now it should work for our purposes
734 $currentBlock = Block
::newFromTarget( $target );
736 if ( $block->equals( $currentBlock ) ) {
737 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
740 # If the name was hidden and the blocking user cannot hide
741 # names, then don't allow any block changes...
742 if ( $currentBlock->mHideName
&& !$performer->isAllowed( 'hideuser' ) ) {
743 return array( 'cant-see-hidden-user' );
746 $currentBlock->isHardblock( $block->isHardblock() );
747 $currentBlock->prevents( 'createaccount', $block->prevents( 'createaccount' ) );
748 $currentBlock->mExpiry
= $block->mExpiry
;
749 $currentBlock->isAutoblocking( $block->isAutoblocking() );
750 $currentBlock->mHideName
= $block->mHideName
;
751 $currentBlock->prevents( 'sendemail', $block->prevents( 'sendemail' ) );
752 $currentBlock->prevents( 'editownusertalk', $block->prevents( 'editownusertalk' ) );
753 $currentBlock->mReason
= $block->mReason
;
755 $status = $currentBlock->update();
757 $logaction = 'reblock';
759 # Unset _deleted fields if requested
760 if ( $currentBlock->mHideName
&& !$data['HideUser'] ) {
761 RevisionDeleteUser
::unsuppressUserName( $target, $userId );
764 # If hiding/unhiding a name, this should go in the private logs
765 if ( (bool)$currentBlock->mHideName
) {
766 $data['HideUser'] = true;
770 $logaction = 'block';
773 Hooks
::run( 'BlockIpComplete', array( $block, $performer ) );
775 # Set *_deleted fields if requested
776 if ( $data['HideUser'] ) {
777 RevisionDeleteUser
::suppressUserName( $target, $userId );
780 # Can't watch a rangeblock
781 if ( $type != Block
::TYPE_RANGE
&& $data['Watch'] ) {
782 WatchAction
::doWatch(
783 Title
::makeTitle( NS_USER
, $target ),
785 WatchedItem
::IGNORE_USER_RIGHTS
789 # Block constructor sanitizes certain block options on insert
790 $data['BlockEmail'] = $block->prevents( 'sendemail' );
791 $data['AutoBlock'] = $block->isAutoblocking();
793 # Prepare log parameters
794 $logParams = array();
795 $logParams['5::duration'] = $data['Expiry'];
796 $logParams['6::flags'] = self
::blockLogFlags( $data, $type );
798 # Make log entry, if the name is hidden, put it in the oversight log
799 $log_type = $data['HideUser'] ?
'suppress' : 'block';
800 $logEntry = new ManualLogEntry( $log_type, $logaction );
801 $logEntry->setTarget( Title
::makeTitle( NS_USER
, $target ) );
802 $logEntry->setComment( $data['Reason'][0] );
803 $logEntry->setPerformer( $performer );
804 $logEntry->setParameters( $logParams );
805 # Relate log ID to block IDs (bug 25763)
806 $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] );
807 $logEntry->setRelations( array( 'ipb_id' => $blockIds ) );
808 $logId = $logEntry->insert();
809 $logEntry->publish( $logId );
816 * Get an array of suggested block durations from MediaWiki:Ipboptions
817 * @todo FIXME: This uses a rather odd syntax for the options, should it be converted
818 * to the standard "**<duration>|<displayname>" format?
819 * @param Language|null $lang The language to get the durations in, or null to use
820 * the wiki's content language
823 public static function getSuggestedDurations( $lang = null ) {
825 $msg = $lang === null
826 ?
wfMessage( 'ipboptions' )->inContentLanguage()->text()
827 : wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
833 foreach ( explode( ',', $msg ) as $option ) {
834 if ( strpos( $option, ':' ) === false ) {
835 $option = "$option:$option";
838 list( $show, $value ) = explode( ':', $option );
846 * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
847 * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
848 * @param string $expiry Whatever was typed into the form
849 * @return string Timestamp or "infinity" string for the DB implementation
851 public static function parseExpiryInput( $expiry ) {
853 if ( $infinity == null ) {
854 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
857 if ( $expiry == 'infinite' ||
$expiry == 'indefinite' ) {
860 $expiry = strtotime( $expiry );
862 if ( $expiry < 0 ||
$expiry === false ) {
866 $expiry = wfTimestamp( TS_MW
, $expiry );
873 * Can we do an email block?
874 * @param User $user The sysop wanting to make a block
877 public static function canBlockEmail( $user ) {
878 global $wgEnableUserEmail, $wgSysopEmailBans;
880 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
884 * bug 15810: blocked admins should not be able to block/unblock
885 * others, and probably shouldn't be able to unblock themselves
887 * @param User|int|string $user
888 * @param User $performer User doing the request
889 * @return bool|string True or error message key
891 public static function checkUnblockSelf( $user, User
$performer ) {
892 if ( is_int( $user ) ) {
893 $user = User
::newFromId( $user );
894 } elseif ( is_string( $user ) ) {
895 $user = User
::newFromName( $user );
898 if ( $performer->isBlocked() ) {
899 if ( $user instanceof User
&& $user->getId() == $performer->getId() ) {
900 # User is trying to unblock themselves
901 if ( $performer->isAllowed( 'unblockself' ) ) {
903 # User blocked themselves and is now trying to reverse it
904 } elseif ( $performer->blockedBy() === $performer->getName() ) {
907 return 'ipbnounblockself';
910 # User is trying to block/unblock someone else
919 * Return a comma-delimited list of "flags" to be passed to the log
920 * reader for this block, to provide more information in the logs
921 * @param array $data From HTMLForm data
922 * @param int $type Block::TYPE_ constant (USER, RANGE, or IP)
925 protected static function blockLogFlags( array $data, $type ) {
926 global $wgBlockAllowsUTEdit;
929 # when blocking a user the option 'anononly' is not available/has no effect
930 # -> do not write this into log
931 if ( !$data['HardBlock'] && $type != Block
::TYPE_USER
) {
932 // For grepping: message block-log-flags-anononly
933 $flags[] = 'anononly';
936 if ( $data['CreateAccount'] ) {
937 // For grepping: message block-log-flags-nocreate
938 $flags[] = 'nocreate';
941 # Same as anononly, this is not displayed when blocking an IP address
942 if ( !$data['AutoBlock'] && $type == Block
::TYPE_USER
) {
943 // For grepping: message block-log-flags-noautoblock
944 $flags[] = 'noautoblock';
947 if ( $data['DisableEmail'] ) {
948 // For grepping: message block-log-flags-noemail
949 $flags[] = 'noemail';
952 if ( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ) {
953 // For grepping: message block-log-flags-nousertalk
954 $flags[] = 'nousertalk';
957 if ( $data['HideUser'] ) {
958 // For grepping: message block-log-flags-hiddenname
959 $flags[] = 'hiddenname';
962 return implode( ',', $flags );
966 * Process the form on POST submission.
968 * @return bool|array True for success, false for didn't-try, array of errors on failure
970 public function onSubmit( array $data ) {
971 // This isn't used since we need that HTMLForm that's passed in the
972 // second parameter. See alterForm for the real function
976 * Do something exciting on successful processing of the form, most likely to show a
977 * confirmation message
979 public function onSuccess() {
980 $out = $this->getOutput();
981 $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
982 $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target
) );
985 protected function getGroupName() {