* of success. If it fails, the result will specify the nature of the error.
*/
public function execute() {
- global $wgContLang;
-
$this->checkUserRightsAny( 'block' );
$user = $this->getUser();
$block = Block::newFromTarget( $target, null, true );
if ( $block instanceof Block ) {
- $res['expiry'] = $wgContLang->formatExpiry( $block->mExpiry, TS_ISO_8601, 'infinite' );
+ $res['expiry'] = ApiResult::formatExpiry( $block->mExpiry, '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' );
}
$resultProtections[] = [
$p[0] => $protections[$p[0]],
- 'expiry' => $wgContLang->formatExpiry( $expiryarray[$p[0]], TS_ISO_8601, 'infinite' ),
+ 'expiry' => ApiResult::formatExpiry( $expiryarray[$p[0]], 'infinite' ),
];
}
}
public function execute() {
- global $wgContLang;
-
$db = $this->getDB();
$params = $this->extractRequestParams();
$this->requireMaxOneParameter( $params, 'users', 'ip' );
$block['timestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
}
if ( $fld_expiry ) {
- $block['expiry'] = $wgContLang->formatExpiry( $row->ipb_expiry, TS_ISO_8601 );
+ $block['expiry'] = ApiResult::formatExpiry( $row->ipb_expiry );
}
if ( $fld_reason ) {
$block['reason'] = $row->ipb_reason;
* Get information about protections and put it in $protections
*/
private function getProtectionInfo() {
- global $wgContLang;
$this->protections = [];
$db = $this->getDB();
$a = [
'type' => $row->pr_type,
'level' => $row->pr_level,
- 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
+ 'expiry' => ApiResult::formatExpiry( $row->pr_expiry )
];
if ( $row->pr_cascade ) {
$a['cascade'] = true;
$this->protections[$row->pt_namespace][$row->pt_title][] = [
'type' => 'create',
'level' => $row->pt_create_perm,
- 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 )
+ 'expiry' => ApiResult::formatExpiry( $row->pt_expiry )
];
}
}
$this->protections[$row->tl_namespace][$row->tl_title][] = [
'type' => $row->pr_type,
'level' => $row->pr_level,
- 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
+ 'expiry' => ApiResult::formatExpiry( $row->pr_expiry ),
'source' => $source->getPrefixedText()
];
}
$this->protections[NS_FILE][$row->il_to][] = [
'type' => $row->pr_type,
'level' => $row->pr_level,
- 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
+ 'expiry' => ApiResult::formatExpiry( $row->pr_expiry ),
'source' => $source->getPrefixedText()
];
}
}
if ( isset( $prop['expiry'] ) ) {
- global $wgContLang;
- $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 );
+ $vals['expiry'] = ApiResult::formatExpiry( $row->pt_expiry );
}
if ( isset( $prop['level'] ) ) {
* - systemblocktype - system block type, if any
*/
public static function getBlockInfo( Block $block ) {
- global $wgContLang;
$vals = [];
$vals['blockid'] = $block->getId();
$vals['blockedby'] = $block->getByName();
$vals['blockedbyid'] = $block->getBy();
$vals['blockreason'] = $block->mReason;
$vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp );
- $vals['blockexpiry'] = $wgContLang->formatExpiry(
- $block->getExpiry(), TS_ISO_8601, 'infinite'
- );
+ $vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
if ( $block->getSystemBlockType() !== null ) {
$vals['systemblocktype'] = $block->getSystemBlockType();
}
}
}
+ /**
+ * Format an expiry timestamp for API output
+ * @since 1.29
+ * @param string $expiry Expiry timestamp, likely from the database
+ * @param string $infinity Use this string for infinite expiry
+ * (only use this to maintain backward compatibility with existing output)
+ * @return string Formatted expiry
+ */
+ public static function formatExpiry( $expiry, $infinity = 'infinity' ) {
+ static $dbInfinity;
+ if ( $dbInfinity === null ) {
+ $dbInfinity = wfGetDB( DB_REPLICA )->getInfinity();
+ }
+
+ if ( $expiry === '' || $expiry === null || $expiry === false ||
+ wfIsInfinity( $expiry ) || $expiry === $dbInfinity
+ ) {
+ return $infinity;
+ } else {
+ return wfTimestamp( TS_ISO_8601, $expiry );
+ }
+ }
+
/**@}*/
}