diff --git a/includes/Html/Html.php b/includes/Html/Html.php index e57b1ad60b5..9f5543be91f 100644 --- a/includes/Html/Html.php +++ b/includes/Html/Html.php @@ -26,7 +26,6 @@ namespace MediaWiki\Html; use FormatJson; -use InvalidArgumentException; use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; use MediaWiki\Request\ContentSecurityPolicy; @@ -109,75 +108,29 @@ class Html { ]; /** - * Modifies a set of attributes meant for button elements - * and apply a set of default attributes when $wgUseMediaWikiUIEverywhere enabled. + * Modifies a set of attributes meant for button elements. + * * @param array $attrs HTML attributes in an associative array * @param string[] $modifiers classes to add to the button * @see https://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers * @return array Modified attributes array */ public static function buttonAttributes( array $attrs, array $modifiers = [] ) { - $useMediaWikiUIEverywhere = - MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ); - if ( $useMediaWikiUIEverywhere ) { - if ( isset( $attrs['class'] ) ) { - if ( is_array( $attrs['class'] ) ) { - $attrs['class'][] = 'mw-ui-button'; - $attrs['class'] = array_merge( $attrs['class'], $modifiers ); - // ensure compatibility with Xml - $attrs['class'] = implode( ' ', $attrs['class'] ); - } else { - $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers ); - } - } else { - // ensure compatibility with Xml - $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers ); - } - } return $attrs; } /** - * Modifies a set of attributes meant for text input elements - * and apply a set of default attributes. + * Modifies a set of attributes meant for text input elements. * * @param array $attrs An attribute array. * @return array Modified attributes array */ public static function getTextInputAttributes( array $attrs ) { - $useMediaWikiUIEverywhere = MediaWikiServices::getInstance() - ->getMainConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ); - if ( $useMediaWikiUIEverywhere ) { - $cdxInputClass = 'cdx-text-input__input'; - // This will only apply if the input is not using official Codex classes. - // In future this should trigger a deprecation warning. - if ( isset( $attrs['class'] ) ) { // see expandAttributes() for supported attr formats - if ( is_array( $attrs['class'] ) ) { - if ( - !in_array( $cdxInputClass, $attrs['class'], true ) && - !( $attrs['class'][$cdxInputClass] ?? false ) - ) { - $attrs['class']['mw-ui-input'] = true; - } - } elseif ( is_string( $attrs['class'] ) ) { - if ( !preg_match( "/(^| )$cdxInputClass($| )/", $attrs['class'] ) ) { - $attrs['class'] .= ' mw-ui-input'; - } - } else { - throw new InvalidArgumentException( - 'Unexpected class attr of type ' . gettype( $attrs['class'] ) - ); - } - } else { - $attrs['class'] = 'mw-ui-input'; - } - } return $attrs; } /** - * Returns an HTML link element in a string styled as a button - * (when $wgUseMediaWikiUIEverywhere is enabled). + * Returns an HTML link element in a string. * * @param string $text The text of the element. Will be escaped (not raw HTML) * @param array $attrs Associative array of attributes, e.g., [ @@ -196,8 +149,7 @@ class Html { } /** - * Returns an HTML link element in a string styled as a button - * (when $wgUseMediaWikiUIEverywhere is enabled). + * Returns an HTML link element in a string styled as a button. * * @param string $contents The raw HTML contents of the element: *not* * escaped! diff --git a/includes/actions/McrUndoAction.php b/includes/actions/McrUndoAction.php index b36212ffa4f..84a2a3c490c 100644 --- a/includes/actions/McrUndoAction.php +++ b/includes/actions/McrUndoAction.php @@ -101,12 +101,6 @@ class McrUndoAction extends FormAction { $out = $this->getOutput(); $out->setRobotPolicy( 'noindex,nofollow' ); - if ( $this->getContext()->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) { - $out->addModuleStyles( [ - 'mediawiki.ui.input', - 'mediawiki.ui.checkbox', - ] ); - } // IP warning headers copied from EditPage // (should more be copied?) diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index dbcfe41aea0..1c8145958e1 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -1415,8 +1415,6 @@ class HTMLForm extends ContextSource { */ public function getButtons() { $buttons = ''; - $useMediaWikiUIEverywhere = - $this->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ); if ( $this->mShowSubmit ) { $attribs = []; @@ -1435,13 +1433,6 @@ class HTMLForm extends ContextSource { $attribs['class'] = [ 'mw-htmlform-submit' ]; - if ( $useMediaWikiUIEverywhere ) { - foreach ( $this->mSubmitFlags as $flag ) { - $attribs['class'][] = 'mw-ui-' . $flag; - } - $attribs['class'][] = 'mw-ui-button'; - } - $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n"; } @@ -1451,7 +1442,6 @@ class HTMLForm extends ContextSource { [ 'type' => 'reset', 'value' => $this->msg( 'htmlform-reset' )->text(), - 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null, ] ) . "\n"; } @@ -1461,7 +1451,6 @@ class HTMLForm extends ContextSource { $buttons .= Html::element( 'a', [ - 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null, 'href' => $target, ], $this->msg( 'cancel' )->text() @@ -1495,11 +1484,6 @@ class HTMLForm extends ContextSource { $attrs['id'] = $button['id']; } - if ( $useMediaWikiUIEverywhere ) { - $attrs['class'] = (array)( $attrs['class'] ?? [] ); - $attrs['class'][] = 'mw-ui-button'; - } - $buttons .= Html::rawElement( 'button', $attrs, $label ) . "\n"; } diff --git a/includes/htmlform/VFormHTMLForm.php b/includes/htmlform/VFormHTMLForm.php index 7597725653b..10a71f8195e 100644 --- a/includes/htmlform/VFormHTMLForm.php +++ b/includes/htmlform/VFormHTMLForm.php @@ -46,10 +46,6 @@ class VFormHTMLForm extends HTMLForm { } public function getHTML( $submitResult ) { - // This is required for VForm HTMLForms that use that style regardless - // of wgUseMediaWikiUIEverywhere (since they pre-date it). - // When wgUseMediaWikiUIEverywhere is removed, this should be consolidated - // with the addModuleStyles in SpecialPage->setHeaders. $this->getOutput()->addModuleStyles( [ 'mediawiki.ui', 'mediawiki.ui.button', diff --git a/includes/htmlform/fields/HTMLButtonField.php b/includes/htmlform/fields/HTMLButtonField.php index 36c156ee66c..08f23c3f94b 100644 --- a/includes/htmlform/fields/HTMLButtonField.php +++ b/includes/htmlform/fields/HTMLButtonField.php @@ -1,7 +1,6 @@ mParent instanceof CodexHTMLForm; - if ( $this->mParent instanceof VFormHTMLForm || - ( !$isCodexForm && $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) - ) { + if ( $this->mParent instanceof VFormHTMLForm ) { $prefix = 'mw-ui-'; // add mw-ui-button separately, so the descriptor doesn't need to set it $flags .= ' ' . $prefix . 'button'; - } - if ( $isCodexForm ) { + } elseif ( $this->mParent instanceof CodexHTMLForm ) { $flags .= ' cdx-button cdx-button--action-progressive cdx-button--weight-primary'; } foreach ( $this->mFlags as $flag ) { diff --git a/includes/htmlform/fields/HTMLCheckField.php b/includes/htmlform/fields/HTMLCheckField.php index 80365e7d8a2..673aea7f7de 100644 --- a/includes/htmlform/fields/HTMLCheckField.php +++ b/includes/htmlform/fields/HTMLCheckField.php @@ -1,7 +1,6 @@ mParent ) { - $useMediaWikiUIEverywhere = $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ); - } - if ( !empty( $this->mParams['invert'] ) ) { $value = !$value; } @@ -55,7 +49,7 @@ class HTMLCheckField extends HTMLFormField { $chkDivider . Html::rawElement( 'label', $attrLabel, $this->mLabel ); - if ( $isCodexForm || $useMediaWikiUIEverywhere || $isVForm ) { + if ( $isCodexForm || $isVForm ) { $chkLabelClass = $isCodexForm ? 'cdx-checkbox' : 'mw-ui-checkbox'; $chkLabel = Html::rawElement( 'div', diff --git a/includes/htmlform/fields/HTMLCheckMatrix.php b/includes/htmlform/fields/HTMLCheckMatrix.php index b6e03cbae07..80238138b81 100644 --- a/includes/htmlform/fields/HTMLCheckMatrix.php +++ b/includes/htmlform/fields/HTMLCheckMatrix.php @@ -1,7 +1,6 @@ mName}[]", $checked, $attribs ); - if ( $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) { - $checkbox = Html::openElement( 'div', [ 'class' => 'mw-ui-checkbox' ] ) . - $checkbox . - Html::element( 'label', [ 'for' => $attribs['id'] ] ) . - Html::closeElement( 'div' ); - } - return $checkbox; + return Xml::check( "{$this->mName}[]", $checked, $attribs ); } protected function isTagForcedOff( $tag ) { diff --git a/includes/htmlform/fields/HTMLMultiSelectField.php b/includes/htmlform/fields/HTMLMultiSelectField.php index 1588badf2a0..b1754bafd65 100644 --- a/includes/htmlform/fields/HTMLMultiSelectField.php +++ b/includes/htmlform/fields/HTMLMultiSelectField.php @@ -1,7 +1,6 @@ $attribs['id'] ], $label ); - if ( $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) { - $checkbox = Html::openElement( 'div', [ 'class' => 'mw-ui-checkbox' ] ) . - $checkbox . - Html::closeElement( 'div' ); - } return $checkbox; } } diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index 9ee38fce8c8..59661892c30 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -700,13 +700,6 @@ class SpecialPage implements MessageLocalizer { $title = ( new RawMessage( '$1' ) )->rawParams( $title ); } $out->setPageTitleMsg( $title ); - if ( $this->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) { - $out->addModuleStyles( [ - 'mediawiki.ui.input', - 'mediawiki.ui.radio', - 'mediawiki.ui.checkbox', - ] ); - } } /** diff --git a/includes/xml/Xml.php b/includes/xml/Xml.php index 126f337a7ab..f89fb6a8133 100644 --- a/includes/xml/Xml.php +++ b/includes/xml/Xml.php @@ -295,8 +295,7 @@ class Xml { $attributes['value'] = $value; } - return self::element( 'input', - Html::getTextInputAttributes( $attributes + $attribs ) ); + return self::element( 'input', $attributes + $attribs ); } /** @@ -430,17 +429,9 @@ class Xml { * @return string HTML */ public static function checkLabel( $label, $name, $id, $checked = false, $attribs = [] ) { - $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()->getMainConfig() - ->get( MainConfigNames::UseMediaWikiUIEverywhere ); - $chkLabel = self::check( $name, $checked, [ 'id' => $id ] + $attribs ) . + return self::check( $name, $checked, [ 'id' => $id ] + $attribs ) . "\u{00A0}" . self::label( $label, $id, $attribs ); - - if ( $useMediaWikiUIEverywhere ) { - $chkLabel = self::openElement( 'div', [ 'class' => 'mw-ui-checkbox' ] ) . - $chkLabel . self::closeElement( 'div' ); - } - return $chkLabel; } /** @@ -464,27 +455,17 @@ class Xml { } /** - * Convenience function to build an HTML submit button - * When $wgUseMediaWikiUIEverywhere is true it will default to a progressive button + * Convenience function to build an HTML submit button. + * * @param string $value Label text for the button (unescaped) * @param array $attribs Optional custom attributes * @return string HTML */ public static function submitButton( $value, $attribs = [] ) { - $useMediaWikiUIEverywhere = MediaWikiServices::getInstance()->getMainConfig() - ->get( MainConfigNames::UseMediaWikiUIEverywhere ); - $baseAttrs = [ + $attribs += [ 'type' => 'submit', 'value' => $value, ]; - // Done conditionally for time being as it is possible - // some submit forms - // might need to be mw-ui-destructive (e.g. delete a page) - if ( $useMediaWikiUIEverywhere ) { - $baseAttrs['class'] = 'mw-ui-button mw-ui-progressive'; - } - // Any custom attributes will take precedence of anything in baseAttrs e.g. override the class - $attribs += $baseAttrs; return Html::element( 'input', $attribs ); } @@ -657,14 +638,12 @@ class Xml { */ public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = [] ) { return self::element( 'textarea', - Html::getTextInputAttributes( - [ - 'name' => $name, - 'id' => $name, - 'cols' => $cols, - 'rows' => $rows - ] + $attribs - ), + [ + 'name' => $name, + 'id' => $name, + 'cols' => $cols, + 'rows' => $rows + ] + $attribs, $content, false ); } diff --git a/tests/phpunit/includes/Html/HtmlTest.php b/tests/phpunit/includes/Html/HtmlTest.php index 6a0a12905d8..20589f9e769 100644 --- a/tests/phpunit/includes/Html/HtmlTest.php +++ b/tests/phpunit/includes/Html/HtmlTest.php @@ -832,65 +832,6 @@ class HtmlTest extends MediaWikiIntegrationTestCase { $this->assertSame( $expected, $html ); } - /** @dataProvider provideGetTextInputAttributes */ - public function testGetTextInputAttributes( - bool $useMediaWikiUIEverywhere, - $classAttribute, - $expectedClassAttribute - ) { - $this->overrideConfigValue( MainConfigNames::UseMediaWikiUIEverywhere, $useMediaWikiUIEverywhere ); - $attrs = Html::getTextInputAttributes( [ 'class' => $classAttribute ] ); - $this->assertSame( $expectedClassAttribute, $attrs['class'] ); - } - - public static function provideGetTextInputAttributes(): iterable { - yield 'MWUI everywhere, non-codex, class string' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => 'foo', - 'expectedClassAttribute' => 'foo mw-ui-input', - ]; - yield 'MWUI everywhere, non-codex, class list' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => [ 'foo' ], - 'expectedClassAttribute' => [ 'foo', 'mw-ui-input' => true ], - ]; - yield 'MWUI everywhere, non-codex, class dict' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => [ 'foo' => true ], - 'expectedClassAttribute' => [ 'foo' => true, 'mw-ui-input' => true ], - ]; - yield 'MWUI everywhere, non-codex, class dict disables mw-ui-input' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => [ 'foo' => true, 'mw-ui-input' => false ], - 'expectedClassAttribute' => [ 'foo' => true, 'mw-ui-input' => true ], - ]; - yield 'MWUI everywhere, codex, class string' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => 'foo cdx-text-input__input', - 'expectedClassAttribute' => 'foo cdx-text-input__input', - ]; - yield 'MWUI everywhere, codex, class list' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => [ 'foo', 'cdx-text-input__input' ], - 'expectedClassAttribute' => [ 'foo', 'cdx-text-input__input' ], - ]; - yield 'MWUI everywhere, codex, class dict' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => [ 'foo' => true, 'cdx-text-input__input' => true ], - 'expectedClassAttribute' => [ 'foo' => true, 'cdx-text-input__input' => true ], - ]; - yield 'MWUI everywhere, class dict disables codex' => [ - 'useMediaWikiUIEverywhere' => true, - 'classAttribute' => [ 'foo' => true, 'cdx-text-input__input' => false ], - 'expectedClassAttribute' => [ 'foo' => true, 'cdx-text-input__input' => false, 'mw-ui-input' => true ], - ]; - yield 'not MWUI everywhere' => [ - 'useMediaWikiUIEverywhere' => false, - 'classAttribute' => 'foo', - 'expectedClassAttribute' => 'foo', - ]; - } - public static function provideEncodeJsVar() { // $expected, $input yield 'boolean' => [ 'true', true ]; diff --git a/tests/phpunit/includes/xml/XmlTest.php b/tests/phpunit/includes/xml/XmlTest.php index 3ef708ad9f6..ebb53b4e1fe 100644 --- a/tests/phpunit/includes/xml/XmlTest.php +++ b/tests/phpunit/includes/xml/XmlTest.php @@ -15,7 +15,6 @@ class XmlTest extends MediaWikiIntegrationTestCase { $this->overrideConfigValues( [ MainConfigNames::LanguageCode => 'en', - MainConfigNames::UseMediaWikiUIEverywhere => false, ] ); $langObj = $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' ); @@ -77,21 +76,6 @@ class XmlTest extends MediaWikiIntegrationTestCase { ); } - /** - * @covers Xml::input - * @covers \MediaWiki\Html\Html::getTextInputAttributes - */ - public function testInputWithMWUIEverywhere() { - $this->overrideConfigValues( [ - MainConfigNames::UseMediaWikiUIEverywhere => true, - ] ); - - $this->assertSame( - '', - Xml::input( 'name', false, false, [ 'class' => 'foo' ] ) - ); - } - public function testOpenElement() { $this->assertEquals( '',