diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2024-02-05 13:59:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2024-02-05 13:59:51 +0000 |
commit | ee6040661798e68dbbcdd03e16c12dd1102d4fe7 (patch) | |
tree | a0000b2ada591570dce01772bf7e744a78bfc86d | |
parent | 4842f12bb7007846a4d14ca2bafebf948045085e (diff) | |
parent | aa7eeeeef92c55c270f8b16bb5abbbd398c5e324 (diff) | |
download | mediawikicore-ee6040661798e68dbbcdd03e16c12dd1102d4fe7.tar.gz mediawikicore-ee6040661798e68dbbcdd03e16c12dd1102d4fe7.zip |
Merge "Remove uses of $wgUseMediaWikiUIEverywhere"
-rw-r--r-- | includes/Html/Html.php | 58 | ||||
-rw-r--r-- | includes/actions/McrUndoAction.php | 6 | ||||
-rw-r--r-- | includes/htmlform/HTMLForm.php | 16 | ||||
-rw-r--r-- | includes/htmlform/VFormHTMLForm.php | 4 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLButtonField.php | 9 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLCheckField.php | 8 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLCheckMatrix.php | 10 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLMultiSelectField.php | 6 | ||||
-rw-r--r-- | includes/specialpage/SpecialPage.php | 7 | ||||
-rw-r--r-- | includes/xml/Xml.php | 43 | ||||
-rw-r--r-- | tests/phpunit/includes/Html/HtmlTest.php | 59 | ||||
-rw-r--r-- | tests/phpunit/includes/xml/XmlTest.php | 16 |
12 files changed, 20 insertions, 222 deletions
diff --git a/includes/Html/Html.php b/includes/Html/Html.php index 91fecddf05ee..f15cbdbaf8f9 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 0acff789584f..480ae5aa826a 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 dbcfe41aea0b..1c8145958e17 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 7597725653b4..10a71f8195e0 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 36c156ee66ca..08f23c3f94b9 100644 --- a/includes/htmlform/fields/HTMLButtonField.php +++ b/includes/htmlform/fields/HTMLButtonField.php @@ -1,7 +1,6 @@ <?php use MediaWiki\Html\Html; -use MediaWiki\MainConfigNames; /** * Adds a generic button inline to the form. Does not do anything, you must add @@ -69,15 +68,11 @@ class HTMLButtonField extends HTMLFormField { public function getInputHTML( $value ) { $flags = ''; $prefix = 'mw-htmlform-'; - $isCodexForm = $this->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 80365e7d8a2d..673aea7f7de0 100644 --- a/includes/htmlform/fields/HTMLCheckField.php +++ b/includes/htmlform/fields/HTMLCheckField.php @@ -1,7 +1,6 @@ <?php use MediaWiki\Html\Html; -use MediaWiki\MainConfigNames; use MediaWiki\Request\WebRequest; /** @@ -16,11 +15,6 @@ class HTMLCheckField extends HTMLFormField { * @stable to override */ public function getInputHTML( $value ) { - $useMediaWikiUIEverywhere = false; - if ( $this->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 b6e03cbae07f..80238138b815 100644 --- a/includes/htmlform/fields/HTMLCheckMatrix.php +++ b/includes/htmlform/fields/HTMLCheckMatrix.php @@ -1,7 +1,6 @@ <?php use MediaWiki\Html\Html; -use MediaWiki\MainConfigNames; use MediaWiki\Request\WebRequest; /** @@ -184,14 +183,7 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { } protected function getOneCheckboxHTML( $checked, $attribs ) { - $checkbox = Xml::check( "{$this->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 ccd54b1fd6e2..af6ed77e2719 100644 --- a/includes/htmlform/fields/HTMLMultiSelectField.php +++ b/includes/htmlform/fields/HTMLMultiSelectField.php @@ -1,7 +1,6 @@ <?php use MediaWiki\Html\Html; -use MediaWiki\MainConfigNames; use MediaWiki\Request\WebRequest; /** @@ -145,11 +144,6 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable [ 'for' => $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 9ee38fce8c88..59661892c308 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 126f337a7abc..f89fb6a8133a 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 d75165bfd7a1..574d1438000b 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 3ef708ad9f62..ebb53b4e1fe1 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( - '<input name="name" class="foo mw-ui-input" />', - Xml::input( 'name', false, false, [ 'class' => 'foo' ] ) - ); - } - public function testOpenElement() { $this->assertEquals( '<element k="v">', |