From 52c4704fd5855d09fc98ce6f19f8fbd7ffe9e7b8 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 14 Nov 2016 11:52:16 -0500 Subject: [PATCH] ApiSandbox: Don't use OO.ui.NumberInputWidget for limit fields According to T150455#2789277 it shouldn't be able to allow 'max' even though this is a mostly-numeric field with one non-numeric value. Oh well. Change-Id: I620a233aab20c715db354eff77ea8a3ffee3bc77 --- .../mediawiki.special.apisandbox.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index 64cfcf5c47..9364e074b3 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -389,19 +389,27 @@ break; case 'limit': - widget = new OO.ui.NumberInputWidget( { - required: Util.apiBool( pi.required ), - isInteger: true + widget = new OO.ui.TextInputWidget( { + required: Util.apiBool( pi.required ) } ); - widget.setIcon = widget.input.setIcon.bind( widget.input ); - widget.setIconTitle = widget.input.setIconTitle.bind( widget.input ); - widget.getValidity = widget.input.getValidity.bind( widget.input ); - widget.input.setValidation( function ( value ) { - return value === 'max' || widget.validateNumber( value ); + widget.setValidation( function ( value ) { + var n, pi = this.paramInfo; + + if ( value === 'max' ) { + return true; + } else { + n = +value; + return !isNaN( n ) && isFinite( n ) && + /* jshint bitwise: false */ + ( n | 0 ) === n && + /* jshint bitwise: true */ + n >= pi.min && n <= pi.apiSandboxMax; + } } ); + pi.min = pi.min || 0; + pi.apiSandboxMax = mw.config.get( 'apihighlimits' ) ? pi.highmax : pi.max; widget.paramInfo = pi; $.extend( widget, WidgetMethods.textInputWidget ); - widget.setRange( pi.min || 0, mw.config.get( 'apihighlimits' ) ? pi.highmax : pi.max ); multiMode = 'enter'; break; -- 2.20.1