Html: Make addition of 'mw-ui-input' conditional on $wgUseMediaWikiUIEverywhere
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 13 Mar 2015 18:49:15 +0000 (19:49 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 13 Mar 2015 19:02:34 +0000 (19:02 +0000)
We were always adding it previously, which seemed harmless since
'mediawiki.ui.input' RL module, providing the styling, was only loaded
if $wgUseMediaWikiUIEverywhere was true… unless someone loaded it
manually to have specific input fields styled. Whoops.

There are a lot more unconditional additions like this in tons of
places in the code, and someone should check whether each one is
intentional or not, but probably no one will. Oh well.

Bug: T92496
Change-Id: I5e91a3852a76ebbbfe64485bccb4c30ddee28b66

includes/Html.php
tests/phpunit/includes/HtmlTest.php
tests/phpunit/includes/XmlTest.php

index bc5cde8..8799225 100644 (file)
@@ -141,16 +141,17 @@ class Html {
                if ( !$attrs ) {
                        $attrs = array();
                }
-               if ( isset( $attrs['class'] ) ) {
-                       if ( is_array( $attrs['class'] ) ) {
-                               $attrs['class'][] = 'mw-ui-input';
+               if ( $wgUseMediaWikiUIEverywhere ) {
+                       if ( isset( $attrs['class'] ) ) {
+                               if ( is_array( $attrs['class'] ) ) {
+                                       $attrs['class'][] = 'mw-ui-input';
+                               } else {
+                                       $attrs['class'] .= ' mw-ui-input';
+                               }
                        } else {
-                               $attrs['class'] .= ' mw-ui-input';
+                               $attrs['class'] = 'mw-ui-input';
                        }
-               } else {
-                       $attrs['class'] = 'mw-ui-input';
-               }
-               if ( $wgUseMediaWikiUIEverywhere ) {
+
                        // Note that size can effect the desired width rendering of mw-ui-input elements
                        // so it is removed. Left intact when mediawiki ui not enabled.
                        unset( $attrs['size'] );
index 992581b..0b58536 100644 (file)
@@ -715,7 +715,7 @@ class HtmlTest extends MediaWikiTestCase {
                        'Input wrapper with type and value.'
                );
                $this->assertEquals(
-                       '<input name=testname class=mw-ui-input>',
+                       '<input name=testname>',
                        Html::input( 'testname' ),
                        'Input wrapper with all default values.'
                );
index e655881..382e3d8 100644 (file)
@@ -81,7 +81,7 @@ class XmlTest extends MediaWikiTestCase {
         */
        public function testElementInputCanHaveAValueOfZero() {
                $this->assertEquals(
-                       '<input name="name" value="0" class="mw-ui-input" />',
+                       '<input name="name" value="0" />',
                        Xml::input( 'name', false, 0 ),
                        'Input with a value of 0 (bug 23797)'
                );
@@ -152,7 +152,7 @@ class XmlTest extends MediaWikiTestCase {
 
                $this->assertEquals(
                        '<label for="year">From year (and earlier):</label> ' .
-                               '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" class="mw-ui-input" /> ' .
+                               '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> ' .
                                '<label for="month">From month (and earlier):</label> ' .
                                '<select id="month" name="month" class="mw-month-selector">' .
                                '<option value="-1">all</option>' . "\n" .
@@ -173,7 +173,7 @@ class XmlTest extends MediaWikiTestCase {
                );
                $this->assertEquals(
                        '<label for="year">From year (and earlier):</label> ' .
-                               '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" class="mw-ui-input" /> ' .
+                               '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> ' .
                                '<label for="month">From month (and earlier):</label> ' .
                                '<select id="month" name="month" class="mw-month-selector">' .
                                '<option value="-1">all</option>' . "\n" .
@@ -207,7 +207,7 @@ class XmlTest extends MediaWikiTestCase {
 
                $this->assertEquals(
                        '<label for="year">From year (and earlier):</label> ' .
-                               '<input id="year" maxlength="4" size="7" type="number" name="year" class="mw-ui-input" /> ' .
+                               '<input id="year" maxlength="4" size="7" type="number" name="year" /> ' .
                                '<label for="month">From month (and earlier):</label> ' .
                                '<select id="month" name="month" class="mw-month-selector">' .
                                '<option value="-1">all</option>' . "\n" .
@@ -233,7 +233,7 @@ class XmlTest extends MediaWikiTestCase {
         */
        public function testTextareaNoContent() {
                $this->assertEquals(
-                       '<textarea name="name" id="name" cols="40" rows="5" class="mw-ui-input"></textarea>',
+                       '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
                        Xml::textarea( 'name', '' ),
                        'textarea() with not content'
                );
@@ -244,7 +244,7 @@ class XmlTest extends MediaWikiTestCase {
         */
        public function testTextareaAttribs() {
                $this->assertEquals(
-                       '<textarea name="name" id="name" cols="20" rows="10" class="mw-ui-input">&lt;txt&gt;</textarea>',
+                       '<textarea name="name" id="name" cols="20" rows="10">&lt;txt&gt;</textarea>',
                        Xml::textarea( 'name', '<txt>', 20, 10 ),
                        'textarea() with custom attribs'
                );