91d8af96ce2a442d6d8949560ad68d23b232586d
[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' => '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( wfMsgForContent( 'ipboptions' ) == '-' ){
143 $a['Expiry']['type'] = 'text';
144 }
145
146 if( self::canBlockEmail( $wgUser ) ) {
147 $a['DisableEmail'] = array(
148 'type' => 'check',
149 'label-message' => 'ipbemailban',
150 );
151 }
152
153 if( $wgBlockAllowsUTEdit ){
154 $a['DisableUTEdit'] = array(
155 'type' => 'check',
156 'label-message' => 'ipb-disableusertalk',
157 'default' => false,
158 );
159 }
160
161 $a['AutoBlock'] = array(
162 'type' => 'check',
163 'label-message' => 'ipbenableautoblock',
164 'default' => true,
165 );
166
167 # Allow some users to hide name from block log, blocklist and listusers
168 if( $wgUser->isAllowed( 'hideuser' ) ) {
169 $a['HideUser'] = array(
170 'type' => 'check',
171 'label-message' => 'ipbhidename',
172 'cssclass' => 'mw-block-hideuser',
173 );
174 }
175
176 # Watchlist their user page? (Only if user is logged in)
177 if( $wgUser->isLoggedIn() ) {
178 $a['Watch'] = array(
179 'type' => 'check',
180 'label-message' => 'ipbwatchuser',
181 );
182 }
183
184 $a['HardBlock'] = array(
185 'type' => 'check',
186 'label-message' => 'ipb-hardblock',
187 'default' => false,
188 );
189
190 $a['AlreadyBlocked'] = array(
191 'type' => 'hidden',
192 'default' => false,
193 );
194
195 return $a;
196 }
197
198 /**
199 * If the user has already been blocked with similar settings, load that block
200 * and change the defaults for the form fields to match the existing settings.
201 * @param &$fields Array HTMLForm descriptor array
202 * @return Bool whether fields were altered (that is, whether the target is
203 * already blocked)
204 */
205 protected function maybeAlterFormDefaults( &$fields ){
206 $fields['Target']['default'] = $this->target;
207
208 $block = self::getBlockFromTargetAndType( $this->target, $this->type );
209
210 if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock
211 && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock
212 || $block->mAddress == $this->target ) # or if it is, the range is what we're about to block
213 )
214 {
215 $fields['HardBlock']['default'] = !$block->mAnonOnly;
216 $fields['CreateAccount']['default'] = $block->mCreateAccount;
217 $fields['AutoBlock']['default'] = $block->mEnableAutoblock;
218 $fields['DisableEmail']['default'] = $block->mBlockEmail;
219 $fields['HideUser']['default'] = $block->mHideName;
220 $fields['DisableUTEdit']['default'] = !$block->mAllowUsertalk;
221 $fields['Reason']['default'] = $block->mReason;
222 $fields['AlreadyBlocked']['default'] = true;
223
224 if( $block->mExpiry == 'infinity' ) {
225 $fields['Expiry']['default'] = 'indefinite';
226 } else {
227 $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry );
228 }
229
230 return true;
231 }
232 return false;
233 }
234
235 /**
236 * Add header elements like block log entries, etc.
237 * @param $form HTMLForm
238 * @return void
239 */
240 protected function doPreText( HTMLForm &$form ){
241 $form->addPreText( wfMsgExt( 'blockiptext', 'parse' ) );
242
243 $otherBlockMessages = array();
244 if( $this->target !== null ) {
245 # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
246 wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target ) );
247
248 if( count( $otherBlockMessages ) ) {
249 $s = Html::rawElement(
250 'h2',
251 array(),
252 wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockMessages ) )
253 ) . "\n";
254 $list = '';
255 foreach( $otherBlockMessages as $link ) {
256 $list .= Html::rawElement( 'li', array(), $link ) . "\n";
257 }
258 $s .= Html::rawElement(
259 'ul',
260 array( 'class' => 'mw-blockip-alreadyblocked' ),
261 $list
262 ) . "\n";
263 $form->addPreText( $s );
264 }
265 }
266
267 # Username/IP is blocked already locally
268 if( $this->alreadyBlocked ) {
269 $form->addPreText( Html::rawElement(
270 'div',
271 array( 'class' => 'mw-ipb-needreblock', ),
272 wfMsgExt(
273 'ipb-needreblock',
274 array( 'parseinline' ),
275 $this->target
276 ) ) );
277 }
278 }
279
280 /**
281 * Add footer elements to the form
282 * @param $form HTMLForm
283 * @return void
284 */
285 protected function doPostText( HTMLForm &$form ){
286 global $wgUser, $wgLang;
287
288 $skin = $wgUser->getSkin();
289
290 # Link to the user's contributions, if applicable
291 if( $this->target instanceof User ){
292 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() );
293 $links[] = $skin->link(
294 $contribsPage,
295 wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->target->getName() )
296 );
297 }
298
299 # Link to unblock the specified user, or to a blank unblock form
300 $list = SpecialPage::getTitleFor( 'Ipblocklist' );
301 $query = array( 'action' => 'unblock' );
302 if( $this->target instanceof User ) {
303 $message = wfMsgExt( 'ipb-unblock-addr', array( 'parseinline' ), $this->target->getName() );
304 $query['ip'] = $this->target->getName();
305 } else {
306 $message = wfMsgExt( 'ipb-unblock', array( 'parseinline' ) );
307 }
308 $links[] = $skin->linkKnown( $list, $message, array(), $query );
309
310 # Link to the block list
311 $links[] = $skin->linkKnown(
312 SpecialPage::getTitleFor( 'Ipblocklist' ),
313 wfMsg( 'ipb-blocklist' )
314 );
315
316 # Link to edit the block dropdown reasons, if applicable
317 if ( $wgUser->isAllowed( 'editinterface' ) ) {
318 $links[] = $skin->link(
319 Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ),
320 wfMsgHtml( 'ipb-edit-dropdown' ),
321 array(),
322 array( 'action' => 'edit' )
323 );
324 }
325
326 $form->addPostText( Html::rawElement(
327 'p',
328 array( 'class' => 'mw-ipb-conveniencelinks' ),
329 $wgLang->pipeList( $links )
330 ) );
331
332 if( $this->target instanceof User ){
333 # Get relevant extracts from the block and suppression logs, if possible
334 $userpage = $this->target->getUserPage();
335 $out = '';
336
337 LogEventsList::showLogExtract(
338 $out,
339 'block',
340 $userpage->getPrefixedText(),
341 '',
342 array(
343 'lim' => 10,
344 'msgKey' => array( 'blocklog-showlog', $userpage->getText() ),
345 'showIfEmpty' => false
346 )
347 );
348 $form->addPostText( $out );
349
350 # Add suppression block entries if allowed
351 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
352 LogEventsList::showLogExtract(
353 $out,
354 'suppress',
355 $userpage->getPrefixedText(),
356 '',
357 array(
358 'lim' => 10,
359 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
360 'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ),
361 'showIfEmpty' => false
362 )
363 );
364 $form->addPostText( $out );
365 }
366 }
367 }
368
369 /**
370 * Determine the target of the block, and the type of target
371 * TODO: should be in Block.php?
372 * @param $par String subpage parameter passed to setup, or data value from
373 * the HTMLForm
374 * @param $request WebRequest optionally try and get data from a request too
375 * @return void
376 */
377 public static function getTargetAndType( $par, WebRequest $request = null ){
378 $i = 0;
379 $target = null;
380 while( true ){
381 switch( $i++ ){
382 case 0:
383 # The HTMLForm will check wpTarget first and only if it doesn't get
384 # a value use the default, which will be generated from the options
385 # below; so this has to have a higher precedence here than $par, or
386 # we could end up with different values in $this->target and the HTMLForm!
387 if( $request instanceof WebRequest ){
388 $target = $request->getText( 'wpTarget', null );
389 }
390 break;
391 case 1:
392 $target = $par;
393 break;
394 case 2:
395 if( $request instanceof WebRequest ){
396 $target = $request->getText( 'ip', null );
397 }
398 break;
399 case 3:
400 # B/C @since 1.18
401 if( $request instanceof WebRequest ){
402 $target = $request->getText( 'wpBlockAddress', null );
403 }
404 break;
405 case 4:
406 break 2;
407 }
408
409 $userObj = User::newFromName( $target );
410 if( $userObj instanceof User ){
411 return array( $userObj, Block::TYPE_USER );
412 } elseif( IP::isValid( $target ) ){
413 # We can still create a User if it's an IP address, but we need to turn
414 # off validation checking (which would exclude IP addresses)
415 return array(
416 User::newFromName( IP::sanitizeIP( $target ), false ),
417 Block::TYPE_IP
418 );
419 break;
420 } elseif( IP::isValidBlock( $target ) ){
421 # Can't create a User from an IP range
422 return array( Block::normaliseRange( $target ), Block::TYPE_RANGE );
423 }
424 }
425 return array( null, null );
426 }
427
428 /**
429 * Given a target and the target's type, get a block object if possible
430 * @param $target String|User
431 * @param $type Block::TYPE_ constant
432 * @return Block|null
433 * TODO: this probably belongs in Block.php when that mess is cleared up
434 */
435 public static function getBlockFromTargetAndType( $target, $type ){
436 if( $target instanceof User ){
437 if( $type == Block::TYPE_IP ){
438 return Block::newFromDB( $target->getName(), 0 );
439 } elseif( $type == Block::TYPE_USER ) {
440 return Block::newFromDB( '', $target->getId() );
441 } else {
442 # Should be unreachable;
443 return null;
444 }
445 } elseif( $type == Block::TYPE_RANGE ){
446 return Block::newFromDB( '', $target );
447 } else {
448 return null;
449 }
450 }
451
452 public static function validateTargetField( $data, $alldata = null ) {
453 global $wgBlockCIDRLimit;
454
455 list( $target, $type ) = self::getTargetAndType( $data );
456
457 if( $type == Block::TYPE_USER ){
458 # TODO: why do we not have a User->exists() method?
459 if( !$target->getId() ){
460 return wfMessage( 'nosuchusershort', $target->getName() );
461 }
462
463 $status = self::checkUnblockSelf( $target );
464 if ( $status !== true ) {
465 return wfMessage( 'badaccess', $status );
466 }
467
468 $user = $target;
469 $target = $user->getName();
470 $userId = $user->getId();
471
472 } elseif( $type == Block::TYPE_RANGE ){
473 list( $ip, $range ) = explode( '/', $target, 2 );
474
475 if( ( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 )
476 || ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPV6'] == 128 ) )
477 {
478 # Range block effectively disabled
479 return wfMessage( 'range_block_disabled' );
480 }
481
482 if( ( IP::isIPv4( $ip ) && $range > 32 )
483 || ( IP::isIPv6( $ip ) && $range > 128 ) )
484 {
485 # Dodgy range
486 return wfMessage( 'ip_range_invalid' );
487 }
488
489 if( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
490 return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
491 }
492
493 if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
494 return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
495 }
496
497 $userId = 0;
498
499 } elseif( $type == Block::TYPE_IP ){
500 # All is well
501 $target = $target->getName();
502 $userId = 0;
503
504 } else {
505 return wfMessage( 'badipaddress' );
506 }
507 }
508
509 /**
510 * Given the form data, actually implement a block
511 * @param $data Array
512 * @return Bool|String
513 */
514 public static function processForm( array $data ){
515 global $wgUser, $wgBlockAllowsUTEdit;
516
517 // Handled by field validator callback
518 // self::validateTargetField( $data['Target'] );
519
520 if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 )
521 || !Block::parseExpiryInput( $data['Expiry'] ) )
522 {
523 return array( 'ipb_expiry_invalid' );
524 }
525
526 if( !$wgBlockAllowsUTEdit ){
527 $data['PreventUTEdit'] = true;
528 }
529
530 # If the user has done the form 'properly', they won't even have been given the
531 # option to suppress-block unless they have the 'hideuser' permission
532 if( !isset( $data['HideUser'] ) ){
533 $data['HideUser'] = false;
534 }
535 if( $data['HideUser'] ) {
536 if( !$wgUser->isAllowed('hideuser') ){
537 # this codepath is unreachable except by a malicious user spoofing forms,
538 # or by race conditions (user has oversight and sysop, loads block form,
539 # and is de-oversighted before submission); so need to fail completely
540 # rather than just silently disable hiding
541 return array( 'badaccess-group0' );
542 }
543
544 # Recheck params here...
545 if( $type != Block::TYPE_USER ) {
546 $data['HideUser'] = false; # IP users should not be hidden
547
548 } elseif( !in_array( $data['Expiry'], array( 'inifinite', 'infinity', 'indefinite' ) ) ) {
549 # Bad expiry.
550 return array( 'ipb_expiry_temp' );
551
552 } elseif( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) {
553 # Typically, the user should have a handful of edits.
554 # Disallow hiding users with many edits for performance.
555 return array( 'ipb_hide_invalid' );
556 }
557 }
558
559 # Create block object. Note that for a user block, ipb_address is only for display purposes
560 # FIXME: Why do we need to pass fourteen optional parameters to do this!?!
561 $block = new Block(
562 $target, # IP address or User name
563 $userId, # User id
564 $wgUser->getId(), # Blocker id
565 $data['Reason'][0], # Reason string
566 wfTimestampNow(), # Block Timestamp
567 0, # Is this an autoblock (no)
568 Block::parseExpiryInput( $data['Expiry'] ), # Expiry time
569 !$data['HardBlock'], # Block anon only
570 $data['CreateAccount'],
571 $data['AutoBlock'],
572 $data['HideUser'],
573 $data['DisableEmail'],
574 !$data['DisableUTEdit'] # *Allow* UTEdit
575 );
576
577 if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
578 return array( 'hookaborted' );
579 }
580
581 # Try to insert block. Is there a conflicting block?
582 if( !$block->insert() ) {
583
584 # Show form unless the user is already aware of this...
585 if( !$data['AlreadyBlocked'] ) {
586 return array( array( 'ipb_already_blocked', $data['Target'] ) );
587
588 # Otherwise, try to update the block...
589 } else {
590
591 # This returns direct blocks before autoblocks/rangeblocks, since we should
592 # be sure the user is blocked by now it should work for our purposes
593 $currentBlock = Block::newFromDB( $target, $userId );
594
595 if( $block->equals( $currentBlock ) ) {
596 return array( 'ipb_already_blocked' );
597 }
598
599 # If the name was hidden and the blocking user cannot hide
600 # names, then don't allow any block changes...
601 if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) {
602 return array( 'cant-see-hidden-user' );
603 }
604
605 $currentBlock->delete();
606 $block->insert();
607 $logaction = 'reblock';
608
609 # Unset _deleted fields if requested
610 if( $currentBlock->mHideName && !$data['HideUser'] ) {
611 RevisionDeleteUser::unsuppressUserName( $target, $userId );
612 }
613
614 # If hiding/unhiding a name, this should go in the private logs
615 if( (bool)$currentBlock->mHideName ){
616 $data['HideUser'] = true;
617 }
618 }
619
620 } else {
621 $logaction = 'block';
622 }
623
624 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
625
626 # Set *_deleted fields if requested
627 if( $data['HideUser'] ) {
628 RevisionDeleteUser::suppressUserName( $target, $userId );
629 }
630
631 # Can't watch a rangeblock
632 if( $type != Block::TYPE_RANGE && $data['Watch'] ) {
633 $wgUser->addWatch( Title::makeTitle( NS_USER, $target ) );
634 }
635
636 # Block constructor sanitizes certain block options on insert
637 $data['BlockEmail'] = $block->mBlockEmail;
638 $data['AutoBlock'] = $block->mEnableAutoblock;
639
640 # Prepare log parameters
641 $logParams = array();
642 $logParams[] = $data['Expiry'];
643 $logParams[] = self::blockLogFlags( $data, $type );
644
645 # Make log entry, if the name is hidden, put it in the oversight log
646 $log_type = $data['HideUser'] ? 'suppress' : 'block';
647 $log = new LogPage( $log_type );
648 $log->addEntry(
649 $logaction,
650 Title::makeTitle( NS_USER, $target ),
651 $data['Reason'][0],
652 $logParams
653 );
654
655 # Report to the user
656 return true;
657 }
658
659 /**
660 * Get an array of suggested block durations from MediaWiki:Ipboptions
661 * FIXME: this uses a rather odd syntax for the options, should it be converted
662 * to the standard "**<duration>|<displayname>" format?
663 * @return Array
664 */
665 protected static function getSuggestedDurations(){
666 $a = array();
667 foreach( explode( ',', wfMsgForContent( 'ipboptions' ) ) as $option ) {
668 if( strpos( $option, ':' ) === false ) $option = "$option:$option";
669 list( $show, $value ) = explode( ':', $option );
670 $a[htmlspecialchars( $show )] = htmlspecialchars( $value );
671 }
672 return $a;
673 }
674
675 /**
676 * Can we do an email block?
677 * @param $user User: the sysop wanting to make a block
678 * @return Boolean
679 */
680 public static function canBlockEmail( $user ) {
681 global $wgEnableUserEmail, $wgSysopEmailBans;
682 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
683 }
684
685 /**
686 * bug 15810: blocked admins should not be able to block/unblock
687 * others, and probably shouldn't be able to unblock themselves
688 * either.
689 * @param $user User|Int|String
690 */
691 public static function checkUnblockSelf( $user ) {
692 global $wgUser;
693 if ( is_int( $user ) ) {
694 $user = User::newFromId( $user );
695 } elseif ( is_string( $user ) ) {
696 $user = User::newFromName( $user );
697 }
698 if( $wgUser->isBlocked() ){
699 if( $user instanceof User && $user->getId() == $wgUser->getId() ) {
700 # User is trying to unblock themselves
701 if ( $wgUser->isAllowed( 'unblockself' ) ) {
702 return true;
703 } else {
704 return 'ipbnounblockself';
705 }
706 } else {
707 # User is trying to block/unblock someone else
708 return 'ipbblocked';
709 }
710 } else {
711 return true;
712 }
713 }
714
715 /**
716 * Return a comma-delimited list of "flags" to be passed to the log
717 * reader for this block, to provide more information in the logs
718 * @param $data Array from HTMLForm data
719 * @param $type Block::TYPE_ constant
720 * @return array
721 */
722 protected static function blockLogFlags( array $data, $type ) {
723 global $wgBlockAllowsUTEdit;
724 $flags = array();
725
726 # when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
727 if( !$data['HardBlock'] && $type != Block::TYPE_USER ){
728 $flags[] = 'anononly';
729 }
730
731 if( $data['CreateAccount'] ){
732 $flags[] = 'nocreate';
733 }
734
735 # Same as anononly, this is not displayed when blocking an IP address
736 if( !$data['AutoBlock'] && $type != Block::TYPE_IP ){
737 $flags[] = 'noautoblock';
738 }
739
740 if( $data['DisableEmail'] ){
741 $flags[] = 'noemail';
742 }
743
744 if( $data['DisableUTEdit'] && $wgBlockAllowsUTEdit ){
745 $flags[] = 'nousertalk';
746 }
747
748 if( $data['HideUser'] ){
749 $flags[] = 'hiddenname';
750 }
751
752 return implode( ',', $flags );
753 }
754 }
755
756 # BC @since 1.18
757 class IPBlockForm extends SpecialBlock {}