Special:Block: Disallow to add an expiry time in the past
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Thu, 7 Jan 2016 16:21:57 +0000 (17:21 +0100)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 14 Jan 2016 13:38:42 +0000 (13:38 +0000)
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

includes/specials/SpecialBlock.php
languages/i18n/en.json
languages/i18n/qqq.json

index 226d633..f10c6e1 100644 (file)
@@ -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'] );
index ed97a36..a9fb094 100644 (file)
        "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.",
index 39873c5..8654523 100644 (file)
        "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}}",