Refactor out 'infinity' variants
authorJuneHyeon Bae <devunt@gmail.com>
Wed, 18 Jun 2014 02:45:32 +0000 (11:45 +0900)
committerAnomie <bjorsch@wikimedia.org>
Thu, 12 Mar 2015 16:38:02 +0000 (16:38 +0000)
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
includes/ProtectionForm.php
includes/api/ApiBlock.php
includes/api/ApiProtect.php
includes/specials/SpecialBlock.php
languages/Language.php

index ace52e0..9ae6cb8 100644 (file)
@@ -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)
index f777a37..1219da5 100644 (file)
@@ -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 );
index dea43ba..f03cef2 100644 (file)
@@ -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'],
index ae7d42b..4736cfb 100644 (file)
@@ -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] );
index efd3e2d..c237401 100644 (file)
@@ -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 );
index 22842f1..3e47453 100644 (file)
@@ -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 ) );
                                }
                        }