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