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 * @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() {
381 wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
382 $dbw = wfGetDB( DB_MASTER
);
384 $this->validateBlockParams();
385 $this->initialiseRange();
387 # Don't collide with expired blocks
388 Block
::purgeExpired();
390 $ipb_id = $dbw->nextSequenceValue( 'ipblocks_ipb_id_seq' );
395 'ipb_address' => $this->mAddress
,
396 'ipb_user' => $this->mUser
,
397 'ipb_by' => $this->mBy
,
398 'ipb_by_text' => $this->mByName
,
399 'ipb_reason' => $this->mReason
,
400 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp
),
401 'ipb_auto' => $this->mAuto
,
402 'ipb_anon_only' => $this->mAnonOnly
,
403 'ipb_create_account' => $this->mCreateAccount
,
404 'ipb_enable_autoblock' => $this->mEnableAutoblock
,
405 'ipb_expiry' => self
::encodeExpiry( $this->mExpiry
, $dbw ),
406 'ipb_range_start' => $this->mRangeStart
,
407 'ipb_range_end' => $this->mRangeEnd
,
408 'ipb_deleted' => intval( $this->mHideName
), // typecast required for SQLite
409 'ipb_block_email' => $this->mBlockEmail
,
410 'ipb_allow_usertalk' => $this->mAllowUsertalk
415 $affected = $dbw->affectedRows();
418 $this->doRetroactiveAutoblock();
420 return (bool)$affected;
424 * Update a block in the DB with new parameters.
425 * The ID field needs to be loaded first.
427 public function update() {
428 wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" );
429 $dbw = wfGetDB( DB_MASTER
);
431 $this->validateBlockParams();
436 'ipb_user' => $this->mUser
,
437 'ipb_by' => $this->mBy
,
438 'ipb_by_text' => $this->mByName
,
439 'ipb_reason' => $this->mReason
,
440 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp
),
441 'ipb_auto' => $this->mAuto
,
442 'ipb_anon_only' => $this->mAnonOnly
,
443 'ipb_create_account' => $this->mCreateAccount
,
444 'ipb_enable_autoblock' => $this->mEnableAutoblock
,
445 'ipb_expiry' => self
::encodeExpiry( $this->mExpiry
, $dbw ),
446 'ipb_range_start' => $this->mRangeStart
,
447 'ipb_range_end' => $this->mRangeEnd
,
448 'ipb_deleted' => $this->mHideName
,
449 'ipb_block_email' => $this->mBlockEmail
,
450 'ipb_allow_usertalk' => $this->mAllowUsertalk
452 array( 'ipb_id' => $this->mId
),
456 return $dbw->affectedRows();
460 * Make sure all the proper members are set to sane values
461 * before adding/updating a block
463 protected function validateBlockParams() {
464 # Unset ipb_anon_only for user blocks, makes no sense
465 if ( $this->mUser
) {
466 $this->mAnonOnly
= 0;
469 # Unset ipb_enable_autoblock for IP blocks, makes no sense
470 if ( !$this->mUser
) {
471 $this->mEnableAutoblock
= 0;
474 # bug 18860: non-anon-only IP blocks should be allowed to block email
475 if ( !$this->mUser
&& $this->mAnonOnly
) {
476 $this->mBlockEmail
= 0;
478 if ( !$this->mByName
) {
480 $this->mByName
= User
::whoIs( $this->mBy
);
483 $this->mByName
= $wgUser->getName();
489 * Retroactively autoblocks the last IP used by the user (if it is a user)
490 * blocked by this Block.
492 * @return Boolean: whether or not a retroactive autoblock was made.
494 public function doRetroactiveAutoblock() {
495 $dbr = wfGetDB( DB_SLAVE
);
496 # If autoblock is enabled, autoblock the LAST IP used
497 # - stolen shamelessly from CheckUser_body.php
499 if ( $this->mEnableAutoblock
&& $this->mUser
) {
500 wfDebug( "Doing retroactive autoblocks for " . $this->mAddress
. "\n" );
502 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
503 $conds = array( 'rc_user_text' => $this->mAddress
);
505 if ( $this->mAngryAutoblock
) {
506 // Block any IP used in the last 7 days. Up to five IPs.
507 $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - ( 7 * 86400 ) ) );
508 $options['LIMIT'] = 5;
510 // Just the last IP used.
511 $options['LIMIT'] = 1;
514 $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
515 __METHOD__
, $options );
517 if ( !$dbr->numRows( $res ) ) {
518 # No results, don't autoblock anything
519 wfDebug( "No IP found to retroactively autoblock\n" );
521 while ( $row = $dbr->fetchObject( $res ) ) {
523 $this->doAutoblock( $row->rc_ip
);
530 * Checks whether a given IP is on the autoblock whitelist.
532 * @param $ip String: The IP to check
535 public static function isWhitelistedFromAutoblocks( $ip ) {
538 // Try to get the autoblock_whitelist from the cache, as it's faster
539 // than getting the msg raw and explode()'ing it.
540 $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
541 $lines = $wgMemc->get( $key );
543 $lines = explode( "\n", wfMsgForContentNoTrans( 'autoblock_whitelist' ) );
544 $wgMemc->set( $key, $lines, 3600 * 24 );
547 wfDebug( "Checking the autoblock whitelist..\n" );
549 foreach ( $lines as $line ) {
551 if ( substr( $line, 0, 1 ) !== '*' ) {
555 $wlEntry = substr( $line, 1 );
556 $wlEntry = trim( $wlEntry );
558 wfDebug( "Checking $ip against $wlEntry..." );
560 # Is the IP in this range?
561 if ( IP
::isInRange( $ip, $wlEntry ) ) {
562 wfDebug( " IP $ip matches $wlEntry, not autoblocking\n" );
565 wfDebug( " No match\n" );
573 * Autoblocks the given IP, referring to this Block.
575 * @param $autoblockIP String: the IP to autoblock.
576 * @param $justInserted Boolean: the main block was just inserted
577 * @return Boolean: whether or not an autoblock was inserted.
579 public function doAutoblock( $autoblockIP, $justInserted = false ) {
580 # If autoblocks are disabled, go away.
581 if ( !$this->mEnableAutoblock
) {
585 # Check for presence on the autoblock whitelist
586 if ( Block
::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
590 # # Allow hooks to cancel the autoblock.
591 if ( !wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) ) ) {
592 wfDebug( "Autoblock aborted by hook.\n" );
596 # It's okay to autoblock. Go ahead and create/insert the block.
598 $ipblock = Block
::newFromDB( $autoblockIP );
600 # If the user is already blocked. Then check if the autoblock would
601 # exceed the user block. If it would exceed, then do nothing, else
603 if ( $this->mExpiry
&&
604 ( $this->mExpiry
< Block
::getAutoblockExpiry( $ipblock->mTimestamp
) ) ) {
607 # Just update the timestamp
608 if ( !$justInserted ) {
609 $ipblock->updateTimestamp();
613 $ipblock = new Block
;
616 # Make a new block object with the desired properties
617 wfDebug( "Autoblocking {$this->mAddress}@" . $autoblockIP . "\n" );
618 $ipblock->mAddress
= $autoblockIP;
620 $ipblock->mBy
= $this->mBy
;
621 $ipblock->mByName
= $this->mByName
;
622 $ipblock->mReason
= wfMsgForContent( 'autoblocker', $this->mAddress
, $this->mReason
);
623 $ipblock->mTimestamp
= wfTimestampNow();
625 $ipblock->mCreateAccount
= $this->mCreateAccount
;
626 # Continue suppressing the name if needed
627 $ipblock->mHideName
= $this->mHideName
;
628 $ipblock->mAllowUsertalk
= $this->mAllowUsertalk
;
629 # If the user is already blocked with an expiry date, we don't
630 # want to pile on top of that!
631 if ( $this->mExpiry
) {
632 $ipblock->mExpiry
= min( $this->mExpiry
, Block
::getAutoblockExpiry( $this->mTimestamp
) );
634 $ipblock->mExpiry
= Block
::getAutoblockExpiry( $this->mTimestamp
);
637 return $ipblock->insert();
641 * Check if a block has expired. Delete it if it is.
644 public function deleteIfExpired() {
645 wfProfileIn( __METHOD__
);
646 if ( $this->isExpired() ) {
647 wfDebug( "Block::deleteIfExpired() -- deleting\n" );
651 wfDebug( "Block::deleteIfExpired() -- not expired\n" );
654 wfProfileOut( __METHOD__
);
659 * Has the block expired?
662 public function isExpired() {
663 wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
664 if ( !$this->mExpiry
) {
667 return wfTimestampNow() > $this->mExpiry
;
672 * Is the block address valid (i.e. not a null string?)
675 public function isValid() {
676 return $this->mAddress
!= '';
680 * Update the timestamp on autoblocks.
682 public function updateTimestamp() {
683 if ( $this->mAuto
) {
684 $this->mTimestamp
= wfTimestamp();
685 $this->mExpiry
= Block
::getAutoblockExpiry( $this->mTimestamp
);
687 $dbw = wfGetDB( DB_MASTER
);
688 $dbw->update( 'ipblocks',
690 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp
),
691 'ipb_expiry' => $dbw->timestamp( $this->mExpiry
),
692 ), array( /* WHERE */
693 'ipb_address' => $this->mAddress
694 ), 'Block::updateTimestamp'
700 * Get the user id of the blocking sysop
704 public function getBy() {
709 * Get the username of the blocking sysop
713 public function getByName() {
714 return $this->mByName
;
718 * Get/set the SELECT ... FOR UPDATE flag
720 public function forUpdate( $x = null ) {
721 return wfSetVar( $this->mForUpdate
, $x );
725 * Get/set a flag determining whether the master is used for reads
727 public function fromMaster( $x = null ) {
728 return wfSetVar( $this->mFromMaster
, $x );
732 * Get the block name, but with autoblocked IPs hidden as per standard privacy policy
735 public function getRedactedName() {
736 if ( $this->mAuto
) {
737 return '#' . $this->mId
;
739 return $this->mAddress
;
744 * Encode expiry for DB
746 * @param $expiry String: timestamp for expiry, or
747 * @param $db Database object
750 public static function encodeExpiry( $expiry, $db ) {
751 if ( $expiry == '' ||
$expiry == Block
::infinity() ) {
752 return Block
::infinity();
754 return $db->timestamp( $expiry );
759 * Decode expiry which has come from the DB
761 * @param $expiry String: Database expiry format
762 * @param $timestampType Requested timestamp format
765 public static function decodeExpiry( $expiry, $timestampType = TS_MW
) {
766 if ( $expiry == '' ||
$expiry == Block
::infinity() ) {
767 return Block
::infinity();
769 return wfTimestamp( $timestampType, $expiry );
774 * Get a timestamp of the expiry for autoblocks
778 public static function getAutoblockExpiry( $timestamp ) {
779 global $wgAutoblockExpiry;
780 return wfTimestamp( TS_MW
, wfTimestamp( TS_UNIX
, $timestamp ) +
$wgAutoblockExpiry );
784 * Gets rid of uneeded numbers in quad-dotted/octet IP strings
785 * For example, 127.111.113.151/24 -> 127.111.113.0/24
786 * @param $range String: IP address to normalize
789 public static function normaliseRange( $range ) {
790 $parts = explode( '/', $range );
791 if ( count( $parts ) == 2 ) {
793 if ( IP
::isIPv6( $range ) && $parts[1] >= 64 && $parts[1] <= 128 ) {
795 $ipint = IP
::toUnsigned6( $parts[0] );
796 # Native 32 bit functions WON'T work here!!!
797 # Convert to a padded binary number
798 $network = wfBaseConvert( $ipint, 10, 2, 128 );
799 # Truncate the last (128-$bits) bits and replace them with zeros
800 $network = str_pad( substr( $network, 0, $bits ), 128, 0, STR_PAD_RIGHT
);
801 # Convert back to an integer
802 $network = wfBaseConvert( $network, 2, 10 );
803 # Reform octet address
804 $newip = IP
::toOctet( $network );
805 $range = "$newip/{$parts[1]}";
807 elseif ( IP
::isIPv4( $range ) && $parts[1] >= 16 && $parts[1] <= 32 ) {
808 $shift = 32 - $parts[1];
809 $ipint = IP
::toUnsigned( $parts[0] );
810 $ipint = $ipint >> $shift << $shift;
811 $newip = long2ip( $ipint );
812 $range = "$newip/{$parts[1]}";
819 * Purge expired blocks from the ipblocks table
821 public static function purgeExpired() {
822 $dbw = wfGetDB( DB_MASTER
);
823 $dbw->delete( 'ipblocks', array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__
);
827 * Get a value to insert into expiry field of the database when infinite expiry
828 * is desired. In principle this could be DBMS-dependant, but currently all
829 * supported DBMS's support the string "infinity", so we just use that.
833 public static function infinity() {
834 # This is a special keyword for timestamps in PostgreSQL, and
835 # works with CHAR(14) as well because "i" sorts after all numbers.
840 * Convert a DB-encoded expiry into a real string that humans can read.
842 * @param $encoded_expiry String: Database encoded expiry time
843 * @return Html-escaped String
845 public static function formatExpiry( $encoded_expiry ) {
848 if ( is_null( $msg ) ) {
850 $keys = array( 'infiniteblock', 'expiringblock' );
851 foreach ( $keys as $key ) {
852 $msg[$key] = wfMsgHtml( $key );
856 $expiry = Block
::decodeExpiry( $encoded_expiry );
857 if ( $expiry == 'infinity' ) {
858 $expirystr = $msg['infiniteblock'];
861 $expiredatestr = htmlspecialchars( $wgLang->date( $expiry, true ) );
862 $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) );
863 $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) );
869 * Convert a typed-in expiry time into something we can put into the database.
870 * @param $expiry_input String: whatever was typed into the form
871 * @return String: more database friendly
873 public static function parseExpiryInput( $expiry_input ) {
874 if ( $expiry_input == 'infinite' ||
$expiry_input == 'indefinite' ) {
875 $expiry = 'infinity';
877 $expiry = strtotime( $expiry_input );
879 if ( $expiry < 0 ||
$expiry === false ) {