Merge "Do not automatically infuse any OOjs UI widgets"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 20 Aug 2016 16:54:50 +0000 (16:54 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 20 Aug 2016 16:54:50 +0000 (16:54 +0000)
13 files changed:
RELEASE-NOTES-1.28
includes/htmlform/HTMLFormField.php
includes/htmlform/fields/HTMLComboboxField.php
includes/htmlform/fields/HTMLRadioField.php
includes/htmlform/fields/HTMLSelectField.php
includes/htmlform/fields/HTMLSelectNamespace.php
includes/htmlform/fields/HTMLTitleTextField.php
includes/htmlform/fields/HTMLUserTextField.php
includes/specials/SpecialMovepage.php
resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.movePage.js
resources/src/mediawiki/htmlform/autoinfuse.js [new file with mode: 0644]
resources/src/mediawiki/page/ready.js

index eac4e2c..5d88fbf 100644 (file)
@@ -118,6 +118,9 @@ changes to languages because of Phabricator reports.
 * AuthenticationRequest::$required is now changed from REQUIRED to PRIMARY_REQUIRED
   on requests needed by primary providers even if all primaries need them.
   Primary providers are discouraged from returning multiple REQUIRED requests.
+* OOjs UI PHP widgets constructed with the `'infusable' => true` config option
+  will no longer be automatically infused. You should call `OO.ui.infuse()`
+  on them yourself from your JavaScript code.
 
 == Compatibility ==
 
index 5f6460d..b47bfa0 100644 (file)
@@ -626,6 +626,11 @@ abstract class HTMLFormField {
                        'infusable' => $infusable,
                ];
 
+               if ( $infusable && $this->shouldInfuseOOUI() ) {
+                       $this->mParent->getOutput()->addModules( 'oojs-ui-core' );
+                       $config['classes'][] = 'mw-htmlform-field-autoinfuse';
+               }
+
                // the element could specify, that the label doesn't need to be added
                $label = $this->getLabel();
                if ( $label ) {
@@ -655,6 +660,18 @@ abstract class HTMLFormField {
                return new OOUI\FieldLayout( $inputField, $config );
        }
 
+       /**
+        * Whether the field should be automatically infused. Note that all OOjs UI HTMLForm fields are
+        * infusable (you can call OO.ui.infuse() on them), but not all are infused by default, since
+        * there is no benefit in doing it e.g. for buttons and it's a small performance hit on page load.
+        *
+        * @return bool
+        */
+       protected function shouldInfuseOOUI() {
+               // Always infuse fields with help text, since the interface for it is nicer with JS
+               return $this->getHelpText() !== null;
+       }
+
        /**
         * Get the complete raw fields for the input, including help text,
         * labels, and whatever.
index 778aedb..0c3bc5a 100644 (file)
@@ -56,4 +56,8 @@ class HTMLComboboxField extends HTMLTextField {
                        'disabled' => $disabled,
                ] + $attribs );
        }
+
+       protected function shouldInfuseOOUI() {
+               return true;
+       }
 }
index e5b5e68..976befe 100644 (file)
@@ -57,6 +57,10 @@ class HTMLRadioField extends HTMLFormField {
                ) );
        }
 
+       protected function shouldInfuseOOUI() {
+               return true;
+       }
+
        function formatOptions( $options, $value ) {
                global $wgUseMediaWikiUIEverywhere;
 
index b6ad46c..40b31b5 100644 (file)
@@ -65,4 +65,8 @@ class HTMLSelectField extends HTMLFormField {
                        'disabled' => $disabled,
                ] + $attribs );
        }
+
+       protected function shouldInfuseOOUI() {
+               return true;
+       }
 }
index ef21969..ffa2500 100644 (file)
@@ -33,4 +33,8 @@ class HTMLSelectNamespace extends HTMLFormField {
                        'includeAllValue' => $this->mAllValue,
                ] );
        }
+
+       protected function shouldInfuseOOUI() {
+               return true;
+       }
 }
index fcf721a..5d5d765 100644 (file)
@@ -81,6 +81,10 @@ class HTMLTitleTextField extends HTMLTextField {
                return new TitleInputWidget( $params );
        }
 
+       protected function shouldInfuseOOUI() {
+               return true;
+       }
+
        public function getInputHtml( $value ) {
                // add mw-searchInput class to enable search suggestions for non-OOUI, too
                $this->mClass .= 'mw-searchInput';
index 5a7e0b9..f21b53d 100644 (file)
@@ -45,6 +45,10 @@ class HTMLUserTextField extends HTMLTextField {
                return new UserInputWidget( $params );
        }
 
+       protected function shouldInfuseOOUI() {
+               return true;
+       }
+
        public function getInputHtml( $value ) {
                // add the required module and css class for user suggestions in non-OOUI mode
                $this->mParent->getOutput()->addModules( 'mediawiki.userSuggest' );
index d0c44c3..9cc6745 100644 (file)
@@ -353,6 +353,7 @@ class MovePageForm extends UnlistedSpecialPage {
                                        'help' => new OOUI\HtmlSnippet( $this->msg( 'movepagetalktext' )->parseAsBlock() ),
                                        'align' => 'inline',
                                        'infusable' => true,
+                                       'id' => 'wpMovetalk-field',
                                ]
                        );
                }
index 1372a8e..3a5b002 100644 (file)
@@ -1071,6 +1071,7 @@ return [
                'scripts' => [
                        'resources/src/mediawiki/htmlform/htmlform.js',
                        'resources/src/mediawiki/htmlform/autocomplete.js',
+                       'resources/src/mediawiki/htmlform/autoinfuse.js',
                        'resources/src/mediawiki/htmlform/checkmatrix.js',
                        'resources/src/mediawiki/htmlform/cloner.js',
                        'resources/src/mediawiki/htmlform/hide-if.js',
index 6d88c51..9af81b8 100644 (file)
@@ -2,6 +2,10 @@
  * JavaScript for Special:MovePage
  */
 jQuery( function () {
+       // Infuse for pretty dropdown
        OO.ui.infuse( 'wpNewTitle' );
+       // Limit to 255 bytes, not characters
        OO.ui.infuse( 'wpReason' ).$input.byteLimit();
+       // Infuse for nicer "help" popup
+       OO.ui.infuse( 'wpMovetalk-field' );
 } );
diff --git a/resources/src/mediawiki/htmlform/autoinfuse.js b/resources/src/mediawiki/htmlform/autoinfuse.js
new file mode 100644 (file)
index 0000000..f77e367
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * HTMLForm enhancements:
+ * Infuse some OOjs UI HTMLForm fields (those which benefit from always being infused).
+ */
+( function ( mw ) {
+
+       mw.hook( 'htmlform.enhance' ).add( function ( $root ) {
+               var $oouiNodes, modules;
+
+               $oouiNodes = $root.find( '.mw-htmlform-field-autoinfuse' );
+               if ( $oouiNodes.length ) {
+                       // The modules are preloaded (added server-side in HTMLFormField, and the individual fields
+                       // which need extra ones), but this module doesn't depend on them. Wait until they're loaded.
+                       modules = [ 'oojs-ui-core' ];
+                       if ( $oouiNodes.filter( '.mw-htmlform-field-HTMLTitleTextField' ).length ) {
+                               // FIXME: TitleInputWidget should be in its own module
+                               modules.push( 'mediawiki.widgets' );
+                       }
+                       if ( $oouiNodes.filter( '.mw-htmlform-field-HTMLUserTextField' ).length ) {
+                               modules.push( 'mediawiki.widgets.UserInputWidget' );
+                       }
+                       if (
+                               $oouiNodes.filter( '.mw-htmlform-field-HTMLSelectNamespace' ).length ||
+                               $oouiNodes.filter( '.mw-htmlform-field-HTMLSelectNamespaceWithButton' ).length
+                       ) {
+                               // FIXME: NamespaceInputWidget should be in its own module (probably?)
+                               modules.push( 'mediawiki.widgets' );
+                       }
+                       mw.loader.using( modules ).done( function () {
+                               $oouiNodes.each( function () {
+                                       OO.ui.infuse( this );
+                               } );
+                       } );
+               }
+
+       } );
+
+}( mediaWiki ) );
index 3b779d1..d228f3e 100644 (file)
@@ -36,7 +36,7 @@
 
        // Things outside the wikipage content
        $( function () {
-               var $nodes, $oouiNodes;
+               var $nodes;
 
                if ( !supportsPlaceholder ) {
                        // Exclude content to avoid hitting it twice for the (first) wikipage content
                // Add accesskey hints to the tooltips
                $( '[accesskey]' ).updateTooltipAccessKeys();
 
-               // Infuse OOUI widgets, if any are present
-               $oouiNodes = $( '[data-ooui]' );
-               if ( $oouiNodes.length ) {
-                       // FIXME: We should only load the widgets that are being infused
-                       mw.loader.using( [
-                               'mediawiki.widgets',
-                               'mediawiki.widgets.UserInputWidget',
-                               'mediawiki.widgets.SearchInputWidget'
-                       ] ).done( function () {
-                               $oouiNodes.each( function () {
-                                       OO.ui.infuse( this );
-                               } );
-                       } );
-               }
-
                $nodes = $( '.catlinks[data-mw="interface"]' );
                if ( $nodes.length ) {
                        /**