Merge "Increase Opera minimum for Grades A and C to 15"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.apisandbox.js
index 9e8d4f4..ff4335a 100644 (file)
                        multi: function () {
                                var map = this.paramInfo.submodules,
                                        v = this.isDisabled() ? this.paramInfo[ 'default' ] : this.getApiValue();
-                               return v === undefined || v === '' ? [] : $.map( String( v ).split( '|' ), function ( v ) {
+                               return v === undefined || v === '' ? [] : String( v ).split( '|' ).map( function ( v ) {
                                        return { value: v, path: map[ v ] };
                                } );
                        }
 
                                case 'string':
                                case 'user':
-                                       if ( pi.tokentype ) {
-                                               widget = new TextInputWithIndicatorWidget( {
-                                                       input: {
-                                                               indicator: 'previous',
-                                                               indicatorTitle: mw.message( 'apisandbox-fetch-token' ).text(),
-                                                               required: Util.apiBool( pi.required )
-                                                       }
-                                               } );
-                                       } else if ( Util.apiBool( pi.multi ) ) {
+                                       if ( Util.apiBool( pi.multi ) ) {
                                                widget = new OO.ui.CapsuleMultiselectWidget( {
                                                        allowArbitrary: true,
                                                        allowDuplicates: Util.apiBool( pi.allowsduplicates ),
                                                widget.setValidation( Validators.generic );
                                        }
                                        if ( pi.tokentype ) {
+                                               widget.paramInfo = pi;
+                                               $.extend( widget, WidgetMethods.textInputWidget );
                                                $.extend( widget, WidgetMethods.tokenWidget );
-                                               widget.input.paramInfo = pi;
-                                               $.extend( widget.input, WidgetMethods.textInputWidget );
-                                               $.extend( widget.input, WidgetMethods.tokenWidget );
-                                               widget.on( 'indicator', widget.fetchToken, [], widget );
                                        }
                                        break;
 
                                                throw new Error( 'Unknown parameter type ' + pi.type );
                                        }
 
-                                       items = $.map( pi.type, function ( v ) {
+                                       items = pi.type.map( function ( v ) {
                                                var config = {
                                                        data: String( v ),
                                                        label: String( v ),
                                .empty()
                                .append( $( '<p>' ).append( Util.parseMsg( 'apisandbox-intro' ) ) )
                                .append(
-                                       $( '<div>', { id: 'mw-apisandbox-ui' } )
+                                       $( '<div>' ).attr( 'id', 'mw-apisandbox-ui' )
                                                .append( $toolbar )
                                                .append( panel.$element )
                                );
 
                Util.fetchModuleInfo( this.apiModule )
                        .done( function ( pi ) {
-                               var prefix, i, j, descriptionContainer, widget, widgetField, helpField, tmp, flag, count,
+                               var prefix, i, j, descriptionContainer, widget, layoutConfig, button, widgetField, helpField, tmp, flag, count,
                                        items = [],
                                        deprecatedItems = [],
                                        buttons = [],
                                                        width: 'auto',
                                                        padded: true,
                                                        $content: $( '<ul>' ).append( $.map( pi.helpurls, function ( link ) {
-                                                               return $( '<li>' ).append( $( '<a>', {
-                                                                       href: link,
-                                                                       target: '_blank',
-                                                                       text: link
-                                                               } ) );
+                                                               return $( '<li>' ).append( $( '<a>' )
+                                                                       .attr( { href: link, target: '_blank' } )
+                                                                       .text( link )
+                                                               );
                                                        } ) )
                                                }
                                        } ) );
                                                        width: 'auto',
                                                        padded: true,
                                                        $content: $( '<ul>' ).append( $.map( pi.examples, function ( example ) {
-                                                               var a = $( '<a>', {
-                                                                       href: '#' + example.query,
-                                                                       html: example.description
-                                                               } );
+                                                               var a = $( '<a>' )
+                                                                       .attr( 'href', '#' + example.query )
+                                                                       .html( example.description );
                                                                a.find( 'a' ).contents().unwrap(); // Can't nest links
                                                                return $( '<li>' ).append( a );
                                                        } ) )
                                                        var $this = $( this );
                                                        $this.parent().prev( 'p' ).append( $this );
                                                } );
-                                               descriptionContainer.append( $( '<div>', { addClass: 'description', append: tmp } ) );
+                                               descriptionContainer.append( $( '<div>' ).addClass( 'description' ).append( tmp ) );
 
                                                if ( pi.parameters[ i ].info && pi.parameters[ i ].info.length ) {
                                                        for ( j = 0; j < pi.parameters[ i ].info.length; j++ ) {
-                                                               descriptionContainer.append( $( '<div>', {
-                                                                       addClass: 'info',
-                                                                       append: Util.parseHTML( pi.parameters[ i ].info[ j ] )
-                                                               } ) );
+                                                               descriptionContainer.append( $( '<div>' )
+                                                                       .addClass( 'info' )
+                                                                       .append( Util.parseHTML( pi.parameters[ i ].info[ j ] ) )
+                                                               );
                                                        }
                                                }
                                                flag = true;
 
                                                        case 'limit':
                                                                if ( pi.parameters[ i ].highmax !== undefined ) {
-                                                                       descriptionContainer.append( $( '<div>', {
-                                                                               addClass: 'info',
-                                                                               append: [
+                                                                       descriptionContainer.append( $( '<div>' )
+                                                                               .addClass( 'info' )
+                                                                               .append(
                                                                                        Util.parseMsg(
                                                                                                'api-help-param-limit2', pi.parameters[ i ].max, pi.parameters[ i ].highmax
                                                                                        ),
                                                                                        ' ',
                                                                                        Util.parseMsg( 'apisandbox-param-limit' )
-                                                                               ]
-                                                                       } ) );
+                                                                               )
+                                                                       );
                                                                } else {
-                                                                       descriptionContainer.append( $( '<div>', {
-                                                                               addClass: 'info',
-                                                                               append: [
+                                                                       descriptionContainer.append( $( '<div>' )
+                                                                               .addClass( 'info' )
+                                                                               .append(
                                                                                        Util.parseMsg( 'api-help-param-limit', pi.parameters[ i ].max ),
                                                                                        ' ',
                                                                                        Util.parseMsg( 'apisandbox-param-limit' )
-                                                                               ]
-                                                                       } ) );
+                                                                               )
+                                                                       );
                                                                }
                                                                break;
 
                                                                        tmp += 'max';
                                                                }
                                                                if ( tmp !== '' ) {
-                                                                       descriptionContainer.append( $( '<div>', {
-                                                                               addClass: 'info',
-                                                                               append: Util.parseMsg(
+                                                                       descriptionContainer.append( $( '<div>' )
+                                                                               .addClass( 'info' )
+                                                                               .append( Util.parseMsg(
                                                                                        'api-help-param-integer-' + tmp,
                                                                                        Util.apiBool( pi.parameters[ i ].multi ) ? 2 : 1,
                                                                                        pi.parameters[ i ].min, pi.parameters[ i ].max
-                                                                               )
-                                                                       } ) );
+                                                                               ) )
+                                                                       );
                                                                }
                                                                break;
 
                                                                );
                                                        }
                                                        if ( tmp.length ) {
-                                                               descriptionContainer.append( $( '<div>', {
-                                                                       addClass: 'info',
-                                                                       append: Util.parseHTML( tmp.join( ' ' ) )
-                                                               } ) );
+                                                               descriptionContainer.append( $( '<div>' )
+                                                                       .addClass( 'info' )
+                                                                       .append( Util.parseHTML( tmp.join( ' ' ) ) )
+                                                               );
                                                        }
                                                }
+                                               if ( 'maxbytes' in pi.parameters[ i ] ) {
+                                                       descriptionContainer.append( $( '<div>' )
+                                                               .addClass( 'info' )
+                                                               .append( Util.parseMsg( 'api-help-param-maxbytes', pi.parameters[ i ].maxbytes ) )
+                                                       );
+                                               }
+                                               if ( 'maxchars' in pi.parameters[ i ] ) {
+                                                       descriptionContainer.append( $( '<div>' )
+                                                               .addClass( 'info' )
+                                                               .append( Util.parseMsg( 'api-help-param-maxchars', pi.parameters[ i ].maxchars ) )
+                                                       );
+                                               }
                                                helpField = new OO.ui.FieldLayout(
                                                        new OO.ui.Widget( {
                                                                $content: '\xa0',
                                                        }
                                                );
 
-                                               widgetField = new OO.ui.FieldLayout(
-                                                       widget,
-                                                       {
-                                                               align: 'left',
-                                                               classes: [ 'mw-apisandbox-widget-field' ],
-                                                               label: prefix + pi.parameters[ i ].name
-                                                       }
-                                               );
+                                               layoutConfig = {
+                                                       align: 'left',
+                                                       classes: [ 'mw-apisandbox-widget-field' ],
+                                                       label: prefix + pi.parameters[ i ].name
+                                               };
+
+                                               if ( pi.parameters[ i ].tokentype ) {
+                                                       button = new OO.ui.ButtonWidget( {
+                                                               label: mw.message( 'apisandbox-fetch-token' ).text()
+                                                       } );
+                                                       button.on( 'click', widget.fetchToken, [], widget );
+
+                                                       widgetField = new OO.ui.ActionFieldLayout( widget, button, layoutConfig );
+                                               } else {
+                                                       widgetField = new OO.ui.FieldLayout( widget, layoutConfig );
+                                               }
 
                                                // We need our own click handler on the widget label to
                                                // turn off the disablement.
                return ret;
        };
 
-       /**
-        * A text input with a clickable indicator
-        *
-        * @class
-        * @private
-        * @constructor
-        * @param {Object} [config] Configuration options
-        */
-       function TextInputWithIndicatorWidget( config ) {
-               var k;
-
-               config = config || {};
-               TextInputWithIndicatorWidget[ 'super' ].call( this, config );
-
-               this.$indicator = $( '<span>' ).addClass( 'mw-apisandbox-clickable-indicator' );
-               OO.ui.mixin.TabIndexedElement.call(
-                       this, $.extend( {}, config, { $tabIndexed: this.$indicator } )
-               );
-
-               this.input = new OO.ui.TextInputWidget( $.extend( {
-                       $indicator: this.$indicator,
-                       disabled: this.isDisabled()
-               }, config.input ) );
-
-               // Forward most methods for convenience
-               for ( k in this.input ) {
-                       if ( $.isFunction( this.input[ k ] ) && !this[ k ] ) {
-                               this[ k ] = this.input[ k ].bind( this.input );
-                       }
-               }
-
-               this.$indicator.on( {
-                       click: this.onIndicatorClick.bind( this ),
-                       keypress: this.onIndicatorKeyPress.bind( this )
-               } );
-
-               this.$element.append( this.input.$element );
-       }
-       OO.inheritClass( TextInputWithIndicatorWidget, OO.ui.Widget );
-       OO.mixinClass( TextInputWithIndicatorWidget, OO.ui.mixin.TabIndexedElement );
-       TextInputWithIndicatorWidget.prototype.onIndicatorClick = function ( e ) {
-               if ( !this.isDisabled() && e.which === 1 ) {
-                       this.emit( 'indicator' );
-               }
-               return false;
-       };
-       TextInputWithIndicatorWidget.prototype.onIndicatorKeyPress = function ( e ) {
-               if ( !this.isDisabled() && ( e.which === OO.ui.Keys.SPACE || e.which === OO.ui.Keys.ENTER ) ) {
-                       this.emit( 'indicator' );
-                       return false;
-               }
-       };
-       TextInputWithIndicatorWidget.prototype.setDisabled = function ( disabled ) {
-               TextInputWithIndicatorWidget[ 'super' ].prototype.setDisabled.call( this, disabled );
-               if ( this.input ) {
-                       this.input.setDisabled( this.isDisabled() );
-               }
-               return this;
-       };
-
        /**
         * A wrapper for a widget that provides an enable/disable button
         *