Hello Bartosz Dziewoński, Esanders, Jack Phoenix, Gergő Tisza, Legoktm, 
jenkins-bot, Anomie,

I'd like you to do a code review.  Please visit

    https://gerrit.wikimedia.org/r/328050

to review the following change.


Change subject: Test: Do not merge
......................................................................

Test: Do not merge

Change-Id: I3e71ad227a74e6b69f1af1455f7e005642fad979
---
M includes/htmlform/fields/HTMLFormFieldCloner.php
M resources/src/mediawiki/htmlform/hide-if.js
2 files changed, 9 insertions(+), 64 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/50/328050/1

diff --git a/includes/htmlform/fields/HTMLFormFieldCloner.php 
b/includes/htmlform/fields/HTMLFormFieldCloner.php
index d8de890..09fe1bc 100644
--- a/includes/htmlform/fields/HTMLFormFieldCloner.php
+++ b/includes/htmlform/fields/HTMLFormFieldCloner.php
@@ -96,17 +96,6 @@
                        } else {
                                $info['id'] = Sanitizer::escapeId( 
"{$this->mID}--$key--$fieldname" );
                        }
-                       // Copy the hide-if rules to "child" fields, so that 
the JavaScript code handling them
-                       // (resources/src/mediawiki/htmlform/hide-if.js) 
doesn't have to handle nested fields.
-                       if ( $this->mHideIf ) {
-                               if ( isset( $info['hide-if'] ) ) {
-                                       // Hide child field if either its rules 
say it's hidden, or parent's rules say it's hidden
-                                       $info['hide-if'] = [ 'OR', 
$info['hide-if'], $this->mHideIf ];
-                               } else {
-                                       // Hide child field if parent's rules 
say it's hidden
-                                       $info['hide-if'] = $this->mHideIf;
-                               }
-                       }
                        $field = HTMLForm::loadInputFromParameters( $name, 
$info, $this->mParent );
                        $fields[$fieldname] = $field;
                }
diff --git a/resources/src/mediawiki/htmlform/hide-if.js 
b/resources/src/mediawiki/htmlform/hide-if.js
index f9cb5de..5f60097 100644
--- a/resources/src/mediawiki/htmlform/hide-if.js
+++ b/resources/src/mediawiki/htmlform/hide-if.js
@@ -201,31 +201,22 @@
        }
 
        mw.hook( 'htmlform.enhance' ).add( function ( $root ) {
-               var
-                       $fields = $root.find( '.mw-htmlform-hide-if' ),
-                       $oouiFields = $fields.filter( '[data-ooui]' ),
+               $root.find( '.mw-htmlform-hide-if' ).each( function () {
+                       var v, i, fields, test, func, spec, self, modules, 
data, extraModules,
+                               $el = $( this );
+
                        modules = [];
-
-               if ( $oouiFields.length ) {
-                       modules.push( 'mediawiki.htmlform.ooui' );
-                       $oouiFields.each( function () {
-                               var data, extraModules,
-                                       $el = $( this );
-
+                       if ( $el.is( '[data-ooui]' ) ) {
+                               modules.push( 'mediawiki.htmlform.ooui' );
                                data = $el.data( 'mw-modules' );
                                if ( data ) {
                                        // We can trust this value, 'data-mw-*' 
attributes are banned from user content in Sanitizer
                                        extraModules = data.split( ',' );
                                        modules.push.apply( modules, 
extraModules );
                                }
-                       } );
-               }
+                       }
 
-               mw.loader.using( modules ).done( function () {
-                       $fields.each( function () {
-                               var v, i, fields, test, func, spec, self,
-                                       $el = $( this );
-
+                       mw.loader.using( modules ).done( function () {
                                if ( $el.is( '[data-ooui]' ) ) {
                                        // self should be a FieldLayout that 
mixes in mw.htmlform.Element
                                        self = OO.ui.FieldLayout.static.infuse( 
$el );
@@ -246,42 +237,7 @@
                                test = v[ 1 ];
                                // The .toggle() method works mostly the same 
for jQuery objects and OO.ui.Widget
                                func = function () {
-                                       var shouldHide = test();
-                                       self.toggle( !shouldHide );
-
-                                       // It is impossible to submit a form 
with hidden fields failing validation, e.g. one that
-                                       // is required. However, validity is 
not checked for disabled fields, as these are not
-                                       // submitted with the form. So we 
should also disable fields when hiding them.
-                                       if ( self instanceof jQuery ) {
-                                               // This also finds elements 
inside any nested fields (in case of HTMLFormFieldCloner),
-                                               // which is problematic. But it 
works because:
-                                               // * 
HTMLFormFieldCloner::createFieldsForKey() copies 'hide-if' rules to nested 
fields
-                                               // * jQuery collections like 
$fields are in document order, so we register event
-                                               //   handlers for parents first
-                                               // * Event handlers are fired 
in the order they were registered, so even if the handler
-                                               //   for parent messed up the 
child, the handle for child will run next and fix it
-                                               self.find( 'input, textarea, 
select' ).each( function () {
-                                                       var $this = $( this );
-                                                       if ( shouldHide ) {
-                                                               if ( 
$this.data( 'was-disabled' ) === undefined ) {
-                                                                       
$this.data( 'was-disabled', $this.prop( 'disabled' ) );
-                                                               }
-                                                               $this.prop( 
'disabled', true );
-                                                       } else {
-                                                               $this.prop( 
'disabled', $this.data( 'was-disabled' ) );
-                                                       }
-                                               } );
-                                       } else {
-                                               // self is a OO.ui.FieldLayout
-                                               if ( shouldHide ) {
-                                                       if ( self.wasDisabled 
=== undefined ) {
-                                                               
self.wasDisabled = self.fieldWidget.isDisabled();
-                                                       }
-                                                       
self.fieldWidget.setDisabled( false );
-                                               } else if ( self.wasDisabled 
!== undefined ) {
-                                                       
self.fieldWidget.setDisabled( self.wasDisabled );
-                                               }
-                                       }
+                                       self.toggle( !test() );
                                };
                                for ( i = 0; i < fields.length; i++ ) {
                                        // The .on() method works mostly the 
same for jQuery objects and OO.ui.Widget

-- 
To view, visit https://gerrit.wikimedia.org/r/328050
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e71ad227a74e6b69f1af1455f7e005642fad979
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to