From 511525a136cb85f9d4e395cbe609fb06c7d18bc7 Mon Sep 17 00:00:00 2001 From: JuneHyeon Bae Date: Wed, 18 Jun 2014 11:45:32 +0900 Subject: [PATCH] Refactor out 'infinity' variants Refactor out 'infinity' vartiant values which used in blocking and protecting actions. This patchset adds GlobalFunction wfIsInfinity. Bug: T68646 Change-Id: I60cc55a5bbd43c72916a1c2ea3807457d4e33765 --- includes/GlobalFunctions.php | 12 ++++++++++++ includes/ProtectionForm.php | 2 +- includes/api/ApiBlock.php | 2 +- includes/api/ApiProtect.php | 2 +- includes/specials/SpecialBlock.php | 4 ++-- languages/Language.php | 10 +++------- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index ace52e0189..9ae6cb8570 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -4143,6 +4143,18 @@ function wfCanIPUseHTTPS( $ip ) { return !!$canDo; } +/** + * Determine input string is represents as infinity + * + * @param string $str The string to determine + * @return bool + * @since 1.25 + */ +function wfIsInfinity( $str ) { + $infinityValues = array( 'infinite', 'indefinite', 'infinity', 'never' ); + return in_array( $str, $infinityValues ); +} + /** * Work out the IP address based on various globals * For trusted proxies, use the XFF client IP (first of the chain) diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index f777a37df4..1219da51d1 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -156,7 +156,7 @@ class ProtectionForm { } else { $value = $this->mExpirySelection[$action]; } - if ( $value == 'infinite' || $value == 'indefinite' || $value == 'infinity' ) { + if ( wfIsInfinity( $value ) ) { $time = wfGetDB( DB_SLAVE )->getInfinity(); } else { $unix = strtotime( $value ); diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index dea43ba0fc..f03cef2c67 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -78,7 +78,7 @@ class ApiBlock extends ApiBase { 'other', $params['reason'] ), - 'Expiry' => $params['expiry'] == 'never' ? 'infinite' : $params['expiry'], + 'Expiry' => $params['expiry'], 'HardBlock' => !$params['anononly'], 'CreateAccount' => $params['nocreate'], 'AutoBlock' => $params['autoblock'], diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index ae7d42b2d0..4736cfb54b 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -77,7 +77,7 @@ class ApiProtect extends ApiBase { $this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) ); } - if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'infinity', 'never' ) ) ) { + if ( wfIsInfinity( $expiry[$i] ) ) { $expiryarray[$p[0]] = $db->getInfinity(); } else { $exp = strtotime( $expiry[$i] ); diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index efd3e2d842..c237401345 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -681,7 +681,7 @@ class SpecialBlock extends FormSpecialPage { # Recheck params here... if ( $type != Block::TYPE_USER ) { $data['HideUser'] = false; # IP users should not be hidden - } elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) { + } elseif ( !wfIsInfinity( $data['Expiry'] ) ) { # Bad expiry. return array( 'ipb_expiry_temp' ); } elseif ( $wgHideUserContribLimit !== false @@ -856,7 +856,7 @@ class SpecialBlock extends FormSpecialPage { $infinity = wfGetDB( DB_SLAVE )->getInfinity(); } - if ( $expiry == 'infinite' || $expiry == 'indefinite' ) { + if ( wfIsInfinity( $expiry ) ) { $expiry = $infinity; } else { $expiry = strtotime( $expiry ); diff --git a/languages/Language.php b/languages/Language.php index 22842f1e0b..3e47453197 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3928,13 +3928,9 @@ class Language { } } - // Since usually only infinite or indefinite is only on list, so try - // equivalents if still here. - $indefs = array( 'infinite', 'infinity', 'indefinite' ); - if ( in_array( $str, $indefs ) ) { - foreach ( $indefs as $val ) { - $show = array_search( $val, $duration, true ); - if ( $show !== false ) { + if ( wfIsInfinity( $str ) ) { + foreach ( $duration as $show => $value ) { + if ( wfIsInfinity( $value ) ) { return htmlspecialchars( trim( $show ) ); } } -- 2.20.1