Remove uses of $wgUseMediaWikiUIEverywhere
Removing the config variable in a separate change: Ib9966bc6a4a94f771cb99a5aa52fb6a1dc826ca5 (just in case something depends on its existence). Bug: T182050 Change-Id: Ic3e038df16fc540ec7f6bcb9a54d73f8d596d305
This commit is contained in:
parent
bc9d87ad60
commit
aa7eeeeef9
12 changed files with 20 additions and 222 deletions
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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?)
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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 ) {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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 ) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ];
|
||||
|
|
|
|||
|
|
@ -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">',
|
||||
|
|
|
|||
Loading…
Reference in a new issue