Unsuppress another phan issue (part 7)
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
index 13e4609..07214af 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 */
@@ -422,6 +423,8 @@ class SpecialBlock extends FormSpecialPage {
                                foreach ( $block->getRestrictions() as $restriction ) {
                                        switch ( $restriction->getType() ) {
                                                case PageRestriction::TYPE:
+                                                       /** @var PageRestriction $restriction */
+                                                       '@phan-var PageRestriction $restriction';
                                                        if ( $restriction->getTitle() ) {
                                                                $pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
                                                        }
@@ -754,17 +757,12 @@ class SpecialBlock extends FormSpecialPage {
         * @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 +841,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 +875,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'] );
@@ -1025,7 +1033,7 @@ class SpecialBlock extends FormSpecialPage {
                $logId = $logEntry->insert();
 
                if ( !empty( $data['Tags'] ) ) {
-                       $logEntry->setTags( $data['Tags'] );
+                       $logEntry->addTags( $data['Tags'] );
                }
 
                $logEntry->publish( $logId );