X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.js;h=18f7f0abda7b33e04e1db6d4884ef75c32b27bec;hb=33eabfd8d6a738ae3ed13e3f52c0bbd7664e581a;hp=33f146b9d46e7fe2426767244542fdecf51edcdc;hpb=cbc23bd4dae818680950d3ddb59939e1eb3b0074;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 33f146b9d4..18f7f0abda 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -52,23 +52,25 @@ /* eslint-enable no-bitwise */ } - // - StringSet = window.Set || ( function () { - /** - * @private - * @class - */ - function StringSet() { - this.set = {}; - } - StringSet.prototype.add = function ( value ) { - this.set[ value ] = true; - }; - StringSet.prototype.has = function ( value ) { - return hasOwn.call( this.set, value ); - }; - return StringSet; - }() ); + function defineFallbacks() { + // + StringSet = window.Set || ( function () { + /** + * @private + * @class + */ + function StringSet() { + this.set = {}; + } + StringSet.prototype.add = function ( value ) { + this.set[ value ] = true; + }; + StringSet.prototype.has = function ( value ) { + return hasOwn.call( this.set, value ); + }; + return StringSet; + }() ); + } /** * Create an object that can be read from or written to via methods that allow @@ -142,7 +144,7 @@ var results, i; fallback = arguments.length > 1 ? fallback : null; - if ( $.isArray( selection ) ) { + if ( Array.isArray( selection ) ) { results = {}; for ( i = 0; i < selection.length; i++ ) { if ( typeof selection[ i ] === 'string' ) { @@ -203,7 +205,7 @@ */ exists: function ( selection ) { var i; - if ( $.isArray( selection ) ) { + if ( Array.isArray( selection ) ) { for ( i = 0; i < selection.length; i++ ) { if ( typeof selection[ i ] !== 'string' || !hasOwn.call( this.values, selection[ i ] ) ) { return false; @@ -413,21 +415,39 @@ } }; + defineFallbacks(); + /* eslint-disable no-console */ log = ( function () { - // Also update the restoration of methods in mediawiki.log.js - // when adding or removing methods here. + /** + * Write a verbose message to the browser's console in debug mode. + * + * This method is mainly intended for verbose logging. It is a no-op in production mode. + * In ResourceLoader debug mode, it will use the browser's console if available, with + * fallback to creating a console interface in the DOM and logging messages there. + * + * See {@link mw.log} for other logging methods. + * + * @member mw + * @param {...string} msg Messages to output to console. + */ var log = function () {}, console = window.console; + // Note: Keep list of methods in sync with restoration in mediawiki.log.js + // when adding or removing mw.log methods below! + /** + * Collection of methods to help log messages to the console. + * * @class mw.log * @singleton */ /** - * Write a message to the console's warning channel. - * Actions not supported by the browser console are silently ignored. + * Write a message to the browser console's warning channel. + * + * This method is a no-op in browsers that don't implement the Console API. * * @param {...string} msg Messages to output to console */ @@ -436,10 +456,12 @@ $.noop; /** - * Write a message to the console's error channel. + * Write a message to the browser console's error channel. * - * Most browsers provide a stacktrace by default if the argument - * is a caught Error object. + * Most browsers also print a stacktrace when calling this method if the + * argument is an Error object. + * + * This method is a no-op in browsers that don't implement the Console API. * * @since 1.26 * @param {Error|...string} msg Messages to output to console @@ -449,7 +471,7 @@ $.noop; /** - * Create a property in a host object that, when accessed, will produce + * Create a property on a host object that, when accessed, will produce * a deprecation warning in the console. * * @param {Object} obj Host object of deprecated property @@ -508,6 +530,12 @@ * @class mw */ mw = { + redefineFallbacksForTest: function () { + if ( !window.QUnit ) { + throw new Error( 'Reset not allowed outside unit tests' ); + } + defineFallbacks(); + }, /** * Get the current time, measured in milliseconds since January 1, 1970 (UTC). @@ -692,11 +720,7 @@ return mw.message.apply( mw.message, arguments ).toString(); }, - /** - * No-op dummy placeholder for {@link mw.log} in debug mode. - * - * @method - */ + // Expose mw.log log: log, /** @@ -730,6 +754,7 @@ * is used) * - load-callback: exception thrown by user callback * - module-execute: exception thrown by module code + * - resolve: failed to sort dependencies for a module in mw.loader.load * - store-eval: could not evaluate module code cached in localStorage * - store-localstorage-init: localStorage or JSON parse error in mw.loader.store.init * - store-localstorage-json: JSON conversion error in mw.loader.store.set @@ -847,7 +872,6 @@ cssBuffer = '', cssBufferTimer = null, cssCallbacks = $.Callbacks(), - isIE9 = document.documentMode === 9, rAF = window.requestAnimationFrame || setTimeout; function getMarker() { @@ -896,8 +920,6 @@ * @param {Function} [callback] */ function addEmbeddedCSS( cssText, callback ) { - var $style, styleEl; - function fireCallbacks() { var oldCallbacks = cssCallbacks; // Reset cssCallbacks variable so it's not polluted by any calls to @@ -940,29 +962,7 @@ cssBuffer = ''; } - // By default, always create a new