| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
header( 'Cache-Control: private, no-cache, must-revalidate' ); |
| 28 |
header( 'Content-Type: text/javascript; charset=utf-8' ); |
| 29 |
|
| 30 |
$moduleImplementations = [ |
| 31 |
'testUsesMissing' => " |
| 32 |
mw.loader.implement( 'testUsesMissing', function () { |
| 33 |
mw.loader.testFail( 'Module usesMissing script should not run.' ); |
| 34 |
}, {}, {}); |
| 35 |
", |
| 36 |
|
| 37 |
'testUsesNestedMissing' => " |
| 38 |
mw.loader.implement( 'testUsesNestedMissing', function () { |
| 39 |
mw.loader.testFail('Module testUsesNestedMissing script should not run.' ); |
| 40 |
}, {}, {}); |
| 41 |
", |
| 42 |
|
| 43 |
'testSkipped' => " |
| 44 |
mw.loader.implement( 'testSkipped', function () { |
| 45 |
mw.loader.testFail( false, 'Module testSkipped was supposed to be skipped.' ); |
| 46 |
}, {}, {}); |
| 47 |
", |
| 48 |
|
| 49 |
'testNotSkipped' => " |
| 50 |
mw.loader.implement( 'testNotSkipped', function () {}, {}, {}); |
| 51 |
", |
| 52 |
|
| 53 |
'testUsesSkippable' => " |
| 54 |
mw.loader.implement( 'testUsesSkippable', function () {}, {}, {}); |
| 55 |
", |
| 56 |
|
| 57 |
'testUrlInc' => " |
| 58 |
mw.loader.implement( 'testUrlInc', function () {} ); |
| 59 |
", |
| 60 |
'testUrlInc.a' => " |
| 61 |
mw.loader.implement( 'testUrlInc.a', function () {} ); |
| 62 |
", |
| 63 |
'testUrlInc.b' => " |
| 64 |
mw.loader.implement( 'testUrlInc.b', function () {} ); |
| 65 |
", |
| 66 |
'testUrlOrder' => " |
| 67 |
mw.loader.implement( 'testUrlOrder', function () {} ); |
| 68 |
", |
| 69 |
'testUrlOrder.a' => " |
| 70 |
mw.loader.implement( 'testUrlOrder.a', function () {} ); |
| 71 |
", |
| 72 |
'testUrlOrder.b' => " |
| 73 |
mw.loader.implement( 'testUrlOrder.b', function () {} ); |
| 74 |
", |
| 75 |
]; |
| 76 |
|
| 77 |
$response = ''; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
if ( isset( $_GET['modules'] ) ) { |
| 83 |
if ( $_GET['modules'] === 'testUrlInc,testUrlIncDump|testUrlInc.a,b' ) { |
| 84 |
$modules = [ 'testUrlInc', 'testUrlIncDump', 'testUrlInc.a', 'testUrlInc.b' ]; |
| 85 |
} elseif ( $_GET['modules'] === 'testUrlOrder,testUrlOrderDump|testUrlOrder.a,b' ) { |
| 86 |
$modules = [ 'testUrlOrder', 'testUrlOrderDump', 'testUrlOrder.a', 'testUrlOrder.b' ]; |
| 87 |
} else { |
| 88 |
$modules = explode( ',', $_GET['modules'] ); |
| 89 |
} |
| 90 |
foreach ( $modules as $module ) { |
| 91 |
if ( isset( $moduleImplementations[$module] ) ) { |
| 92 |
$response .= $moduleImplementations[$module]; |
| 93 |
} elseif ( preg_match( '/^test.*Dump$/', $module ) === 1 ) { |
| 94 |
$queryModules = $_GET['modules']; |
| 95 |
$queryVersion = isset( $_GET['version'] ) ? strval( $_GET['version'] ) : null; |
| 96 |
$response .= 'mw.loader.implement( ' . json_encode( $module ) |
| 97 |
. ', function ( $, jQuery, require, module ) {' |
| 98 |
. 'module.exports.query = { ' |
| 99 |
. 'modules: ' . json_encode( $queryModules ) . ',' |
| 100 |
. 'version: ' . json_encode( $queryVersion ) |
| 101 |
. ' };' |
| 102 |
. '} );'; |
| 103 |
} else { |
| 104 |
|
| 105 |
$response .= 'mw.loader.state(' . json_encode( [ $module => 'missing' ] ) . ');' . "\n"; |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
echo $response; |