SpecialBlock: Don't fill in form defaults for a partial autoblock

SpecialBlock::maybeAlterFormDefaults fills in defaults if there is an
existing block against the target that is not an autoblock. Before
this, partial block fields were getting filled even for autoblocks.

Bug: T250490
Change-Id: I941a41f4cd308d5992c60634981d943634980621
This commit is contained in:
Thalia 2020-04-17 14:57:26 +01:00
parent 8855e7d45b
commit 1367b506de

View file

@ -178,6 +178,7 @@ class SpecialBlock extends FormSpecialPage {
$a['EditingRestriction'] = [
'type' => 'radio',
'cssclass' => 'mw-block-editing-restriction',
'default' => 'sitewide',
'options' => [
$this->msg( 'ipb-sitewide' )->escaped() .
new \OOUI\LabelWidget( [
@ -400,6 +401,33 @@ class SpecialBlock extends FormSpecialPage {
$fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->getExpiry() );
}
if ( !$block->isSitewide() ) {
$fields['EditingRestriction']['default'] = 'partial';
$pageRestrictions = [];
$namespaceRestrictions = [];
foreach ( $block->getRestrictions() as $restriction ) {
if ( $restriction instanceof PageRestriction && $restriction->getTitle() ) {
$pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
} elseif ( $restriction instanceof NamespaceRestriction ) {
$namespaceRestrictions[] = $restriction->getValue();
}
}
// Sort the restrictions so they are in alphabetical order.
sort( $pageRestrictions );
$fields['PageRestrictions']['default'] = implode( "\n", $pageRestrictions );
sort( $namespaceRestrictions );
$fields['NamespaceRestrictions']['default'] = implode( "\n", $namespaceRestrictions );
if (
empty( $pageRestrictions ) &&
empty( $namespaceRestrictions )
) {
$fields['Editing']['default'] = false;
}
}
$this->alreadyBlocked = true;
$this->preErrors[] = [ 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) ];
}
@ -423,45 +451,6 @@ class SpecialBlock extends FormSpecialPage {
unset( $fields['Confirm']['default'] );
$this->preErrors[] = [ 'ipb-blockingself', 'ipb-confirmaction' ];
}
if ( $block instanceof DatabaseBlock && !$block->isSitewide() ) {
$fields['EditingRestriction']['default'] = 'partial';
} else {
$fields['EditingRestriction']['default'] = 'sitewide';
}
if ( $block instanceof DatabaseBlock ) {
$pageRestrictions = [];
$namespaceRestrictions = [];
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();
}
break;
case NamespaceRestriction::TYPE:
$namespaceRestrictions[] = $restriction->getValue();
break;
}
}
if (
!$block->isSitewide() &&
empty( $pageRestrictions ) &&
empty( $namespaceRestrictions )
) {
$fields['Editing']['default'] = false;
}
// Sort the restrictions so they are in alphabetical order.
sort( $pageRestrictions );
$fields['PageRestrictions']['default'] = implode( "\n", $pageRestrictions );
sort( $namespaceRestrictions );
$fields['NamespaceRestrictions']['default'] = implode( "\n", $namespaceRestrictions );
}
}
/**