3 * ResourceLoader stub working with pre-defined test modules.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 header( 'Content-Type: text/javascript; charset=utf-8' );
27 require_once "../../../includes/Xml.php";
30 'test.use_missing' => array (
31 'src' => 'mw.loader.implement("test.use_missing", function () {start(); ok(false, "Module test.use_missing should not run.");}, {}, {});',
32 'deps' => array ( 'test.missing' )
34 'test.use_missing2' => array (
35 'src' => 'mw.loader.implement("test.use_missing2", function () {start(); ok(false, "Module test.use_missing2 should not run.");}, {}, {});',
36 'deps' => array ( 'test.missing2' )
40 // Copied from ResourceLoaderContext
41 function expandModuleNames( $modules ) {
43 // For backwards compatibility with an earlier hack, replace ! with .
44 $modules = str_replace( '!', '.', $modules );
45 $exploded = explode( '|', $modules );
46 foreach ( $exploded as $group ) {
47 if ( strpos( $group, ',' ) === false ) {
48 // This is not a set of modules in foo.bar,baz notation
49 // but a single module
52 // This is a set of modules in foo.bar,baz notation
53 $pos = strrpos( $group, '.' );
54 if ( $pos === false ) {
55 // Prefixless modules, i.e. without dots
56 $retval = explode( ',', $group );
58 // We have a prefix and a bunch of suffixes
59 $prefix = substr( $group, 0, $pos ); // 'foo'
60 $suffixes = explode( ',', substr( $group, $pos +
1 ) ); // array( 'bar', 'baz' )
61 foreach ( $suffixes as $suffix ) {
62 $retval[] = "$prefix.$suffix";
70 function addModule ( $moduleName, &$gotten ) {
74 if ( isset( $gotten[$moduleName] ) ) {
77 $gotten[$moduleName] = true;
78 if ( isset( $modules[$moduleName] ) ) {
79 $deps = $modules[$moduleName]['deps'];
80 foreach ( $deps as $depName ) {
81 $result .= addModule( $depName, $gotten ) . "\n";
83 $result .= $modules[$moduleName]['src'] . "\n";
85 $result .= 'mw.loader.state( ' . Xml
::encodeJsVar( $moduleName ) . ', "missing" );' . "\n";
87 return $result . "\n";
92 if ( isset( $_GET['modules'] ) ) {
93 $toGet = expandModuleNames( $_GET['modules'] );
95 foreach ( $toGet as $moduleName ) {
96 $result .= addModule( $moduleName, $gotten );