c26f0d40b1454d569bb352d7b64f6d0621d69506
[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::newFromTargetAndType( $this->target, $this->type );
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->mAddress == $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->mEnableAutoblock;
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'] = true;
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 } elseif( $type == Block::TYPE_RANGE ){
490 $userId = 0;
491 } elseif( $type == Block::TYPE_IP ){
492 $target = $target->getName();
493 $userId = 0;
494 } else {
495 # This should have been caught in the form field validation
496 return array( 'badipaddress' );
497 }
498
499 if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 )
500 || !self::parseExpiryInput( $data['Expiry'] ) )
501 {
502 return array( 'ipb_expiry_invalid' );
503 }
504
505 # If the user has done the form 'properly', they won't even have been given the
506 # option to suppress-block unless they have the 'hideuser' permission
507 if( !isset( $data['HideUser'] ) ){
508 $data['HideUser'] = false;
509 }
510 if( $data['HideUser'] ) {
511 if( !$wgUser->isAllowed('hideuser') ){
512 # this codepath is unreachable except by a malicious user spoofing forms,
513 # or by race conditions (user has oversight and sysop, loads block form,
514 # and is de-oversighted before submission); so need to fail completely
515 # rather than just silently disable hiding
516 return array( 'badaccess-group0' );
517 }
518
519 # Recheck params here...
520 if( $type != Block::TYPE_USER ) {
521 $data['HideUser'] = false; # IP users should not be hidden
522
523 } elseif( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
524 # Bad expiry.
525 return array( 'ipb_expiry_temp' );
526
527 } elseif( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) {
528 # Typically, the user should have a handful of edits.
529 # Disallow hiding users with many edits for performance.
530 return array( 'ipb_hide_invalid' );
531 }
532 }
533
534 # Create block object. Note that for a user block, ipb_address is only for display purposes
535 # FIXME: Why do we need to pass fourteen optional parameters to do this!?!
536 $block = new Block(
537 $target, # IP address or User name
538 $userId, # User id
539 $wgUser->getId(), # Blocker id
540 $data['Reason'][0], # Reason string
541 wfTimestampNow(), # Block Timestamp
542 0, # Is this an autoblock (no)
543 self::parseExpiryInput( $data['Expiry'] ), # Expiry time
544 !$data['HardBlock'], # Block anon only
545 $data['CreateAccount'],
546 $data['AutoBlock'],
547 $data['HideUser']
548 );
549
550 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
551 $block->prevents( 'sendemail', $data['DisableEmail'] );
552
553 if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
554 return array( 'hookaborted' );
555 }
556
557 # Try to insert block. Is there a conflicting block?
558 if( !$block->insert() ) {
559
560 # Show form unless the user is already aware of this...
561 if( !$data['AlreadyBlocked'] ) {
562 return array( array( 'ipb_already_blocked', $data['Target'] ) );
563
564 # Otherwise, try to update the block...
565 } else {
566
567 # This returns direct blocks before autoblocks/rangeblocks, since we should
568 # be sure the user is blocked by now it should work for our purposes
569 $currentBlock = Block::newFromTargetAndType( $target, $type );
570
571 if( $block->equals( $currentBlock ) ) {
572 return array( 'ipb_already_blocked' );
573 }
574
575 # If the name was hidden and the blocking user cannot hide
576 # names, then don't allow any block changes...
577 if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) {
578 return array( 'cant-see-hidden-user' );
579 }
580
581 $currentBlock->delete();
582 $block->insert();
583 $logaction = 'reblock';
584
585 # Unset _deleted fields if requested
586 if( $currentBlock->mHideName && !$data['HideUser'] ) {
587 RevisionDeleteUser::unsuppressUserName( $target, $userId );
588 }
589
590 # If hiding/unhiding a name, this should go in the private logs
591 if( (bool)$currentBlock->mHideName ){
592 $data['HideUser'] = true;
593 }
594 }
595
596 } else {
597 $logaction = 'block';
598 }
599
600 wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) );
601
602 # Set *_deleted fields if requested
603 if( $data['HideUser'] ) {
604 RevisionDeleteUser::suppressUserName( $target, $userId );
605 }
606
607 # Can't watch a rangeblock
608 if( $type != Block::TYPE_RANGE && $data['Watch'] ) {
609 $wgUser->addWatch( Title::makeTitle( NS_USER, $target ) );
610 }
611
612 # Block constructor sanitizes certain block options on insert
613 $data['BlockEmail'] = $block->prevents( 'sendemail' );
614 $data['AutoBlock'] = $block->mEnableAutoblock;
615
616 # Prepare log parameters
617 $logParams = array();
618 $logParams[] = $data['Expiry'];
619 $logParams[] = self::blockLogFlags( $data, $type );
620
621 # Make log entry, if the name is hidden, put it in the oversight log
622 $log_type = $data['HideUser'] ? 'suppress' : 'block';
623 $log = new LogPage( $log_type );
624 $log->addEntry(
625 $logaction,
626 Title::makeTitle( NS_USER, $target ),
627 $data['Reason'][0],
628 $logParams
629 );
630
631 # Report to the user
632 return true;
633 }
634
635 /**
636 * Get an array of suggested block durations from MediaWiki:Ipboptions
637 * FIXME: this uses a rather odd syntax for the options, should it be converted
638 * to the standard "**<duration>|<displayname>" format?
639 * @return Array
640 */
641 public static function getSuggestedDurations( $lang = null ){
642 $a = array();
643 $msg = $lang === null
644 ? wfMessage( 'ipboptions' )->inContentLanguage()
645 : wfMessage( 'ipboptions' )->inLanguage( $lang );
646
647 if( $msg == '-' ){
648 return array();
649 }
650
651 foreach( explode( ',', $msg ) as $option ) {
652 if( strpos( $option, ':' ) === false ){
653 $option = "$option:$option";
654 }
655 list( $show, $value ) = explode( ':', $option );
656 $a[htmlspecialchars( $show )] = htmlspecialchars( $value );
657 }
658 return $a;
659 }
660
661 /**
662 * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
663 * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
664 * @param $expiry String: whatever was typed into the form
665 * @return String: timestamp or "infinity" string for the DB implementation
666 */
667 public static function parseExpiryInput( $expiry ) {
668 static $infinity;
669 if( $infinity == null ){
670 $infinity = wfGetDB( DB_READ )->getInfinity();
671 }
672 if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
673 $expiry = $infinity;
674 } else {
675 $expiry = strtotime( $expiry );
676 if ( $expiry < 0 || $expiry === false ) {
677 return false;
678 }
679 $expiry = wfTimestamp( TS_MW, $expiry );
680 }
681 return $expiry;
682 }
683
684 /**
685 * Can we do an email block?
686 * @param $user User: the sysop wanting to make a block
687 * @return Boolean
688 */
689 public static function canBlockEmail( $user ) {
690 global $wgEnableUserEmail, $wgSysopEmailBans;
691 return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
692 }
693
694 /**
695 * bug 15810: blocked admins should not be able to block/unblock
696 * others, and probably shouldn't be able to unblock themselves
697 * either.
698 * @param $user User|Int|String
699 */
700 public static function checkUnblockSelf( $user ) {
701 global $wgUser;
702 if ( is_int( $user ) ) {
703 $user = User::newFromId( $user );
704 } elseif ( is_string( $user ) ) {
705 $user = User::newFromName( $user );
706 }
707 if( $wgUser->isBlocked() ){
708 if( $user instanceof User && $user->getId() == $wgUser->getId() ) {
709 # User is trying to unblock themselves
710 if ( $wgUser->isAllowed( 'unblockself' ) ) {
711 return true;
712 } else {
713 return 'ipbnounblockself';
714 }
715 } else {
716 # User is trying to block/unblock someone else
717 return 'ipbblocked';
718 }
719 } else {
720 return true;
721 }
722 }
723
724 /**
725 * Return a comma-delimited list of "flags" to be passed to the log
726 * reader for this block, to provide more information in the logs
727 * @param $data Array from HTMLForm data
728 * @param $type Block::TYPE_ constant
729 * @return array
730 */
731 protected static function blockLogFlags( array $data, $type ) {
732 global $wgBlockAllowsUTEdit;
733 $flags = array();
734
735 # when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
736 if( !$data['HardBlock'] && $type != Block::TYPE_USER ){
737 $flags[] = 'anononly';
738 }
739
740 if( $data['CreateAccount'] ){
741 $flags[] = 'nocreate';
742 }
743
744 # Same as anononly, this is not displayed when blocking an IP address
745 if( !$data['AutoBlock'] && $type != Block::TYPE_IP ){
746 $flags[] = 'noautoblock';
747 }
748
749 if( $data['DisableEmail'] ){
750 $flags[] = 'noemail';
751 }
752
753 if( $data['DisableUTEdit'] && $wgBlockAllowsUTEdit ){
754 $flags[] = 'nousertalk';
755 }
756
757 if( $data['HideUser'] ){
758 $flags[] = 'hiddenname';
759 }
760
761 return implode( ',', $flags );
762 }
763 }
764
765 # BC @since 1.18
766 class IPBlockForm extends SpecialBlock {}