Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/301112
Change subject: Do not automatically infuse any OOjs UI widgets
......................................................................
Do not automatically infuse any OOjs UI widgets
This is not really what we had in mind when developing the infusion
feature and I think it's not helpful. Most of the time there is just
no benefit; a ButtonWidget generated in PHP and in JS behaves and
looks pretty much the same, and rebuilding it through infusion is a
small performance hit. If you're not adding any even handlers, it only
makes sense for various dropdowns, which have themed styling.
For the primary use case of adding JS behaviors to PHP widgets you
need to call OO.ui.infuse() anyway to get a reference to the JS
widget, and not infusing automatically should make it easier to reason
about your code. Infusion tries to be very transparent, but it can't
hide the fact that the DOM is re-built, making your references to DOM
nodes from before infusion useless and losing anything from PHP that
wasn't included in the config (e.g. custom attributes).
This commit removes automated infusion from mediawiki.page.ready
and adds some custom code in mediawiki.special.movePage and
mediawiki.htmlform. I see only two extensions using infusable OOjs UI
widgets in Gerrit (ArticlePlaceholder and ExtensionDistributor) and
neither should be affected by this change.
Change-Id: I56608c537fc57c5c54960b0603694f2612f45618
---
M includes/htmlform/HTMLComboboxField.php
M includes/htmlform/HTMLFormField.php
M includes/htmlform/HTMLRadioField.php
M includes/htmlform/HTMLSelectField.php
M includes/htmlform/HTMLSelectNamespace.php
M includes/htmlform/HTMLTitleTextField.php
M includes/htmlform/HTMLUserTextField.php
M includes/specials/SpecialMovepage.php
M resources/src/mediawiki.special/mediawiki.special.movePage.js
M resources/src/mediawiki/mediawiki.htmlform.js
M resources/src/mediawiki/page/ready.js
11 files changed, 69 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/12/301112/1
diff --git a/includes/htmlform/HTMLComboboxField.php
b/includes/htmlform/HTMLComboboxField.php
index 778aedb..0c3bc5a 100644
--- a/includes/htmlform/HTMLComboboxField.php
+++ b/includes/htmlform/HTMLComboboxField.php
@@ -56,4 +56,8 @@
'disabled' => $disabled,
] + $attribs );
}
+
+ protected function shouldInfuseOOUI() {
+ return true;
+ }
}
diff --git a/includes/htmlform/HTMLFormField.php
b/includes/htmlform/HTMLFormField.php
index 5f6460d..b47bfa0 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -626,6 +626,11 @@
'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 ) {
@@ -656,6 +661,18 @@
}
/**
+ * 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.
* @since 1.20
diff --git a/includes/htmlform/HTMLRadioField.php
b/includes/htmlform/HTMLRadioField.php
index e5b5e68..976befe 100644
--- a/includes/htmlform/HTMLRadioField.php
+++ b/includes/htmlform/HTMLRadioField.php
@@ -57,6 +57,10 @@
) );
}
+ protected function shouldInfuseOOUI() {
+ return true;
+ }
+
function formatOptions( $options, $value ) {
global $wgUseMediaWikiUIEverywhere;
diff --git a/includes/htmlform/HTMLSelectField.php
b/includes/htmlform/HTMLSelectField.php
index b6ad46c..40b31b5 100644
--- a/includes/htmlform/HTMLSelectField.php
+++ b/includes/htmlform/HTMLSelectField.php
@@ -65,4 +65,8 @@
'disabled' => $disabled,
] + $attribs );
}
+
+ protected function shouldInfuseOOUI() {
+ return true;
+ }
}
diff --git a/includes/htmlform/HTMLSelectNamespace.php
b/includes/htmlform/HTMLSelectNamespace.php
index ef21969..ffa2500 100644
--- a/includes/htmlform/HTMLSelectNamespace.php
+++ b/includes/htmlform/HTMLSelectNamespace.php
@@ -33,4 +33,8 @@
'includeAllValue' => $this->mAllValue,
] );
}
+
+ protected function shouldInfuseOOUI() {
+ return true;
+ }
}
diff --git a/includes/htmlform/HTMLTitleTextField.php
b/includes/htmlform/HTMLTitleTextField.php
index fcf721a..5d5d765 100644
--- a/includes/htmlform/HTMLTitleTextField.php
+++ b/includes/htmlform/HTMLTitleTextField.php
@@ -81,6 +81,10 @@
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';
diff --git a/includes/htmlform/HTMLUserTextField.php
b/includes/htmlform/HTMLUserTextField.php
index 5a7e0b9..f21b53d 100644
--- a/includes/htmlform/HTMLUserTextField.php
+++ b/includes/htmlform/HTMLUserTextField.php
@@ -45,6 +45,10 @@
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' );
diff --git a/includes/specials/SpecialMovepage.php
b/includes/specials/SpecialMovepage.php
index d0c44c3..9cc6745 100644
--- a/includes/specials/SpecialMovepage.php
+++ b/includes/specials/SpecialMovepage.php
@@ -353,6 +353,7 @@
'help' => new OOUI\HtmlSnippet(
$this->msg( 'movepagetalktext' )->parseAsBlock() ),
'align' => 'inline',
'infusable' => true,
+ 'id' => 'wpMovetalk-field',
]
);
}
diff --git a/resources/src/mediawiki.special/mediawiki.special.movePage.js
b/resources/src/mediawiki.special/mediawiki.special.movePage.js
index 6d88c51..9af81b8 100644
--- a/resources/src/mediawiki.special/mediawiki.special.movePage.js
+++ b/resources/src/mediawiki.special/mediawiki.special.movePage.js
@@ -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/mediawiki.htmlform.js
b/resources/src/mediawiki/mediawiki.htmlform.js
index 4cc7f09..8a5db0d 100644
--- a/resources/src/mediawiki/mediawiki.htmlform.js
+++ b/resources/src/mediawiki/mediawiki.htmlform.js
@@ -430,7 +430,29 @@
}
$( function () {
+ var $oouiNodes, modules;
+
enhance( $( document ) );
+
+ // Infuse OOjs UI HTMLForm fields
+ $oouiNodes = $( '.mw-htmlform-field-autoinfuse' );
+ if ( $oouiNodes.length ) {
+ // The modules are added to the page client-side and
should already be loading, but this
+ // module doesn't depend on them, so we have to 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' );
+ }
+ mw.loader.using( modules ).done( function () {
+ $oouiNodes.each( function () {
+ OO.ui.infuse( this );
+ } );
+ } );
+ }
} );
/**
diff --git a/resources/src/mediawiki/page/ready.js
b/resources/src/mediawiki/page/ready.js
index 3b779d1..d228f3e 100644
--- a/resources/src/mediawiki/page/ready.js
+++ b/resources/src/mediawiki/page/ready.js
@@ -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
@@ -45,21 +45,6 @@
// 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 ) {
--
To view, visit https://gerrit.wikimedia.org/r/301112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I56608c537fc57c5c54960b0603694f2612f45618
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits