jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/375020 )

Change subject: Stop requiring deprecated EditPage::getCheckboxes()
......................................................................


Stop requiring deprecated EditPage::getCheckboxes()

Instead, use getCheckboxesDefinition(), and build our save form
checkboxes from that rather than extracting them from the HTML.

The ability to have non-checkbox fields there is removed, as that was
never intentional and is now impossible.

To avoid transient problems during deployment (old JS code cached in
the user's browser receiving the new format of API responses), the old
property is kept in the API response. We should remove it next week.

Bug: T174613
Bug: T174686
Change-Id: I5bfca5e116fe790302c3b6ac1357e80237fb1ed2
---
M ApiVisualEditor.php
M modules/ve-mw/init/ve.init.mw.ArticleTarget.js
2 files changed, 50 insertions(+), 51 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jforrester: Looks good to me, approved



diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index dff76d7..f508f10 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -449,7 +449,24 @@
                                                ( $user->getOption( 
'watchcreations' ) && !$title->exists() ) ||
                                                $user->isWatched( $title ),
                                ];
-                               $checkboxes = $editPage->getCheckboxes( 
$tabindex, $states );
+                               $checkboxes = method_exists( $editPage, 
'getCheckboxes' )
+                                       ? $editPage->getCheckboxes( $tabindex, 
$states ) : '';
+                               $checkboxesDef = 
$editPage->getCheckboxesDefinition( $states );
+                               $checkboxesMessages = [];
+                               foreach ( $checkboxesDef as $name => $options ) 
{
+                                       if ( isset( $options['tooltip'] ) ) {
+                                               $checkboxesMessages[ 
"accesskey-{$options['tooltip']}" ] =
+                                                       $this->msg( 
"accesskey-{$options['tooltip']}" )->plain();
+                                               $checkboxesMessages[ 
"tooltip-{$options['tooltip']}" ] =
+                                                       $this->msg( 
"tooltip-{$options['tooltip']}" )->plain();
+                                       }
+                                       if ( isset( $options['title-message'] ) 
) {
+                                               $checkboxesMessages[ 
$options['title-message'] ] =
+                                                       $this->msg( 
$options['title-message'] )->plain();
+                                       }
+                                       $checkboxesMessages[ 
$options['label-message'] ] =
+                                               $this->msg( 
$options['label-message'] )->plain();
+                               }
                                $templates = 
$editPage->makeTemplatesOnThisPageList( $editPage->getTemplates() );
 
                                // HACK: Find out which red links are on the 
page
@@ -493,10 +510,16 @@
 
                                // On parser cache miss, just don't bother 
populating red link data
 
+                               foreach ( $checkboxesDef as &$value ) {
+                                       // Don't convert the boolean to empty 
string with formatversion=1
+                                       $value[ApiResult::META_BC_BOOLS] = [ 
'default' ];
+                               }
                                $result = [
                                        'result' => 'success',
                                        'notices' => $notices,
                                        'checkboxes' => $checkboxes,
+                                       'checkboxesDef' => $checkboxesDef,
+                                       'checkboxesMessages' => 
$checkboxesMessages,
                                        'templates' => $templates,
                                        'links' => $links,
                                        'protectedClasses' => implode( ' ', 
$protectedClasses ),
diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js 
b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
index 2d0bde9..b20832c 100644
--- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
+++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
@@ -48,7 +48,6 @@
        this.$templatesUsed = null;
        this.checkboxFields = null;
        this.checkboxesByName = null;
-       this.$otherFields = null;
 
        // Sometimes we actually don't want to send a useful oldid
        // if we do, PostEdit will give us a 'page restored' message
@@ -259,8 +258,8 @@
  * @param {string} status Text status message
  */
 ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) {
-       var i, len, linkData, aboutDoc, docRevId, docRevIdMatches, $checkboxes, 
defaults,
-               target = this,
+       var i, len, linkData, aboutDoc, docRevId, docRevIdMatches,
+               name, options, accesskey, title, $label, checkbox,
                data = response ? ( response.visualeditor || 
response.visualeditoredit ) : null;
 
        if ( !data || typeof data.content !== 'string' ) {
@@ -280,7 +279,8 @@
                this.startTimeStamp = data.starttimestamp;
                this.revid = data.oldid;
 
-               this.checkboxes = data.checkboxes;
+               this.checkboxesDef = data.checkboxesDef;
+               mw.messages.set( data.checkboxesMessages );
                this.$templatesUsed = $( data.templates );
 
                aboutDoc = this.doc.documentElement.getAttribute( 'about' );
@@ -340,60 +340,43 @@
 
        this.checkboxFields = [];
        this.checkboxesByName = {};
-       this.$otherFields = $( [] );
        if ( [ 'edit', 'submit' ].indexOf( mw.util.getParamValue( 'action' ) ) 
!== -1 ) {
                $( '#firstHeading' ).text(
                        mw.Title.newFromText( mw.config.get( 'wgPageName' ) 
).getPrefixedText()
                );
        }
 
-       if ( this.checkboxes ) {
-               defaults = {};
-               $( '.editCheckboxes input' ).each( function () {
-                       defaults[ this.name ] = this.checked;
-               } );
+       if ( this.checkboxesDef ) {
+               for ( name in this.checkboxesDef ) {
+                       options = this.checkboxesDef[ name ];
 
-               $checkboxes = $( '<div>' ).html( ve.getObjectValues( 
this.checkboxes ).join( '' ) );
-               $checkboxes.find( 'input[type=checkbox]' ).each( function () {
-                       var $label, title, checkbox,
-                               $this = $( this ),
-                               name = $this.attr( 'name' ),
-                               id = $this.attr( 'id' );
+                       accesskey = null;
+                       title = null;
+                       if ( options.tooltip ) {
+                               accesskey = mw.message( 'accesskey-' + 
options.tooltip ).text();
+                               title = mw.message( 'tooltip-' + 
options.tooltip ).text();
+                       }
+                       if ( options[ 'title-message' ] ) {
+                               title = mw.message( options[ 'title-message' ] 
).text();
+                       }
+                       $label = $( '<span>' ).append( mw.message( options[ 
'label-message' ] ).parseDom() );
+                       ve.targetLinksToNewWindow( $label[ 0 ] );
 
-                       if ( !name ) {
-                               // This really shouldn't happen..
-                               return;
-                       }
-
-                       // Label with for=id
-                       if ( id ) {
-                               $label = $checkboxes.find( 'label[for=' + id + 
']' );
-                       }
-                       // Label wrapped input
-                       if ( !$label ) {
-                               $label = $this.closest( 'label' );
-                       }
-                       if ( $label ) {
-                               title = $label.attr( 'title' );
-                               ve.targetLinksToNewWindow( $label[ 0 ] );
-                       }
                        checkbox = new OO.ui.CheckboxInputWidget( {
-                               value: $this.attr( 'value' ),
-                               selected: defaults[ name ] !== undefined ? 
defaults[ name ] : $this.prop( 'checked' ),
+                               accessKey: accesskey,
+                               selected: options.default,
                                classes: [ 've-ui-mwSaveDialog-checkbox-' + 
name ]
                        } );
-                       // HACK: CheckboxInputWidget doesn't support access keys
-                       checkbox.$input.attr( 'accesskey', $( this ).attr( 
'accesskey' ) );
-                       target.checkboxFields.push(
+
+                       this.checkboxFields.push(
                                new OO.ui.FieldLayout( checkbox, {
                                        align: 'inline',
-                                       label: $label ? $label.contents() : 
undefined,
+                                       label: $label.contents(),
                                        title: title
                                } )
                        );
-                       target.checkboxesByName[ name ] = checkbox;
-               } );
-               this.$otherFields = $checkboxes.find( 'input[type!=checkbox]' );
+                       this.checkboxesByName[ name ] = checkbox;
+               }
        }
 };
 
@@ -1538,13 +1521,6 @@
                        fields[ name ] = this.checkboxesByName[ name 
].getValue();
                }
        }
-       this.$otherFields.each( function () {
-               var $this = $( this ),
-                       name = $this.prop( 'name' );
-               if ( name ) {
-                       fields[ name ] = $this.val();
-               }
-       } );
 
        return fields;
 };
@@ -2224,7 +2200,7 @@
                                data.basetimestamp = target.baseTimeStamp;
                                data.starttimestamp = target.startTimeStamp;
                                data.oldid = target.revid;
-                               data.checkboxes = target.checkboxes;
+                               data.checkboxesDef = target.checkboxesDef;
                                return response;
                        } );
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5bfca5e116fe790302c3b6ac1357e80237fb1ed2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to