00001 <?php
00016 class Block {
00017 var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry,
00018 $mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName,
00019 $mBlockEmail, $mByName, $mAngryAutoblock, $mAllowUsertalk;
00020 var $mNetworkBits, $mIntegerAddr, $mForUpdate, $mFromMaster;
00021
00022 const EB_KEEP_EXPIRED = 1;
00023 const EB_FOR_UPDATE = 2;
00024 const EB_RANGE_ONLY = 4;
00025
00026 function __construct( $address = '', $user = 0, $by = 0, $reason = '',
00027 $timestamp = '' , $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
00028 $hideName = 0, $blockEmail = 0, $allowUsertalk = 0 )
00029 {
00030 $this->mId = 0;
00031 # Expand valid IPv6 addresses
00032 $address = IP::sanitizeIP( $address );
00033 $this->mAddress = $address;
00034 $this->mUser = $user;
00035 $this->mBy = $by;
00036 $this->mReason = $reason;
00037 $this->mTimestamp = wfTimestamp(TS_MW,$timestamp);
00038 $this->mAuto = $auto;
00039 $this->mAnonOnly = $anonOnly;
00040 $this->mCreateAccount = $createAccount;
00041 $this->mExpiry = self::decodeExpiry( $expiry );
00042 $this->mEnableAutoblock = $enableAutoblock;
00043 $this->mHideName = $hideName;
00044 $this->mBlockEmail = $blockEmail;
00045 $this->mAllowUsertalk = $allowUsertalk;
00046 $this->mForUpdate = false;
00047 $this->mFromMaster = false;
00048 $this->mByName = false;
00049 $this->mAngryAutoblock = false;
00050 $this->initialiseRange();
00051 }
00052
00063 public static function newFromDB( $address, $user = 0, $killExpired = true ) {
00064 $block = new Block;
00065 $block->load( $address, $user, $killExpired );
00066 if ( $block->isValid() ) {
00067 return $block;
00068 } else {
00069 return null;
00070 }
00071 }
00072
00079 public static function newFromID( $id ) {
00080 $dbr = wfGetDB( DB_SLAVE );
00081 $res = $dbr->resultObject( $dbr->select( 'ipblocks', '*',
00082 array( 'ipb_id' => $id ), __METHOD__ ) );
00083 $block = new Block;
00084 if ( $block->loadFromResult( $res ) ) {
00085 return $block;
00086 } else {
00087 return null;
00088 }
00089 }
00090
00096 public function equals( Block $block ) {
00097 return (
00098 $this->mAddress == $block->mAddress
00099 && $this->mUser == $block->mUser
00100 && $this->mAuto == $block->mAuto
00101 && $this->mAnonOnly == $block->mAnonOnly
00102 && $this->mCreateAccount == $block->mCreateAccount
00103 && $this->mExpiry == $block->mExpiry
00104 && $this->mEnableAutoblock == $block->mEnableAutoblock
00105 && $this->mHideName == $block->mHideName
00106 && $this->mBlockEmail == $block->mBlockEmail
00107 && $this->mAllowUsertalk == $block->mAllowUsertalk
00108 && $this->mReason == $block->mReason
00109 );
00110 }
00111
00116 public function clear() {
00117 $this->mAddress = $this->mReason = $this->mTimestamp = '';
00118 $this->mId = $this->mAnonOnly = $this->mCreateAccount =
00119 $this->mEnableAutoblock = $this->mAuto = $this->mUser =
00120 $this->mBy = $this->mHideName = $this->mBlockEmail = $this->mAllowUsertalk = 0;
00121 $this->mByName = false;
00122 }
00123
00131 protected function &getDBOptions( &$options ) {
00132 global $wgAntiLockFlags;
00133 if ( $this->mForUpdate || $this->mFromMaster ) {
00134 $db = wfGetDB( DB_MASTER );
00135 if ( !$this->mForUpdate || ($wgAntiLockFlags & ALF_NO_BLOCK_LOCK) ) {
00136 $options = array();
00137 } else {
00138 $options = array( 'FOR UPDATE' );
00139 }
00140 } else {
00141 $db = wfGetDB( DB_SLAVE );
00142 $options = array();
00143 }
00144 return $db;
00145 }
00146
00156 public function load( $address = '', $user = 0, $killExpired = true ) {
00157 wfDebug( "Block::load: '$address', '$user', $killExpired\n" );
00158
00159 $options = array();
00160 $db =& $this->getDBOptions( $options );
00161
00162 if ( 0 == $user && $address == '' ) {
00163 # Invalid user specification, not blocked
00164 $this->clear();
00165 return false;
00166 }
00167
00168 # Try user block
00169 if ( $user ) {
00170 $res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ),
00171 __METHOD__, $options ) );
00172 if ( $this->loadFromResult( $res, $killExpired ) ) {
00173 return true;
00174 }
00175 }
00176
00177 # Try IP block
00178 # TODO: improve performance by merging this query with the autoblock one
00179 # Slightly tricky while handling killExpired as well
00180 if ( $address ) {
00181 $conds = array( 'ipb_address' => $address, 'ipb_auto' => 0 );
00182 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
00183 if ( $this->loadFromResult( $res, $killExpired ) ) {
00184 if ( $user && $this->mAnonOnly ) {
00185 # Block is marked anon-only
00186 # Whitelist this IP address against autoblocks and range blocks
00187 # (but not account creation blocks -- bug 13611)
00188 if( !$this->mCreateAccount ) {
00189 $this->clear();
00190 }
00191 return false;
00192 } else {
00193 return true;
00194 }
00195 }
00196 }
00197
00198 # Try range block
00199 if ( $this->loadRange( $address, $killExpired, $user ) ) {
00200 if ( $user && $this->mAnonOnly ) {
00201 # Respect account creation blocks on logged-in users -- bug 13611
00202 if( !$this->mCreateAccount ) {
00203 $this->clear();
00204 }
00205 return false;
00206 } else {
00207 return true;
00208 }
00209 }
00210
00211 # Try autoblock
00212 if ( $address ) {
00213 $conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 );
00214 if ( $user ) {
00215 $conds['ipb_anon_only'] = 0;
00216 }
00217 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
00218 if ( $this->loadFromResult( $res, $killExpired ) ) {
00219 return true;
00220 }
00221 }
00222
00223 # Give up
00224 $this->clear();
00225 return false;
00226 }
00227
00235 protected function loadFromResult( ResultWrapper $res, $killExpired = true ) {
00236 $ret = false;
00237 if ( 0 != $res->numRows() ) {
00238 # Get first block
00239 $row = $res->fetchObject();
00240 $this->initFromRow( $row );
00241
00242 if ( $killExpired ) {
00243 # If requested, delete expired rows
00244 do {
00245 $killed = $this->deleteIfExpired();
00246 if ( $killed ) {
00247 $row = $res->fetchObject();
00248 if ( $row ) {
00249 $this->initFromRow( $row );
00250 }
00251 }
00252 } while ( $killed && $row );
00253
00254 # If there were any left after the killing finished, return true
00255 if ( $row ) {
00256 $ret = true;
00257 }
00258 } else {
00259 $ret = true;
00260 }
00261 }
00262 $res->free();
00263 return $ret;
00264 }
00265
00275 public function loadRange( $address, $killExpired = true, $user = 0 ) {
00276 $iaddr = IP::toHex( $address );
00277 if ( $iaddr === false ) {
00278 # Invalid address
00279 return false;
00280 }
00281
00282 # Only scan ranges which start in this /16, this improves search speed
00283 # Blocks should not cross a /16 boundary.
00284 $range = substr( $iaddr, 0, 4 );
00285
00286 $options = array();
00287 $db =& $this->getDBOptions( $options );
00288 $conds = array(
00289 "ipb_range_start LIKE '$range%'",
00290 "ipb_range_start <= '$iaddr'",
00291 "ipb_range_end >= '$iaddr'"
00292 );
00293
00294 if ( $user ) {
00295 $conds['ipb_anon_only'] = 0;
00296 }
00297
00298 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
00299 $success = $this->loadFromResult( $res, $killExpired );
00300 return $success;
00301 }
00302
00309 public function initFromRow( $row ) {
00310 $this->mAddress = $row->ipb_address;
00311 $this->mReason = $row->ipb_reason;
00312 $this->mTimestamp = wfTimestamp(TS_MW,$row->ipb_timestamp);
00313 $this->mUser = $row->ipb_user;
00314 $this->mBy = $row->ipb_by;
00315 $this->mAuto = $row->ipb_auto;
00316 $this->mAnonOnly = $row->ipb_anon_only;
00317 $this->mCreateAccount = $row->ipb_create_account;
00318 $this->mEnableAutoblock = $row->ipb_enable_autoblock;
00319 $this->mBlockEmail = $row->ipb_block_email;
00320 $this->mAllowUsertalk = $row->ipb_allow_usertalk;
00321 $this->mHideName = $row->ipb_deleted;
00322 $this->mId = $row->ipb_id;
00323 $this->mExpiry = self::decodeExpiry( $row->ipb_expiry );
00324 if ( isset( $row->user_name ) ) {
00325 $this->mByName = $row->user_name;
00326 } else {
00327 $this->mByName = $row->ipb_by_text;
00328 }
00329 $this->mRangeStart = $row->ipb_range_start;
00330 $this->mRangeEnd = $row->ipb_range_end;
00331 }
00332
00337 protected function initialiseRange() {
00338 $this->mRangeStart = '';
00339 $this->mRangeEnd = '';
00340
00341 if ( $this->mUser == 0 ) {
00342 list( $this->mRangeStart, $this->mRangeEnd ) = IP::parseRange( $this->mAddress );
00343 }
00344 }
00345
00351 public function delete() {
00352 if ( wfReadOnly() ) {
00353 return false;
00354 }
00355 if ( !$this->mId ) {
00356 throw new MWException( "Block::delete() now requires that the mId member be filled\n" );
00357 }
00358
00359 $dbw = wfGetDB( DB_MASTER );
00360 $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId ), __METHOD__ );
00361 return $dbw->affectedRows() > 0;
00362 }
00363
00370 public function insert() {
00371 wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
00372 $dbw = wfGetDB( DB_MASTER );
00373
00374 $this->validateBlockParams();
00375 $this->initialiseRange();
00376
00377 # Don't collide with expired blocks
00378 Block::purgeExpired();
00379
00380 $ipb_id = $dbw->nextSequenceValue('ipblocks_ipb_id_val');
00381 $dbw->insert( 'ipblocks',
00382 array(
00383 'ipb_id' => $ipb_id,
00384 'ipb_address' => $this->mAddress,
00385 'ipb_user' => $this->mUser,
00386 'ipb_by' => $this->mBy,
00387 'ipb_by_text' => $this->mByName,
00388 'ipb_reason' => $this->mReason,
00389 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp),
00390 'ipb_auto' => $this->mAuto,
00391 'ipb_anon_only' => $this->mAnonOnly,
00392 'ipb_create_account' => $this->mCreateAccount,
00393 'ipb_enable_autoblock' => $this->mEnableAutoblock,
00394 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ),
00395 'ipb_range_start' => $this->mRangeStart,
00396 'ipb_range_end' => $this->mRangeEnd,
00397 'ipb_deleted' => $this->mHideName,
00398 'ipb_block_email' => $this->mBlockEmail,
00399 'ipb_allow_usertalk' => $this->mAllowUsertalk
00400 ), 'Block::insert', array( 'IGNORE' )
00401 );
00402 $affected = $dbw->affectedRows();
00403
00404 if ($affected)
00405 $this->doRetroactiveAutoblock();
00406
00407 return (bool)$affected;
00408 }
00409
00414 public function update() {
00415 wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" );
00416 $dbw = wfGetDB( DB_MASTER );
00417
00418 $this->validateBlockParams();
00419
00420 $dbw->update( 'ipblocks',
00421 array(
00422 'ipb_user' => $this->mUser,
00423 'ipb_by' => $this->mBy,
00424 'ipb_by_text' => $this->mByName,
00425 'ipb_reason' => $this->mReason,
00426 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp),
00427 'ipb_auto' => $this->mAuto,
00428 'ipb_anon_only' => $this->mAnonOnly,
00429 'ipb_create_account' => $this->mCreateAccount,
00430 'ipb_enable_autoblock' => $this->mEnableAutoblock,
00431 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ),
00432 'ipb_range_start' => $this->mRangeStart,
00433 'ipb_range_end' => $this->mRangeEnd,
00434 'ipb_deleted' => $this->mHideName,
00435 'ipb_block_email' => $this->mBlockEmail,
00436 'ipb_allow_usertalk' => $this->mAllowUsertalk ),
00437 array( 'ipb_id' => $this->mId ),
00438 'Block::update' );
00439
00440 return $dbw->affectedRows();
00441 }
00442
00447 protected function validateBlockParams() {
00448 # Unset ipb_anon_only for user blocks, makes no sense
00449 if ( $this->mUser ) {
00450 $this->mAnonOnly = 0;
00451 }
00452
00453 # Unset ipb_enable_autoblock for IP blocks, makes no sense
00454 if ( !$this->mUser ) {
00455 $this->mEnableAutoblock = 0;
00456 $this->mBlockEmail = 0;
00457 }
00458
00459 if( !$this->mByName ) {
00460 if( $this->mBy ) {
00461 $this->mByName = User::whoIs( $this->mBy );
00462 } else {
00463 global $wgUser;
00464 $this->mByName = $wgUser->getName();
00465 }
00466 }
00467 }
00468
00469
00476 public function doRetroactiveAutoblock() {
00477 $dbr = wfGetDB( DB_SLAVE );
00478 #If autoblock is enabled, autoblock the LAST IP used
00479 # - stolen shamelessly from CheckUser_body.php
00480
00481 if ($this->mEnableAutoblock && $this->mUser) {
00482 wfDebug("Doing retroactive autoblocks for " . $this->mAddress . "\n");
00483
00484 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
00485 $conds = array( 'rc_user_text' => $this->mAddress );
00486
00487 if ($this->mAngryAutoblock) {
00488
00489 $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - (7*86400) ) );
00490 $options['LIMIT'] = 5;
00491 } else {
00492
00493 $options['LIMIT'] = 1;
00494 }
00495
00496 $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
00497 __METHOD__ , $options);
00498
00499 if ( !$dbr->numRows( $res ) ) {
00500 #No results, don't autoblock anything
00501 wfDebug("No IP found to retroactively autoblock\n");
00502 } else {
00503 while ( $row = $dbr->fetchObject( $res ) ) {
00504 if ( $row->rc_ip )
00505 $this->doAutoblock( $row->rc_ip );
00506 }
00507 }
00508 }
00509 }
00510
00517 public static function isWhitelistedFromAutoblocks( $ip ) {
00518 global $wgMemc;
00519
00520
00521
00522 $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
00523 $lines = $wgMemc->get( $key );
00524 if ( !$lines ) {
00525 $lines = explode( "\n", wfMsgForContentNoTrans( 'autoblock_whitelist' ) );
00526 $wgMemc->set( $key, $lines, 3600 * 24 );
00527 }
00528
00529 wfDebug("Checking the autoblock whitelist..\n");
00530
00531 foreach( $lines as $line ) {
00532 # List items only
00533 if ( substr( $line, 0, 1 ) !== '*' ) {
00534 continue;
00535 }
00536
00537 $wlEntry = substr($line, 1);
00538 $wlEntry = trim($wlEntry);
00539
00540 wfDebug("Checking $ip against $wlEntry...");
00541
00542 # Is the IP in this range?
00543 if (IP::isInRange( $ip, $wlEntry )) {
00544 wfDebug(" IP $ip matches $wlEntry, not autoblocking\n");
00545 return true;
00546 } else {
00547 wfDebug( " No match\n" );
00548 }
00549 }
00550
00551 return false;
00552 }
00553
00561 public function doAutoblock( $autoblockIP, $justInserted = false ) {
00562 # If autoblocks are disabled, go away.
00563 if ( !$this->mEnableAutoblock ) {
00564 return;
00565 }
00566
00567 # Check for presence on the autoblock whitelist
00568 if (Block::isWhitelistedFromAutoblocks($autoblockIP)) {
00569 return;
00570 }
00571
00572 ## Allow hooks to cancel the autoblock.
00573 if (!wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) )) {
00574 wfDebug( "Autoblock aborted by hook.\n" );
00575 return false;
00576 }
00577
00578 # It's okay to autoblock. Go ahead and create/insert the block.
00579
00580 $ipblock = Block::newFromDB( $autoblockIP );
00581 if ( $ipblock ) {
00582 # If the user is already blocked. Then check if the autoblock would
00583 # exceed the user block. If it would exceed, then do nothing, else
00584 # prolong block time
00585 if ($this->mExpiry &&
00586 ($this->mExpiry < Block::getAutoblockExpiry($ipblock->mTimestamp))) {
00587 return;
00588 }
00589 # Just update the timestamp
00590 if ( !$justInserted ) {
00591 $ipblock->updateTimestamp();
00592 }
00593 return;
00594 } else {
00595 $ipblock = new Block;
00596 }
00597
00598 # Make a new block object with the desired properties
00599 wfDebug( "Autoblocking {$this->mAddress}@" . $autoblockIP . "\n" );
00600 $ipblock->mAddress = $autoblockIP;
00601 $ipblock->mUser = 0;
00602 $ipblock->mBy = $this->mBy;
00603 $ipblock->mByName = $this->mByName;
00604 $ipblock->mReason = wfMsgForContent( 'autoblocker', $this->mAddress, $this->mReason );
00605 $ipblock->mTimestamp = wfTimestampNow();
00606 $ipblock->mAuto = 1;
00607 $ipblock->mCreateAccount = $this->mCreateAccount;
00608 # Continue suppressing the name if needed
00609 $ipblock->mHideName = $this->mHideName;
00610 $ipblock->mAllowUsertalk = $this->mAllowUsertalk;
00611 # If the user is already blocked with an expiry date, we don't
00612 # want to pile on top of that!
00613 if($this->mExpiry) {
00614 $ipblock->mExpiry = min ( $this->mExpiry, Block::getAutoblockExpiry( $this->mTimestamp ));
00615 } else {
00616 $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
00617 }
00618 # Insert it
00619 return $ipblock->insert();
00620 }
00621
00626 public function deleteIfExpired() {
00627 $fname = 'Block::deleteIfExpired';
00628 wfProfileIn( $fname );
00629 if ( $this->isExpired() ) {
00630 wfDebug( "Block::deleteIfExpired() -- deleting\n" );
00631 $this->delete();
00632 $retVal = true;
00633 } else {
00634 wfDebug( "Block::deleteIfExpired() -- not expired\n" );
00635 $retVal = false;
00636 }
00637 wfProfileOut( $fname );
00638 return $retVal;
00639 }
00640
00645 public function isExpired() {
00646 wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
00647 if ( !$this->mExpiry ) {
00648 return false;
00649 } else {
00650 return wfTimestampNow() > $this->mExpiry;
00651 }
00652 }
00653
00658 public function isValid() {
00659 return $this->mAddress != '';
00660 }
00661
00665 public function updateTimestamp() {
00666 if ( $this->mAuto ) {
00667 $this->mTimestamp = wfTimestamp();
00668 $this->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
00669
00670 $dbw = wfGetDB( DB_MASTER );
00671 $dbw->update( 'ipblocks',
00672 array(
00673 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp),
00674 'ipb_expiry' => $dbw->timestamp($this->mExpiry),
00675 ), array(
00676 'ipb_address' => $this->mAddress
00677 ), 'Block::updateTimestamp'
00678 );
00679 }
00680 }
00681
00687 public function getBy() {
00688 return $this->mBy;
00689 }
00690
00696 public function getByName() {
00697 return $this->mByName;
00698 }
00699
00703 public function forUpdate( $x = NULL ) {
00704 return wfSetVar( $this->mForUpdate, $x );
00705 }
00706
00710 public function fromMaster( $x = NULL ) {
00711 return wfSetVar( $this->mFromMaster, $x );
00712 }
00713
00718 public function getRedactedName() {
00719 if ( $this->mAuto ) {
00720 return '#' . $this->mId;
00721 } else {
00722 return $this->mAddress;
00723 }
00724 }
00725
00733 public static function encodeExpiry( $expiry, $db ) {
00734 if ( $expiry == '' || $expiry == Block::infinity() ) {
00735 return Block::infinity();
00736 } else {
00737 return $db->timestamp( $expiry );
00738 }
00739 }
00740
00748 public static function decodeExpiry( $expiry, $timestampType = TS_MW ) {
00749 if ( $expiry == '' || $expiry == Block::infinity() ) {
00750 return Block::infinity();
00751 } else {
00752 return wfTimestamp( $timestampType, $expiry );
00753 }
00754 }
00755
00761 public static function getAutoblockExpiry( $timestamp ) {
00762 global $wgAutoblockExpiry;
00763 return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry );
00764 }
00765
00772 public static function normaliseRange( $range ) {
00773 $parts = explode( '/', $range );
00774 if ( count( $parts ) == 2 ) {
00775
00776 if ( IP::isIPv6($range) && $parts[1] >= 64 && $parts[1] <= 128 ) {
00777 $bits = $parts[1];
00778 $ipint = IP::toUnsigned6( $parts[0] );
00779 # Native 32 bit functions WONT work here!!!
00780 # Convert to a padded binary number
00781 $network = wfBaseConvert( $ipint, 10, 2, 128 );
00782 # Truncate the last (128-$bits) bits and replace them with zeros
00783 $network = str_pad( substr( $network, 0, $bits ), 128, 0, STR_PAD_RIGHT );
00784 # Convert back to an integer
00785 $network = wfBaseConvert( $network, 2, 10 );
00786 # Reform octet address
00787 $newip = IP::toOctet( $network );
00788 $range = "$newip/{$parts[1]}";
00789 }
00790 else if ( IP::isIPv4($range) && $parts[1] >= 16 && $parts[1] <= 32 ) {
00791 $shift = 32 - $parts[1];
00792 $ipint = IP::toUnsigned( $parts[0] );
00793 $ipint = $ipint >> $shift << $shift;
00794 $newip = long2ip( $ipint );
00795 $range = "$newip/{$parts[1]}";
00796 }
00797 }
00798 return $range;
00799 }
00800
00804 public static function purgeExpired() {
00805 $dbw = wfGetDB( DB_MASTER );
00806 $dbw->delete( 'ipblocks', array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
00807 }
00808
00816 public static function infinity() {
00817 # This is a special keyword for timestamps in PostgreSQL, and
00818 # works with CHAR(14) as well because "i" sorts after all numbers.
00819 return 'infinity';
00820 }
00821
00828 public static function formatExpiry( $encoded_expiry ) {
00829 static $msg = null;
00830
00831 if( is_null( $msg ) ) {
00832 $msg = array();
00833 $keys = array( 'infiniteblock', 'expiringblock' );
00834 foreach( $keys as $key ) {
00835 $msg[$key] = wfMsgHtml( $key );
00836 }
00837 }
00838
00839 $expiry = Block::decodeExpiry( $encoded_expiry );
00840 if ($expiry == 'infinity') {
00841 $expirystr = $msg['infiniteblock'];
00842 } else {
00843 global $wgLang;
00844 $expiretimestr = $wgLang->timeanddate( $expiry, true );
00845 $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array($expiretimestr) );
00846 }
00847 return $expirystr;
00848 }
00849
00855 public static function parseExpiryInput( $expiry_input ) {
00856 if ( $expiry_input == 'infinite' || $expiry_input == 'indefinite' ) {
00857 $expiry = 'infinity';
00858 } else {
00859 $expiry = strtotime( $expiry_input );
00860 if ($expiry < 0 || $expiry === false) {
00861 return false;
00862 }
00863 }
00864 return $expiry;
00865 }
00866
00867 }