From: Florian Date: Thu, 7 Jan 2016 16:21:57 +0000 (+0100) Subject: Special:Block: Disallow to add an expiry time in the past X-Git-Tag: 1.31.0-rc.0~8336^2 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;ds=sidebyside;h=cdf10cac69ef8e90384fcc8beac45e681d34b4c4;p=lhc%2Fweb%2Fwiklou.git Special:Block: Disallow to add an expiry time in the past Like the protect action, adding a block with an expiry time in the past doesn't make any sense and should throw an error message, instead of creating a useless block. Bug: T123069 Change-Id: Ib168ace80ada248f0209af896ab8b8ecfac3ef29 --- diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 226d6334b8..f10c6e161c 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -646,12 +646,25 @@ class SpecialBlock extends FormSpecialPage { return array( 'badipaddress' ); } - if ( ( strlen( $data['Expiry'] ) == 0 ) || ( strlen( $data['Expiry'] ) > 50 ) - || !self::parseExpiryInput( $data['Expiry'] ) + $expiryTime = self::parseExpiryInput( $data['Expiry'] ); + + if ( + // an expiry time is needed + ( strlen( $data['Expiry'] ) == 0 ) || + // can't be a larger string as 50 (it should be a time format in any way) + ( strlen( $data['Expiry'] ) > 50 ) || + // check, if the time could be parsed + !$expiryTime ) { return array( 'ipb_expiry_invalid' ); } + // an expiry time should be in the future, not in the + // past (wouldn't make any sense) - bug T123069 + if ( $expiryTime < wfTimestampNow() ) { + return array( 'ipb_expiry_old' ); + } + if ( !isset( $data['DisableEmail'] ) ) { $data['DisableEmail'] = false; } @@ -695,7 +708,7 @@ class SpecialBlock extends FormSpecialPage { $block->setBlocker( $performer ); # Truncate reason for whole multibyte characters $block->mReason = $wgContLang->truncate( $data['Reason'][0], 255 ); - $block->mExpiry = self::parseExpiryInput( $data['Expiry'] ); + $block->mExpiry = $expiryTime; $block->prevents( 'createaccount', $data['CreateAccount'] ); $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) ); $block->prevents( 'sendemail', $data['DisableEmail'] ); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index ed97a365f9..a9fb094c0e 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2355,6 +2355,7 @@ "block-log-flags-hiddenname": "username hidden", "range_block_disabled": "The administrator ability to create range blocks is disabled.", "ipb_expiry_invalid": "Expiry time invalid.", + "ipb_expiry_old": "Expiry time is in the past.", "ipb_expiry_temp": "Hidden username blocks must be permanent.", "ipb_hide_invalid": "Unable to suppress this account; it has more than {{PLURAL:$1|one edit|$1 edits}}.", "ipb_already_blocked": "\"$1\" is already blocked.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 39873c54c7..8654523f73 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2530,6 +2530,7 @@ "block-log-flags-hiddenname": "Used as a block log flag in [[Special:Log/block]] and in [[Special:Block]].\n\n{{Related|Block-log-flags}}", "range_block_disabled": "Used as error message in [[Special:Block]].\n\nSee also:\n* {{msg-mw|Range block disabled}}\n* {{msg-mw|Ip range invalid}}\n* {{msg-mw|Ip range toolarge}}", "ipb_expiry_invalid": "Used as error message in [[Special:Block]].", + "ipb_expiry_old": "Used as error message in [[Special:Block]], if the expiry time is in the past.\n{{Identical|protect_expiry_old}}", "ipb_expiry_temp": "Warning message displayed on [[Special:BlockIP]] if the option \"hide username\" is selected but the expiry time is not infinite.", "ipb_hide_invalid": "Used as error message in [[Special:Block]].\n* $1 - Number of edits (Value of [[mw:Manual:$wgHideUserContribLimit]])", "ipb_already_blocked": "{{Identical|$1 is already blocked}}",