Switch some HTMLForms in special pages to OOUI
[lhc/web/wiklou.git] / includes / Block.php
1 <?php
2 /**
3 * Blocks and bans object
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 */
22 class Block {
23 /** @var string */
24 public $mReason;
25
26 /** @var string */
27 public $mTimestamp;
28
29 /** @var bool */
30 public $mAuto;
31
32 /** @var string */
33 public $mExpiry;
34
35 /** @var bool */
36 public $mHideName;
37
38 /** @var int */
39 public $mParentBlockId;
40
41 /** @var int */
42 protected $mId;
43
44 /** @var bool */
45 protected $mFromMaster;
46
47 /** @var bool */
48 protected $mBlockEmail;
49
50 /** @var bool */
51 protected $mDisableUsertalk;
52
53 /** @var bool */
54 protected $mCreateAccount;
55
56 /** @var User|string */
57 protected $target;
58
59 /** @var int Hack for foreign blocking (CentralAuth) */
60 protected $forcedTargetID;
61
62 /** @var int Block::TYPE_ constant. Can only be USER, IP or RANGE internally */
63 protected $type;
64
65 /** @var User */
66 protected $blocker;
67
68 /** @var bool */
69 protected $isHardblock;
70
71 /** @var bool */
72 protected $isAutoblocking;
73
74 # TYPE constants
75 const TYPE_USER = 1;
76 const TYPE_IP = 2;
77 const TYPE_RANGE = 3;
78 const TYPE_AUTO = 4;
79 const TYPE_ID = 5;
80
81 /**
82 * Create a new block with specified parameters on a user, IP or IP range.
83 *
84 * @param array $options Parameters of the block:
85 * address string|User Target user name, User object, IP address or IP range
86 * user int Override target user ID (for foreign users)
87 * by int User ID of the blocker
88 * reason string Reason of the block
89 * timestamp string The time at which the block comes into effect
90 * auto bool Is this an automatic block?
91 * expiry string Timestamp of expiration of the block or 'infinity'
92 * anonOnly bool Only disallow anonymous actions
93 * createAccount bool Disallow creation of new accounts
94 * enableAutoblock bool Enable automatic blocking
95 * hideName bool Hide the target user name
96 * blockEmail bool Disallow sending emails
97 * allowUsertalk bool Allow the target to edit its own talk page
98 * byText string Username of the blocker (for foreign users)
99 *
100 * @since 1.26 accepts $options array instead of individual parameters; order
101 * of parameters above reflects the original order
102 */
103 function __construct( $options = array() ) {
104 $defaults = array(
105 'address' => '',
106 'user' => null,
107 'by' => null,
108 'reason' => '',
109 'timestamp' => '',
110 'auto' => false,
111 'expiry' => '',
112 'anonOnly' => false,
113 'createAccount' => false,
114 'enableAutoblock' => false,
115 'hideName' => false,
116 'blockEmail' => false,
117 'allowUsertalk' => false,
118 'byText' => '',
119 );
120
121 if ( func_num_args() > 1 || !is_array( $options ) ) {
122 $options = array_combine(
123 array_slice( array_keys( $defaults ), 0, func_num_args() ),
124 func_get_args()
125 );
126 wfDeprecated( __METHOD__ . ' with multiple arguments', '1.26' );
127 }
128
129 $options += $defaults;
130
131 $this->setTarget( $options['address'] );
132
133 if ( $this->target instanceof User && $options['user'] ) {
134 # Needed for foreign users
135 $this->forcedTargetID = $options['user'];
136 }
137
138 if ( $options['by'] ) {
139 # Local user
140 $this->setBlocker( User::newFromID( $options['by'] ) );
141 } else {
142 # Foreign user
143 $this->setBlocker( $options['byText'] );
144 }
145
146 $this->mReason = $options['reason'];
147 $this->mTimestamp = wfTimestamp( TS_MW, $options['timestamp'] );
148 $this->mExpiry = wfGetDB( DB_SLAVE )->decodeExpiry( $options['expiry'] );
149
150 # Boolean settings
151 $this->mAuto = (bool)$options['auto'];
152 $this->mHideName = (bool)$options['hideName'];
153 $this->isHardblock( !$options['anonOnly'] );
154 $this->isAutoblocking( (bool)$options['enableAutoblock'] );
155
156 # Prevention measures
157 $this->prevents( 'sendemail', (bool)$options['blockEmail'] );
158 $this->prevents( 'editownusertalk', !$options['allowUsertalk'] );
159 $this->prevents( 'createaccount', (bool)$options['createAccount'] );
160
161 $this->mFromMaster = false;
162 }
163
164 /**
165 * Load a blocked user from their block id.
166 *
167 * @param int $id Block id to search for
168 * @return Block|null
169 */
170 public static function newFromID( $id ) {
171 $dbr = wfGetDB( DB_SLAVE );
172 $res = $dbr->selectRow(
173 'ipblocks',
174 self::selectFields(),
175 array( 'ipb_id' => $id ),
176 __METHOD__
177 );
178 if ( $res ) {
179 return self::newFromRow( $res );
180 } else {
181 return null;
182 }
183 }
184
185 /**
186 * Return the list of ipblocks fields that should be selected to create
187 * a new block.
188 * @return array
189 */
190 public static function selectFields() {
191 return array(
192 'ipb_id',
193 'ipb_address',
194 'ipb_by',
195 'ipb_by_text',
196 'ipb_reason',
197 'ipb_timestamp',
198 'ipb_auto',
199 'ipb_anon_only',
200 'ipb_create_account',
201 'ipb_enable_autoblock',
202 'ipb_expiry',
203 'ipb_deleted',
204 'ipb_block_email',
205 'ipb_allow_usertalk',
206 'ipb_parent_block_id',
207 );
208 }
209
210 /**
211 * Check if two blocks are effectively equal. Doesn't check irrelevant things like
212 * the blocking user or the block timestamp, only things which affect the blocked user
213 *
214 * @param Block $block
215 *
216 * @return bool
217 */
218 public function equals( Block $block ) {
219 return (
220 (string)$this->target == (string)$block->target
221 && $this->type == $block->type
222 && $this->mAuto == $block->mAuto
223 && $this->isHardblock() == $block->isHardblock()
224 && $this->prevents( 'createaccount' ) == $block->prevents( 'createaccount' )
225 && $this->mExpiry == $block->mExpiry
226 && $this->isAutoblocking() == $block->isAutoblocking()
227 && $this->mHideName == $block->mHideName
228 && $this->prevents( 'sendemail' ) == $block->prevents( 'sendemail' )
229 && $this->prevents( 'editownusertalk' ) == $block->prevents( 'editownusertalk' )
230 && $this->mReason == $block->mReason
231 );
232 }
233
234 /**
235 * Load a block from the database which affects the already-set $this->target:
236 * 1) A block directly on the given user or IP
237 * 2) A rangeblock encompassing the given IP (smallest first)
238 * 3) An autoblock on the given IP
239 * @param User|string $vagueTarget Also search for blocks affecting this target. Doesn't
240 * make any sense to use TYPE_AUTO / TYPE_ID here. Leave blank to skip IP lookups.
241 * @throws MWException
242 * @return bool Whether a relevant block was found
243 */
244 protected function newLoad( $vagueTarget = null ) {
245 $db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_SLAVE );
246
247 if ( $this->type !== null ) {
248 $conds = array(
249 'ipb_address' => array( (string)$this->target ),
250 );
251 } else {
252 $conds = array( 'ipb_address' => array() );
253 }
254
255 # Be aware that the != '' check is explicit, since empty values will be
256 # passed by some callers (bug 29116)
257 if ( $vagueTarget != '' ) {
258 list( $target, $type ) = self::parseTarget( $vagueTarget );
259 switch ( $type ) {
260 case self::TYPE_USER:
261 # Slightly weird, but who are we to argue?
262 $conds['ipb_address'][] = (string)$target;
263 break;
264
265 case self::TYPE_IP:
266 $conds['ipb_address'][] = (string)$target;
267 $conds[] = self::getRangeCond( IP::toHex( $target ) );
268 $conds = $db->makeList( $conds, LIST_OR );
269 break;
270
271 case self::TYPE_RANGE:
272 list( $start, $end ) = IP::parseRange( $target );
273 $conds['ipb_address'][] = (string)$target;
274 $conds[] = self::getRangeCond( $start, $end );
275 $conds = $db->makeList( $conds, LIST_OR );
276 break;
277
278 default:
279 throw new MWException( "Tried to load block with invalid type" );
280 }
281 }
282
283 $res = $db->select( 'ipblocks', self::selectFields(), $conds, __METHOD__ );
284
285 # This result could contain a block on the user, a block on the IP, and a russian-doll
286 # set of rangeblocks. We want to choose the most specific one, so keep a leader board.
287 $bestRow = null;
288
289 # Lower will be better
290 $bestBlockScore = 100;
291
292 # This is begging for $this = $bestBlock, but that's not allowed in PHP :(
293 $bestBlockPreventsEdit = null;
294
295 foreach ( $res as $row ) {
296 $block = self::newFromRow( $row );
297
298 # Don't use expired blocks
299 if ( $block->deleteIfExpired() ) {
300 continue;
301 }
302
303 # Don't use anon only blocks on users
304 if ( $this->type == self::TYPE_USER && !$block->isHardblock() ) {
305 continue;
306 }
307
308 if ( $block->getType() == self::TYPE_RANGE ) {
309 # This is the number of bits that are allowed to vary in the block, give
310 # or take some floating point errors
311 $end = wfBaseconvert( $block->getRangeEnd(), 16, 10 );
312 $start = wfBaseconvert( $block->getRangeStart(), 16, 10 );
313 $size = log( $end - $start + 1, 2 );
314
315 # This has the nice property that a /32 block is ranked equally with a
316 # single-IP block, which is exactly what it is...
317 $score = self::TYPE_RANGE - 1 + ( $size / 128 );
318
319 } else {
320 $score = $block->getType();
321 }
322
323 if ( $score < $bestBlockScore ) {
324 $bestBlockScore = $score;
325 $bestRow = $row;
326 $bestBlockPreventsEdit = $block->prevents( 'edit' );
327 }
328 }
329
330 if ( $bestRow !== null ) {
331 $this->initFromRow( $bestRow );
332 $this->prevents( 'edit', $bestBlockPreventsEdit );
333 return true;
334 } else {
335 return false;
336 }
337 }
338
339 /**
340 * Get a set of SQL conditions which will select rangeblocks encompassing a given range
341 * @param string $start Hexadecimal IP representation
342 * @param string $end Hexadecimal IP representation, or null to use $start = $end
343 * @return string
344 */
345 public static function getRangeCond( $start, $end = null ) {
346 if ( $end === null ) {
347 $end = $start;
348 }
349 # Per bug 14634, we want to include relevant active rangeblocks; for
350 # rangeblocks, we want to include larger ranges which enclose the given
351 # range. We know that all blocks must be smaller than $wgBlockCIDRLimit,
352 # so we can improve performance by filtering on a LIKE clause
353 $chunk = self::getIpFragment( $start );
354 $dbr = wfGetDB( DB_SLAVE );
355 $like = $dbr->buildLike( $chunk, $dbr->anyString() );
356
357 # Fairly hard to make a malicious SQL statement out of hex characters,
358 # but stranger things have happened...
359 $safeStart = $dbr->addQuotes( $start );
360 $safeEnd = $dbr->addQuotes( $end );
361
362 return $dbr->makeList(
363 array(
364 "ipb_range_start $like",
365 "ipb_range_start <= $safeStart",
366 "ipb_range_end >= $safeEnd",
367 ),
368 LIST_AND
369 );
370 }
371
372 /**
373 * Get the component of an IP address which is certain to be the same between an IP
374 * address and a rangeblock containing that IP address.
375 * @param string $hex Hexadecimal IP representation
376 * @return string
377 */
378 protected static function getIpFragment( $hex ) {
379 global $wgBlockCIDRLimit;
380 if ( substr( $hex, 0, 3 ) == 'v6-' ) {
381 return 'v6-' . substr( substr( $hex, 3 ), 0, floor( $wgBlockCIDRLimit['IPv6'] / 4 ) );
382 } else {
383 return substr( $hex, 0, floor( $wgBlockCIDRLimit['IPv4'] / 4 ) );
384 }
385 }
386
387 /**
388 * Given a database row from the ipblocks table, initialize
389 * member variables
390 * @param stdClass $row A row from the ipblocks table
391 */
392 protected function initFromRow( $row ) {
393 $this->setTarget( $row->ipb_address );
394 if ( $row->ipb_by ) { // local user
395 $this->setBlocker( User::newFromId( $row->ipb_by ) );
396 } else { // foreign user
397 $this->setBlocker( $row->ipb_by_text );
398 }
399
400 $this->mReason = $row->ipb_reason;
401 $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
402 $this->mAuto = $row->ipb_auto;
403 $this->mHideName = $row->ipb_deleted;
404 $this->mId = (int)$row->ipb_id;
405 $this->mParentBlockId = $row->ipb_parent_block_id;
406
407 // I wish I didn't have to do this
408 $this->mExpiry = wfGetDB( DB_SLAVE )->decodeExpiry( $row->ipb_expiry );
409
410 $this->isHardblock( !$row->ipb_anon_only );
411 $this->isAutoblocking( $row->ipb_enable_autoblock );
412
413 $this->prevents( 'createaccount', $row->ipb_create_account );
414 $this->prevents( 'sendemail', $row->ipb_block_email );
415 $this->prevents( 'editownusertalk', !$row->ipb_allow_usertalk );
416 }
417
418 /**
419 * Create a new Block object from a database row
420 * @param stdClass $row Row from the ipblocks table
421 * @return Block
422 */
423 public static function newFromRow( $row ) {
424 $block = new Block;
425 $block->initFromRow( $row );
426 return $block;
427 }
428
429 /**
430 * Delete the row from the IP blocks table.
431 *
432 * @throws MWException
433 * @return bool
434 */
435 public function delete() {
436 if ( wfReadOnly() ) {
437 return false;
438 }
439
440 if ( !$this->getId() ) {
441 throw new MWException( "Block::delete() requires that the mId member be filled\n" );
442 }
443
444 $dbw = wfGetDB( DB_MASTER );
445 $dbw->delete( 'ipblocks', array( 'ipb_parent_block_id' => $this->getId() ), __METHOD__ );
446 $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->getId() ), __METHOD__ );
447
448 return $dbw->affectedRows() > 0;
449 }
450
451 /**
452 * Insert a block into the block table. Will fail if there is a conflicting
453 * block (same name and options) already in the database.
454 *
455 * @param DatabaseBase $dbw If you have one available
456 * @return bool|array False on failure, assoc array on success:
457 * ('id' => block ID, 'autoIds' => array of autoblock IDs)
458 */
459 public function insert( $dbw = null ) {
460 wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
461
462 if ( $dbw === null ) {
463 $dbw = wfGetDB( DB_MASTER );
464 }
465
466 # Periodic purge via commit hooks
467 if ( mt_rand( 0, 9 ) == 0 ) {
468 Block::purgeExpired();
469 }
470
471 $row = $this->getDatabaseArray();
472 $row['ipb_id'] = $dbw->nextSequenceValue( "ipblocks_ipb_id_seq" );
473
474 $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) );
475 $affected = $dbw->affectedRows();
476 $this->mId = $dbw->insertId();
477
478 # Don't collide with expired blocks.
479 # Do this after trying to insert to avoid locking.
480 if ( !$affected ) {
481 # T96428: The ipb_address index uses a prefix on a field, so
482 # use a standard SELECT + DELETE to avoid annoying gap locks.
483 $ids = $dbw->selectFieldValues( 'ipblocks',
484 'ipb_id',
485 array(
486 'ipb_address' => $row['ipb_address'],
487 'ipb_user' => $row['ipb_user'],
488 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() )
489 ),
490 __METHOD__
491 );
492 if ( $ids ) {
493 $dbw->delete( 'ipblocks', array( 'ipb_id' => $ids ), __METHOD__ );
494 $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) );
495 $affected = $dbw->affectedRows();
496 $this->mId = $dbw->insertId();
497 }
498 }
499
500 if ( $affected ) {
501 $auto_ipd_ids = $this->doRetroactiveAutoblock();
502 return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );
503 }
504
505 return false;
506 }
507
508 /**
509 * Update a block in the DB with new parameters.
510 * The ID field needs to be loaded first.
511 *
512 * @return bool|array False on failure, array on success:
513 * ('id' => block ID, 'autoIds' => array of autoblock IDs)
514 */
515 public function update() {
516 wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" );
517 $dbw = wfGetDB( DB_MASTER );
518
519 $dbw->startAtomic( __METHOD__ );
520
521 $dbw->update(
522 'ipblocks',
523 $this->getDatabaseArray( $dbw ),
524 array( 'ipb_id' => $this->getId() ),
525 __METHOD__
526 );
527
528 $affected = $dbw->affectedRows();
529
530 if ( $this->isAutoblocking() ) {
531 // update corresponding autoblock(s) (bug 48813)
532 $dbw->update(
533 'ipblocks',
534 $this->getAutoblockUpdateArray(),
535 array( 'ipb_parent_block_id' => $this->getId() ),
536 __METHOD__
537 );
538 } else {
539 // autoblock no longer required, delete corresponding autoblock(s)
540 $dbw->delete(
541 'ipblocks',
542 array( 'ipb_parent_block_id' => $this->getId() ),
543 __METHOD__
544 );
545 }
546
547 $dbw->endAtomic( __METHOD__ );
548
549 if ( $affected ) {
550 $auto_ipd_ids = $this->doRetroactiveAutoblock();
551 return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );
552 }
553
554 return false;
555 }
556
557 /**
558 * Get an array suitable for passing to $dbw->insert() or $dbw->update()
559 * @param DatabaseBase $db
560 * @return array
561 */
562 protected function getDatabaseArray( $db = null ) {
563 if ( !$db ) {
564 $db = wfGetDB( DB_SLAVE );
565 }
566 $expiry = $db->encodeExpiry( $this->mExpiry );
567
568 if ( $this->forcedTargetID ) {
569 $uid = $this->forcedTargetID;
570 } else {
571 $uid = $this->target instanceof User ? $this->target->getID() : 0;
572 }
573
574 $a = array(
575 'ipb_address' => (string)$this->target,
576 'ipb_user' => $uid,
577 'ipb_by' => $this->getBy(),
578 'ipb_by_text' => $this->getByName(),
579 'ipb_reason' => $this->mReason,
580 'ipb_timestamp' => $db->timestamp( $this->mTimestamp ),
581 'ipb_auto' => $this->mAuto,
582 'ipb_anon_only' => !$this->isHardblock(),
583 'ipb_create_account' => $this->prevents( 'createaccount' ),
584 'ipb_enable_autoblock' => $this->isAutoblocking(),
585 'ipb_expiry' => $expiry,
586 'ipb_range_start' => $this->getRangeStart(),
587 'ipb_range_end' => $this->getRangeEnd(),
588 'ipb_deleted' => intval( $this->mHideName ), // typecast required for SQLite
589 'ipb_block_email' => $this->prevents( 'sendemail' ),
590 'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
591 'ipb_parent_block_id' => $this->mParentBlockId
592 );
593
594 return $a;
595 }
596
597 /**
598 * @return array
599 */
600 protected function getAutoblockUpdateArray() {
601 return array(
602 'ipb_by' => $this->getBy(),
603 'ipb_by_text' => $this->getByName(),
604 'ipb_reason' => $this->mReason,
605 'ipb_create_account' => $this->prevents( 'createaccount' ),
606 'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite
607 'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
608 );
609 }
610
611 /**
612 * Retroactively autoblocks the last IP used by the user (if it is a user)
613 * blocked by this Block.
614 *
615 * @return array Block IDs of retroactive autoblocks made
616 */
617 protected function doRetroactiveAutoblock() {
618 $blockIds = array();
619 # If autoblock is enabled, autoblock the LAST IP(s) used
620 if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) {
621 wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" );
622
623 $continue = Hooks::run(
624 'PerformRetroactiveAutoblock', array( $this, &$blockIds ) );
625
626 if ( $continue ) {
627 self::defaultRetroactiveAutoblock( $this, $blockIds );
628 }
629 }
630 return $blockIds;
631 }
632
633 /**
634 * Retroactively autoblocks the last IP used by the user (if it is a user)
635 * blocked by this Block. This will use the recentchanges table.
636 *
637 * @param Block $block
638 * @param array &$blockIds
639 */
640 protected static function defaultRetroactiveAutoblock( Block $block, array &$blockIds ) {
641 global $wgPutIPinRC;
642
643 // No IPs are in recentchanges table, so nothing to select
644 if ( !$wgPutIPinRC ) {
645 return;
646 }
647
648 $dbr = wfGetDB( DB_SLAVE );
649
650 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
651 $conds = array( 'rc_user_text' => (string)$block->getTarget() );
652
653 // Just the last IP used.
654 $options['LIMIT'] = 1;
655
656 $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
657 __METHOD__, $options );
658
659 if ( !$res->numRows() ) {
660 # No results, don't autoblock anything
661 wfDebug( "No IP found to retroactively autoblock\n" );
662 } else {
663 foreach ( $res as $row ) {
664 if ( $row->rc_ip ) {
665 $id = $block->doAutoblock( $row->rc_ip );
666 if ( $id ) {
667 $blockIds[] = $id;
668 }
669 }
670 }
671 }
672 }
673
674 /**
675 * Checks whether a given IP is on the autoblock whitelist.
676 * TODO: this probably belongs somewhere else, but not sure where...
677 *
678 * @param string $ip The IP to check
679 * @return bool
680 */
681 public static function isWhitelistedFromAutoblocks( $ip ) {
682 global $wgMemc;
683
684 // Try to get the autoblock_whitelist from the cache, as it's faster
685 // than getting the msg raw and explode()'ing it.
686 $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
687 $lines = $wgMemc->get( $key );
688 if ( !$lines ) {
689 $lines = explode( "\n", wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() );
690 $wgMemc->set( $key, $lines, 3600 * 24 );
691 }
692
693 wfDebug( "Checking the autoblock whitelist..\n" );
694
695 foreach ( $lines as $line ) {
696 # List items only
697 if ( substr( $line, 0, 1 ) !== '*' ) {
698 continue;
699 }
700
701 $wlEntry = substr( $line, 1 );
702 $wlEntry = trim( $wlEntry );
703
704 wfDebug( "Checking $ip against $wlEntry..." );
705
706 # Is the IP in this range?
707 if ( IP::isInRange( $ip, $wlEntry ) ) {
708 wfDebug( " IP $ip matches $wlEntry, not autoblocking\n" );
709 return true;
710 } else {
711 wfDebug( " No match\n" );
712 }
713 }
714
715 return false;
716 }
717
718 /**
719 * Autoblocks the given IP, referring to this Block.
720 *
721 * @param string $autoblockIP The IP to autoblock.
722 * @return int|bool Block ID if an autoblock was inserted, false if not.
723 */
724 public function doAutoblock( $autoblockIP ) {
725 # If autoblocks are disabled, go away.
726 if ( !$this->isAutoblocking() ) {
727 return false;
728 }
729
730 # Check for presence on the autoblock whitelist.
731 if ( self::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
732 return false;
733 }
734
735 # Allow hooks to cancel the autoblock.
736 if ( !Hooks::run( 'AbortAutoblock', array( $autoblockIP, &$this ) ) ) {
737 wfDebug( "Autoblock aborted by hook.\n" );
738 return false;
739 }
740
741 # It's okay to autoblock. Go ahead and insert/update the block...
742
743 # Do not add a *new* block if the IP is already blocked.
744 $ipblock = Block::newFromTarget( $autoblockIP );
745 if ( $ipblock ) {
746 # Check if the block is an autoblock and would exceed the user block
747 # if renewed. If so, do nothing, otherwise prolong the block time...
748 if ( $ipblock->mAuto && // @todo Why not compare $ipblock->mExpiry?
749 $this->mExpiry > Block::getAutoblockExpiry( $ipblock->mTimestamp )
750 ) {
751 # Reset block timestamp to now and its expiry to
752 # $wgAutoblockExpiry in the future
753 $ipblock->updateTimestamp();
754 }
755 return false;
756 }
757
758 # Make a new block object with the desired properties.
759 $autoblock = new Block;
760 wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP . "\n" );
761 $autoblock->setTarget( $autoblockIP );
762 $autoblock->setBlocker( $this->getBlocker() );
763 $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason )
764 ->inContentLanguage()->plain();
765 $timestamp = wfTimestampNow();
766 $autoblock->mTimestamp = $timestamp;
767 $autoblock->mAuto = 1;
768 $autoblock->prevents( 'createaccount', $this->prevents( 'createaccount' ) );
769 # Continue suppressing the name if needed
770 $autoblock->mHideName = $this->mHideName;
771 $autoblock->prevents( 'editownusertalk', $this->prevents( 'editownusertalk' ) );
772 $autoblock->mParentBlockId = $this->mId;
773
774 if ( $this->mExpiry == 'infinity' ) {
775 # Original block was indefinite, start an autoblock now
776 $autoblock->mExpiry = Block::getAutoblockExpiry( $timestamp );
777 } else {
778 # If the user is already blocked with an expiry date, we don't
779 # want to pile on top of that.
780 $autoblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( $timestamp ) );
781 }
782
783 # Insert the block...
784 $status = $autoblock->insert();
785 return $status
786 ? $status['id']
787 : false;
788 }
789
790 /**
791 * Check if a block has expired. Delete it if it is.
792 * @return bool
793 */
794 public function deleteIfExpired() {
795
796 if ( $this->isExpired() ) {
797 wfDebug( "Block::deleteIfExpired() -- deleting\n" );
798 $this->delete();
799 $retVal = true;
800 } else {
801 wfDebug( "Block::deleteIfExpired() -- not expired\n" );
802 $retVal = false;
803 }
804
805 return $retVal;
806 }
807
808 /**
809 * Has the block expired?
810 * @return bool
811 */
812 public function isExpired() {
813 $timestamp = wfTimestampNow();
814 wfDebug( "Block::isExpired() checking current " . $timestamp . " vs $this->mExpiry\n" );
815
816 if ( !$this->mExpiry ) {
817 return false;
818 } else {
819 return $timestamp > $this->mExpiry;
820 }
821 }
822
823 /**
824 * Is the block address valid (i.e. not a null string?)
825 * @return bool
826 */
827 public function isValid() {
828 return $this->getTarget() != null;
829 }
830
831 /**
832 * Update the timestamp on autoblocks.
833 */
834 public function updateTimestamp() {
835 if ( $this->mAuto ) {
836 $this->mTimestamp = wfTimestamp();
837 $this->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
838
839 $dbw = wfGetDB( DB_MASTER );
840 $dbw->update( 'ipblocks',
841 array( /* SET */
842 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
843 'ipb_expiry' => $dbw->timestamp( $this->mExpiry ),
844 ),
845 array( /* WHERE */
846 'ipb_address' => (string)$this->getTarget()
847 ),
848 __METHOD__
849 );
850 }
851 }
852
853 /**
854 * Get the IP address at the start of the range in Hex form
855 * @throws MWException
856 * @return string IP in Hex form
857 */
858 public function getRangeStart() {
859 switch ( $this->type ) {
860 case self::TYPE_USER:
861 return '';
862 case self::TYPE_IP:
863 return IP::toHex( $this->target );
864 case self::TYPE_RANGE:
865 list( $start, /*...*/ ) = IP::parseRange( $this->target );
866 return $start;
867 default:
868 throw new MWException( "Block with invalid type" );
869 }
870 }
871
872 /**
873 * Get the IP address at the end of the range in Hex form
874 * @throws MWException
875 * @return string IP in Hex form
876 */
877 public function getRangeEnd() {
878 switch ( $this->type ) {
879 case self::TYPE_USER:
880 return '';
881 case self::TYPE_IP:
882 return IP::toHex( $this->target );
883 case self::TYPE_RANGE:
884 list( /*...*/, $end ) = IP::parseRange( $this->target );
885 return $end;
886 default:
887 throw new MWException( "Block with invalid type" );
888 }
889 }
890
891 /**
892 * Get the user id of the blocking sysop
893 *
894 * @return int (0 for foreign users)
895 */
896 public function getBy() {
897 $blocker = $this->getBlocker();
898 return ( $blocker instanceof User )
899 ? $blocker->getId()
900 : 0;
901 }
902
903 /**
904 * Get the username of the blocking sysop
905 *
906 * @return string
907 */
908 public function getByName() {
909 $blocker = $this->getBlocker();
910 return ( $blocker instanceof User )
911 ? $blocker->getName()
912 : (string)$blocker; // username
913 }
914
915 /**
916 * Get the block ID
917 * @return int
918 */
919 public function getId() {
920 return $this->mId;
921 }
922
923 /**
924 * Get/set a flag determining whether the master is used for reads
925 *
926 * @param bool|null $x
927 * @return bool
928 */
929 public function fromMaster( $x = null ) {
930 return wfSetVar( $this->mFromMaster, $x );
931 }
932
933 /**
934 * Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range)
935 * @param bool|null $x
936 * @return bool
937 */
938 public function isHardblock( $x = null ) {
939 wfSetVar( $this->isHardblock, $x );
940
941 # You can't *not* hardblock a user
942 return $this->getType() == self::TYPE_USER
943 ? true
944 : $this->isHardblock;
945 }
946
947 /**
948 * @param null|bool $x
949 * @return bool
950 */
951 public function isAutoblocking( $x = null ) {
952 wfSetVar( $this->isAutoblocking, $x );
953
954 # You can't put an autoblock on an IP or range as we don't have any history to
955 # look over to get more IPs from
956 return $this->getType() == self::TYPE_USER
957 ? $this->isAutoblocking
958 : false;
959 }
960
961 /**
962 * Get/set whether the Block prevents a given action
963 * @param string $action
964 * @param bool|null $x
965 * @return bool
966 */
967 public function prevents( $action, $x = null ) {
968 switch ( $action ) {
969 case 'edit':
970 # For now... <evil laugh>
971 return true;
972
973 case 'createaccount':
974 return wfSetVar( $this->mCreateAccount, $x );
975
976 case 'sendemail':
977 return wfSetVar( $this->mBlockEmail, $x );
978
979 case 'editownusertalk':
980 return wfSetVar( $this->mDisableUsertalk, $x );
981
982 default:
983 return null;
984 }
985 }
986
987 /**
988 * Get the block name, but with autoblocked IPs hidden as per standard privacy policy
989 * @return string Text is escaped
990 */
991 public function getRedactedName() {
992 if ( $this->mAuto ) {
993 return Html::rawElement(
994 'span',
995 array( 'class' => 'mw-autoblockid' ),
996 wfMessage( 'autoblockid', $this->mId )
997 );
998 } else {
999 return htmlspecialchars( $this->getTarget() );
1000 }
1001 }
1002
1003 /**
1004 * Get a timestamp of the expiry for autoblocks
1005 *
1006 * @param string|int $timestamp
1007 * @return string
1008 */
1009 public static function getAutoblockExpiry( $timestamp ) {
1010 global $wgAutoblockExpiry;
1011
1012 return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry );
1013 }
1014
1015 /**
1016 * Purge expired blocks from the ipblocks table
1017 */
1018 public static function purgeExpired() {
1019 if ( wfReadOnly() ) {
1020 return;
1021 }
1022
1023 $method = __METHOD__;
1024 $dbw = wfGetDB( DB_MASTER );
1025 $dbw->onTransactionIdle( function () use ( $dbw, $method ) {
1026 $dbw->delete( 'ipblocks',
1027 array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), $method );
1028 } );
1029 }
1030
1031 /**
1032 * Given a target and the target's type, get an existing Block object if possible.
1033 * @param string|User|int $specificTarget A block target, which may be one of several types:
1034 * * A user to block, in which case $target will be a User
1035 * * An IP to block, in which case $target will be a User generated by using
1036 * User::newFromName( $ip, false ) to turn off name validation
1037 * * An IP range, in which case $target will be a String "123.123.123.123/18" etc
1038 * * The ID of an existing block, in the format "#12345" (since pure numbers are valid
1039 * usernames
1040 * Calling this with a user, IP address or range will not select autoblocks, and will
1041 * only select a block where the targets match exactly (so looking for blocks on
1042 * 1.2.3.4 will not select 1.2.0.0/16 or even 1.2.3.4/32)
1043 * @param string|User|int $vagueTarget As above, but we will search for *any* block which
1044 * affects that target (so for an IP address, get ranges containing that IP; and also
1045 * get any relevant autoblocks). Leave empty or blank to skip IP-based lookups.
1046 * @param bool $fromMaster Whether to use the DB_MASTER database
1047 * @return Block|null (null if no relevant block could be found). The target and type
1048 * of the returned Block will refer to the actual block which was found, which might
1049 * not be the same as the target you gave if you used $vagueTarget!
1050 */
1051 public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
1052
1053 list( $target, $type ) = self::parseTarget( $specificTarget );
1054 if ( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ) {
1055 return Block::newFromID( $target );
1056
1057 } elseif ( $target === null && $vagueTarget == '' ) {
1058 # We're not going to find anything useful here
1059 # Be aware that the == '' check is explicit, since empty values will be
1060 # passed by some callers (bug 29116)
1061 return null;
1062
1063 } elseif ( in_array(
1064 $type,
1065 array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) )
1066 ) {
1067 $block = new Block();
1068 $block->fromMaster( $fromMaster );
1069
1070 if ( $type !== null ) {
1071 $block->setTarget( $target );
1072 }
1073
1074 if ( $block->newLoad( $vagueTarget ) ) {
1075 return $block;
1076 }
1077 }
1078 return null;
1079 }
1080
1081 /**
1082 * Get all blocks that match any IP from an array of IP addresses
1083 *
1084 * @param array $ipChain List of IPs (strings), usually retrieved from the
1085 * X-Forwarded-For header of the request
1086 * @param bool $isAnon Exclude anonymous-only blocks if false
1087 * @param bool $fromMaster Whether to query the master or slave database
1088 * @return array Array of Blocks
1089 * @since 1.22
1090 */
1091 public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
1092 if ( !count( $ipChain ) ) {
1093 return array();
1094 }
1095
1096 $conds = array();
1097 foreach ( array_unique( $ipChain ) as $ipaddr ) {
1098 # Discard invalid IP addresses. Since XFF can be spoofed and we do not
1099 # necessarily trust the header given to us, make sure that we are only
1100 # checking for blocks on well-formatted IP addresses (IPv4 and IPv6).
1101 # Do not treat private IP spaces as special as it may be desirable for wikis
1102 # to block those IP ranges in order to stop misbehaving proxies that spoof XFF.
1103 if ( !IP::isValid( $ipaddr ) ) {
1104 continue;
1105 }
1106 # Don't check trusted IPs (includes local squids which will be in every request)
1107 if ( IP::isTrustedProxy( $ipaddr ) ) {
1108 continue;
1109 }
1110 # Check both the original IP (to check against single blocks), as well as build
1111 # the clause to check for rangeblocks for the given IP.
1112 $conds['ipb_address'][] = $ipaddr;
1113 $conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
1114 }
1115
1116 if ( !count( $conds ) ) {
1117 return array();
1118 }
1119
1120 if ( $fromMaster ) {
1121 $db = wfGetDB( DB_MASTER );
1122 } else {
1123 $db = wfGetDB( DB_SLAVE );
1124 }
1125 $conds = $db->makeList( $conds, LIST_OR );
1126 if ( !$isAnon ) {
1127 $conds = array( $conds, 'ipb_anon_only' => 0 );
1128 }
1129 $selectFields = array_merge(
1130 array( 'ipb_range_start', 'ipb_range_end' ),
1131 Block::selectFields()
1132 );
1133 $rows = $db->select( 'ipblocks',
1134 $selectFields,
1135 $conds,
1136 __METHOD__
1137 );
1138
1139 $blocks = array();
1140 foreach ( $rows as $row ) {
1141 $block = self::newFromRow( $row );
1142 if ( !$block->deleteIfExpired() ) {
1143 $blocks[] = $block;
1144 }
1145 }
1146
1147 return $blocks;
1148 }
1149
1150 /**
1151 * From a list of multiple blocks, find the most exact and strongest Block.
1152 *
1153 * The logic for finding the "best" block is:
1154 * - Blocks that match the block's target IP are preferred over ones in a range
1155 * - Hardblocks are chosen over softblocks that prevent account creation
1156 * - Softblocks that prevent account creation are chosen over other softblocks
1157 * - Other softblocks are chosen over autoblocks
1158 * - If there are multiple exact or range blocks at the same level, the one chosen
1159 * is random
1160 * This should be used when $blocks where retrieved from the user's IP address
1161 * and $ipChain is populated from the same IP address information.
1162 *
1163 * @param array $blocks Array of Block objects
1164 * @param array $ipChain List of IPs (strings). This is used to determine how "close"
1165 * a block is to the server, and if a block matches exactly, or is in a range.
1166 * The order is furthest from the server to nearest e.g., (Browser, proxy1, proxy2,
1167 * local-squid, ...)
1168 * @throws MWException
1169 * @return Block|null The "best" block from the list
1170 */
1171 public static function chooseBlock( array $blocks, array $ipChain ) {
1172 if ( !count( $blocks ) ) {
1173 return null;
1174 } elseif ( count( $blocks ) == 1 ) {
1175 return $blocks[0];
1176 }
1177
1178 // Sort hard blocks before soft ones and secondarily sort blocks
1179 // that disable account creation before those that don't.
1180 usort( $blocks, function ( Block $a, Block $b ) {
1181 $aWeight = (int)$a->isHardblock() . (int)$a->prevents( 'createaccount' );
1182 $bWeight = (int)$b->isHardblock() . (int)$b->prevents( 'createaccount' );
1183 return strcmp( $bWeight, $aWeight ); // highest weight first
1184 } );
1185
1186 $blocksListExact = array(
1187 'hard' => false,
1188 'disable_create' => false,
1189 'other' => false,
1190 'auto' => false
1191 );
1192 $blocksListRange = array(
1193 'hard' => false,
1194 'disable_create' => false,
1195 'other' => false,
1196 'auto' => false
1197 );
1198 $ipChain = array_reverse( $ipChain );
1199
1200 /** @var Block $block */
1201 foreach ( $blocks as $block ) {
1202 // Stop searching if we have already have a "better" block. This
1203 // is why the order of the blocks matters
1204 if ( !$block->isHardblock() && $blocksListExact['hard'] ) {
1205 break;
1206 } elseif ( !$block->prevents( 'createaccount' ) && $blocksListExact['disable_create'] ) {
1207 break;
1208 }
1209
1210 foreach ( $ipChain as $checkip ) {
1211 $checkipHex = IP::toHex( $checkip );
1212 if ( (string)$block->getTarget() === $checkip ) {
1213 if ( $block->isHardblock() ) {
1214 $blocksListExact['hard'] = $blocksListExact['hard'] ?: $block;
1215 } elseif ( $block->prevents( 'createaccount' ) ) {
1216 $blocksListExact['disable_create'] = $blocksListExact['disable_create'] ?: $block;
1217 } elseif ( $block->mAuto ) {
1218 $blocksListExact['auto'] = $blocksListExact['auto'] ?: $block;
1219 } else {
1220 $blocksListExact['other'] = $blocksListExact['other'] ?: $block;
1221 }
1222 // We found closest exact match in the ip list, so go to the next Block
1223 break;
1224 } elseif ( array_filter( $blocksListExact ) == array()
1225 && $block->getRangeStart() <= $checkipHex
1226 && $block->getRangeEnd() >= $checkipHex
1227 ) {
1228 if ( $block->isHardblock() ) {
1229 $blocksListRange['hard'] = $blocksListRange['hard'] ?: $block;
1230 } elseif ( $block->prevents( 'createaccount' ) ) {
1231 $blocksListRange['disable_create'] = $blocksListRange['disable_create'] ?: $block;
1232 } elseif ( $block->mAuto ) {
1233 $blocksListRange['auto'] = $blocksListRange['auto'] ?: $block;
1234 } else {
1235 $blocksListRange['other'] = $blocksListRange['other'] ?: $block;
1236 }
1237 break;
1238 }
1239 }
1240 }
1241
1242 if ( array_filter( $blocksListExact ) == array() ) {
1243 $blocksList = &$blocksListRange;
1244 } else {
1245 $blocksList = &$blocksListExact;
1246 }
1247
1248 $chosenBlock = null;
1249 if ( $blocksList['hard'] ) {
1250 $chosenBlock = $blocksList['hard'];
1251 } elseif ( $blocksList['disable_create'] ) {
1252 $chosenBlock = $blocksList['disable_create'];
1253 } elseif ( $blocksList['other'] ) {
1254 $chosenBlock = $blocksList['other'];
1255 } elseif ( $blocksList['auto'] ) {
1256 $chosenBlock = $blocksList['auto'];
1257 } else {
1258 throw new MWException( "Proxy block found, but couldn't be classified." );
1259 }
1260
1261 return $chosenBlock;
1262 }
1263
1264 /**
1265 * From an existing Block, get the target and the type of target.
1266 * Note that, except for null, it is always safe to treat the target
1267 * as a string; for User objects this will return User::__toString()
1268 * which in turn gives User::getName().
1269 *
1270 * @param string|int|User|null $target
1271 * @return array( User|String|null, Block::TYPE_ constant|null )
1272 */
1273 public static function parseTarget( $target ) {
1274 # We may have been through this before
1275 if ( $target instanceof User ) {
1276 if ( IP::isValid( $target->getName() ) ) {
1277 return array( $target, self::TYPE_IP );
1278 } else {
1279 return array( $target, self::TYPE_USER );
1280 }
1281 } elseif ( $target === null ) {
1282 return array( null, null );
1283 }
1284
1285 $target = trim( $target );
1286
1287 if ( IP::isValid( $target ) ) {
1288 # We can still create a User if it's an IP address, but we need to turn
1289 # off validation checking (which would exclude IP addresses)
1290 return array(
1291 User::newFromName( IP::sanitizeIP( $target ), false ),
1292 Block::TYPE_IP
1293 );
1294
1295 } elseif ( IP::isValidBlock( $target ) ) {
1296 # Can't create a User from an IP range
1297 return array( IP::sanitizeRange( $target ), Block::TYPE_RANGE );
1298 }
1299
1300 # Consider the possibility that this is not a username at all
1301 # but actually an old subpage (bug #29797)
1302 if ( strpos( $target, '/' ) !== false ) {
1303 # An old subpage, drill down to the user behind it
1304 $parts = explode( '/', $target );
1305 $target = $parts[0];
1306 }
1307
1308 $userObj = User::newFromName( $target );
1309 if ( $userObj instanceof User ) {
1310 # Note that since numbers are valid usernames, a $target of "12345" will be
1311 # considered a User. If you want to pass a block ID, prepend a hash "#12345",
1312 # since hash characters are not valid in usernames or titles generally.
1313 return array( $userObj, Block::TYPE_USER );
1314
1315 } elseif ( preg_match( '/^#\d+$/', $target ) ) {
1316 # Autoblock reference in the form "#12345"
1317 return array( substr( $target, 1 ), Block::TYPE_AUTO );
1318
1319 } else {
1320 # WTF?
1321 return array( null, null );
1322 }
1323 }
1324
1325 /**
1326 * Get the type of target for this particular block
1327 * @return int Block::TYPE_ constant, will never be TYPE_ID
1328 */
1329 public function getType() {
1330 return $this->mAuto
1331 ? self::TYPE_AUTO
1332 : $this->type;
1333 }
1334
1335 /**
1336 * Get the target and target type for this particular Block. Note that for autoblocks,
1337 * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
1338 * in this situation.
1339 * @return array( User|String, Block::TYPE_ constant )
1340 * @todo FIXME: This should be an integral part of the Block member variables
1341 */
1342 public function getTargetAndType() {
1343 return array( $this->getTarget(), $this->getType() );
1344 }
1345
1346 /**
1347 * Get the target for this particular Block. Note that for autoblocks,
1348 * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
1349 * in this situation.
1350 * @return User|string
1351 */
1352 public function getTarget() {
1353 return $this->target;
1354 }
1355
1356 /**
1357 * @since 1.19
1358 *
1359 * @return mixed|string
1360 */
1361 public function getExpiry() {
1362 return $this->mExpiry;
1363 }
1364
1365 /**
1366 * Set the target for this block, and update $this->type accordingly
1367 * @param mixed $target
1368 */
1369 public function setTarget( $target ) {
1370 list( $this->target, $this->type ) = self::parseTarget( $target );
1371 }
1372
1373 /**
1374 * Get the user who implemented this block
1375 * @return User|string Local User object or string for a foreign user
1376 */
1377 public function getBlocker() {
1378 return $this->blocker;
1379 }
1380
1381 /**
1382 * Set the user who implemented (or will implement) this block
1383 * @param User|string $user Local User object or username string for foreign users
1384 */
1385 public function setBlocker( $user ) {
1386 $this->blocker = $user;
1387 }
1388
1389 /**
1390 * Get the key and parameters for the corresponding error message.
1391 *
1392 * @since 1.22
1393 * @param IContextSource $context
1394 * @return array
1395 */
1396 public function getPermissionsError( IContextSource $context ) {
1397 $blocker = $this->getBlocker();
1398 if ( $blocker instanceof User ) { // local user
1399 $blockerUserpage = $blocker->getUserPage();
1400 $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
1401 } else { // foreign user
1402 $link = $blocker;
1403 }
1404
1405 $reason = $this->mReason;
1406 if ( $reason == '' ) {
1407 $reason = $context->msg( 'blockednoreason' )->text();
1408 }
1409
1410 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1411 * This could be a username, an IP range, or a single IP. */
1412 $intended = $this->getTarget();
1413
1414 $lang = $context->getLanguage();
1415 return array(
1416 $this->mAuto ? 'autoblockedtext' : 'blockedtext',
1417 $link,
1418 $reason,
1419 $context->getRequest()->getIP(),
1420 $this->getByName(),
1421 $this->getId(),
1422 $lang->formatExpiry( $this->mExpiry ),
1423 (string)$intended,
1424 $lang->userTimeAndDate( $this->mTimestamp, $context->getUser() ),
1425 );
1426 }
1427 }