4 * Blocks and bans object
9 * All the functions in this class assume the object is either explicitly
10 * loaded or filled. It is not load-on-demand. There are no accessors.
12 * Globals used: $wgAutoblockExpiry, $wgAntiLockFlags
14 * @todo This could be used everywhere, but it isn't.
17 /* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry,
18 $mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName,
19 $mBlockEmail, $mByName, $mAngryAutoblock, $mAllowUsertalk;
20 /* private */ var $mNetworkBits, $mIntegerAddr, $mForUpdate, $mFromMaster;
22 const EB_KEEP_EXPIRED
= 1;
23 const EB_FOR_UPDATE
= 2;
24 const EB_RANGE_ONLY
= 4;
26 function __construct( $address = '', $user = 0, $by = 0, $reason = '',
27 $timestamp = '' , $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
28 $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byName = false )
31 # Expand valid IPv6 addresses
32 $address = IP
::sanitizeIP( $address );
33 $this->mAddress
= $address;
36 $this->mReason
= $reason;
37 $this->mTimestamp
= wfTimestamp( TS_MW
, $timestamp );
39 $this->mAnonOnly
= $anonOnly;
40 $this->mCreateAccount
= $createAccount;
41 $this->mExpiry
= self
::decodeExpiry( $expiry );
42 $this->mEnableAutoblock
= $enableAutoblock;
43 $this->mHideName
= $hideName;
44 $this->mBlockEmail
= $blockEmail;
45 $this->mAllowUsertalk
= $allowUsertalk;
46 $this->mForUpdate
= false;
47 $this->mFromMaster
= false;
48 $this->mByName
= $byName;
49 $this->mAngryAutoblock
= false;
50 $this->initialiseRange();
54 * Load a block from the database, using either the IP address or
55 * user ID. Tries the user ID first, and if that doesn't work, tries
58 * @param $address String: IP address of user/anon
59 * @param $user Integer: user id of user
60 * @param $killExpired Boolean: delete expired blocks on load
61 * @return Block Object
63 public static function newFromDB( $address, $user = 0, $killExpired = true ) {
65 $block->load( $address, $user, $killExpired );
66 if ( $block->isValid() ) {
74 * Load a blocked user from their block id.
76 * @param $id Integer: Block id to search for
77 * @return Block object
79 public static function newFromID( $id ) {
80 $dbr = wfGetDB( DB_SLAVE
);
81 $res = $dbr->resultObject( $dbr->select( 'ipblocks', '*',
82 array( 'ipb_id' => $id ), __METHOD__
) );
84 if ( $block->loadFromResult( $res ) ) {
92 * Check if two blocks are effectively equal
96 public function equals( Block
$block ) {
98 $this->mAddress
== $block->mAddress
99 && $this->mUser
== $block->mUser
100 && $this->mAuto
== $block->mAuto
101 && $this->mAnonOnly
== $block->mAnonOnly
102 && $this->mCreateAccount
== $block->mCreateAccount
103 && $this->mExpiry
== $block->mExpiry
104 && $this->mEnableAutoblock
== $block->mEnableAutoblock
105 && $this->mHideName
== $block->mHideName
106 && $this->mBlockEmail
== $block->mBlockEmail
107 && $this->mAllowUsertalk
== $block->mAllowUsertalk
108 && $this->mReason
== $block->mReason
113 * Clear all member variables in the current object. Does not clear
114 * the block from the DB.
116 public function clear() {
117 $this->mAddress
= $this->mReason
= $this->mTimestamp
= '';
118 $this->mId
= $this->mAnonOnly
= $this->mCreateAccount
=
119 $this->mEnableAutoblock
= $this->mAuto
= $this->mUser
=
120 $this->mBy
= $this->mHideName
= $this->mBlockEmail
= $this->mAllowUsertalk
= 0;
121 $this->mByName
= false;
125 * Get the DB object and set the reference parameter to the select options.
126 * The options array will contain FOR UPDATE if appropriate.
128 * @param $options Array
131 protected function &getDBOptions( &$options ) {
132 global $wgAntiLockFlags;
134 if ( $this->mForUpdate ||
$this->mFromMaster
) {
135 $db = wfGetDB( DB_MASTER
);
136 if ( !$this->mForUpdate ||
( $wgAntiLockFlags & ALF_NO_BLOCK_LOCK
) ) {
139 $options = array( 'FOR UPDATE' );
142 $db = wfGetDB( DB_SLAVE
);
149 * Get a block from the DB, with either the given address or the given username
151 * @param $address string The IP address of the user, or blank to skip IP blocks
152 * @param $user int The user ID, or zero for anonymous users
153 * @param $killExpired bool Whether to delete expired rows while loading
154 * @return Boolean: the user is blocked from editing
157 public function load( $address = '', $user = 0, $killExpired = true ) {
158 wfDebug( "Block::load: '$address', '$user', $killExpired\n" );
161 $db =& $this->getDBOptions( $options );
163 if ( 0 == $user && $address === '' ) {
164 # Invalid user specification, not blocked
171 $res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ),
172 __METHOD__
, $options ) );
173 if ( $this->loadFromResult( $res, $killExpired ) ) {
179 # TODO: improve performance by merging this query with the autoblock one
180 # Slightly tricky while handling killExpired as well
181 if ( $address !== '' ) {
182 $conds = array( 'ipb_address' => $address, 'ipb_auto' => 0 );
183 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__
, $options ) );
185 if ( $this->loadFromResult( $res, $killExpired ) ) {
186 if ( $user && $this->mAnonOnly
) {
187 # Block is marked anon-only
188 # Whitelist this IP address against autoblocks and range blocks
189 # (but not account creation blocks -- bug 13611)
190 if ( !$this->mCreateAccount
) {
201 if ( $this->loadRange( $address, $killExpired, $user ) ) {
202 if ( $user && $this->mAnonOnly
) {
203 # Respect account creation blocks on logged-in users -- bug 13611
204 if ( !$this->mCreateAccount
) {
215 $conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 );
218 $conds['ipb_anon_only'] = 0;
221 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__
, $options ) );
223 if ( $this->loadFromResult( $res, $killExpired ) ) {
234 * Fill in member variables from a result wrapper
236 * @param $res ResultWrapper: row from the ipblocks table
237 * @param $killExpired Boolean: whether to delete expired rows while loading
240 protected function loadFromResult( ResultWrapper
$res, $killExpired = true ) {
243 if ( 0 != $res->numRows() ) {
245 $row = $res->fetchObject();
246 $this->initFromRow( $row );
248 if ( $killExpired ) {
249 # If requested, delete expired rows
251 $killed = $this->deleteIfExpired();
253 $row = $res->fetchObject();
255 $this->initFromRow( $row );
258 } while ( $killed && $row );
260 # If there were any left after the killing finished, return true
273 * Search the database for any range blocks matching the given address, and
274 * load the row if one is found.
276 * @param $address String: IP address range
277 * @param $killExpired Boolean: whether to delete expired rows while loading
278 * @param $userid Integer: if not 0, then sets ipb_anon_only
281 public function loadRange( $address, $killExpired = true, $user = 0 ) {
282 $iaddr = IP
::toHex( $address );
284 if ( $iaddr === false ) {
289 # Only scan ranges which start in this /16, this improves search speed
290 # Blocks should not cross a /16 boundary.
291 $range = substr( $iaddr, 0, 4 );
294 $db =& $this->getDBOptions( $options );
296 'ipb_range_start' . $db->buildLike( $range, $db->anyString() ),
297 "ipb_range_start <= '$iaddr'",
298 "ipb_range_end >= '$iaddr'"
302 $conds['ipb_anon_only'] = 0;
305 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__
, $options ) );
306 $success = $this->loadFromResult( $res, $killExpired );
311 * Given a database row from the ipblocks table, initialize
314 * @param $row ResultWrapper: a row from the ipblocks table
316 public function initFromRow( $row ) {
317 $this->mAddress
= $row->ipb_address
;
318 $this->mReason
= $row->ipb_reason
;
319 $this->mTimestamp
= wfTimestamp( TS_MW
, $row->ipb_timestamp
);
320 $this->mUser
= $row->ipb_user
;
321 $this->mBy
= $row->ipb_by
;
322 $this->mAuto
= $row->ipb_auto
;
323 $this->mAnonOnly
= $row->ipb_anon_only
;
324 $this->mCreateAccount
= $row->ipb_create_account
;
325 $this->mEnableAutoblock
= $row->ipb_enable_autoblock
;
326 $this->mBlockEmail
= $row->ipb_block_email
;
327 $this->mAllowUsertalk
= $row->ipb_allow_usertalk
;
328 $this->mHideName
= $row->ipb_deleted
;
329 $this->mId
= $row->ipb_id
;
330 $this->mExpiry
= self
::decodeExpiry( $row->ipb_expiry
);
332 if ( isset( $row->user_name
) ) {
333 $this->mByName
= $row->user_name
;
335 $this->mByName
= $row->ipb_by_text
;
338 $this->mRangeStart
= $row->ipb_range_start
;
339 $this->mRangeEnd
= $row->ipb_range_end
;
343 * Once $mAddress has been set, get the range they came from.
344 * Wrapper for IP::parseRange
346 protected function initialiseRange() {
347 $this->mRangeStart
= '';
348 $this->mRangeEnd
= '';
350 if ( $this->mUser
== 0 ) {
351 list( $this->mRangeStart
, $this->mRangeEnd
) = IP
::parseRange( $this->mAddress
);
356 * Delete the row from the IP blocks table.
360 public function delete() {
361 if ( wfReadOnly() ) {
366 throw new MWException( "Block::delete() now requires that the mId member be filled\n" );
369 $dbw = wfGetDB( DB_MASTER
);
370 $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId
), __METHOD__
);
371 return $dbw->affectedRows() > 0;
375 * Insert a block into the block table. Will fail if there is a conflicting
376 * block (same name and options) already in the database.
378 * @return Boolean: whether or not the insertion was successful.
380 public function insert( $dbw = null ) {
381 wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
383 $dbw = wfGetDB( DB_MASTER
);
385 $this->validateBlockParams();
386 $this->initialiseRange();
388 # Don't collide with expired blocks
389 Block
::purgeExpired();
391 $ipb_id = $dbw->nextSequenceValue( 'ipblocks_ipb_id_seq' );
396 'ipb_address' => $this->mAddress
,
397 'ipb_user' => $this->mUser
,
398 'ipb_by' => $this->mBy
,
399 'ipb_by_text' => $this->mByName
,
400 'ipb_reason' => $this->mReason
,
401 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp
),
402 'ipb_auto' => $this->mAuto
,
403 'ipb_anon_only' => $this->mAnonOnly
,
404 'ipb_create_account' => $this->mCreateAccount
,
405 'ipb_enable_autoblock' => $this->mEnableAutoblock
,
406 'ipb_expiry' => self
::encodeExpiry( $this->mExpiry
, $dbw ),
407 'ipb_range_start' => $this->mRangeStart
,
408 'ipb_range_end' => $this->mRangeEnd
,
409 'ipb_deleted' => intval( $this->mHideName
), // typecast required for SQLite
410 'ipb_block_email' => $this->mBlockEmail
,
411 'ipb_allow_usertalk' => $this->mAllowUsertalk
416 $affected = $dbw->affectedRows();
419 $this->doRetroactiveAutoblock();
421 return (bool)$affected;
425 * Update a block in the DB with new parameters.
426 * The ID field needs to be loaded first.
428 public function update() {
429 wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" );
430 $dbw = wfGetDB( DB_MASTER
);
432 $this->validateBlockParams();
437 'ipb_user' => $this->mUser
,
438 'ipb_by' => $this->mBy
,
439 'ipb_by_text' => $this->mByName
,
440 'ipb_reason' => $this->mReason
,
441 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp
),
442 'ipb_auto' => $this->mAuto
,
443 'ipb_anon_only' => $this->mAnonOnly
,
444 'ipb_create_account' => $this->mCreateAccount
,
445 'ipb_enable_autoblock' => $this->mEnableAutoblock
,
446 'ipb_expiry' => self
::encodeExpiry( $this->mExpiry
, $dbw ),
447 'ipb_range_start' => $this->mRangeStart
,
448 'ipb_range_end' => $this->mRangeEnd
,
449 'ipb_deleted' => $this->mHideName
,
450 'ipb_block_email' => $this->mBlockEmail
,
451 'ipb_allow_usertalk' => $this->mAllowUsertalk
453 array( 'ipb_id' => $this->mId
),
457 return $dbw->affectedRows();
461 * Make sure all the proper members are set to sane values
462 * before adding/updating a block
464 protected function validateBlockParams() {
465 # Unset ipb_anon_only for user blocks, makes no sense
466 if ( $this->mUser
) {
467 $this->mAnonOnly
= 0;
470 # Unset ipb_enable_autoblock for IP blocks, makes no sense
471 if ( !$this->mUser
) {
472 $this->mEnableAutoblock
= 0;
475 # bug 18860: non-anon-only IP blocks should be allowed to block email
476 if ( !$this->mUser
&& $this->mAnonOnly
) {
477 $this->mBlockEmail
= 0;
479 if ( !$this->mByName
) {
481 $this->mByName
= User
::whoIs( $this->mBy
);
484 $this->mByName
= $wgUser->getName();
490 * Retroactively autoblocks the last IP used by the user (if it is a user)
491 * blocked by this Block.
493 * @return Boolean: whether or not a retroactive autoblock was made.
495 public function doRetroactiveAutoblock() {
496 $dbr = wfGetDB( DB_SLAVE
);
497 # If autoblock is enabled, autoblock the LAST IP used
498 # - stolen shamelessly from CheckUser_body.php
500 if ( $this->mEnableAutoblock
&& $this->mUser
) {
501 wfDebug( "Doing retroactive autoblocks for " . $this->mAddress
. "\n" );
503 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
504 $conds = array( 'rc_user_text' => $this->mAddress
);
506 if ( $this->mAngryAutoblock
) {
507 // Block any IP used in the last 7 days. Up to five IPs.
508 $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - ( 7 * 86400 ) ) );
509 $options['LIMIT'] = 5;
511 // Just the last IP used.
512 $options['LIMIT'] = 1;
515 $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
516 __METHOD__
, $options );
518 if ( !$dbr->numRows( $res ) ) {
519 # No results, don't autoblock anything
520 wfDebug( "No IP found to retroactively autoblock\n" );
522 while ( $row = $dbr->fetchObject( $res ) ) {
524 $this->doAutoblock( $row->rc_ip
);
531 * Checks whether a given IP is on the autoblock whitelist.
533 * @param $ip String: The IP to check
536 public static function isWhitelistedFromAutoblocks( $ip ) {
539 // Try to get the autoblock_whitelist from the cache, as it's faster
540 // than getting the msg raw and explode()'ing it.
541 $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
542 $lines = $wgMemc->get( $key );
544 $lines = explode( "\n", wfMsgForContentNoTrans( 'autoblock_whitelist' ) );
545 $wgMemc->set( $key, $lines, 3600 * 24 );
548 wfDebug( "Checking the autoblock whitelist..\n" );
550 foreach ( $lines as $line ) {
552 if ( substr( $line, 0, 1 ) !== '*' ) {
556 $wlEntry = substr( $line, 1 );
557 $wlEntry = trim( $wlEntry );
559 wfDebug( "Checking $ip against $wlEntry..." );
561 # Is the IP in this range?
562 if ( IP
::isInRange( $ip, $wlEntry ) ) {
563 wfDebug( " IP $ip matches $wlEntry, not autoblocking\n" );
566 wfDebug( " No match\n" );
574 * Autoblocks the given IP, referring to this Block.
576 * @param $autoblockIP String: the IP to autoblock.
577 * @param $justInserted Boolean: the main block was just inserted
578 * @return Boolean: whether or not an autoblock was inserted.
580 public function doAutoblock( $autoblockIP, $justInserted = false ) {
581 # If autoblocks are disabled, go away.
582 if ( !$this->mEnableAutoblock
) {
586 # Check for presence on the autoblock whitelist
587 if ( Block
::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
591 # # Allow hooks to cancel the autoblock.
592 if ( !wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) ) ) {
593 wfDebug( "Autoblock aborted by hook.\n" );
597 # It's okay to autoblock. Go ahead and create/insert the block.
599 $ipblock = Block
::newFromDB( $autoblockIP );
601 # If the user is already blocked. Then check if the autoblock would
602 # exceed the user block. If it would exceed, then do nothing, else
604 if ( $this->mExpiry
&&
605 ( $this->mExpiry
< Block
::getAutoblockExpiry( $ipblock->mTimestamp
) ) ) {
608 # Just update the timestamp
609 if ( !$justInserted ) {
610 $ipblock->updateTimestamp();
614 $ipblock = new Block
;
617 # Make a new block object with the desired properties
618 wfDebug( "Autoblocking {$this->mAddress}@" . $autoblockIP . "\n" );
619 $ipblock->mAddress
= $autoblockIP;
621 $ipblock->mBy
= $this->mBy
;
622 $ipblock->mByName
= $this->mByName
;
623 $ipblock->mReason
= wfMsgForContent( 'autoblocker', $this->mAddress
, $this->mReason
);
624 $ipblock->mTimestamp
= wfTimestampNow();
626 $ipblock->mCreateAccount
= $this->mCreateAccount
;
627 # Continue suppressing the name if needed
628 $ipblock->mHideName
= $this->mHideName
;
629 $ipblock->mAllowUsertalk
= $this->mAllowUsertalk
;
630 # If the user is already blocked with an expiry date, we don't
631 # want to pile on top of that!
632 if ( $this->mExpiry
) {
633 $ipblock->mExpiry
= min( $this->mExpiry
, Block
::getAutoblockExpiry( $this->mTimestamp
) );
635 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $this->mTimestamp
);
638 return $ipblock->insert();
642 * Check if a block has expired. Delete it if it is.
645 public function deleteIfExpired() {
646 wfProfileIn( __METHOD__
);
647 if ( $this->isExpired() ) {
648 wfDebug( "Block::deleteIfExpired() -- deleting\n" );
652 wfDebug( "Block::deleteIfExpired() -- not expired\n" );
655 wfProfileOut( __METHOD__
);
660 * Has the block expired?
663 public function isExpired() {
664 wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
665 if ( !$this->mExpiry
) {
668 return wfTimestampNow() > $this->mExpiry
;
673 * Is the block address valid (i.e. not a null string?)
676 public function isValid() {
677 return $this->mAddress
!= '';
681 * Update the timestamp on autoblocks.
683 public function updateTimestamp() {
684 if ( $this->mAuto
) {
685 $this->mTimestamp
= wfTimestamp();
686 $this->mExpiry
= Block
::getAutoblockExpiry( $this->mTimestamp
);
688 $dbw = wfGetDB( DB_MASTER
);
689 $dbw->update( 'ipblocks',
691 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp
),
692 'ipb_expiry' => $dbw->timestamp( $this->mExpiry
),
693 ), array( /* WHERE */
694 'ipb_address' => $this->mAddress
695 ), 'Block::updateTimestamp'
701 * Get the user id of the blocking sysop
705 public function getBy() {
710 * Get the username of the blocking sysop
714 public function getByName() {
715 return $this->mByName
;
719 * Get/set the SELECT ... FOR UPDATE flag
721 public function forUpdate( $x = null ) {
722 return wfSetVar( $this->mForUpdate
, $x );
726 * Get/set a flag determining whether the master is used for reads
728 public function fromMaster( $x = null ) {
729 return wfSetVar( $this->mFromMaster
, $x );
733 * Get the block name, but with autoblocked IPs hidden as per standard privacy policy
736 public function getRedactedName() {
737 if ( $this->mAuto
) {
738 return '#' . $this->mId
;
740 return $this->mAddress
;
745 * Encode expiry for DB
747 * @param $expiry String: timestamp for expiry, or
748 * @param $db Database object
751 public static function encodeExpiry( $expiry, $db ) {
752 if ( $expiry == '' ||
$expiry == Block
::infinity() ) {
753 return Block
::infinity();
755 return $db->timestamp( $expiry );
760 * Decode expiry which has come from the DB
762 * @param $expiry String: Database expiry format
763 * @param $timestampType Requested timestamp format
766 public static function decodeExpiry( $expiry, $timestampType = TS_MW
) {
767 if ( $expiry == '' ||
$expiry == Block
::infinity() ) {
768 return Block
::infinity();
770 return wfTimestamp( $timestampType, $expiry );
775 * Get a timestamp of the expiry for autoblocks
779 public static function getAutoblockExpiry( $timestamp ) {
780 global $wgAutoblockExpiry;
781 return wfTimestamp( TS_MW
, wfTimestamp( TS_UNIX
, $timestamp ) +
$wgAutoblockExpiry );
785 * Gets rid of uneeded numbers in quad-dotted/octet IP strings
786 * For example, 127.111.113.151/24 -> 127.111.113.0/24
787 * @param $range String: IP address to normalize
790 public static function normaliseRange( $range ) {
791 $parts = explode( '/', $range );
792 if ( count( $parts ) == 2 ) {
794 if ( IP
::isIPv6( $range ) && $parts[1] >= 64 && $parts[1] <= 128 ) {
796 $ipint = IP
::toUnsigned6( $parts[0] );
797 # Native 32 bit functions WON'T work here!!!
798 # Convert to a padded binary number
799 $network = wfBaseConvert( $ipint, 10, 2, 128 );
800 # Truncate the last (128-$bits) bits and replace them with zeros
801 $network = str_pad( substr( $network, 0, $bits ), 128, 0, STR_PAD_RIGHT
);
802 # Convert back to an integer
803 $network = wfBaseConvert( $network, 2, 10 );
804 # Reform octet address
805 $newip = IP
::toOctet( $network );
806 $range = "$newip/{$parts[1]}";
808 elseif ( IP
::isIPv4( $range ) && $parts[1] >= 16 && $parts[1] <= 32 ) {
809 $shift = 32 - $parts[1];
810 $ipint = IP
::toUnsigned( $parts[0] );
811 $ipint = $ipint >> $shift << $shift;
812 $newip = long2ip( $ipint );
813 $range = "$newip/{$parts[1]}";
820 * Purge expired blocks from the ipblocks table
822 public static function purgeExpired() {
823 $dbw = wfGetDB( DB_MASTER
);
824 $dbw->delete( 'ipblocks', array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__
);
828 * Get a value to insert into expiry field of the database when infinite expiry
829 * is desired. In principle this could be DBMS-dependant, but currently all
830 * supported DBMS's support the string "infinity", so we just use that.
834 public static function infinity() {
835 # This is a special keyword for timestamps in PostgreSQL, and
836 # works with CHAR(14) as well because "i" sorts after all numbers.
841 * Convert a DB-encoded expiry into a real string that humans can read.
843 * @param $encoded_expiry String: Database encoded expiry time
844 * @return Html-escaped String
846 public static function formatExpiry( $encoded_expiry ) {
849 if ( is_null( $msg ) ) {
851 $keys = array( 'infiniteblock', 'expiringblock' );
852 foreach ( $keys as $key ) {
853 $msg[$key] = wfMsgHtml( $key );
857 $expiry = Block
::decodeExpiry( $encoded_expiry );
858 if ( $expiry == 'infinity' ) {
859 $expirystr = $msg['infiniteblock'];
862 $expiredatestr = htmlspecialchars( $wgLang->date( $expiry, true ) );
863 $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) );
864 $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) );
870 * Convert a typed-in expiry time into something we can put into the database.
871 * @param $expiry_input String: whatever was typed into the form
872 * @return String: more database friendly
874 public static function parseExpiryInput( $expiry_input ) {
875 if ( $expiry_input == 'infinite' ||
$expiry_input == 'indefinite' ) {
876 $expiry = 'infinity';
878 $expiry = strtotime( $expiry_input );
880 if ( $expiry < 0 ||
$expiry === false ) {