* Move Block::parseExpiryInput() to the frontend SpecialBlock::parseExpiryInput()
* consolidate the several implementations of the MediaWiki:Ipblockoptions parsing into SpecialBlock::getSuggestedDurations()
}
}
- $expiry = Block::decodeExpiry( $encoded_expiry );
- if ( $expiry == 'infinity' ) {
+ $expiry = self::decodeExpiry( $encoded_expiry );
+ if ( $expiry == self::infinity() ) {
$expirystr = $msg['infiniteblock'];
} else {
global $wgLang;
return $expirystr;
}
+ # FIXME: everything above here is a mess, needs much cleaning up
+
/**
- * Convert a typed-in expiry time into something we can put into the database.
- * @param $expiry_input String: whatever was typed into the form
- * @return String: more database friendly
+ * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
+ * ("24 May 2034"), into an absolute timestamp we can put into the database.
+ * @param $expiry String: whatever was typed into the form
+ * @return String: timestamp or "infinity" string for th DB implementation
+ * @deprecated since 1.18 moved to SpecialBlock::parseExpiryInput()
*/
- public static function parseExpiryInput( $expiry_input ) {
- if ( $expiry_input == 'infinite' || $expiry_input == 'indefinite' ) {
- $expiry = 'infinity';
- } else {
- $expiry = strtotime( $expiry_input );
-
- if ( $expiry < 0 || $expiry === false ) {
- return false;
- }
- }
-
- return $expiry;
+ public static function parseExpiryInput( $expiry ) {
+ wfDeprecated( __METHOD__ );
+ return SpecialBlock::parseExpiryInput( $expiry );
}
- # FIXME: everything above here is a mess, needs much cleaning up
-
/**
* Given a target and the target's type, get an existing Block object if possible.
* Note that passing an IP address will get an applicable rangeblock if the IP is
}
public function getType(){
- list( $target, $type ) = $this->getTargetAndType();
+ list( /*...*/, $type ) = $this->getTargetAndType();
return $type;
}
public function getTarget(){
- list( $target, $type ) = $this->getTargetAndType();
+ list( $target, /*...*/ ) = $this->getTargetAndType();
return $target;
}
}
list( $vals2['duration'], $vals2['flags'] ) = $params;
// Indefinite blocks have no expiry time
- if ( Block::parseExpiryInput( $params[0] ) !== Block::infinity() ) {
+ if ( SpecialBlock::parseExpiryInput( $params[0] ) !== Block::infinity() ) {
$vals2['expiry'] = wfTimestamp( TS_ISO_8601,
strtotime( $params[0], wfTimestamp( TS_UNIX, $ts ) ) );
}
'validation-callback' => array( __CLASS__, 'validateTargetField' ),
),
'Expiry' => array(
- 'type' => 'selectorother',
+ 'type' => self::getSuggestedDurations() === array() ? 'text' : 'selectorother',
'label-message' => 'ipbexpiry',
'required' => true,
'tabindex' => '2',
),
);
- if( wfMsgForContent( 'ipboptions' ) == '-' ){
- $a['Expiry']['type'] = 'text';
- }
-
if( self::canBlockEmail( $wgUser ) ) {
$a['DisableEmail'] = array(
'type' => 'check',
}
if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 )
- || !Block::parseExpiryInput( $data['Expiry'] ) )
+ || !self::parseExpiryInput( $data['Expiry'] ) )
{
return array( 'ipb_expiry_invalid' );
}
$data['Reason'][0], # Reason string
wfTimestampNow(), # Block Timestamp
0, # Is this an autoblock (no)
- Block::parseExpiryInput( $data['Expiry'] ), # Expiry time
+ self::parseExpiryInput( $data['Expiry'] ), # Expiry time
!$data['HardBlock'], # Block anon only
$data['CreateAccount'],
$data['AutoBlock'],
* to the standard "**<duration>|<displayname>" format?
* @return Array
*/
- protected static function getSuggestedDurations(){
+ public static function getSuggestedDurations( $lang = null ){
$a = array();
- foreach( explode( ',', wfMsgForContent( 'ipboptions' ) ) as $option ) {
- if( strpos( $option, ':' ) === false ) $option = "$option:$option";
+ $msg = $lang === null
+ ? wfMessage( 'ipboptions' )->inContentLanguage()
+ : wfMessage( 'ipboptions' )->inLanguage( $lang );
+
+ if( $msg == '-' ){
+ return array();
+ }
+
+ foreach( explode( ',', $msg ) as $option ) {
+ if( strpos( $option, ':' ) === false ){
+ $option = "$option:$option";
+ }
list( $show, $value ) = explode( ':', $option );
$a[htmlspecialchars( $show )] = htmlspecialchars( $value );
}
return $a;
}
+ /**
+ * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
+ * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
+ * @param $expiry String: whatever was typed into the form
+ * @return String: timestamp or "infinity" string for the DB implementation
+ */
+ public static function parseExpiryInput( $expiry ) {
+ if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
+ $expiry = Block::infinity();
+ } else {
+ $expiry = strtotime( $expiry );
+ if ( $expiry < 0 || $expiry === false ) {
+ return false;
+ }
+ $expiry = wfTimestamp( TS_MW, $expiry );
+ }
+ return $expiry;
+ }
+
/**
* Can we do an email block?
* @param $user User: the sysop wanting to make a block
}
/**
- * For translating of expiry times
- * @param $str String: the validated block time in English
- * @return Somehow translated block time
+ * Maybe translate block durations. Note that this function is somewhat misnamed: it
+ * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time
+ * (which is an absolute timestamp).
+ * @param $str String: the validated block duration in English
+ * @return Somehow translated block duration
* @see LanguageFi.php for example implementation
*/
function translateBlockExpiry( $str ) {
- $scBlockExpiryOptions = $this->getMessageFromDB( 'ipboptions' );
-
- if ( $scBlockExpiryOptions == '-' ) {
- return $str;
- }
-
- foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
- if ( strpos( $option, ':' ) === false ) {
- continue;
- }
- list( $show, $value ) = explode( ':', $option );
+ foreach( SpecialBlock::getSuggestedDurations( $this ) as $show => $value ){
if ( strcmp( $str, $value ) == 0 ) {
return htmlspecialchars( trim( $show ) );
}
}
-
return $str;
}