Merge "objectcache: defined some missing methods in MultiWriteBagOStuff"
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
index a00c42c..0cf790b 100644 (file)
@@ -143,6 +143,8 @@ class SpecialBlock extends FormSpecialPage {
        protected function getFormFields() {
                global $wgBlockAllowsUTEdit;
 
+               $this->getOutput()->enableOOUI();
+
                $user = $this->getUser();
 
                $suggestedDurations = self::getSuggestedDurations();
@@ -177,8 +179,16 @@ class SpecialBlock extends FormSpecialPage {
                                'type' => 'radio',
                                'cssclass' => 'mw-block-editing-restriction',
                                'options' => [
-                                       $this->msg( 'ipb-sitewide' )->escaped() => 'sitewide',
-                                       $this->msg( 'ipb-partial' )->escaped() => 'partial',
+                                       $this->msg( 'ipb-sitewide' )->escaped() .
+                                               new \OOUI\LabelWidget( [
+                                                       'classes' => [ 'oo-ui-inline-help' ],
+                                                       'label' => $this->msg( 'ipb-sitewide-help' )->text(),
+                                               ] ) => 'sitewide',
+                                       $this->msg( 'ipb-partial' )->escaped() .
+                                               new \OOUI\LabelWidget( [
+                                                       'classes' => [ 'oo-ui-inline-help' ],
+                                                       'label' => $this->msg( 'ipb-partial-help' )->text(),
+                                               ] ) => 'partial',
                                ],
                                'section' => 'actions',
                        ];
@@ -298,6 +308,18 @@ class SpecialBlock extends FormSpecialPage {
                        'cssclass' => 'mw-block-confirm',
                ];
 
+               // Block Id if a block already exists matching the target
+               $a['BlockId'] = [
+                       'type' => 'hidden',
+                       'default' => '',
+               ];
+
+               // Has the form been submitted
+               $a['WasPosted'] = [
+                       'type' => 'hidden',
+                       'default' => '',
+               ];
+
                $this->maybeAlterFormDefaults( $a );
 
                // Allow extensions to add more fields
@@ -310,8 +332,6 @@ class SpecialBlock extends FormSpecialPage {
         * If the user has already been blocked with similar settings, load that block
         * and change the defaults for the form fields to match the existing settings.
         * @param array &$fields HTMLForm descriptor array
-        * @return bool Whether fields were altered (that is, whether the target is
-        *     already blocked)
         */
        protected function maybeAlterFormDefaults( &$fields ) {
                # This will be overwritten by request data
@@ -330,9 +350,11 @@ class SpecialBlock extends FormSpecialPage {
 
                $block = Block::newFromTarget( $this->target );
 
-               if ( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock
-                       && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock
-                               || $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block
+               // Populate fields if there is a block that is not an autoblock; if it is a range
+               // block, only populate the fields if the range is the same as $this->target
+               if ( $block instanceof Block && $block->getType() !== Block::TYPE_AUTO
+                       && ( $this->type != Block::TYPE_RANGE
+                               || $block->getTarget() == $this->target )
                ) {
                        $fields['HardBlock']['default'] = $block->isHardblock();
                        $fields['CreateAccount']['default'] = $block->isCreateAccountBlocked();
@@ -343,7 +365,7 @@ class SpecialBlock extends FormSpecialPage {
                        }
 
                        if ( isset( $fields['HideUser'] ) ) {
-                               $fields['HideUser']['default'] = $block->mHideName;
+                               $fields['HideUser']['default'] = $block->getHideName();
                        }
 
                        if ( isset( $fields['DisableUTEdit'] ) ) {
@@ -352,8 +374,8 @@ class SpecialBlock extends FormSpecialPage {
 
                        // If the username was hidden (ipb_deleted == 1), don't show the reason
                        // unless this user also has rights to hideuser: T37839
-                       if ( !$block->mHideName || $this->getUser()->isAllowed( 'hideuser' ) ) {
-                               $fields['Reason']['default'] = $block->mReason;
+                       if ( !$block->getHideName() || $this->getUser()->isAllowed( 'hideuser' ) ) {
+                               $fields['Reason']['default'] = $block->getReason();
                        } else {
                                $fields['Reason']['default'] = '';
                        }
@@ -369,16 +391,22 @@ class SpecialBlock extends FormSpecialPage {
                                $fields['Confirm']['default'] = 1;
                        }
 
-                       if ( $block->mExpiry == 'infinity' ) {
+                       if ( $block->getExpiry() == 'infinity' ) {
                                $fields['Expiry']['default'] = 'infinite';
                        } else {
-                               $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry );
+                               $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->getExpiry() );
                        }
 
+                       $fields['BlockId']['default'] = $block->getId();
+
                        $this->alreadyBlocked = true;
                        $this->preErrors[] = [ 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) ];
                }
 
+               if ( $this->getRequest()->wasPosted() ) {
+                       $fields['WasPosted']['default'] = true;
+               }
+
                # We always need confirmation to do HideUser
                if ( $this->requestedHideUser ) {
                        $fields['Confirm']['type'] = 'check';
@@ -847,14 +875,14 @@ class SpecialBlock extends FormSpecialPage {
                $block = new Block();
                $block->setTarget( $target );
                $block->setBlocker( $performer );
-               $block->mReason = $data['Reason'][0];
-               $block->mExpiry = $expiryTime;
+               $block->setReason( $data['Reason'][0] );
+               $block->setExpiry( $expiryTime );
                $block->isCreateAccountBlocked( $data['CreateAccount'] );
                $block->isUsertalkEditAllowed( !$wgBlockAllowsUTEdit || !$data['DisableUTEdit'] );
                $block->isEmailBlocked( $data['DisableEmail'] );
                $block->isHardblock( $data['HardBlock'] );
                $block->isAutoblocking( $data['AutoBlock'] );
-               $block->mHideName = $data['HideUser'];
+               $block->setHideName( $data['HideUser'] );
 
                if ( $isPartialBlock ) {
                        $block->isSitewide( false );
@@ -913,19 +941,19 @@ class SpecialBlock extends FormSpecialPage {
                                }
                                # If the name was hidden and the blocking user cannot hide
                                # names, then don't allow any block changes...
-                               if ( $currentBlock->mHideName && !$performer->isAllowed( 'hideuser' ) ) {
+                               if ( $currentBlock->getHideName() && !$performer->isAllowed( 'hideuser' ) ) {
                                        return [ 'cant-see-hidden-user' ];
                                }
 
                                $priorBlock = clone $currentBlock;
                                $currentBlock->isHardblock( $block->isHardblock() );
                                $currentBlock->isCreateAccountBlocked( $block->isCreateAccountBlocked() );
-                               $currentBlock->mExpiry = $block->mExpiry;
+                               $currentBlock->setExpiry( $block->getExpiry() );
                                $currentBlock->isAutoblocking( $block->isAutoblocking() );
-                               $currentBlock->mHideName = $block->mHideName;
+                               $currentBlock->setHideName( $block->getHideName() );
                                $currentBlock->isEmailBlocked( $block->isEmailBlocked() );
                                $currentBlock->isUsertalkEditAllowed( $block->isUsertalkEditAllowed() );
-                               $currentBlock->mReason = $block->mReason;
+                               $currentBlock->setReason( $block->getReason() );
 
                                if ( $enablePartialBlocks ) {
                                        // Maintain the sitewide status. If partial blocks is not enabled,
@@ -944,12 +972,12 @@ class SpecialBlock extends FormSpecialPage {
                                $logaction = 'reblock';
 
                                # Unset _deleted fields if requested
-                               if ( $currentBlock->mHideName && !$data['HideUser'] ) {
+                               if ( $currentBlock->getHideName() && !$data['HideUser'] ) {
                                        RevisionDeleteUser::unsuppressUserName( $target, $userId );
                                }
 
                                # If hiding/unhiding a name, this should go in the private logs
-                               if ( (bool)$currentBlock->mHideName ) {
+                               if ( (bool)$currentBlock->getHideName() ) {
                                        $data['HideUser'] = true;
                                }