Add rate limiter to Special:ConfirmEmail
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
index 810fbd2..59d2806 100644 (file)
@@ -34,7 +34,8 @@ use MediaWiki\MediaWikiServices;
  */
 class SpecialBlock extends FormSpecialPage {
        /** @var User|string|null User to be blocked, as passed either by parameter (url?wpTarget=Foo)
-        * or as subpage (Special:Block/Foo) */
+        * or as subpage (Special:Block/Foo)
+        */
        protected $target;
 
        /** @var int DatabaseBlock::TYPE_ constant */
@@ -751,20 +752,15 @@ class SpecialBlock extends FormSpecialPage {
         *
         * @param array $data
         * @param IContextSource $context
-        * @return bool|string
+        * @return bool|array
         */
        public static function processForm( array $data, IContextSource $context ) {
-               global $wgBlockAllowsUTEdit, $wgHideUserContribLimit;
-
                $performer = $context->getUser();
                $enablePartialBlocks = $context->getConfig()->get( 'EnablePartialBlocks' );
                $isPartialBlock = $enablePartialBlocks &&
                        isset( $data['EditingRestriction'] ) &&
                        $data['EditingRestriction'] === 'partial';
 
-               // Handled by field validator callback
-               // self::validateTargetField( $data['Target'] );
-
                # This might have been a hidden field or a checkbox, so interesting data
                # can come from it
                $data['Confirm'] = !in_array( $data['Confirm'], [ '', '0', null, false ], true );
@@ -843,23 +839,33 @@ class SpecialBlock extends FormSpecialPage {
                        }
 
                        # Recheck params here...
+                       $hideUserContribLimit = $context->getConfig()->get( 'HideUserContribLimit' );
                        if ( $type != DatabaseBlock::TYPE_USER ) {
                                $data['HideUser'] = false; # IP users should not be hidden
                        } elseif ( !wfIsInfinity( $data['Expiry'] ) ) {
                                # Bad expiry.
                                return [ 'ipb_expiry_temp' ];
-                       } elseif ( $wgHideUserContribLimit !== false
-                               && $user->getEditCount() > $wgHideUserContribLimit
+                       } elseif ( $hideUserContribLimit !== false
+                               && $user->getEditCount() > $hideUserContribLimit
                        ) {
                                # Typically, the user should have a handful of edits.
                                # Disallow hiding users with many edits for performance.
                                return [ [ 'ipb_hide_invalid',
-                                       Message::numParam( $wgHideUserContribLimit ) ] ];
+                                       Message::numParam( $hideUserContribLimit ) ] ];
                        } elseif ( !$data['Confirm'] ) {
                                return [ 'ipb-confirmhideuser', 'ipb-confirmaction' ];
                        }
                }
 
+               $blockAllowsUTEdit = $context->getConfig()->get( 'BlockAllowsUTEdit' );
+               $userTalkEditAllowed = !$blockAllowsUTEdit || !$data['DisableUTEdit'];
+               if ( !$userTalkEditAllowed &&
+                       $isPartialBlock &&
+                       !in_array( NS_USER_TALK, explode( "\n", $data['NamespaceRestrictions'] ) )
+               ) {
+                       return [ 'ipb-prevent-user-talk-edit' ];
+               }
+
                # Create block object.
                $block = new DatabaseBlock();
                $block->setTarget( $target );
@@ -867,7 +873,7 @@ class SpecialBlock extends FormSpecialPage {
                $block->setReason( $data['Reason'][0] );
                $block->setExpiry( $expiryTime );
                $block->isCreateAccountBlocked( $data['CreateAccount'] );
-               $block->isUsertalkEditAllowed( !$wgBlockAllowsUTEdit || !$data['DisableUTEdit'] );
+               $block->isUsertalkEditAllowed( $userTalkEditAllowed );
                $block->isEmailBlocked( $data['DisableEmail'] );
                $block->isHardblock( $data['HardBlock'] );
                $block->isAutoblocking( $data['AutoBlock'] );
@@ -1130,8 +1136,6 @@ class SpecialBlock extends FormSpecialPage {
                if ( $performer->getBlock() ) {
                        if ( $target instanceof User && $target->getId() == $performer->getId() ) {
                                # User is trying to unblock themselves
-                               // @TODO Ensure that the block does not apply to the `unblockself`
-                               //       right.
                                if ( $performer->isAllowed( 'unblockself' ) ) {
                                        return true;
                                        # User blocked themselves and is now trying to reverse it