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 )
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
= false;
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 * @return Block Object
59 * @param $address string IP address of user/anon
60 * @param $user int User id of user
61 * @param $killExpired bool Delete expired blocks on load
63 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 * @return Block object
77 * @param $id int Block id to search for
79 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 * Clear all member variables in the current object. Does not clear
93 * the block from the DB.
96 $this->mAddress
= $this->mReason
= $this->mTimestamp
= '';
97 $this->mId
= $this->mAnonOnly
= $this->mCreateAccount
=
98 $this->mEnableAutoblock
= $this->mAuto
= $this->mUser
=
99 $this->mBy
= $this->mHideName
= $this->mBlockEmail
= $this->mAllowUsertalk
= 0;
100 $this->mByName
= false;
104 * Get the DB object and set the reference parameter to the select options.
105 * The options array will contain FOR UPDATE if appropriate.
107 * @param array $options
110 function &getDBOptions( &$options ) {
111 global $wgAntiLockFlags;
112 if ( $this->mForUpdate ||
$this->mFromMaster
) {
113 $db = wfGetDB( DB_MASTER
);
114 if ( !$this->mForUpdate ||
($wgAntiLockFlags & ALF_NO_BLOCK_LOCK
) ) {
117 $options = array( 'FOR UPDATE' );
120 $db = wfGetDB( DB_SLAVE
);
127 * Get a block from the DB, with either the given address or the given username
129 * @param $address string The IP address of the user, or blank to skip IP blocks
130 * @param $user int The user ID, or zero for anonymous users
131 * @param $killExpired bool Whether to delete expired rows while loading
132 * @return bool The user is blocked from editing
135 function load( $address = '', $user = 0, $killExpired = true ) {
136 wfDebug( "Block::load: '$address', '$user', $killExpired\n" );
139 $db =& $this->getDBOptions( $options );
141 if ( 0 == $user && $address == '' ) {
142 # Invalid user specification, not blocked
149 $res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ),
150 __METHOD__
, $options ) );
151 if ( $this->loadFromResult( $res, $killExpired ) ) {
157 # TODO: improve performance by merging this query with the autoblock one
158 # Slightly tricky while handling killExpired as well
160 $conds = array( 'ipb_address' => $address, 'ipb_auto' => 0 );
161 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__
, $options ) );
162 if ( $this->loadFromResult( $res, $killExpired ) ) {
163 if ( $user && $this->mAnonOnly
) {
164 # Block is marked anon-only
165 # Whitelist this IP address against autoblocks and range blocks
166 # (but not account creation blocks -- bug 13611)
167 if( !$this->mCreateAccount
) {
178 if ( $this->loadRange( $address, $killExpired, $user ) ) {
179 if ( $user && $this->mAnonOnly
) {
180 # Respect account creation blocks on logged-in users -- bug 13611
181 if( !$this->mCreateAccount
) {
192 $conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 );
194 $conds['ipb_anon_only'] = 0;
196 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__
, $options ) );
197 if ( $this->loadFromResult( $res, $killExpired ) ) {
208 * Fill in member variables from a result wrapper
211 * @param $res ResultWrapper Row from the ipblocks table
212 * @param $killExpired bool Whether to delete expired rows while loading
214 function loadFromResult( ResultWrapper
$res, $killExpired = true ) {
216 if ( 0 != $res->numRows() ) {
218 $row = $res->fetchObject();
219 $this->initFromRow( $row );
221 if ( $killExpired ) {
222 # If requested, delete expired rows
224 $killed = $this->deleteIfExpired();
226 $row = $res->fetchObject();
228 $this->initFromRow( $row );
231 } while ( $killed && $row );
233 # If there were any left after the killing finished, return true
246 * Search the database for any range blocks matching the given address, and
247 * load the row if one is found.
250 * @param $address string IP address range
251 * @param $killExpired bool Whether to delete expired rows while loading
252 * @param $userid int If not 0, then sets ipb_anon_only
254 function loadRange( $address, $killExpired = true, $user = 0 ) {
255 $iaddr = IP
::toHex( $address );
256 if ( $iaddr === false ) {
261 # Only scan ranges which start in this /16, this improves search speed
262 # Blocks should not cross a /16 boundary.
263 $range = substr( $iaddr, 0, 4 );
266 $db =& $this->getDBOptions( $options );
268 "ipb_range_start LIKE '$range%'",
269 "ipb_range_start <= '$iaddr'",
270 "ipb_range_end >= '$iaddr'"
274 $conds['ipb_anon_only'] = 0;
277 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__
, $options ) );
278 $success = $this->loadFromResult( $res, $killExpired );
283 * Determine if a given integer IPv4 address is in a given CIDR network
284 * @deprecated Use IP::isInRange
286 function isAddressInRange( $addr, $range ) {
287 return IP
::isInRange( $addr, $range );
291 * Given a database row from the ipblocks table, initialize
294 * @param $row ResultWrapper A row from the ipblocks table
296 function initFromRow( $row ) {
297 $this->mAddress
= $row->ipb_address
;
298 $this->mReason
= $row->ipb_reason
;
299 $this->mTimestamp
= wfTimestamp(TS_MW
,$row->ipb_timestamp
);
300 $this->mUser
= $row->ipb_user
;
301 $this->mBy
= $row->ipb_by
;
302 $this->mAuto
= $row->ipb_auto
;
303 $this->mAnonOnly
= $row->ipb_anon_only
;
304 $this->mCreateAccount
= $row->ipb_create_account
;
305 $this->mEnableAutoblock
= $row->ipb_enable_autoblock
;
306 $this->mBlockEmail
= $row->ipb_block_email
;
307 $this->mAllowUsertalk
= $row->ipb_allow_usertalk
;
308 $this->mHideName
= $row->ipb_deleted
;
309 $this->mId
= $row->ipb_id
;
310 $this->mExpiry
= self
::decodeExpiry( $row->ipb_expiry
);
311 if ( isset( $row->user_name
) ) {
312 $this->mByName
= $row->user_name
;
314 $this->mByName
= $row->ipb_by_text
;
316 $this->mRangeStart
= $row->ipb_range_start
;
317 $this->mRangeEnd
= $row->ipb_range_end
;
321 * Once $mAddress has been set, get the range they came from.
322 * Wrapper for IP::parseRange
324 function initialiseRange() {
325 $this->mRangeStart
= '';
326 $this->mRangeEnd
= '';
328 if ( $this->mUser
== 0 ) {
329 list( $this->mRangeStart
, $this->mRangeEnd
) = IP
::parseRange( $this->mAddress
);
334 * Callback with a Block object for every block
336 * @deprecated Unlimited row count, do your own queries instead
338 * @return integer number of blocks
340 /*static*/ function enumBlocks( $callback, $tag, $flags = 0 ) {
341 global $wgAntiLockFlags;
344 if ( $flags & Block
::EB_FOR_UPDATE
) {
345 $db = wfGetDB( DB_MASTER
);
346 if ( $wgAntiLockFlags & ALF_NO_BLOCK_LOCK
) {
349 $options = 'FOR UPDATE';
351 $block->forUpdate( true );
353 $db = wfGetDB( DB_SLAVE
);
356 if ( $flags & Block
::EB_RANGE_ONLY
) {
357 $cond = " AND ipb_range_start <> ''";
362 $now = wfTimestampNow();
364 list( $ipblocks, $user ) = $db->tableNamesN( 'ipblocks', 'user' );
366 $sql = "SELECT $ipblocks.*,user_name FROM $ipblocks,$user " .
367 "WHERE user_id=ipb_by $cond ORDER BY ipb_timestamp DESC $options";
368 $res = $db->query( $sql, 'Block::enumBlocks' );
369 $num_rows = $db->numRows( $res );
371 while ( $row = $db->fetchObject( $res ) ) {
372 $block->initFromRow( $row );
373 if ( ( $flags & Block
::EB_RANGE_ONLY
) && $block->mRangeStart
== '' ) {
377 if ( !( $flags & Block
::EB_KEEP_EXPIRED
) ) {
378 if ( $block->mExpiry
&& $now > $block->mExpiry
) {
381 call_user_func( $callback, $block, $tag );
384 call_user_func( $callback, $block, $tag );
387 $db->freeResult( $res );
392 * Delete the row from the IP blocks table.
401 throw new MWException( "Block::delete() now requires that the mId member be filled\n" );
404 $dbw = wfGetDB( DB_MASTER
);
405 $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId
), __METHOD__
);
406 return $dbw->affectedRows() > 0;
410 * Insert a block into the block table. Will fail if there is a conflicting
411 * block (same name and options) already in the database.
413 * @return bool Whether or not the insertion was successful.
416 wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
417 $dbw = wfGetDB( DB_MASTER
);
419 $this->validateBlockParams();
421 # Don't collide with expired blocks
422 Block
::purgeExpired();
424 $ipb_id = $dbw->nextSequenceValue('ipblocks_ipb_id_val');
425 $dbw->insert( 'ipblocks',
428 'ipb_address' => $this->mAddress
,
429 'ipb_user' => $this->mUser
,
430 'ipb_by' => $this->mBy
,
431 'ipb_by_text' => $this->mByName
,
432 'ipb_reason' => $this->mReason
,
433 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp
),
434 'ipb_auto' => $this->mAuto
,
435 'ipb_anon_only' => $this->mAnonOnly
,
436 'ipb_create_account' => $this->mCreateAccount
,
437 'ipb_enable_autoblock' => $this->mEnableAutoblock
,
438 'ipb_expiry' => self
::encodeExpiry( $this->mExpiry
, $dbw ),
439 'ipb_range_start' => $this->mRangeStart
,
440 'ipb_range_end' => $this->mRangeEnd
,
441 'ipb_deleted' => $this->mHideName
,
442 'ipb_block_email' => $this->mBlockEmail
,
443 'ipb_allow_usertalk' => $this->mAllowUsertalk
444 ), 'Block::insert', array( 'IGNORE' )
446 $affected = $dbw->affectedRows();
449 $this->doRetroactiveAutoblock();
451 return (bool)$affected;
455 * Update a block in the DB with new parameters.
456 * The ID field needs to be loaded first.
458 public function update() {
459 wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" );
460 $dbw = wfGetDB( DB_MASTER
);
462 $this->validateBlockParams();
464 $dbw->update( 'ipblocks',
466 'ipb_user' => $this->mUser
,
467 'ipb_by' => $this->mBy
,
468 'ipb_by_text' => $this->mByName
,
469 'ipb_reason' => $this->mReason
,
470 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp
),
471 'ipb_auto' => $this->mAuto
,
472 'ipb_anon_only' => $this->mAnonOnly
,
473 'ipb_create_account' => $this->mCreateAccount
,
474 'ipb_enable_autoblock' => $this->mEnableAutoblock
,
475 'ipb_expiry' => self
::encodeExpiry( $this->mExpiry
, $dbw ),
476 'ipb_range_start' => $this->mRangeStart
,
477 'ipb_range_end' => $this->mRangeEnd
,
478 'ipb_deleted' => $this->mHideName
,
479 'ipb_block_email' => $this->mBlockEmail
,
480 'ipb_allow_usertalk' => $this->mAllowUsertalk
),
481 array( 'ipb_id' => $this->mId
),
484 return $dbw->affectedRows();
488 * Make sure all the proper members are set to sane values
489 * before adding/updating a block
491 private function validateBlockParams() {
492 # Unset ipb_anon_only for user blocks, makes no sense
493 if ( $this->mUser
) {
494 $this->mAnonOnly
= 0;
497 # Unset ipb_enable_autoblock for IP blocks, makes no sense
498 if ( !$this->mUser
) {
499 $this->mEnableAutoblock
= 0;
500 $this->mBlockEmail
= 0; //Same goes for email...
503 if( !$this->mByName
) {
505 $this->mByName
= User
::whoIs( $this->mBy
);
508 $this->mByName
= $wgUser->getName();
515 * Retroactively autoblocks the last IP used by the user (if it is a user)
516 * blocked by this Block.
518 * @return bool Whether or not a retroactive autoblock was made.
520 function doRetroactiveAutoblock() {
521 $dbr = wfGetDB( DB_SLAVE
);
522 #If autoblock is enabled, autoblock the LAST IP used
523 # - stolen shamelessly from CheckUser_body.php
525 if ($this->mEnableAutoblock
&& $this->mUser
) {
526 wfDebug("Doing retroactive autoblocks for " . $this->mAddress
. "\n");
528 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
529 $conds = array( 'rc_user_text' => $this->mAddress
);
531 if ($this->mAngryAutoblock
) {
532 // Block any IP used in the last 7 days. Up to five IPs.
533 $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - (7*86400) ) );
534 $options['LIMIT'] = 5;
536 // Just the last IP used.
537 $options['LIMIT'] = 1;
540 $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
541 __METHOD__
, $options);
543 if ( !$dbr->numRows( $res ) ) {
544 #No results, don't autoblock anything
545 wfDebug("No IP found to retroactively autoblock\n");
547 while ( $row = $dbr->fetchObject( $res ) ) {
549 $this->doAutoblock( $row->rc_ip
);
556 * Checks whether a given IP is on the autoblock whitelist.
559 * @param string $ip The IP to check
561 function isWhitelistedFromAutoblocks( $ip ) {
564 // Try to get the autoblock_whitelist from the cache, as it's faster
565 // than getting the msg raw and explode()'ing it.
566 $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
567 $lines = $wgMemc->get( $key );
569 $lines = explode( "\n", wfMsgForContentNoTrans( 'autoblock_whitelist' ) );
570 $wgMemc->set( $key, $lines, 3600 * 24 );
573 wfDebug("Checking the autoblock whitelist..\n");
575 foreach( $lines as $line ) {
577 if ( substr( $line, 0, 1 ) !== '*' ) {
581 $wlEntry = substr($line, 1);
582 $wlEntry = trim($wlEntry);
584 wfDebug("Checking $ip against $wlEntry...");
586 # Is the IP in this range?
587 if (IP
::isInRange( $ip, $wlEntry )) {
588 wfDebug(" IP $ip matches $wlEntry, not autoblocking\n");
591 wfDebug( " No match\n" );
599 * Autoblocks the given IP, referring to this Block.
601 * @param string $autoblockIP The IP to autoblock.
602 * @param bool $justInserted The main block was just inserted
603 * @return bool Whether or not an autoblock was inserted.
605 function doAutoblock( $autoblockIP, $justInserted = false ) {
606 # If autoblocks are disabled, go away.
607 if ( !$this->mEnableAutoblock
) {
611 # Check for presence on the autoblock whitelist
612 if (Block
::isWhitelistedFromAutoblocks($autoblockIP)) {
616 ## Allow hooks to cancel the autoblock.
617 if (!wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) )) {
618 wfDebug( "Autoblock aborted by hook." );
622 # It's okay to autoblock. Go ahead and create/insert the block.
624 $ipblock = Block
::newFromDB( $autoblockIP );
626 # If the user is already blocked. Then check if the autoblock would
627 # exceed the user block. If it would exceed, then do nothing, else
629 if ($this->mExpiry
&&
630 ($this->mExpiry
< Block
::getAutoblockExpiry($ipblock->mTimestamp
))) {
633 # Just update the timestamp
634 if ( !$justInserted ) {
635 $ipblock->updateTimestamp();
639 $ipblock = new Block
;
642 # Make a new block object with the desired properties
643 wfDebug( "Autoblocking {$this->mAddress}@" . $autoblockIP . "\n" );
644 $ipblock->mAddress
= $autoblockIP;
646 $ipblock->mBy
= $this->mBy
;
647 $ipblock->mByName
= $this->mByName
;
648 $ipblock->mReason
= wfMsgForContent( 'autoblocker', $this->mAddress
, $this->mReason
);
649 $ipblock->mTimestamp
= wfTimestampNow();
651 $ipblock->mCreateAccount
= $this->mCreateAccount
;
652 # Continue suppressing the name if needed
653 $ipblock->mHideName
= $this->mHideName
;
654 $ipblock->mAllowUsertalk
= $this->mAllowUsertalk
;
655 # If the user is already blocked with an expiry date, we don't
656 # want to pile on top of that!
658 $ipblock->mExpiry
= min ( $this->mExpiry
, Block
::getAutoblockExpiry( $this->mTimestamp
));
660 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $this->mTimestamp
);
663 return $ipblock->insert();
667 * Check if a block has expired. Delete it if it is.
670 function deleteIfExpired() {
671 $fname = 'Block::deleteIfExpired';
672 wfProfileIn( $fname );
673 if ( $this->isExpired() ) {
674 wfDebug( "Block::deleteIfExpired() -- deleting\n" );
678 wfDebug( "Block::deleteIfExpired() -- not expired\n" );
681 wfProfileOut( $fname );
686 * Has the block expired?
689 function isExpired() {
690 wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
691 if ( !$this->mExpiry
) {
694 return wfTimestampNow() > $this->mExpiry
;
699 * Is the block address valid (i.e. not a null string?)
703 return $this->mAddress
!= '';
707 * Update the timestamp on autoblocks.
709 function updateTimestamp() {
710 if ( $this->mAuto
) {
711 $this->mTimestamp
= wfTimestamp();
712 $this->mExpiry
= Block
::getAutoblockExpiry( $this->mTimestamp
);
714 $dbw = wfGetDB( DB_MASTER
);
715 $dbw->update( 'ipblocks',
717 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp
),
718 'ipb_expiry' => $dbw->timestamp($this->mExpiry
),
719 ), array( /* WHERE */
720 'ipb_address' => $this->mAddress
721 ), 'Block::updateTimestamp'
727 * Get the user id of the blocking sysop
731 public function getBy() {
736 * Get the username of the blocking sysop
740 function getByName() {
741 return $this->mByName
;
745 * Get/set the SELECT ... FOR UPDATE flag
747 function forUpdate( $x = NULL ) {
748 return wfSetVar( $this->mForUpdate
, $x );
752 * Get/set a flag determining whether the master is used for reads
754 function fromMaster( $x = NULL ) {
755 return wfSetVar( $this->mFromMaster
, $x );
759 * Get the block name, but with autoblocked IPs hidden as per standard privacy policy
762 function getRedactedName() {
763 if ( $this->mAuto
) {
764 return '#' . $this->mId
;
766 return $this->mAddress
;
771 * Encode expiry for DB
774 * @param $expiry string Timestamp for expiry, or
775 * @param $db Database object
777 static function encodeExpiry( $expiry, $db ) {
778 if ( $expiry == '' ||
$expiry == Block
::infinity() ) {
779 return Block
::infinity();
781 return $db->timestamp( $expiry );
786 * Decode expiry which has come from the DB
789 * @param $expiry string Database expiry format
790 * @param $timestampType Requested timestamp format
792 static function decodeExpiry( $expiry, $timestampType = TS_MW
) {
793 if ( $expiry == '' ||
$expiry == Block
::infinity() ) {
794 return Block
::infinity();
796 return wfTimestamp( $timestampType, $expiry );
801 * Get a timestamp of the expiry for autoblocks
805 static function getAutoblockExpiry( $timestamp ) {
806 global $wgAutoblockExpiry;
807 return wfTimestamp( TS_MW
, wfTimestamp( TS_UNIX
, $timestamp ) +
$wgAutoblockExpiry );
811 * Gets rid of uneeded numbers in quad-dotted/octet IP strings
812 * For example, 127.111.113.151/24 -> 127.111.113.0/24
813 * @param $range string IP address to normalize
816 static function normaliseRange( $range ) {
817 $parts = explode( '/', $range );
818 if ( count( $parts ) == 2 ) {
820 if ( IP
::isIPv6($range) && $parts[1] >= 64 && $parts[1] <= 128 ) {
822 $ipint = IP
::toUnsigned6( $parts[0] );
823 # Native 32 bit functions WONT work here!!!
824 # Convert to a padded binary number
825 $network = wfBaseConvert( $ipint, 10, 2, 128 );
826 # Truncate the last (128-$bits) bits and replace them with zeros
827 $network = str_pad( substr( $network, 0, $bits ), 128, 0, STR_PAD_RIGHT
);
828 # Convert back to an integer
829 $network = wfBaseConvert( $network, 2, 10 );
830 # Reform octet address
831 $newip = IP
::toOctet( $network );
832 $range = "$newip/{$parts[1]}";
834 else if ( IP
::isIPv4($range) && $parts[1] >= 16 && $parts[1] <= 32 ) {
835 $shift = 32 - $parts[1];
836 $ipint = IP
::toUnsigned( $parts[0] );
837 $ipint = $ipint >> $shift << $shift;
838 $newip = long2ip( $ipint );
839 $range = "$newip/{$parts[1]}";
846 * Purge expired blocks from the ipblocks table
848 static function purgeExpired() {
849 $dbw = wfGetDB( DB_MASTER
);
850 $dbw->delete( 'ipblocks', array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__
);
854 * Get a value to insert into expiry field of the database when infinite expiry
855 * is desired. In principle this could be DBMS-dependant, but currently all
856 * supported DBMS's support the string "infinity", so we just use that.
860 static function infinity() {
861 # This is a special keyword for timestamps in PostgreSQL, and
862 # works with CHAR(14) as well because "i" sorts after all numbers.
867 * Convert a DB-encoded expiry into a real string that humans can read.
869 * @param $encoded_expiry string Database encoded expiry time
872 static function formatExpiry( $encoded_expiry ) {
876 if( is_null( $msg ) ) {
878 $keys = array( 'infiniteblock', 'expiringblock' );
879 foreach( $keys as $key ) {
880 $msg[$key] = wfMsgHtml( $key );
884 $expiry = Block
::decodeExpiry( $encoded_expiry );
885 if ($expiry == 'infinity') {
886 $expirystr = $msg['infiniteblock'];
889 $expiretimestr = $wgLang->timeanddate( $expiry, true );
890 $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array($expiretimestr) );
897 * Convert a typed-in expiry time into something we can put into the database.
898 * @param $expiry_input string Whatever was typed into the form
899 * @return string More database friendly
901 static function parseExpiryInput( $expiry_input ) {
902 if ( $expiry_input == 'infinite' ||
$expiry_input == 'indefinite' ) {
903 $expiry = 'infinity';
905 $expiry = strtotime( $expiry_input );
906 if ($expiry < 0 ||
$expiry === false) {