Merge "objectcache: define makeKey()/makeGlobalKey() for ReplicatedBagOStuff"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 27 Jun 2018 15:55:27 +0000 (15:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 27 Jun 2018 15:55:27 +0000 (15:55 +0000)
includes/resourceloader/ResourceLoaderFileModule.php
includes/resourceloader/ResourceLoaderImageModule.php
resources/Resources.php
resources/src/mediawiki.base/mediawiki.base.js
resources/src/mediawiki.inspect.js
resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js [deleted file]
resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js
resources/src/mediawiki.widgets/mw.widgets.CategoryTagItemWidget.js [new file with mode: 0644]
tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php

index e572aa4..68ea0c0 100644 (file)
@@ -486,16 +486,13 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        }
 
        /**
-        * Helper method to gather file hashes for getDefinitionSummary.
-        *
-        * This function is context-sensitive, only computing hashes of files relevant to the
-        * given language, skin, etc.
+        * Helper method for getDefinitionSummary.
         *
         * @see ResourceLoaderModule::getFileDependencies
         * @param ResourceLoaderContext $context
         * @return array
         */
-       protected function getFileHashes( ResourceLoaderContext $context ) {
+       private function getFileHashes( ResourceLoaderContext $context ) {
                $files = [];
 
                // Flatten style files into $files
@@ -673,12 +670,12 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        }
 
        /**
-        * Get a list of file paths for all scripts in this module, in order of proper execution.
+        * Get a list of script file paths for this module, in order of proper execution.
         *
         * @param ResourceLoaderContext $context
         * @return array List of file paths
         */
-       protected function getScriptFiles( ResourceLoaderContext $context ) {
+       private function getScriptFiles( ResourceLoaderContext $context ) {
                $files = array_merge(
                        $this->scripts,
                        $this->getLanguageScripts( $context->getLanguage() ),
@@ -717,6 +714,9 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        /**
         * Get a list of file paths for all styles in this module, in order of proper inclusion.
         *
+        * This is considered a private method. Exposed for internal use by WebInstallerOutput.
+        *
+        * @private
         * @param ResourceLoaderContext $context
         * @return array List of file paths
         */
@@ -790,13 +790,13 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        }
 
        /**
-        * Gets the contents of a list of JavaScript files.
+        * Get the contents of a list of JavaScript files. Helper for getScript().
         *
         * @param array $scripts List of file paths to scripts to read, remap and concetenate
-        * @throws MWException
         * @return string Concatenated and remapped JavaScript data from $scripts
+        * @throws MWException
         */
-       protected function readScriptFiles( array $scripts ) {
+       private function readScriptFiles( array $scripts ) {
                if ( empty( $scripts ) ) {
                        return '';
                }
@@ -819,17 +819,17 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
        }
 
        /**
-        * Gets the contents of a list of CSS files.
+        * Get the contents of a list of CSS files.
+        *
+        * This is considered a private method. Exposed for internal use by WebInstallerOutput.
         *
-        * @param array $styles List of media type/list of file paths pairs, to read, remap and
-        * concetenate
+        * @private
+        * @param array $styles Map of media type to file paths to read, remap, and concatenate
         * @param bool $flip
         * @param ResourceLoaderContext $context
-        *
-        * @throws MWException
         * @return array List of concatenated and remapped CSS data from $styles,
         *     keyed by media type
-        *
+        * @throws MWException
         * @since 1.27 Calling this method without a ResourceLoaderContext instance
         *   is deprecated.
         */
index e1bddcc..26d5e98 100644 (file)
@@ -426,7 +426,7 @@ class ResourceLoaderImageModule extends ResourceLoaderModule {
         * @param ResourceLoaderContext $context
         * @return array
         */
-       protected function getFileHashes( ResourceLoaderContext $context ) {
+       private function getFileHashes( ResourceLoaderContext $context ) {
                $this->loadFromDefinition();
                $files = [];
                foreach ( $this->getImages( $context ) as $name => $image ) {
index dea9293..b4b921f 100644 (file)
@@ -2644,7 +2644,7 @@ return [
        ],
        'mediawiki.widgets.CategoryMultiselectWidget' => [
                'scripts' => [
-                       'resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js',
+                       'resources/src/mediawiki.widgets/mw.widgets.CategoryTagItemWidget.js',
                        'resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js',
                ],
                'dependencies' => [
index ed24af3..1c3dde6 100644 (file)
         */
        mw.inspect = function () {
                var args = arguments;
+               // Lazy-load
                mw.loader.using( 'mediawiki.inspect', function () {
                        mw.inspect.runReports.apply( mw.inspect, args );
                } );
index 6478fd9..e2030c9 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Tools for inspecting page composition and performance.
+ * The mediawiki.inspect module.
  *
  * @author Ori Livneh
  * @since 1.22
@@ -9,7 +9,19 @@
 
 ( function ( mw, $ ) {
 
-       var inspect,
+       // mw.inspect is a singleton class with static methods
+       // that itself can also be invoked as a function (mediawiki.base/mw#inspect).
+       // In JavaScript, that is implemented by starting with a function,
+       // and subsequently setting additional properties on the function object.
+
+       /**
+        * Tools for inspecting page composition and performance.
+        *
+        * @class mw.inspect
+        * @singleton
+        */
+
+       var inspect = mw.inspect,
                byteLength = require( 'mediawiki.String' ).byteLength,
                hasOwn = Object.prototype.hasOwnProperty;
 
        }
 
        /**
-        * @class mw.inspect
-        * @singleton
+        * Return a map of all dependency relationships between loaded modules.
+        *
+        * @return {Object} Maps module names to objects. Each sub-object has
+        *  two properties, 'requires' and 'requiredBy'.
         */
-       inspect = {
+       inspect.getDependencyGraph = function () {
+               var modules = inspect.getLoadedModules(),
+                       graph = {};
 
-               /**
-                * Return a map of all dependency relationships between loaded modules.
-                *
-                * @return {Object} Maps module names to objects. Each sub-object has
-                *  two properties, 'requires' and 'requiredBy'.
-                */
-               getDependencyGraph: function () {
-                       var modules = inspect.getLoadedModules(),
-                               graph = {};
+               modules.forEach( function ( moduleName ) {
+                       var dependencies = mw.loader.moduleRegistry[ moduleName ].dependencies || [];
 
-                       modules.forEach( function ( moduleName ) {
-                               var dependencies = mw.loader.moduleRegistry[ moduleName ].dependencies || [];
+                       if ( !hasOwn.call( graph, moduleName ) ) {
+                               graph[ moduleName ] = { requiredBy: [] };
+                       }
+                       graph[ moduleName ].requires = dependencies;
 
-                               if ( !hasOwn.call( graph, moduleName ) ) {
-                                       graph[ moduleName ] = { requiredBy: [] };
+                       dependencies.forEach( function ( depName ) {
+                               if ( !hasOwn.call( graph, depName ) ) {
+                                       graph[ depName ] = { requiredBy: [] };
                                }
-                               graph[ moduleName ].requires = dependencies;
-
-                               dependencies.forEach( function ( depName ) {
-                                       if ( !hasOwn.call( graph, depName ) ) {
-                                               graph[ depName ] = { requiredBy: [] };
-                                       }
-                                       graph[ depName ].requiredBy.push( moduleName );
-                               } );
+                               graph[ depName ].requiredBy.push( moduleName );
                        } );
-                       return graph;
-               },
+               } );
+               return graph;
+       };
 
-               /**
-                * Calculate the byte size of a ResourceLoader module.
-                *
-                * @param {string} moduleName The name of the module
-                * @return {number|null} Module size in bytes or null
-                */
-               getModuleSize: function ( moduleName ) {
-                       var module = mw.loader.moduleRegistry[ moduleName ],
-                               args, i, size;
+       /**
+        * Calculate the byte size of a ResourceLoader module.
+        *
+        * @param {string} moduleName The name of the module
+        * @return {number|null} Module size in bytes or null
+        */
+       inspect.getModuleSize = function ( moduleName ) {
+               var module = mw.loader.moduleRegistry[ moduleName ],
+                       args, i, size;
 
-                       if ( module.state !== 'ready' ) {
-                               return null;
-                       }
+               if ( module.state !== 'ready' ) {
+                       return null;
+               }
+
+               if ( !module.style && !module.script ) {
+                       return 0;
+               }
 
-                       if ( !module.style && !module.script ) {
-                               return 0;
+               function getFunctionBody( func ) {
+                       return String( func )
+                               // To ensure a deterministic result, replace the start of the function
+                               // declaration with a fixed string. For example, in Chrome 55, it seems
+                               // V8 seemingly-at-random decides to sometimes put a line break between
+                               // the opening brace and first statement of the function body. T159751.
+                               .replace( /^\s*function\s*\([^)]*\)\s*{\s*/, 'function(){' )
+                               .replace( /\s*}\s*$/, '}' );
+               }
+
+               // Based on the load.php response for this module.
+               // For example: `mw.loader.implement("example", function(){}, {"css":[".x{color:red}"]});`
+               // @see mw.loader.store.set().
+               args = [
+                       moduleName,
+                       module.script,
+                       module.style,
+                       module.messages,
+                       module.templates
+               ];
+               // Trim trailing null or empty object, as load.php would have done.
+               // @see ResourceLoader::makeLoaderImplementScript and ResourceLoader::trimArray.
+               i = args.length;
+               while ( i-- ) {
+                       if ( args[ i ] === null || ( $.isPlainObject( args[ i ] ) && $.isEmptyObject( args[ i ] ) ) ) {
+                               args.splice( i, 1 );
+                       } else {
+                               break;
                        }
+               }
 
-                       function getFunctionBody( func ) {
-                               return String( func )
-                                       // To ensure a deterministic result, replace the start of the function
-                                       // declaration with a fixed string. For example, in Chrome 55, it seems
-                                       // V8 seemingly-at-random decides to sometimes put a line break between
-                                       // the opening brace and first statement of the function body. T159751.
-                                       .replace( /^\s*function\s*\([^)]*\)\s*{\s*/, 'function(){' )
-                                       .replace( /\s*}\s*$/, '}' );
+               size = 0;
+               for ( i = 0; i < args.length; i++ ) {
+                       if ( typeof args[ i ] === 'function' ) {
+                               size += byteLength( getFunctionBody( args[ i ] ) );
+                       } else {
+                               size += byteLength( JSON.stringify( args[ i ] ) );
                        }
+               }
 
-                       // Based on the load.php response for this module.
-                       // For example: `mw.loader.implement("example", function(){}, {"css":[".x{color:red}"]});`
-                       // @see mw.loader.store.set().
-                       args = [
-                               moduleName,
-                               module.script,
-                               module.style,
-                               module.messages,
-                               module.templates
-                       ];
-                       // Trim trailing null or empty object, as load.php would have done.
-                       // @see ResourceLoader::makeLoaderImplementScript and ResourceLoader::trimArray.
-                       i = args.length;
-                       while ( i-- ) {
-                               if ( args[ i ] === null || ( $.isPlainObject( args[ i ] ) && $.isEmptyObject( args[ i ] ) ) ) {
-                                       args.splice( i, 1 );
-                               } else {
-                                       break;
+               return size;
+       };
+
+       /**
+        * Given CSS source, count both the total number of selectors it
+        * contains and the number which match some element in the current
+        * document.
+        *
+        * @param {string} css CSS source
+        * @return {Object} Selector counts
+        * @return {number} return.selectors Total number of selectors
+        * @return {number} return.matched Number of matched selectors
+        */
+       inspect.auditSelectors = function ( css ) {
+               var selectors = { total: 0, matched: 0 },
+                       style = document.createElement( 'style' );
+
+               style.textContent = css;
+               document.body.appendChild( style );
+               $.each( style.sheet.cssRules, function ( index, rule ) {
+                       selectors.total++;
+                       // document.querySelector() on prefixed pseudo-elements can throw exceptions
+                       // in Firefox and Safari. Ignore these exceptions.
+                       // https://bugs.webkit.org/show_bug.cgi?id=149160
+                       // https://bugzilla.mozilla.org/show_bug.cgi?id=1204880
+                       try {
+                               if ( document.querySelector( rule.selectorText ) !== null ) {
+                                       selectors.matched++;
                                }
+                       } catch ( e ) {}
+               } );
+               document.body.removeChild( style );
+               return selectors;
+       };
+
+       /**
+        * Get a list of all loaded ResourceLoader modules.
+        *
+        * @return {Array} List of module names
+        */
+       inspect.getLoadedModules = function () {
+               return mw.loader.getModuleNames().filter( function ( module ) {
+                       return mw.loader.getState( module ) === 'ready';
+               } );
+       };
+
+       /**
+        * Print tabular data to the console, using console.table, console.log,
+        * or mw.log (in declining order of preference).
+        *
+        * @param {Array} data Tabular data represented as an array of objects
+        *  with common properties.
+        */
+       inspect.dumpTable = function ( data ) {
+               try {
+                       // Bartosz made me put this here.
+                       if ( window.opera ) { throw window.opera; }
+                       // Use Function.prototype#call to force an exception on Firefox,
+                       // which doesn't define console#table but doesn't complain if you
+                       // try to invoke it.
+                       // eslint-disable-next-line no-useless-call
+                       console.table.call( console, data );
+                       return;
+               } catch ( e ) {}
+               try {
+                       console.log( JSON.stringify( data, null, 2 ) );
+                       return;
+               } catch ( e ) {}
+               mw.log( data );
+       };
+
+       /**
+        * Generate and print reports.
+        *
+        * When invoked without arguments, prints all available reports.
+        *
+        * @param {...string} [reports] One or more of "size", "css", or "store".
+        */
+       inspect.runReports = function () {
+               var reports = arguments.length > 0 ?
+                       Array.prototype.slice.call( arguments ) :
+                       Object.keys( inspect.reports );
+
+               reports.forEach( function ( name ) {
+                       inspect.dumpTable( inspect.reports[ name ]() );
+               } );
+       };
+
+       /**
+        * Perform a string search across the JavaScript and CSS source code
+        * of all loaded modules and return an array of the names of the
+        * modules that matched.
+        *
+        * @param {string|RegExp} pattern String or regexp to match.
+        * @return {Array} Array of the names of modules that matched.
+        */
+       inspect.grep = function ( pattern ) {
+               if ( typeof pattern.test !== 'function' ) {
+                       pattern = new RegExp( mw.RegExp.escape( pattern ), 'g' );
+               }
+
+               return inspect.getLoadedModules().filter( function ( moduleName ) {
+                       var module = mw.loader.moduleRegistry[ moduleName ];
+
+                       // Grep module's JavaScript
+                       if ( $.isFunction( module.script ) && pattern.test( module.script.toString() ) ) {
+                               return true;
                        }
 
-                       size = 0;
-                       for ( i = 0; i < args.length; i++ ) {
-                               if ( typeof args[ i ] === 'function' ) {
-                                       size += byteLength( getFunctionBody( args[ i ] ) );
-                               } else {
-                                       size += byteLength( JSON.stringify( args[ i ] ) );
-                               }
+                       // Grep module's CSS
+                       if (
+                               $.isPlainObject( module.style ) && Array.isArray( module.style.css ) &&
+                               pattern.test( module.style.css.join( '' ) )
+                       ) {
+                               // Module's CSS source matches
+                               return true;
                        }
 
-                       return size;
-               },
+                       return false;
+               } );
+       };
 
+       /**
+        * @class mw.inspect.reports
+        * @singleton
+        */
+       inspect.reports = {
                /**
-                * Given CSS source, count both the total number of selectors it
-                * contains and the number which match some element in the current
-                * document.
+                * Generate a breakdown of all loaded modules and their size in
+                * kilobytes. Modules are ordered from largest to smallest.
                 *
-                * @param {string} css CSS source
-                * @return {Object} Selector counts
-                * @return {number} return.selectors Total number of selectors
-                * @return {number} return.matched Number of matched selectors
+                * @return {Object[]} Size reports
                 */
-               auditSelectors: function ( css ) {
-                       var selectors = { total: 0, matched: 0 },
-                               style = document.createElement( 'style' );
-
-                       style.textContent = css;
-                       document.body.appendChild( style );
-                       $.each( style.sheet.cssRules, function ( index, rule ) {
-                               selectors.total++;
-                               // document.querySelector() on prefixed pseudo-elements can throw exceptions
-                               // in Firefox and Safari. Ignore these exceptions.
-                               // https://bugs.webkit.org/show_bug.cgi?id=149160
-                               // https://bugzilla.mozilla.org/show_bug.cgi?id=1204880
-                               try {
-                                       if ( document.querySelector( rule.selectorText ) !== null ) {
-                                               selectors.matched++;
-                                       }
-                               } catch ( e ) {}
+               size: function () {
+                       // Map each module to a descriptor object.
+                       var modules = inspect.getLoadedModules().map( function ( module ) {
+                               return {
+                                       name: module,
+                                       size: inspect.getModuleSize( module )
+                               };
                        } );
-                       document.body.removeChild( style );
-                       return selectors;
-               },
 
-               /**
-                * Get a list of all loaded ResourceLoader modules.
-                *
-                * @return {Array} List of module names
-                */
-               getLoadedModules: function () {
-                       return mw.loader.getModuleNames().filter( function ( module ) {
-                               return mw.loader.getState( module ) === 'ready';
+                       // Sort module descriptors by size, largest first.
+                       sortByProperty( modules, 'size', true );
+
+                       // Convert size to human-readable string.
+                       modules.forEach( function ( module ) {
+                               module.sizeInBytes = module.size;
+                               module.size = humanSize( module.size );
                        } );
-               },
 
-               /**
-                * Print tabular data to the console, using console.table, console.log,
-                * or mw.log (in declining order of preference).
-                *
-                * @param {Array} data Tabular data represented as an array of objects
-                *  with common properties.
-                */
-               dumpTable: function ( data ) {
-                       try {
-                               // Bartosz made me put this here.
-                               if ( window.opera ) { throw window.opera; }
-                               // Use Function.prototype#call to force an exception on Firefox,
-                               // which doesn't define console#table but doesn't complain if you
-                               // try to invoke it.
-                               // eslint-disable-next-line no-useless-call
-                               console.table.call( console, data );
-                               return;
-                       } catch ( e ) {}
-                       try {
-                               console.log( JSON.stringify( data, null, 2 ) );
-                               return;
-                       } catch ( e ) {}
-                       mw.log( data );
+                       return modules;
                },
 
                /**
-                * Generate and print one more reports. When invoked with no arguments,
-                * print all reports.
+                * For each module with styles, count the number of selectors, and
+                * count how many match against some element currently in the DOM.
                 *
-                * @param {...string} [reports] Report names to run, or unset to print
-                *  all available reports.
+                * @return {Object[]} CSS reports
                 */
-               runReports: function () {
-                       var reports = arguments.length > 0 ?
-                               Array.prototype.slice.call( arguments ) :
-                               $.map( inspect.reports, function ( v, k ) { return k; } );
+               css: function () {
+                       var modules = [];
 
-                       reports.forEach( function ( name ) {
-                               inspect.dumpTable( inspect.reports[ name ]() );
-                       } );
-               },
+                       inspect.getLoadedModules().forEach( function ( name ) {
+                               var css, stats, module = mw.loader.moduleRegistry[ name ];
 
-               /**
-                * @class mw.inspect.reports
-                * @singleton
-                */
-               reports: {
-                       /**
-                        * Generate a breakdown of all loaded modules and their size in
-                        * kilobytes. Modules are ordered from largest to smallest.
-                        *
-                        * @return {Object[]} Size reports
-                        */
-                       size: function () {
-                               // Map each module to a descriptor object.
-                               var modules = inspect.getLoadedModules().map( function ( module ) {
-                                       return {
-                                               name: module,
-                                               size: inspect.getModuleSize( module )
-                                       };
-                               } );
-
-                               // Sort module descriptors by size, largest first.
-                               sortByProperty( modules, 'size', true );
-
-                               // Convert size to human-readable string.
-                               modules.forEach( function ( module ) {
-                                       module.sizeInBytes = module.size;
-                                       module.size = humanSize( module.size );
-                               } );
-
-                               return modules;
-                       },
-
-                       /**
-                        * For each module with styles, count the number of selectors, and
-                        * count how many match against some element currently in the DOM.
-                        *
-                        * @return {Object[]} CSS reports
-                        */
-                       css: function () {
-                               var modules = [];
-
-                               inspect.getLoadedModules().forEach( function ( name ) {
-                                       var css, stats, module = mw.loader.moduleRegistry[ name ];
-
-                                       try {
-                                               css = module.style.css.join();
-                                       } catch ( e ) { return; } // skip
-
-                                       stats = inspect.auditSelectors( css );
-                                       modules.push( {
-                                               module: name,
-                                               allSelectors: stats.total,
-                                               matchedSelectors: stats.matched,
-                                               percentMatched: stats.total !== 0 ?
-                                                       ( stats.matched / stats.total * 100 ).toFixed( 2 ) + '%' : null
-                                       } );
+                               try {
+                                       css = module.style.css.join();
+                               } catch ( e ) { return; } // skip
+
+                               stats = inspect.auditSelectors( css );
+                               modules.push( {
+                                       module: name,
+                                       allSelectors: stats.total,
+                                       matchedSelectors: stats.matched,
+                                       percentMatched: stats.total !== 0 ?
+                                               ( stats.matched / stats.total * 100 ).toFixed( 2 ) + '%' : null
                                } );
-                               sortByProperty( modules, 'allSelectors', true );
-                               return modules;
-                       },
-
-                       /**
-                        * Report stats on mw.loader.store: the number of localStorage
-                        * cache hits and misses, the number of items purged from the
-                        * cache, and the total size of the module blob in localStorage.
-                        *
-                        * @return {Object[]} Store stats
-                        */
-                       store: function () {
-                               var raw, stats = { enabled: mw.loader.store.enabled };
-                               if ( stats.enabled ) {
-                                       $.extend( stats, mw.loader.store.stats );
-                                       try {
-                                               raw = localStorage.getItem( mw.loader.store.getStoreKey() );
-                                               stats.totalSizeInBytes = byteLength( raw );
-                                               stats.totalSize = humanSize( byteLength( raw ) );
-                                       } catch ( e ) {}
-                               }
-                               return [ stats ];
-                       }
+                       } );
+                       sortByProperty( modules, 'allSelectors', true );
+                       return modules;
                },
 
                /**
-                * Perform a string search across the JavaScript and CSS source code
-                * of all loaded modules and return an array of the names of the
-                * modules that matched.
+                * Report stats on mw.loader.store: the number of localStorage
+                * cache hits and misses, the number of items purged from the
+                * cache, and the total size of the module blob in localStorage.
                 *
-                * @param {string|RegExp} pattern String or regexp to match.
-                * @return {Array} Array of the names of modules that matched.
+                * @return {Object[]} Store stats
                 */
-               grep: function ( pattern ) {
-                       if ( typeof pattern.test !== 'function' ) {
-                               pattern = new RegExp( mw.RegExp.escape( pattern ), 'g' );
+               store: function () {
+                       var raw, stats = { enabled: mw.loader.store.enabled };
+                       if ( stats.enabled ) {
+                               $.extend( stats, mw.loader.store.stats );
+                               try {
+                                       raw = localStorage.getItem( mw.loader.store.getStoreKey() );
+                                       stats.totalSizeInBytes = byteLength( raw );
+                                       stats.totalSize = humanSize( byteLength( raw ) );
+                               } catch ( e ) {}
                        }
-
-                       return inspect.getLoadedModules().filter( function ( moduleName ) {
-                               var module = mw.loader.moduleRegistry[ moduleName ];
-
-                               // Grep module's JavaScript
-                               if ( $.isFunction( module.script ) && pattern.test( module.script.toString() ) ) {
-                                       return true;
-                               }
-
-                               // Grep module's CSS
-                               if (
-                                       $.isPlainObject( module.style ) && Array.isArray( module.style.css ) &&
-                                       pattern.test( module.style.css.join( '' ) )
-                               ) {
-                                       // Module's CSS source matches
-                                       return true;
-                               }
-
-                               return false;
-                       } );
+                       return [ stats ];
                }
        };
 
                mw.log( 'mw.inspect: reports are not available in debug mode.' );
        }
 
-       mw.inspect = inspect;
-
 }( mediaWiki, jQuery ) );
diff --git a/resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js b/resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js
deleted file mode 100644 (file)
index 17da7d8..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*!
- * MediaWiki Widgets - CategoryCapsuleItemWidget class.
- *
- * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
- * @license The MIT License (MIT); see LICENSE.txt
- */
-( function ( $, mw ) {
-
-       var hasOwn = Object.prototype.hasOwnProperty;
-
-       /**
-        * @class mw.widgets.PageExistenceCache
-        * @private
-        * @param {mw.Api} [api]
-        */
-       function PageExistenceCache( api ) {
-               this.api = api || new mw.Api();
-               this.processExistenceCheckQueueDebounced = OO.ui.debounce( this.processExistenceCheckQueue );
-               this.currentRequest = null;
-               this.existenceCache = {};
-               this.existenceCheckQueue = {};
-       }
-
-       /**
-        * Check for existence of pages in the queue.
-        *
-        * @private
-        */
-       PageExistenceCache.prototype.processExistenceCheckQueue = function () {
-               var queue, titles,
-                       cache = this;
-               if ( this.currentRequest ) {
-                       // Don't fire off a million requests at the same time
-                       this.currentRequest.always( function () {
-                               cache.currentRequest = null;
-                               cache.processExistenceCheckQueueDebounced();
-                       } );
-                       return;
-               }
-               queue = this.existenceCheckQueue;
-               this.existenceCheckQueue = {};
-               titles = Object.keys( queue ).filter( function ( title ) {
-                       if ( hasOwn.call( cache.existenceCache, title ) ) {
-                               queue[ title ].resolve( cache.existenceCache[ title ] );
-                       }
-                       return !hasOwn.call( cache.existenceCache, title );
-               } );
-               if ( !titles.length ) {
-                       return;
-               }
-               this.currentRequest = this.api.get( {
-                       formatversion: 2,
-                       action: 'query',
-                       prop: [ 'info' ],
-                       titles: titles
-               } ).done( function ( response ) {
-                       var
-                               normalized = {},
-                               pages = {};
-                       $.each( response.query.normalized || [], function ( index, data ) {
-                               normalized[ data.fromencoded ? decodeURIComponent( data.from ) : data.from ] = data.to;
-                       } );
-                       $.each( response.query.pages, function ( index, page ) {
-                               pages[ page.title ] = !page.missing;
-                       } );
-                       titles.forEach( function ( title ) {
-                               var normalizedTitle = title;
-                               while ( hasOwn.call( normalized, normalizedTitle ) ) {
-                                       normalizedTitle = normalized[ normalizedTitle ];
-                               }
-                               cache.existenceCache[ title ] = pages[ normalizedTitle ];
-                               queue[ title ].resolve( cache.existenceCache[ title ] );
-                       } );
-               } );
-       };
-
-       /**
-        * Register a request to check whether a page exists.
-        *
-        * @private
-        * @param {mw.Title} title
-        * @return {jQuery.Promise} Promise resolved with true if the page exists or false otherwise
-        */
-       PageExistenceCache.prototype.checkPageExistence = function ( title ) {
-               var key = title.getPrefixedText();
-               if ( !hasOwn.call( this.existenceCheckQueue, key ) ) {
-                       this.existenceCheckQueue[ key ] = $.Deferred();
-               }
-               this.processExistenceCheckQueueDebounced();
-               return this.existenceCheckQueue[ key ].promise();
-       };
-
-       /**
-        * @class mw.widgets.ForeignTitle
-        * @private
-        * @extends mw.Title
-        *
-        * @constructor
-        * @param {string} title
-        * @param {number} [namespace]
-        */
-       function ForeignTitle( title, namespace ) {
-               // We only need to handle categories here... but we don't know the target language.
-               // So assume that any namespace-like prefix is the 'Category' namespace...
-               title = title.replace( /^(.+?)_*:_*(.*)$/, 'Category:$2' ); // HACK
-               ForeignTitle.parent.call( this, title, namespace );
-       }
-       OO.inheritClass( ForeignTitle, mw.Title );
-       ForeignTitle.prototype.getNamespacePrefix = function () {
-               // We only need to handle categories here...
-               return 'Category:'; // HACK
-       };
-
-       /**
-        * Category selector capsule item widget. Extends OO.ui.CapsuleItemWidget with the ability to link
-        * to the given page, and to show its existence status (i.e., whether it is a redlink).
-        *
-        * @class mw.widgets.CategoryCapsuleItemWidget
-        * @uses mw.Api
-        * @extends OO.ui.CapsuleItemWidget
-        *
-        * @constructor
-        * @param {Object} config Configuration options
-        * @cfg {mw.Title} title Page title to use (required)
-        * @cfg {string} [apiUrl] API URL, if not the current wiki's API
-        */
-       mw.widgets.CategoryCapsuleItemWidget = function MWWCategoryCapsuleItemWidget( config ) {
-               var widget = this;
-               // Parent constructor
-               mw.widgets.CategoryCapsuleItemWidget.parent.call( this, $.extend( {
-                       data: config.title.getMainText(),
-                       label: config.title.getMainText()
-               }, config ) );
-
-               // Properties
-               this.title = config.title;
-               this.apiUrl = config.apiUrl || '';
-               this.$link = $( '<a>' )
-                       .text( this.label )
-                       .attr( 'target', '_blank' )
-                       .on( 'click', function ( e ) {
-                               // CapsuleMultiselectWidget really wants to prevent you from clicking the link, don't let it
-                               e.stopPropagation();
-                       } );
-
-               // Initialize
-               this.setMissing( false );
-               this.$label.replaceWith( this.$link );
-               this.setLabelElement( this.$link );
-
-               if ( !this.constructor.static.pageExistenceCaches[ this.apiUrl ] ) {
-                       this.constructor.static.pageExistenceCaches[ this.apiUrl ] =
-                               new PageExistenceCache( new mw.ForeignApi( this.apiUrl ) );
-               }
-               this.constructor.static.pageExistenceCaches[ this.apiUrl ]
-                       .checkPageExistence( new ForeignTitle( this.title.getPrefixedText() ) )
-                       .done( function ( exists ) {
-                               widget.setMissing( !exists );
-                       } );
-       };
-
-       /* Setup */
-
-       OO.inheritClass( mw.widgets.CategoryCapsuleItemWidget, OO.ui.CapsuleItemWidget );
-
-       /* Static Properties */
-
-       /**
-        * Map of API URLs to PageExistenceCache objects.
-        *
-        * @static
-        * @inheritable
-        * @property {Object}
-        */
-       mw.widgets.CategoryCapsuleItemWidget.static.pageExistenceCaches = {
-               '': new PageExistenceCache()
-       };
-
-       /* Methods */
-
-       /**
-        * Update label link href and CSS classes to reflect page existence status.
-        *
-        * @private
-        * @param {boolean} missing Whether the page is missing (does not exist)
-        */
-       mw.widgets.CategoryCapsuleItemWidget.prototype.setMissing = function ( missing ) {
-               var
-                       title = new ForeignTitle( this.title.getPrefixedText() ), // HACK
-                       prefix = this.apiUrl.replace( '/w/api.php', '' ); // HACK
-
-               this.missing = missing;
-
-               if ( !missing ) {
-                       this.$link
-                               .attr( 'href', prefix + title.getUrl() )
-                               .attr( 'title', title.getPrefixedText() )
-                               .removeClass( 'new' );
-               } else {
-                       this.$link
-                               .attr( 'href', prefix + title.getUrl( { action: 'edit', redlink: 1 } ) )
-                               .attr( 'title', mw.msg( 'red-link-title', title.getPrefixedText() ) )
-                               .addClass( 'new' );
-               }
-       };
-
-}( jQuery, mediaWiki ) );
index 354fcd9..c506379 100644 (file)
@@ -9,7 +9,7 @@
                NS_CATEGORY = mw.config.get( 'wgNamespaceIds' ).category;
 
        /**
-        * Category selector widget. Displays an OO.ui.CapsuleMultiselectWidget
+        * Category selector widget. Displays an OO.ui.MenuTagMultiselectWidget
         * and autocompletes with available categories.
         *
         *     mw.loader.using( 'mediawiki.widgets.CategoryMultiselectWidget', function () {
@@ -27,7 +27,7 @@
         *
         * @class mw.widgets.CategoryMultiselectWidget
         * @uses mw.Api
-        * @extends OO.ui.CapsuleMultiselectWidget
+        * @extends OO.ui.MenuTagMultiselectWidget
         * @mixins OO.ui.mixin.PendingElement
         *
         * @constructor
@@ -62,7 +62,7 @@
                OO.ui.mixin.PendingElement.call( this, $.extend( {}, config, { $pending: this.$handle } ) );
 
                // Event handler to call the autocomplete methods
-               this.$input.on( 'change input cut paste', OO.ui.debounce( this.updateMenuItems.bind( this ), 100 ) );
+               this.input.$input.on( 'change input cut paste', OO.ui.debounce( this.updateMenuItems.bind( this ), 100 ) );
 
                // Initialize
                this.api = config.api || new mw.Api();
@@ -71,7 +71,7 @@
 
        /* Setup */
 
-       OO.inheritClass( mw.widgets.CategoryMultiselectWidget, OO.ui.CapsuleMultiselectWidget );
+       OO.inheritClass( mw.widgets.CategoryMultiselectWidget, OO.ui.MenuTagMultiselectWidget );
        OO.mixinClass( mw.widgets.CategoryMultiselectWidget, OO.ui.mixin.PendingElement );
 
        /* Methods */
         */
        mw.widgets.CategoryMultiselectWidget.prototype.updateMenuItems = function () {
                this.getMenu().clearItems();
-               this.getNewMenuItems( this.$input.val() ).then( function ( items ) {
+               this.getNewMenuItems( this.input.$input.val() ).then( function ( items ) {
                        var existingItems, filteredItems,
                                menu = this.getMenu();
 
                        // Never show the menu if the input lost focus in the meantime
-                       if ( !this.$input.is( ':focus' ) ) {
+                       if ( !this.input.$input.is( ':focus' ) ) {
                                return;
                        }
 
        /**
         * @inheritdoc
         */
-       mw.widgets.CategoryMultiselectWidget.prototype.createItemWidget = function ( data ) {
+       mw.widgets.CategoryMultiselectWidget.prototype.createTagItemWidget = function ( data ) {
                var title = mw.Title.makeTitle( NS_CATEGORY, data );
-               if ( !title ) {
-                       return null;
-               }
-               return new mw.widgets.CategoryCapsuleItemWidget( {
+
+               return new mw.widgets.CategoryTagItemWidget( {
                        apiUrl: this.api.apiUrl || undefined,
                        title: title
                } );
         */
        mw.widgets.CategoryMultiselectWidget.prototype.findItemFromData = function ( data ) {
                // This is a bit of a hack... We have to canonicalize the data in the same way that
-               // #createItemWidget and CategoryCapsuleItemWidget will do, otherwise we won't find duplicates.
+               // #createItemWidget and CategoryTagItemWidget will do, otherwise we won't find duplicates.
                var title = mw.Title.makeTitle( NS_CATEGORY, data );
                if ( !title ) {
                        return null;
diff --git a/resources/src/mediawiki.widgets/mw.widgets.CategoryTagItemWidget.js b/resources/src/mediawiki.widgets/mw.widgets.CategoryTagItemWidget.js
new file mode 100644 (file)
index 0000000..f0b2d44
--- /dev/null
@@ -0,0 +1,209 @@
+/*!
+ * MediaWiki Widgets - CategoryTagItemWidget class.
+ *
+ * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+( function ( $, mw ) {
+
+       var hasOwn = Object.prototype.hasOwnProperty;
+
+       /**
+        * @class mw.widgets.PageExistenceCache
+        * @private
+        * @param {mw.Api} [api]
+        */
+       function PageExistenceCache( api ) {
+               this.api = api || new mw.Api();
+               this.processExistenceCheckQueueDebounced = OO.ui.debounce( this.processExistenceCheckQueue );
+               this.currentRequest = null;
+               this.existenceCache = {};
+               this.existenceCheckQueue = {};
+       }
+
+       /**
+        * Check for existence of pages in the queue.
+        *
+        * @private
+        */
+       PageExistenceCache.prototype.processExistenceCheckQueue = function () {
+               var queue, titles,
+                       cache = this;
+               if ( this.currentRequest ) {
+                       // Don't fire off a million requests at the same time
+                       this.currentRequest.always( function () {
+                               cache.currentRequest = null;
+                               cache.processExistenceCheckQueueDebounced();
+                       } );
+                       return;
+               }
+               queue = this.existenceCheckQueue;
+               this.existenceCheckQueue = {};
+               titles = Object.keys( queue ).filter( function ( title ) {
+                       if ( hasOwn.call( cache.existenceCache, title ) ) {
+                               queue[ title ].resolve( cache.existenceCache[ title ] );
+                       }
+                       return !hasOwn.call( cache.existenceCache, title );
+               } );
+               if ( !titles.length ) {
+                       return;
+               }
+               this.currentRequest = this.api.get( {
+                       formatversion: 2,
+                       action: 'query',
+                       prop: [ 'info' ],
+                       titles: titles
+               } ).done( function ( response ) {
+                       var
+                               normalized = {},
+                               pages = {};
+                       $.each( response.query.normalized || [], function ( index, data ) {
+                               normalized[ data.fromencoded ? decodeURIComponent( data.from ) : data.from ] = data.to;
+                       } );
+                       $.each( response.query.pages, function ( index, page ) {
+                               pages[ page.title ] = !page.missing;
+                       } );
+                       titles.forEach( function ( title ) {
+                               var normalizedTitle = title;
+                               while ( hasOwn.call( normalized, normalizedTitle ) ) {
+                                       normalizedTitle = normalized[ normalizedTitle ];
+                               }
+                               cache.existenceCache[ title ] = pages[ normalizedTitle ];
+                               queue[ title ].resolve( cache.existenceCache[ title ] );
+                       } );
+               } );
+       };
+
+       /**
+        * Register a request to check whether a page exists.
+        *
+        * @private
+        * @param {mw.Title} title
+        * @return {jQuery.Promise} Promise resolved with true if the page exists or false otherwise
+        */
+       PageExistenceCache.prototype.checkPageExistence = function ( title ) {
+               var key = title.getPrefixedText();
+               if ( !hasOwn.call( this.existenceCheckQueue, key ) ) {
+                       this.existenceCheckQueue[ key ] = $.Deferred();
+               }
+               this.processExistenceCheckQueueDebounced();
+               return this.existenceCheckQueue[ key ].promise();
+       };
+
+       /**
+        * @class mw.widgets.ForeignTitle
+        * @private
+        * @extends mw.Title
+        *
+        * @constructor
+        * @param {string} title
+        * @param {number} [namespace]
+        */
+       function ForeignTitle( title, namespace ) {
+               // We only need to handle categories here... but we don't know the target language.
+               // So assume that any namespace-like prefix is the 'Category' namespace...
+               title = title.replace( /^(.+?)_*:_*(.*)$/, 'Category:$2' ); // HACK
+               ForeignTitle.parent.call( this, title, namespace );
+       }
+       OO.inheritClass( ForeignTitle, mw.Title );
+       ForeignTitle.prototype.getNamespacePrefix = function () {
+               // We only need to handle categories here...
+               return 'Category:'; // HACK
+       };
+
+       /**
+        * Category selector capsule item widget. Extends OO.ui.CapsuleItemWidget with the ability to link
+        * to the given page, and to show its existence status (i.e., whether it is a redlink).
+        *
+        * @class mw.widgets.CategoryTagItemWidget
+        * @uses mw.Api
+        * @extends OO.ui.TagItemWidget
+        *
+        * @constructor
+        * @param {Object} config Configuration options
+        * @cfg {mw.Title} title Page title to use (required)
+        * @cfg {string} [apiUrl] API URL, if not the current wiki's API
+        */
+       mw.widgets.CategoryTagItemWidget = function MWWCategoryTagItemWidget( config ) {
+               var widget = this;
+               // Parent constructor
+               mw.widgets.CategoryTagItemWidget.parent.call( this, $.extend( {
+                       data: config.title.getMainText(),
+                       label: config.title.getMainText()
+               }, config ) );
+
+               // Properties
+               this.title = config.title;
+               this.apiUrl = config.apiUrl || '';
+               this.$link = $( '<a>' )
+                       .text( this.label )
+                       .attr( 'target', '_blank' )
+                       .on( 'click', function ( e ) {
+                               // TagMultiselectWidget really wants to prevent you from clicking the link, don't let it
+                               e.stopPropagation();
+                       } );
+
+               // Initialize
+               this.setMissing( false );
+               this.$label.replaceWith( this.$link );
+               this.setLabelElement( this.$link );
+
+               if ( !this.constructor.static.pageExistenceCaches[ this.apiUrl ] ) {
+                       this.constructor.static.pageExistenceCaches[ this.apiUrl ] =
+                               new PageExistenceCache( new mw.ForeignApi( this.apiUrl ) );
+               }
+               this.constructor.static.pageExistenceCaches[ this.apiUrl ]
+                       .checkPageExistence( new ForeignTitle( this.title.getPrefixedText() ) )
+                       .done( function ( exists ) {
+                               widget.setMissing( !exists );
+                       } );
+       };
+
+       /* Setup */
+
+       OO.inheritClass( mw.widgets.CategoryTagItemWidget, OO.ui.TagItemWidget );
+
+       /* Static Properties */
+
+       /**
+        * Map of API URLs to PageExistenceCache objects.
+        *
+        * @static
+        * @inheritable
+        * @property {Object}
+        */
+       mw.widgets.CategoryTagItemWidget.static.pageExistenceCaches = {
+               '': new PageExistenceCache()
+       };
+
+       /* Methods */
+
+       /**
+        * Update label link href and CSS classes to reflect page existence status.
+        *
+        * @private
+        * @param {boolean} missing Whether the page is missing (does not exist)
+        */
+       mw.widgets.CategoryTagItemWidget.prototype.setMissing = function ( missing ) {
+               var
+                       title = new ForeignTitle( this.title.getPrefixedText() ), // HACK
+                       prefix = this.apiUrl.replace( '/w/api.php', '' ); // HACK
+
+               this.missing = missing;
+
+               if ( !missing ) {
+                       this.$link
+                               .attr( 'href', prefix + title.getUrl() )
+                               .attr( 'title', title.getPrefixedText() )
+                               .removeClass( 'new' );
+               } else {
+                       this.$link
+                               .attr( 'href', prefix + title.getUrl( { action: 'edit', redlink: 1 } ) )
+                               .attr( 'title', mw.msg( 'red-link-title', title.getPrefixedText() ) )
+                               .addClass( 'new' );
+               }
+       };
+
+       // For backwards compatibility. See T183299.
+       mw.widgets.CategoryCapsuleItemWidget = mw.widgets.CategoryTagItemWidget;
+}( jQuery, mediaWiki ) );
index e82bab7..71966b7 100644 (file)
@@ -140,6 +140,8 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
 
        /**
         * @covers ResourceLoaderFileModule::getScript
+        * @covers ResourceLoaderFileModule::getScriptFiles
+        * @covers ResourceLoaderFileModule::readScriptFiles
         */
        public function testGetScript() {
                $module = new ResourceLoaderFileModule( [
@@ -220,6 +222,8 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
         *
         * @covers ResourceLoaderFileModule::getStyles
         * @covers ResourceLoaderFileModule::getStyleFiles
+        * @covers ResourceLoaderFileModule::readStyleFiles
+        * @covers ResourceLoaderFileModule::readStyleFile
         */
        public function testMixedCssAnnotations() {
                $basePath = __DIR__ . '/../../data/css';
@@ -334,6 +338,7 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
 
        /**
         * @covers ResourceLoaderFileModule::getDefinitionSummary
+        * @covers ResourceLoaderFileModule::getFileHashes
         */
        public function testGetVersionHash() {
                $context = $this->getResourceLoaderContext();
index 0ea4e2b..c925339 100644 (file)
@@ -64,6 +64,19 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
                );
        }
 
+       /**
+        * @covers ResourceLoaderModule::getVersionHash
+        */
+       public function testGetVersionHash_parentDefinition() {
+               $context = $this->getResourceLoaderContext();
+               $module = $this->getMockBuilder( ResourceLoaderModule::class )
+                       ->setMethods( [ 'getDefinitionSummary' ] )->getMock();
+               $module->method( 'getDefinitionSummary' )->willReturn( [ 'a' => 'summary' ] );
+
+               $this->setExpectedException( LogicException::class, 'must call parent' );
+               $module->getVersionHash( $context );
+       }
+
        /**
         * @covers ResourceLoaderModule::validateScriptFile
         */