if ( !isset( $expiry[$action] ) )
$expiry[$action] = Block::infinity();
- $encodedExpiry[$action] = Block::encodeExpiry( $expiry[$action], $dbw );
+ $encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] );
if ( $restrictions != '' ) {
$protect_description .= "[$action=$restrictions] (";
if ( $encodedExpiry[$action] != 'infinity' ) {
$this->mAuto = $auto;
$this->mAnonOnly = $anonOnly;
$this->mCreateAccount = $createAccount;
- $this->mExpiry = self::decodeExpiry( $expiry );
+ $this->mExpiry = $expiry;
$this->mEnableAutoblock = $enableAutoblock;
$this->mHideName = $hideName;
$this->mBlockEmail = $blockEmail;
$this->mAllowUsertalk = $row->ipb_allow_usertalk;
$this->mHideName = $row->ipb_deleted;
$this->mId = $row->ipb_id;
- $this->mExpiry = self::decodeExpiry( $row->ipb_expiry );
+ $this->mExpiry = $row->ipb_expiry;
if ( isset( $row->user_name ) ) {
$this->mByName = $row->user_name;
'ipb_anon_only' => $this->mAnonOnly,
'ipb_create_account' => $this->mCreateAccount,
'ipb_enable_autoblock' => $this->mEnableAutoblock,
- 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ),
+ 'ipb_expiry' => $dbw->encodeExpiry( $this->mExpiry ),
'ipb_range_start' => $this->mRangeStart,
'ipb_range_end' => $this->mRangeEnd,
'ipb_deleted' => intval( $this->mHideName ), // typecast required for SQLite
'ipb_anon_only' => $this->mAnonOnly,
'ipb_create_account' => $this->mCreateAccount,
'ipb_enable_autoblock' => $this->mEnableAutoblock,
- 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ),
+ 'ipb_expiry' => $dbw->encodeExpiry( $this->mExpiry ),
'ipb_range_start' => $this->mRangeStart,
'ipb_range_end' => $this->mRangeEnd,
'ipb_deleted' => $this->mHideName,
* @param $expiry String: timestamp for expiry, or
* @param $db Database object
* @return String
+ * @deprecated since 1.18; use $dbw->encodeExpiry() instead
*/
public static function encodeExpiry( $expiry, $db ) {
if ( $expiry == '' || $expiry == Block::infinity() ) {
* @param $expiry String: Database expiry format
* @param $timestampType Requested timestamp format
* @return String
+ * @deprecated since 1.18; use $wgLang->decodeExpiry() instead
*/
public static function decodeExpiry( $expiry, $timestampType = TS_MW ) {
- if ( $expiry == '' || $expiry == Block::infinity() ) {
- return Block::infinity();
- } else {
- return wfTimestamp( $timestampType, $expiry );
- }
+ global $wgContLang;
+ return $wgContLang->formatExpiry( $expiry, $timestampType );
}
/**
*
* @param $encoded_expiry String: Database encoded expiry time
* @return Html-escaped String
+ * @deprecated since 1.18; use $wgLang->formatExpiry() instead
*/
public static function formatExpiry( $encoded_expiry ) {
+ global $wgContLang;
static $msg = null;
if ( is_null( $msg ) ) {
}
}
- $expiry = self::decodeExpiry( $encoded_expiry );
+ $expiry = $wgContLang->formatExpiry( $encoded_expiry, TS_MW );
if ( $expiry == self::infinity() ) {
$expirystr = $msg['infiniteblock'];
} else {
$blockid = $wgUser->mBlock->mId;
$blockExpiry = $wgUser->mBlock->mExpiry;
- if ( $blockExpiry == 'infinity' ) {
- // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
- // Search for localization in 'ipboptions'
- $scBlockExpiryOptions = wfMsg( 'ipboptions' );
- foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
- if ( strpos( $option, ':' ) === false ) {
- continue;
- }
- list( $show, $value ) = explode( ':', $option );
- if ( $value == 'infinite' || $value == 'indefinite' ) {
- $blockExpiry = $show;
- break;
- }
- }
+ if ( $blockExpiry == Block::infinity() ) {
+ $blockExpiry = wfMessage( 'infiniteblock' );
} else {
$blockExpiry = $wgLang->timeanddate(
wfTimestamp( TS_MW, $blockExpiry ),
$blockExpiry = $user->mBlock->mExpiry;
$blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
if ( $blockExpiry == 'infinity' ) {
- // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
- $scBlockExpiryOptions = wfMsg( 'ipboptions' );
-
- foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
- if ( !strpos( $option, ':' ) )
- continue;
-
- list( $show, $value ) = explode( ':', $option );
-
- if ( $value == 'infinite' || $value == 'indefinite' ) {
- $blockExpiry = $show;
- break;
- }
- }
+ $blockExpiry = wfMessage( 'infiniteblock' );
} else {
$blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
}
$dbw = wfGetDB( DB_MASTER );
- $encodedExpiry = Block::encodeExpiry( $expiry, $dbw );
+ $encodedExpiry = $dbw->encodeExpiry( $expiry );
$expiry_description = '';
- if ( $encodedExpiry != 'infinity' ) {
+ if ( $encodedExpiry != $dbw->getInfinity() ) {
$expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ),
$wgContLang->date( $expiry ) , $wgContLang->time( $expiry ) ) . ')';
} else {
'pt_namespace' => $namespace,
'pt_title' => $title,
'pt_create_perm' => $create_perm,
- 'pt_timestamp' => Block::encodeExpiry( wfTimestampNow(), $dbw ),
+ 'pt_timestamp' => $dbw->encodeExpiry( wfTimestampNow() ),
'pt_expiry' => $encodedExpiry,
'pt_user' => $wgUser->getId(),
'pt_reason' => $reason,
* contains a array of unique groups.
*/
public function getCascadeProtectionSources( $getPages = true ) {
+ global $wgContLang;
$pagerestrictions = array();
if ( isset( $this->mCascadeSources ) && $getPages ) {
$purgeExpired = false;
foreach ( $res as $row ) {
- $expiry = Block::decodeExpiry( $row->pr_expiry );
+ $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
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] = Block::decodeExpiry( '' );
+ $this->mRestrictionsExpiry[$type] = $wgContLang->formatExpiry( '', TS_MW );
}
$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 = Block::decodeExpiry( $row->pr_expiry );
+ $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
// 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 ) {
if ( $this->exists() ) {
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'page_restrictions', '*',
- array( 'pr_page' => $this->getArticleId() ), __METHOD__ );
+ $res = $dbr->select(
+ 'page_restrictions',
+ '*',
+ array( 'pr_page' => $this->getArticleId() ),
+ __METHOD__
+ );
$this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
} else {
if ( $title_protection ) {
$now = wfTimestampNow();
- $expiry = Block::decodeExpiry( $title_protection['pt_expiry'] );
+ $expiry = $wgContLang->formatExpiry( $title_protection['pt_expiry'], TS_MW );
if ( !$expiry || $expiry > $now ) {
// Apply the restrictions
$this->mTitleProtection = false;
}
} else {
- $this->mRestrictionsExpiry['create'] = Block::decodeExpiry( '' );
+ $this->mRestrictionsExpiry['create'] = $wgContLang->formatExpiry( '', TS_MW );
}
$this->mRestrictionsLoaded = true;
}
}
public function execute() {
- global $wgUser;
+ global $wgUser, $wgContLang;
$params = $this->extractRequestParams();
if ( isset( $params['users'] ) && isset( $params['ip'] ) ) {
$block['timestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
}
if ( $fld_expiry ) {
- $block['expiry'] = Block::decodeExpiry( $row->ipb_expiry, TS_ISO_8601 );
+ $block['expiry'] = $wgContLang->formatExpiry( $row->ipb_expiry, TS_ISO_8601 );
}
if ( $fld_reason ) {
$block['reason'] = $row->ipb_reason;
* Get information about protections and put it in $protections
*/
private function getProtectionInfo() {
+ global $wgContLang;
$this->protections = array();
$db = $this->getDB();
$a = array(
'type' => $row->pr_type,
'level' => $row->pr_level,
- 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 )
+ 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
);
if ( $row->pr_cascade ) {
$a['cascade'] = '';
$this->protections[$row->pt_namespace][$row->pt_title][] = array(
'type' => 'create',
'level' => $row->pt_create_perm,
- 'expiry' => Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 )
+ 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 )
);
}
}
$this->protections[$row->tl_namespace][$row->tl_title][] = array(
'type' => $row->pr_type,
'level' => $row->pr_level,
- 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
+ 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
'source' => $source->getPrefixedText()
);
}
$this->protections[NS_FILE][$row->il_to][] = array(
'type' => $row->pr_type,
'level' => $row->pr_level,
- 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
+ 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
'source' => $source->getPrefixedText()
);
}
}
if ( isset( $prop['expiry'] ) ) {
- $vals['expiry'] = Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 );
+ global $wgContLang;
+ $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 );
}
if ( isset( $prop['level'] ) ) {
return 'infinity';
}
+ /**
+ * Encode an expiry time
+ *
+ * @param $expiry String: timestamp for expiry, or the 'infinity' string
+ * @return String
+ */
+ public function encodeExpiry( $expiry ) {
+ if ( $expiry == '' || $expiry == $this->getInfinity() ) {
+ return $this->getInfinity();
+ } else {
+ return $this->timestamp( $expiry );
+ }
+ }
+
/**
* Allow or deny "big selects" for this session only. This is done by setting
* the sql_big_selects session variable.
wfProfileIn( __METHOD__ );
- static $skin=null;
+ static $skin = null, $dbr = null;
- if( is_null( $skin ) )
+ if( is_null( $skin ) ){
$skin = $wgUser->getSkin();
+ $dbr = wfGetDB( DB_READ );
+ }
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
$link = $skin->link( $title );
$stxt = '';
- if( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
- $expiry = Block::decodeExpiry( $row->pr_expiry );
+ $expiry = $wgLang->formatExpiry( $row->pr_expiry, TS_MW );
+ if( $expiry != $dbr->getInfinity() ) {
- $expiry_description = wfMsg( 'protect-expiring' , $wgLang->timeanddate( $expiry ) ,
- $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
+ $expiry_description = wfMsg(
+ 'protect-expiring',
+ $wgLang->timeanddate( $expiry ),
+ $wgLang->date( $expiry ),
+ $wgLang->time( $expiry )
+ );
$description_items[] = htmlspecialchars($expiry_description);
}
$stxt = '';
if ( $row->pt_expiry != 'infinity' && strlen($row->pt_expiry) ) {
- $expiry = Block::decodeExpiry( $row->pt_expiry );
+ $expiry = $wgLang->formatExpiry( $row->pt_expiry );
$expiry_description = wfMsg( 'protect-expiring', $wgLang->timeanddate( $expiry ) , $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
return array( $wikiUpperChars, $wikiLowerChars );
}
+ /**
+ * Decode an expiry (block, protection, etc) which has come from the DB
+ *
+ * @param $expiry String: Database expiry String
+ * @param $format Bool|Int true to process using language functions, or TS_ constant
+ * to return the expiry in a given timestamp
+ * @return String
+ */
+ public function formatExpiry( $expiry, $format = true ) {
+ static $dbr, $msg;
+ if( !$dbr ){
+ $dbr = wfGetDB( DB_SLAVE );
+ $msg = wfMessage( 'infiniteblock' );
+ }
+
+ if ( $expiry == '' || $expiry == $dbr->getInfinity() ) {
+ return $format === true
+ ? $msg
+ : $dbr->getInfinity();
+ } else {
+ return $format === true
+ ? $this->timeanddate( $expiry )
+ : wfTimestamp( $format, $expiry );
+ }
+ }
+
+ /**
+ * @todo Document
+ * @param $seconds String
+ * @return string
+ */
function formatTimePeriod( $seconds ) {
if ( round( $seconds * 10 ) < 100 ) {
return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . $this->getMessageFromDB( 'seconds-abbrev' );