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)
} else {
$value = $this->mExpirySelection[$action];
}
- if ( $value == 'infinite' || $value == 'indefinite' || $value == 'infinity' ) {
+ if ( wfIsInfinity( $value ) ) {
$time = wfGetDB( DB_SLAVE )->getInfinity();
} else {
$unix = strtotime( $value );
'other',
$params['reason']
),
- 'Expiry' => $params['expiry'] == 'never' ? 'infinite' : $params['expiry'],
+ 'Expiry' => $params['expiry'],
'HardBlock' => !$params['anononly'],
'CreateAccount' => $params['nocreate'],
'AutoBlock' => $params['autoblock'],
$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] );
# 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
$infinity = wfGetDB( DB_SLAVE )->getInfinity();
}
- if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
+ if ( wfIsInfinity( $expiry ) ) {
$expiry = $infinity;
} else {
$expiry = strtotime( $expiry );
}
}
- // 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 ) );
}
}