Follow-up r85025 - use strict comparison
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
1 <?php
2 /**
3 * Implements Special:Block
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that allows users with 'block' right to block users from
26 * editing pages and other actions
27 *
28 * @ingroup SpecialPage
29 */
30 class SpecialBlock extends SpecialPage {
31
32 /** The maximum number of edits a user can have and still be hidden
33 * TODO: config setting? */
34 const HIDEUSER_CONTRIBLIMIT = 1000;
35
36 /** @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
37 * or as subpage (Special:Block/Foo) */
38 protected $target;
39
40 /// @var Block::TYPE_ constant
41 protected $type;
42
43 /// @var Bool
44 protected $alreadyBlocked;
45
46 public function __construct() {
47 parent::__construct( 'Block', 'block' );
48 }
49
50 public function execute( $par ) {
51 global $wgUser, $wgOut, $wgRequest;
52
53 # Can't block when the database is locked
54 if( wfReadOnly() ) {
55 $wgOut->readOnlyPage();
56 return;
57 }
58 # Permission check
59 if( !$this->userCanExecute( $wgUser ) ) {
60 $wgOut->permissionRequired( 'block' );
61 return;
62 }
63
64 # Extract variables from the request. Try not to get into a situation where we
65 # need to extract *every* variable from the form just for processing here, but
66 # there are legitimate uses for some variables
67 list( $this->target, $this->type ) = self::getTargetAndType( $par, $wgRequest );
68 if ( $this->target instanceof User ) {
69 # Set the 'relevant user' in the skin, so it displays links like Contributions,
70 # User logs, UserRights, etc.
71 $wgUser->getSkin()->setRelevantUser( $this->target );
72 }
73
74 # bug 15810: blocked admins should have limited access here
75 $status = self::checkUnblockSelf( $this->target );
76 if ( $status !== true ) {
77 throw new ErrorPageError( 'badaccess', $status );
78 }
79
80 $wgOut->setPageTitle( wfMsg( 'blockip-title' ) );
81 $wgOut->addModules( 'mediawiki.special', 'mediawiki.special.block' );
82
83 $fields = self::getFormFields();
84 $this->alreadyBlocked = $this->maybeAlterFormDefaults( $fields );
85
86 $form = new HTMLForm( $fields );
87 $form->setTitle( $this->getTitle() );
88 $form->setWrapperLegend( wfMsg( 'blockip-legend' ) );
89 $form->setSubmitCallback( array( __CLASS__, 'processForm' ) );
90
91 $t = $this->alreadyBlocked
92 ? wfMsg( 'ipb-change-block' )
93 : wfMsg( 'ipbsubmit' );
94 $form->setSubmitText( $t );
95
96 $this->doPreText( $form );
97 $this->doPostText( $form );
98
99 if( $form->show() ){
100 $wgOut->setPageTitle( wfMsg( 'blockipsuccesssub' ) );
101 $wgOut->addWikiMsg( 'blockipsuccesstext', $this->target );
102 }
103 }
104
105 /**
106 * Get the HTMLForm descriptor array for the block form
107 * @return Array
108 */
109 protected static function getFormFields(){
110 global $wgUser, $wgBlockAllowsUTEdit;
111
112 $a = array(
113 'Target' => array(
114 'type' => 'text',
115 'label-message' => 'ipadressorusername',
116 'tabindex' => '1',
117 'id' => 'mw-bi-target',
118 'size' => '45',
119 'required' => true,
120 'validation-callback' => array( __CLASS__, 'validateTargetField' ),
121 ),
122 'Expiry' => array(
123 'type' => !count( self::getSuggestedDurations() ) ? 'text' : 'selectorother',
124 'label-message' => 'ipbexpiry',
125 'required' => true,
126 'tabindex' => '2',
127 'options' => self::getSuggestedDurations(),
128 'other' => wfMsg( 'ipbother' ),
129 ),
130 'Reason' => array(
131 'type' => 'selectandother',
132 'label-message' => 'ipbreason',
133 'options-message' => 'ipbreason-dropdown',
134 ),
135 'CreateAccount' => array(
136 'type' => 'check',
137 'label-message' => 'ipbcreateaccount',
138 'default' => true,
139 ),
140 );
141
142 if( self::canBlockEmail( $wgUser ) ) {
143 $a['DisableEmail'] = array(
144 'type' => 'check',
145 'label-message' => 'ipbemailban',
146 );
147 }
148
149 if( $wgBlockAllowsUTEdit ){
150 $a['DisableUTEdit'] = array(
151 'type' => 'check',
152 'label-message' => 'ipb-disableusertalk',
153 'default' => false,
154 );
155 }
156
157 $a['AutoBlock'] = array(
158 'type' => 'check',
159 'label-message' => 'ipbenableautoblock',
160 'default' => true,
161 );
162
163 # Allow some users to hide name from block log, blocklist and listusers
164 if( $wgUser->isAllowed( 'hideuser' ) ) {
165 $a['HideUser'] = array(
166 'type' => 'check',
167 'label-message' => 'ipbhidename',
168 'cssclass' => 'mw-block-hideuser',
169 );
170 }
171
172 # Watchlist their user page? (Only if user is logged in)
173 if( $wgUser->isLoggedIn() ) {
174 $a['Watch'] = array(
175 'type' => 'check',
176 'label-message' => 'ipbwatchuser',
177 );
178 }
179
180 $a['HardBlock'] = array(
181 'type' => 'check',
182 'label-message' => 'ipb-hardblock',
183 'default' => false,
184 );
185
186 $a['AlreadyBlocked'] = array(
187 'type' => 'hidden',
188 'default' => false,
189 );
190
191 return $a;
192 }
193
194 /**
195 * If the user has already been blocked with similar settings, load that block
196 * and change the defaults for the form fields to match the existing settings.
197 * @param &$fields Array HTMLForm descriptor array
198 * @return Bool whether fields were altered (that is, whether the target is
199 * already blocked)
200 */
201 protected function maybeAlterFormDefaults( &$fields ){
202 $fields['Target']['default'] = (string)$this->target;
203
204 $block = Block::newFromTarget( $this->target );
205
206 if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock
207 && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock
208 || $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block
209 )
210 {
211 $fields['HardBlock']['default'] = $block->isHardblock();
212 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
213 $fields['AutoBlock']['default'] = $block->isAutoblocking();
214 if( isset( $fields['DisableEmail'] ) ){
215 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
216 }
217 if( isset( $fields['HideUser'] ) ){
218 $fields['HideUser']['default'] = $block->mHideName;
219 }
220 if( isset( $fields['DisableUTEdit'] ) ){
221 $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
222 }
223 $fields['Reason']['default'] = $block->mReason;
224 $fields['AlreadyBlocked']['default'] = htmlspecialchars( $block->getTarget() );
225
226 if( $block->mExpiry == 'infinity' ) {
227 $fields['Expiry']['default'] = 'indefinite';
228 } else {
229 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry );
230 }
231
232 return true;
233 }
234 return false;
235 }
236
237 /**
238 * Add header elements like block log entries, etc.
239 * @param $form HTMLForm
240 * @return void
241 */
242 protected function doPreText( HTMLForm &$form ){
243 $form->addPreText( wfMsgExt( 'blockiptext', 'parse' ) );
244
245 $otherBlockMessages = array();
246 if( $this->target !== null ) {
247 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
248 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target ) );
249
250 if( count( $otherBlockMessages ) ) {
251 $s = Html::rawElement(
252 'h2',
253 array(),
254 wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockMessages ) )
255 ) . "\n";
256 $list = '';
257 foreach( $otherBlockMessages as $link ) {
258 $list .= Html::rawElement( 'li', array(), $link ) . "\n";
259 }
260 $s .= Html::rawElement(
261 'ul',
262 array( 'class' => 'mw-blockip-alreadyblocked' ),
263 $list
264 ) . "\n";
265 $form->addPreText( $s );
266 }
267 }
268
269 # Username/IP is blocked already locally
270 if( $this->alreadyBlocked ) {
271 $form->addPreText( Html::rawElement(
272 'div',
273 array( 'class' => 'mw-ipb-needreblock', ),
274 wfMsgExt(
275 'ipb-needreblock',
276 array( 'parseinline' ),
277 $this->target
278 ) ) );
279 }
280 }
281
282 /**
283 * Add footer elements to the form
284 * @param $form HTMLForm
285 * @return void
286 */
287 protected function doPostText( HTMLForm &$form ){
288 global $wgUser, $wgLang;
289
290 $skin = $wgUser->getSkin();
291
292 # Link to the user's contributions, if applicable
293 if( $this->target instanceof User ){
294 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() );
295 $links[] = $skin->link(
296 $contribsPage,
297 wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->target->getName() )
298 );
299 }
300
301 # Link to unblock the specified user, or to a blank unblock form
302 if( $this->target instanceof User ) {
303 $message = wfMsgExt( 'ipb-unblock-addr', array( 'parseinline' ), $this->target->getName() );
304 $list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() );
305 } else {
306 $message = wfMsgExt( 'ipb-unblock', array( 'parseinline' ) );
307 $list = SpecialPage::getTitleFor( 'Unblock' );
308 }
309 $links[] = $skin->linkKnown( $list, $message, array() );
310
311 # Link to the block list
312 $links[] = $skin->linkKnown(
313 SpecialPage::getTitleFor( 'BlockList' ),
314 wfMsg( 'ipb-blocklist' )
315 );
316
317 # Link to edit the block dropdown reasons, if applicable
318 if ( $wgUser->isAllowed( 'editinterface' ) ) {
319 $links[] = $skin->link(
320 Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ),
321 wfMsgHtml( 'ipb-edit-dropdown' ),
322 array(),
323 array( 'action' => 'edit' )
324 );
325 }
326
327 $form->addPostText( Html::rawElement(
328 'p',
329 array( 'class' => 'mw-ipb-conveniencelinks' ),
330 $wgLang->pipeList( $links )
331 ) );
332
333 if( $this->target instanceof User ){
334 # Get relevant extracts from the block and suppression logs, if possible
335 $userpage = $this->target->getUserPage();
336 $out = '';
337
338 LogEventsList::showLogExtract(
339 $out,
340 'block',
341 $userpage->getPrefixedText(),
342 '',
343 array(
344 'lim' => 10,
345 'msgKey' => array( 'blocklog-showlog', $userpage->getText() ),
346 'showIfEmpty' => false
347 )
348 );
349 $form->addPostText( $out );
350
351 # Add suppression block entries if allowed
352 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
353 LogEventsList::showLogExtract(
354 $out,
355 'suppress',
356 $userpage->getPrefixedText(),
357 '',
358 array(
359 'lim' => 10,
360 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
361 'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ),
362 'showIfEmpty' => false
363 )
364 );
365 $form->addPostText( $out );
366 }
367 }
368 }
369
370 /**
371 * Determine the target of the block, and the type of target
372 * TODO: should be in Block.php?
373 * @param $par String subpage parameter passed to setup, or data value from
374 * the HTMLForm
375 * @param $request WebRequest optionally try and get data from a request too
376 * @return void
377 */
378 public static function getTargetAndType( $par, WebRequest $request = null ){
379 $i = 0;
380 $target = null;
381 while( true ){
382 switch( $i++ ){
383 case 0:
384 # The HTMLForm will check wpTarget first and only if it doesn't get
385 # a value use the default, which will be generated from the options
386 # below; so this has to have a higher precedence here than $par, or
387 # we could end up with different values in $this->target and the HTMLForm!
388 if( $request instanceof WebRequest ){
389 $target = $request->getText( 'wpTarget', null );
390 }
391 break;
392 case 1:
393 $target = $par;
394 break;
395 case 2:
396 if( $request instanceof WebRequest ){
397 $target = $request->getText( 'ip', null );
398 }
399 break;
400 case 3:
401 # B/C @since 1.18
402 if( $request instanceof WebRequest ){
403 $target = $request->getText( 'wpBlockAddress', null );
404 }
405 break;
406 case 4:
407 break 2;
408 }
409 list( $target, $type ) = Block::parseTarget( $target );
410 if( $type !== null ){
411 return array( $target, $type );
412 }
413 }
414 return array( null, null );
415 }
416
417 /**
418 * HTMLForm field validation-callback for Target field.
419 * @since 1.18
420 * @return Message
421 */
422 public static function validateTargetField( $value, $alldata = null ) {
423 global $wgBlockCIDRLimit;
424
425 list( $target, $type ) = self::getTargetAndType( $value );
426
427 if( $type == Block::TYPE_USER ){
428 # TODO: why do we not have a User->exists() method?
429 if( !$target->getId() ){
430 return wfMessage( 'nosuchusershort', $target->getName() );
431 }
432
433 $status = self::checkUnblockSelf( $target );
434 if ( $status !== true ) {
435 return wfMessage( 'badaccess', $status );
436 }
437
438 } elseif( $type == Block::TYPE_RANGE ){
439 list( $ip, $range ) = explode( '/', $target, 2 );
440
441 if( ( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 )
442 || ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPV6'] == 128 ) )
443 {
444 # Range block effectively disabled
445 return wfMessage( 'range_block_disabled' );
446 }
447
448 if( ( IP::isIPv4( $ip ) && $range > 32 )
449 || ( IP::isIPv6( $ip ) && $range > 128 ) )
450 {
451 # Dodgy range
452 return wfMessage( 'ip_range_invalid' );
453 }
454
455 if( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
456 return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
457 }
458
459 if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
460 return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
461 }
462
463 } elseif( $type == Block::TYPE_IP ){
464 # All is well
465
466 } else {
467 return wfMessage( 'badipaddress' );
468 }
469
470 return true;
471 }
472
473 /**
474 * Given the form data, actually implement a block
475 * @param $data Array
476 * @return Bool|String
477 */
478 public static function processForm( array $data ){
479 global $wgUser, $wgBlockAllowsUTEdit;
480
481 // Handled by field validator callback
482 // self::validateTargetField( $data['Target'] );
483
484 list( $target, $type ) = self::getTargetAndType( $data['Target'] );
485 if( $type == Block::TYPE_USER ){
486 $user = $target;
487 $target = $user->getName();
488 $userId = $user->getId();
489
490 # Give admins a heads-up before they go and block themselves. Much messier
491 # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
492 # permission anyway, although the code does allow for it
493 if( $target === $wgUser->getName()
494 && $data['AlreadyBlocked'] != htmlspecialchars( $wgUser->getName() ) )
495 {
496 return array( 'ipb-blockingself' );
497 }
498
499 } elseif( $type == Block::TYPE_RANGE ){
500 $userId = 0;
501
502 } elseif( $type == Block::TYPE_IP ){
503 $target = $target->getName();
504 $userId = 0;
505
506 } else {
507 # This should have been caught in the form field validation
508 return array( 'badipaddress' );
509 }
510
511 if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 )
512 || !self::parseExpiryInput( $data['Expiry'] ) )
513 {
514 return array( 'ipb_expiry_invalid' );
515 }
516
517 if( !isset( $data['DisableEmail'] ) ){
518 $data['DisableEmail'] = false;
519 }
520
521 # If the user has done the form 'properly', they won't even have been given the
522 # option to suppress-block unless they have the 'hideuser' permission
523 if( !isset( $data['HideUser'] ) ){
524 $data['HideUser'] = false;
525 }
526 if( $data['HideUser'] ) {
527 if( !$wgUser->isAllowed('hideuser') ){
528 # this codepath is unreachable except by a malicious user spoofing forms,
529 # or by race conditions (user has oversight and sysop, loads block form,
530 # and is de-oversighted before submission); so need to fail completely
531 # rather than just silently disable hiding
532 return array( 'badaccess-group0' );
533 }
534
535 # Recheck params here...
536 if( $type != Block::TYPE_USER ) {
537 $data['HideUser'] = false; # IP users should not be hidden
538
539 } elseif( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
540 # Bad expiry.
541 return array( 'ipb_expiry_temp' );
542
543 } elseif( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) {
544 # Typically, the user should have a handful of edits.
545 # Disallow hiding users with many edits for performance.
546 return array( 'ipb_hide_invalid' );
547 }
548 }
549
550 # Create block object.
551 $block = new Block();
552 $block->setTarget( $target );
553 $block->setBlocker( $wgUser );
554 $block->mReason = $data['Reason'][0];
555 $block->mExpiry = self::parseExpiryInput( $data['Expiry'] );
556 $block->prevents( 'createaccount', $data['CreateAccount'] );
557 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
558 $block->prevents( 'sendemail', $data['DisableEmail'] );
559 $block->isHardblock( $data['HardBlock'] );
560 $block->isAutoblocking( $data['AutoBlock'] );
561 $block->mHideName = $data['HideUser'];
562
563 if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
564 return array( 'hookaborted' );
565 }
566
567 # Try to insert block. Is there a conflicting block?
568 $status = $block->insert();
569 if( !$status ) {
570 # Show form unless the user is already aware of this...
571 if( $data['AlreadyBlocked'] != htmlspecialchars( $block->getTarget() ) ) {
572 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
573 # Otherwise, try to update the block...
574 } else {
575 # This returns direct blocks before autoblocks/rangeblocks, since we should
576 # be sure the user is blocked by now it should work for our purposes
577 $currentBlock = Block::newFromTarget( $target );
578
579 if( $block->equals( $currentBlock ) ) {
580 return array( array( 'ipb_already_blocked', $block->getTarget() ) );
581 }
582
583 # If the name was hidden and the blocking user cannot hide
584 # names, then don't allow any block changes...
585 if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) {
586 return array( 'cant-see-hidden-user' );
587 }
588
589 $currentBlock->delete();
590 $status = $block->insert();
591 $logaction = 'reblock';
592
593 # Unset _deleted fields if requested
594 if( $currentBlock->mHideName && !$data['HideUser'] ) {
595 RevisionDeleteUser::unsuppressUserName( $target, $userId );
596 }
597
598 # If hiding/unhiding a name, this should go in the private logs
599 if( (bool)$currentBlock->mHideName ){
600 $data['HideUser'] = true;
601 }
602 }
603 } else {
604 $logaction = 'block';
605 }
606
607 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
608
609 # Set *_deleted fields if requested
610 if( $data['HideUser'] ) {
611 RevisionDeleteUser::suppressUserName( $target, $userId );
612 }
613
614 # Can't watch a rangeblock
615 if( $type != Block::TYPE_RANGE && $data['Watch'] ) {
616 $wgUser->addWatch( Title::makeTitle( NS_USER, $target ) );
617 }
618
619 # Block constructor sanitizes certain block options on insert
620 $data['BlockEmail'] = $block->prevents( 'sendemail' );
621 $data['AutoBlock'] = $block->isAutoblocking();
622
623 # Prepare log parameters
624 $logParams = array();
625 $logParams[] = $data['Expiry'];
626 $logParams[] = self::blockLogFlags( $data, $type );
627
628 # Make log entry, if the name is hidden, put it in the oversight log
629 $log_type = $data['HideUser'] ? 'suppress' : 'block';
630 $log = new LogPage( $log_type );
631 $log_id = $log->addEntry(
632 $logaction,
633 Title::makeTitle( NS_USER, $target ),
634 $data['Reason'][0],
635 $logParams
636 );
637 # Relate log ID to block IDs (bug 25763)
638 $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] );
639 $log->addRelations( 'ipb_id', $blockIds, $log_id );
640
641 # Report to the user
642 return true;
643 }
644
645 /**
646 * Get an array of suggested block durations from MediaWiki:Ipboptions
647 * FIXME: this uses a rather odd syntax for the options, should it be converted
648 * to the standard "**<duration>|<displayname>" format?
649 * @return Array
650 */
651 public static function getSuggestedDurations( $lang = null ){
652 $a = array();
653 $msg = $lang === null
654 ? wfMessage( 'ipboptions' )->inContentLanguage()->text()
655 : wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
656
657 if( $msg == '-' ){
658 return array();
659 }
660
661 foreach( explode( ',', $msg ) as $option ) {
662 if( strpos( $option, ':' ) === false ){
663 $option = "$option:$option";
664 }
665 list( $show, $value ) = explode( ':', $option );
666 $a[htmlspecialchars( $show )] = htmlspecialchars( $value );
667 }
668 return $a;
669 }
670
671 /**
672 * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
673 * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
674 * @param $expiry String: whatever was typed into the form
675 * @return String: timestamp or "infinity" string for the DB implementation
676 */
677 public static function parseExpiryInput( $expiry ) {
678 static $infinity;
679 if( $infinity == null ){
680 $infinity = wfGetDB( DB_READ )->getInfinity();
681 }
682 if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
683 $expiry = $infinity;
684 } else {
685 $expiry = strtotime( $expiry );
686 if ( $expiry < 0 || $expiry === false ) {
687 return false;
688 }
689 $expiry = wfTimestamp( TS_MW, $expiry );
690 }
691 return $expiry;
692 }
693
694 /**
695 * Can we do an email block?
696 * @param $user User: the sysop wanting to make a block
697 * @return Boolean
698 */
699 public static function canBlockEmail( $user ) {
700 global $wgEnableUserEmail, $wgSysopEmailBans;
701 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
702 }
703
704 /**
705 * bug 15810: blocked admins should not be able to block/unblock
706 * others, and probably shouldn't be able to unblock themselves
707 * either.
708 * @param $user User|Int|String
709 */
710 public static function checkUnblockSelf( $user ) {
711 global $wgUser;
712 if ( is_int( $user ) ) {
713 $user = User::newFromId( $user );
714 } elseif ( is_string( $user ) ) {
715 $user = User::newFromName( $user );
716 }
717 if( $wgUser->isBlocked() ){
718 if( $user instanceof User && $user->getId() == $wgUser->getId() ) {
719 # User is trying to unblock themselves
720 if ( $wgUser->isAllowed( 'unblockself' ) ) {
721 return true;
722 } else {
723 return 'ipbnounblockself';
724 }
725 } else {
726 # User is trying to block/unblock someone else
727 return 'ipbblocked';
728 }
729 } else {
730 return true;
731 }
732 }
733
734 /**
735 * Return a comma-delimited list of "flags" to be passed to the log
736 * reader for this block, to provide more information in the logs
737 * @param $data Array from HTMLForm data
738 * @param $type Block::TYPE_ constant
739 * @return array
740 */
741 protected static function blockLogFlags( array $data, $type ) {
742 global $wgBlockAllowsUTEdit;
743 $flags = array();
744
745 # when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
746 if( !$data['HardBlock'] && $type != Block::TYPE_USER ){
747 $flags[] = 'anononly';
748 }
749
750 if( $data['CreateAccount'] ){
751 $flags[] = 'nocreate';
752 }
753
754 # Same as anononly, this is not displayed when blocking an IP address
755 if( !$data['AutoBlock'] && $type != Block::TYPE_IP ){
756 $flags[] = 'noautoblock';
757 }
758
759 if( $data['DisableEmail'] ){
760 $flags[] = 'noemail';
761 }
762
763 if( $data['DisableUTEdit'] && $wgBlockAllowsUTEdit ){
764 $flags[] = 'nousertalk';
765 }
766
767 if( $data['HideUser'] ){
768 $flags[] = 'hiddenname';
769 }
770
771 return implode( ',', $flags );
772 }
773 }
774
775 # BC @since 1.18
776 class IPBlockForm extends SpecialBlock {}