$this->mAuto = $auto;
$this->isHardblock( !$anonOnly );
$this->prevents( 'createaccount', $createAccount );
- if ( $expiry == 'infinity' || $expiry == wfGetDB( DB_SLAVE )->getInfinity() ) {
- $this->mExpiry = 'infinity';
- } else {
- $this->mExpiry = wfTimestamp( TS_MW, $expiry );
- }
+ $this->mExpiry = wfGetDB( DB_SLAVE )->decodeExpiry( $expiry );
$this->isAutoblocking( $enableAutoblock );
$this->mHideName = $hideName;
$this->prevents( 'sendemail', $blockEmail );
$this->mParentBlockId = $row->ipb_parent_block_id;
// I wish I didn't have to do this
- $db = wfGetDB( DB_SLAVE );
- if ( $row->ipb_expiry == $db->getInfinity() ) {
- $this->mExpiry = 'infinity';
- } else {
- $this->mExpiry = wfTimestamp( TS_MW, $row->ipb_expiry );
- }
+ $this->mExpiry = wfGetDB( DB_SLAVE )->decodeExpiry( $row->ipb_expiry );
$this->isHardblock( !$row->ipb_anon_only );
$this->isAutoblocking( $row->ipb_enable_autoblock );
$value = $this->mExpirySelection[$action];
}
if ( wfIsInfinity( $value ) ) {
- $time = wfGetDB( DB_SLAVE )->getInfinity();
+ $time = 'infinity';
} else {
$unix = strtotime( $value );
if ( $row['permission'] == 'autoconfirmed' ) {
$row['permission'] = 'editsemiprotected'; // B/C
}
+ $row['expiry'] = $dbr->decodeExpiry( $row['expiry'] );
}
$this->mTitleProtection = $row;
}
* false.
*/
public function getCascadeProtectionSources( $getPages = true ) {
- global $wgContLang;
$pagerestrictions = array();
if ( $this->mCascadeSources !== null && $getPages ) {
$now = wfTimestampNow();
foreach ( $res as $row ) {
- $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
+ $expiry = $dbr->decodeExpiry( $row->pr_expiry );
if ( $expiry > $now ) {
if ( $getPages ) {
$page_id = $row->pr_page;
* restrictions from page table (pre 1.10)
*/
public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
- global $wgContLang;
$dbr = wfGetDB( DB_SLAVE );
$restrictionTypes = $this->getRestrictionTypes();
foreach ( $restrictionTypes as $type ) {
$this->mRestrictions[$type] = array();
- $this->mRestrictionsExpiry[$type] = $wgContLang->formatExpiry( '', TS_MW );
+ $this->mRestrictionsExpiry[$type] = 'infinity';
}
$this->mCascadeRestriction = false;
// This code should be refactored, now that it's being used more generally,
// But I don't really see any harm in leaving it in Block for now -werdna
- $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
+ $expiry = $dbr->decodeExpiry( $row->pr_expiry );
// Only apply the restrictions if they haven't expired!
if ( !$expiry || $expiry > $now ) {
* restrictions from page table (pre 1.10)
*/
public function loadRestrictions( $oldFashionedRestrictions = null ) {
- global $wgContLang;
if ( !$this->mRestrictionsLoaded ) {
+ $dbr = wfGetDB( DB_SLAVE );
if ( $this->exists() ) {
- $dbr = wfGetDB( DB_SLAVE );
-
$res = $dbr->select(
'page_restrictions',
array( 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ),
if ( $title_protection ) {
$now = wfTimestampNow();
- $expiry = $wgContLang->formatExpiry( $title_protection['expiry'], TS_MW );
+ $expiry = $dbr->decodeExpiry( $title_protection['expiry'] );
if ( !$expiry || $expiry > $now ) {
// Apply the restrictions
$this->mTitleProtection = false;
}
} else {
- $this->mRestrictionsExpiry['create'] = $wgContLang->formatExpiry( '', TS_MW );
+ $this->mRestrictionsExpiry['create'] = 'infinity';
}
$this->mRestrictionsLoaded = true;
}
* of success. If it fails, the result will specify the nature of the error.
*/
public function execute() {
+ global $wgContLang;
+
$user = $this->getUser();
$params = $this->extractRequestParams();
$res['user'] = $params['user'];
$res['userID'] = $target instanceof User ? $target->getId() : 0;
- $block = Block::newFromTarget( $target );
+ $block = Block::newFromTarget( $target, null, true );
if ( $block instanceof Block ) {
- $res['expiry'] = $block->mExpiry == $this->getDB()->getInfinity()
- ? 'infinite'
- : wfTimestamp( TS_ISO_8601, $block->mExpiry );
+ $res['expiry'] = $wgContLang->formatExpiry( $block->mExpiry, TS_ISO_8601, 'infinite' );
$res['id'] = $block->getId();
} else {
# should be unreachable
*/
class ApiProtect extends ApiBase {
public function execute() {
+ global $wgContLang;
+
$params = $this->extractRequestParams();
$pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
}
if ( wfIsInfinity( $expiry[$i] ) ) {
- $expiryarray[$p[0]] = $db->getInfinity();
+ $expiryarray[$p[0]] = 'infinity';
} else {
$exp = strtotime( $expiry[$i] );
if ( $exp < 0 || !$exp ) {
}
$resultProtections[] = array(
$p[0] => $protections[$p[0]],
- 'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity()
- ? 'infinite'
- : wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] )
- )
+ 'expiry' => $wgContLang->formatExpiry( $expiryarray[$p[0]], TS_ISO_8601, 'infinite' ),
);
}
$vals2['flags'] = isset( $params[$flagsKey] ) ? $params[$flagsKey] : '';
// Indefinite blocks have no expiry time
- if ( SpecialBlock::parseExpiryInput( $params[$durationKey] ) !== wfGetDB( DB_SLAVE )->getInfinity() ) {
+ if ( SpecialBlock::parseExpiryInput( $params[$durationKey] ) !== 'infinity' ) {
$vals2['expiry'] = wfTimestamp( TS_ISO_8601,
strtotime( $params[$durationKey], wfTimestamp( TS_UNIX, $ts ) ) );
}
}
protected function getCurrentUserInfo() {
+ global $wgContLang;
+
$user = $this->getUser();
$result = $this->getResult();
$vals = array();
$vals['blockedbyid'] = $block->getBy();
$vals['blockreason'] = $user->blockedFor();
$vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp );
- $vals['blockexpiry'] = $block->getExpiry() === 'infinity'
- ? 'infinite'
- : wfTimestamp( TS_ISO_8601, $block->getExpiry() );
+ $vals['blockexpiry'] = $wgContLang->formatExpiry(
+ $block->getExpiry(), TS_ISO_8601, 'infinite'
+ );
}
}
* @return string
*/
public function decodeExpiry( $expiry, $format = TS_MW ) {
- return ( $expiry == '' || $expiry == $this->getInfinity() )
+ return ( $expiry == '' || $expiry == 'infinity' || $expiry == $this->getInfinity() )
? 'infinity'
: wfTimestamp( $format, $expiry );
}
$dbw = wfGetDB( DB_MASTER );
foreach ( $restrictionTypes as $action ) {
- if ( !isset( $expiry[$action] ) ) {
- $expiry[$action] = $dbw->getInfinity();
+ if ( !isset( $expiry[$action] ) || $expiry[$action] === $dbw->getInfinity() ) {
+ $expiry[$action] = 'infinity';
}
if ( !isset( $limit[$action] ) ) {
$limit[$action] = '';
*/
protected function formatExpiry( $expiry ) {
global $wgContLang;
- $dbr = wfGetDB( DB_SLAVE );
- $encodedExpiry = $dbr->encodeExpiry( $expiry );
- if ( $encodedExpiry != 'infinity' ) {
+ if ( $expiry != 'infinity' ) {
return wfMessage(
'protect-expiring',
$wgContLang->timeanddate( $expiry, false, false ),
* Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
* ("24 May 2034", etc), into an absolute timestamp we can put into the database.
* @param string $expiry Whatever was typed into the form
- * @return string Timestamp or "infinity" string for the DB implementation
+ * @return string Timestamp or 'infinity'
*/
public static function parseExpiryInput( $expiry ) {
- static $infinity;
- if ( $infinity == null ) {
- $infinity = wfGetDB( DB_SLAVE )->getInfinity();
- }
-
if ( wfIsInfinity( $expiry ) ) {
- $expiry = $infinity;
+ $expiry = 'infinity';
} else {
$expiry = strtotime( $expiry );
*/
function formatRow( $row ) {
- static $infinity = null;
-
- if ( is_null( $infinity ) ) {
- $infinity = wfGetDB( DB_SLAVE )->getInfinity();
- }
-
$title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
if ( !$title ) {
$lang = $this->getLanguage();
$expiry = strlen( $row->pt_expiry ) ?
$lang->formatExpiry( $row->pt_expiry, TS_MW ) :
- $infinity;
+ 'infinity';
- if ( $expiry != $infinity ) {
+ if ( $expiry !== 'infinity' ) {
$user = $this->getUser();
$description_items[] = $this->msg(
'protect-expiring-local',
/**
* Decode an expiry (block, protection, etc) which has come from the DB
*
- * @todo FIXME: why are we returnings DBMS-dependent strings???
- *
* @param string $expiry Database expiry String
* @param bool|int $format True to process using language functions, or TS_ constant
* to return the expiry in a given timestamp
+ * @param string $inifinity If $format is not true, use this string for infinite expiry
* @return string
* @since 1.18
*/
- public function formatExpiry( $expiry, $format = true ) {
- static $infinity;
- if ( $infinity === null ) {
- $infinity = wfGetDB( DB_SLAVE )->getInfinity();
+ public function formatExpiry( $expiry, $format = true, $infinity = 'infinity' ) {
+ static $dbInfinity;
+ if ( $dbInfinity === null ) {
+ $dbInfinity = wfGetDB( DB_SLAVE )->getInfinity();
}
- if ( $expiry == '' || $expiry == $infinity ) {
+ if ( $expiry == '' || $expiry === 'infinity' || $expiry == $dbInfinity ) {
return $format === true
? $this->getMessageFromDB( 'infiniteblock' )
: $infinity;
$this->setTitle( NS_MAIN, "test page" );
$this->title->mTitleProtection['permission'] = '';
$this->title->mTitleProtection['user'] = $this->user->getID();
- $this->title->mTitleProtection['expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
+ $this->title->mTitleProtection['expiry'] = 'infinity';
$this->title->mTitleProtection['reason'] = 'test';
$this->title->mCascadeRestriction = false;