Resolved bug 26791 by replacing JSMin with a new library called JavaScriptDistiller...
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @author Roan Kattouw
20 * @author Trevor Parscal
21 */
22
23 /**
24 * Dynamic JavaScript and CSS resource loading system.
25 *
26 * Most of the documention is on the MediaWiki documentation wiki starting at:
27 * http://www.mediawiki.org/wiki/ResourceLoader
28 */
29 class ResourceLoader {
30
31 /* Protected Static Members */
32
33 /** Array: List of module name/ResourceLoaderModule object pairs */
34 protected $modules = array();
35 /** Associative array mapping module name to info associative array */
36 protected $moduleInfos = array();
37
38 /* Protected Methods */
39
40 /**
41 * Loads information stored in the database about modules.
42 *
43 * This method grabs modules dependencies from the database and updates modules
44 * objects.
45 *
46 * This is not inside the module code because it is much faster to
47 * request all of the information at once than it is to have each module
48 * requests its own information. This sacrifice of modularity yields a substantial
49 * performance improvement.
50 *
51 * @param $modules Array: List of module names to preload information for
52 * @param $context ResourceLoaderContext: Context to load the information within
53 */
54 public function preloadModuleInfo( array $modules, ResourceLoaderContext $context ) {
55 if ( !count( $modules ) ) {
56 return; // or else Database*::select() will explode, plus it's cheaper!
57 }
58 $dbr = wfGetDB( DB_SLAVE );
59 $skin = $context->getSkin();
60 $lang = $context->getLanguage();
61
62 // Get file dependency information
63 $res = $dbr->select( 'module_deps', array( 'md_module', 'md_deps' ), array(
64 'md_module' => $modules,
65 'md_skin' => $context->getSkin()
66 ), __METHOD__
67 );
68
69 // Set modules' dependencies
70 $modulesWithDeps = array();
71 foreach ( $res as $row ) {
72 $this->getModule( $row->md_module )->setFileDependencies( $skin,
73 FormatJson::decode( $row->md_deps, true )
74 );
75 $modulesWithDeps[] = $row->md_module;
76 }
77
78 // Register the absence of a dependency row too
79 foreach ( array_diff( $modules, $modulesWithDeps ) as $name ) {
80 $this->getModule( $name )->setFileDependencies( $skin, array() );
81 }
82
83 // Get message blob mtimes. Only do this for modules with messages
84 $modulesWithMessages = array();
85 foreach ( $modules as $name ) {
86 if ( count( $this->getModule( $name )->getMessages() ) ) {
87 $modulesWithMessages[] = $name;
88 }
89 }
90 $modulesWithoutMessages = array_flip( $modules ); // Will be trimmed down by the loop below
91 if ( count( $modulesWithMessages ) ) {
92 $res = $dbr->select( 'msg_resource', array( 'mr_resource', 'mr_timestamp' ), array(
93 'mr_resource' => $modulesWithMessages,
94 'mr_lang' => $lang
95 ), __METHOD__
96 );
97 foreach ( $res as $row ) {
98 $this->getModule( $row->mr_resource )->setMsgBlobMtime( $lang, $row->mr_timestamp );
99 unset( $modulesWithoutMessages[$row->mr_resource] );
100 }
101 }
102 foreach ( array_keys( $modulesWithoutMessages ) as $name ) {
103 $this->getModule( $name )->setMsgBlobMtime( $lang, 0 );
104 }
105 }
106
107 /**
108 * Runs JavaScript or CSS data through a filter, caching the filtered result for future calls.
109 *
110 * Available filters are:
111 * - minify-js \see JavaScriptDistiller::stripWhiteSpace
112 * - minify-css \see CSSMin::minify
113 *
114 * If $data is empty, only contains whitespace or the filter was unknown,
115 * $data is returned unmodified.
116 *
117 * @param $filter String: Name of filter to run
118 * @param $data String: Text to filter, such as JavaScript or CSS text
119 * @return String: Filtered data, or a comment containing an error message
120 */
121 protected function filter( $filter, $data ) {
122 global $wgResourceLoaderMinifyJSVerticalSpace;
123
124 wfProfileIn( __METHOD__ );
125
126 // For empty/whitespace-only data or for unknown filters, don't perform
127 // any caching or processing
128 if ( trim( $data ) === ''
129 || !in_array( $filter, array( 'minify-js', 'minify-css' ) ) )
130 {
131 wfProfileOut( __METHOD__ );
132 return $data;
133 }
134
135 // Try for cache hit
136 // Use CACHE_ANYTHING since filtering is very slow compared to DB queries
137 $key = wfMemcKey( 'resourceloader', 'filter', $filter, md5( $data ) );
138 $cache = wfGetCache( CACHE_ANYTHING );
139 $cacheEntry = $cache->get( $key );
140 if ( is_string( $cacheEntry ) ) {
141 wfProfileOut( __METHOD__ );
142 return $cacheEntry;
143 }
144
145 // Run the filter - we've already verified one of these will work
146 try {
147 switch ( $filter ) {
148 case 'minify-js':
149 $result = JavaScriptDistiller::stripWhiteSpace(
150 $data, $wgResourceLoaderMinifyJSVerticalSpace
151 );
152 break;
153 case 'minify-css':
154 $result = CSSMin::minify( $data );
155 break;
156 }
157
158 // Save filtered text to Memcached
159 $cache->set( $key, $result );
160 } catch ( Exception $exception ) {
161 // Return exception as a comment
162 $result = "/*\n{$exception->__toString()}\n*/\n";
163 }
164
165 wfProfileOut( __METHOD__ );
166
167 return $result;
168 }
169
170 /* Methods */
171
172 /**
173 * Registers core modules and runs registration hooks.
174 */
175 public function __construct() {
176 global $IP, $wgResourceModules;
177
178 wfProfileIn( __METHOD__ );
179
180 // Register core modules
181 $this->register( include( "$IP/resources/Resources.php" ) );
182 // Register extension modules
183 wfRunHooks( 'ResourceLoaderRegisterModules', array( &$this ) );
184 $this->register( $wgResourceModules );
185
186 wfProfileOut( __METHOD__ );
187 }
188
189 /**
190 * Registers a module with the ResourceLoader system.
191 *
192 * @param $name Mixed: Name of module as a string or List of name/object pairs as an array
193 * @param $info Module info array. For backwards compatibility with 1.17alpha,
194 * this may also be a ResourceLoaderModule object. Optional when using
195 * multiple-registration calling style.
196 * @throws MWException: If a duplicate module registration is attempted
197 * @throws MWException: If something other than a ResourceLoaderModule is being registered
198 * @return Boolean: False if there were any errors, in which case one or more modules were not
199 * registered
200 */
201 public function register( $name, $info = null ) {
202 wfProfileIn( __METHOD__ );
203
204 // Allow multiple modules to be registered in one call
205 if ( is_array( $name ) ) {
206 foreach ( $name as $key => $value ) {
207 $this->register( $key, $value );
208 }
209 return;
210 }
211
212 // Disallow duplicate registrations
213 if ( isset( $this->moduleInfos[$name] ) ) {
214 // A module has already been registered by this name
215 throw new MWException(
216 'ResourceLoader duplicate registration error. ' .
217 'Another module has already been registered as ' . $name
218 );
219 }
220
221 // Attach module
222 if ( is_object( $info ) ) {
223 // Old calling convention
224 // Validate the input
225 if ( !( $info instanceof ResourceLoaderModule ) ) {
226 throw new MWException( 'ResourceLoader invalid module error. ' .
227 'Instances of ResourceLoaderModule expected.' );
228 }
229
230 $this->moduleInfos[$name] = array( 'object' => $info );
231 $info->setName( $name );
232 $this->modules[$name] = $info;
233 } else {
234 // New calling convention
235 $this->moduleInfos[$name] = $info;
236 }
237
238 wfProfileOut( __METHOD__ );
239 }
240
241 /**
242 * Get a list of module names
243 *
244 * @return Array: List of module names
245 */
246 public function getModuleNames() {
247 return array_keys( $this->moduleInfos );
248 }
249
250 /**
251 * Get the ResourceLoaderModule object for a given module name.
252 *
253 * @param $name String: Module name
254 * @return Mixed: ResourceLoaderModule if module has been registered, null otherwise
255 */
256 public function getModule( $name ) {
257 if ( !isset( $this->modules[$name] ) ) {
258 if ( !isset( $this->moduleInfos[$name] ) ) {
259 // No such module
260 return null;
261 }
262 // Construct the requested object
263 $info = $this->moduleInfos[$name];
264 if ( isset( $info['object'] ) ) {
265 // Object given in info array
266 $object = $info['object'];
267 } else {
268 if ( !isset( $info['class'] ) ) {
269 $class = 'ResourceLoaderFileModule';
270 } else {
271 $class = $info['class'];
272 }
273 $object = new $class( $info );
274 }
275 $object->setName( $name );
276 $this->modules[$name] = $object;
277 }
278
279 return $this->modules[$name];
280 }
281
282 /**
283 * Outputs a response to a resource load-request, including a content-type header.
284 *
285 * @param $context ResourceLoaderContext: Context in which a response should be formed
286 */
287 public function respond( ResourceLoaderContext $context ) {
288 global $wgResourceLoaderMaxage, $wgCacheEpoch;
289
290 // Buffer output to catch warnings. Normally we'd use ob_clean() on the
291 // top-level output buffer to clear warnings, but that breaks when ob_gzhandler
292 // is used: ob_clean() will clear the GZIP header in that case and it won't come
293 // back for subsequent output, resulting in invalid GZIP. So we have to wrap
294 // the whole thing in our own output buffer to be sure the active buffer
295 // doesn't use ob_gzhandler.
296 // See http://bugs.php.net/bug.php?id=36514
297 ob_start();
298
299 wfProfileIn( __METHOD__ );
300 $exceptions = '';
301
302 // Split requested modules into two groups, modules and missing
303 $modules = array();
304 $missing = array();
305 foreach ( $context->getModules() as $name ) {
306 if ( isset( $this->moduleInfos[$name] ) ) {
307 $modules[$name] = $this->getModule( $name );
308 } else {
309 $missing[] = $name;
310 }
311 }
312
313 // If a version wasn't specified we need a shorter expiry time for updates
314 // to propagate to clients quickly
315 if ( is_null( $context->getVersion() ) ) {
316 $maxage = $wgResourceLoaderMaxage['unversioned']['client'];
317 $smaxage = $wgResourceLoaderMaxage['unversioned']['server'];
318 }
319 // If a version was specified we can use a longer expiry time since changing
320 // version numbers causes cache misses
321 else {
322 $maxage = $wgResourceLoaderMaxage['versioned']['client'];
323 $smaxage = $wgResourceLoaderMaxage['versioned']['server'];
324 }
325
326 // Preload information needed to the mtime calculation below
327 try {
328 $this->preloadModuleInfo( array_keys( $modules ), $context );
329 } catch( Exception $e ) {
330 // Add exception to the output as a comment
331 $exceptions .= "/*\n{$e->__toString()}\n*/\n";
332 }
333
334 wfProfileIn( __METHOD__.'-getModifiedTime' );
335
336 $private = false;
337 // To send Last-Modified and support If-Modified-Since, we need to detect
338 // the last modified time
339 $mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch );
340 foreach ( $modules as $module ) {
341 try {
342 // Bypass Squid and other shared caches if the request includes any private modules
343 if ( $module->getGroup() === 'private' ) {
344 $private = true;
345 }
346 // Calculate maximum modified time
347 $mtime = max( $mtime, $module->getModifiedTime( $context ) );
348 } catch ( Exception $e ) {
349 // Add exception to the output as a comment
350 $exceptions .= "/*\n{$e->__toString()}\n*/\n";
351 }
352 }
353
354 wfProfileOut( __METHOD__.'-getModifiedTime' );
355
356 if ( $context->getOnly() === 'styles' ) {
357 header( 'Content-Type: text/css' );
358 } else {
359 header( 'Content-Type: text/javascript' );
360 }
361 header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) );
362 if ( $context->getDebug() ) {
363 // Do not cache debug responses
364 header( 'Cache-Control: private, no-cache, must-revalidate' );
365 header( 'Pragma: no-cache' );
366 } else {
367 if ( $private ) {
368 header( "Cache-Control: private, max-age=$maxage" );
369 $exp = $maxage;
370 } else {
371 header( "Cache-Control: public, max-age=$maxage, s-maxage=$smaxage" );
372 $exp = min( $maxage, $smaxage );
373 }
374 header( 'Expires: ' . wfTimestamp( TS_RFC2822, $exp + time() ) );
375 }
376
377 // If there's an If-Modified-Since header, respond with a 304 appropriately
378 // Some clients send "timestamp;length=123". Strip the part after the first ';'
379 // so we get a valid timestamp.
380 $ims = $context->getRequest()->getHeader( 'If-Modified-Since' );
381 if ( $ims !== false ) {
382 $imsTS = strtok( $ims, ';' );
383 if ( $mtime <= wfTimestamp( TS_UNIX, $imsTS ) ) {
384 // There's another bug in ob_gzhandler (see also the comment at
385 // the top of this function) that causes it to gzip even empty
386 // responses, meaning it's impossible to produce a truly empty
387 // response (because the gzip header is always there). This is
388 // a problem because 304 responses have to be completely empty
389 // per the HTTP spec, and Firefox behaves buggily when they're not.
390 // See also http://bugs.php.net/bug.php?id=51579
391 // To work around this, we tear down all output buffering before
392 // sending the 304.
393 // On some setups, ob_get_level() doesn't seem to go down to zero
394 // no matter how often we call ob_get_clean(), so instead of doing
395 // the more intuitive while ( ob_get_level() > 0 ) ob_get_clean();
396 // we have to be safe here and avoid an infinite loop.
397 for ( $i = 0; $i < ob_get_level(); $i++ ) {
398 ob_end_clean();
399 }
400
401 header( 'HTTP/1.0 304 Not Modified' );
402 header( 'Status: 304 Not Modified' );
403 wfProfileOut( __METHOD__ );
404 return;
405 }
406 }
407
408 // Generate a response
409 $response = $this->makeModuleResponse( $context, $modules, $missing );
410
411 // Prepend comments indicating exceptions
412 $response = $exceptions . $response;
413
414 // Capture any PHP warnings from the output buffer and append them to the
415 // response in a comment if we're in debug mode.
416 if ( $context->getDebug() && strlen( $warnings = ob_get_contents() ) ) {
417 $response = "/*\n$warnings\n*/\n" . $response;
418 }
419
420 // Remove the output buffer and output the response
421 ob_end_clean();
422 echo $response;
423
424 wfProfileOut( __METHOD__ );
425 }
426
427 /**
428 * Generates code for a response
429 *
430 * @param $context ResourceLoaderContext: Context in which to generate a response
431 * @param $modules Array: List of module objects keyed by module name
432 * @param $missing Array: List of unavailable modules (optional)
433 * @return String: Response data
434 */
435 public function makeModuleResponse( ResourceLoaderContext $context,
436 array $modules, $missing = array() )
437 {
438 $out = '';
439 $exceptions = '';
440 if ( $modules === array() && $missing === array() ) {
441 return '/* No modules requested. Max made me put this here */';
442 }
443
444 // Pre-fetch blobs
445 if ( $context->shouldIncludeMessages() ) {
446 try {
447 $blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
448 } catch ( Exception $e ) {
449 // Add exception to the output as a comment
450 $exceptions .= "/*\n{$e->__toString()}\n*/\n";
451 }
452 } else {
453 $blobs = array();
454 }
455
456 // Generate output
457 foreach ( $modules as $name => $module ) {
458 wfProfileIn( __METHOD__ . '-' . $name );
459 try {
460 // Scripts
461 $scripts = '';
462 if ( $context->shouldIncludeScripts() ) {
463 $scripts .= $module->getScript( $context ) . "\n";
464 }
465
466 // Styles
467 $styles = array();
468 if ( $context->shouldIncludeStyles() ) {
469 $styles = $module->getStyles( $context );
470 }
471
472 // Messages
473 $messagesBlob = isset( $blobs[$name] ) ? $blobs[$name] : '{}';
474
475 // Append output
476 switch ( $context->getOnly() ) {
477 case 'scripts':
478 $out .= $scripts;
479 break;
480 case 'styles':
481 $out .= self::makeCombinedStyles( $styles );
482 break;
483 case 'messages':
484 $out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
485 break;
486 default:
487 // Minify CSS before embedding in mediaWiki.loader.implement call
488 // (unless in debug mode)
489 if ( !$context->getDebug() ) {
490 foreach ( $styles as $media => $style ) {
491 $styles[$media] = $this->filter( 'minify-css', $style );
492 }
493 }
494 $out .= self::makeLoaderImplementScript( $name, $scripts, $styles,
495 new XmlJsCode( $messagesBlob ) );
496 break;
497 }
498 } catch ( Exception $e ) {
499 // Add exception to the output as a comment
500 $exceptions .= "/*\n{$e->__toString()}\n*/\n";
501
502 // Register module as missing
503 $missing[] = $name;
504 unset( $modules[$name] );
505 }
506 wfProfileOut( __METHOD__ . '-' . $name );
507 }
508
509 // Update module states
510 if ( $context->shouldIncludeScripts() ) {
511 // Set the state of modules loaded as only scripts to ready
512 if ( count( $modules ) && $context->getOnly() === 'scripts'
513 && !isset( $modules['startup'] ) )
514 {
515 $out .= self::makeLoaderStateScript(
516 array_fill_keys( array_keys( $modules ), 'ready' ) );
517 }
518 // Set the state of modules which were requested but unavailable as missing
519 if ( is_array( $missing ) && count( $missing ) ) {
520 $out .= self::makeLoaderStateScript( array_fill_keys( $missing, 'missing' ) );
521 }
522 }
523
524 if ( $context->getDebug() ) {
525 return $exceptions . $out;
526 } else {
527 if ( $context->getOnly() === 'styles' ) {
528 return $exceptions . $this->filter( 'minify-css', $out );
529 } else {
530 return $exceptions . $this->filter( 'minify-js', $out );
531 }
532 }
533 }
534
535 /* Static Methods */
536
537 /**
538 * Returns JS code to call to mediaWiki.loader.implement for a module with
539 * given properties.
540 *
541 * @param $name Module name
542 * @param $scripts Array: List of JavaScript code snippets to be executed after the
543 * module is loaded
544 * @param $styles Array: List of CSS strings keyed by media type
545 * @param $messages Mixed: List of messages associated with this module. May either be an
546 * associative array mapping message key to value, or a JSON-encoded message blob containing
547 * the same data, wrapped in an XmlJsCode object.
548 */
549 public static function makeLoaderImplementScript( $name, $scripts, $styles, $messages ) {
550 if ( is_array( $scripts ) ) {
551 $scripts = implode( $scripts, "\n" );
552 }
553 return Xml::encodeJsCall(
554 'mediaWiki.loader.implement',
555 array(
556 $name,
557 new XmlJsCode( "function( $, mw ) {{$scripts}}" ),
558 (object)$styles,
559 (object)$messages
560 ) );
561 }
562
563 /**
564 * Returns JS code which, when called, will register a given list of messages.
565 *
566 * @param $messages Mixed: Either an associative array mapping message key to value, or a
567 * JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object.
568 */
569 public static function makeMessageSetScript( $messages ) {
570 return Xml::encodeJsCall( 'mediaWiki.messages.set', array( (object)$messages ) );
571 }
572
573 /**
574 * Combines an associative array mapping media type to CSS into a
575 * single stylesheet with @media blocks.
576 *
577 * @param $styles Array: List of CSS strings keyed by media type
578 */
579 public static function makeCombinedStyles( array $styles ) {
580 $out = '';
581 foreach ( $styles as $media => $style ) {
582 // Transform the media type based on request params and config
583 // The way that this relies on $wgRequest to propagate request params is slightly evil
584 $media = OutputPage::transformCssMedia( $media );
585
586 if ( $media === null ) {
587 // Skip
588 } else if ( $media === '' || $media == 'all' ) {
589 // Don't output invalid or frivolous @media statements
590 $out .= "$style\n";
591 } else {
592 $out .= "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
593 }
594 }
595 return $out;
596 }
597
598 /**
599 * Returns a JS call to mediaWiki.loader.state, which sets the state of a
600 * module or modules to a given value. Has two calling conventions:
601 *
602 * - ResourceLoader::makeLoaderStateScript( $name, $state ):
603 * Set the state of a single module called $name to $state
604 *
605 * - ResourceLoader::makeLoaderStateScript( array( $name => $state, ... ) ):
606 * Set the state of modules with the given names to the given states
607 */
608 public static function makeLoaderStateScript( $name, $state = null ) {
609 if ( is_array( $name ) ) {
610 return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name ) );
611 } else {
612 return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name, $state ) );
613 }
614 }
615
616 /**
617 * Returns JS code which calls the script given by $script. The script will
618 * be called with local variables name, version, dependencies and group,
619 * which will have values corresponding to $name, $version, $dependencies
620 * and $group as supplied.
621 *
622 * @param $name String: Module name
623 * @param $version Integer: Module version number as a timestamp
624 * @param $dependencies Array: List of module names on which this module depends
625 * @param $group String: Group which the module is in.
626 * @param $script String: JavaScript code
627 */
628 public static function makeCustomLoaderScript( $name, $version, $dependencies, $group, $script ) {
629 $script = str_replace( "\n", "\n\t", trim( $script ) );
630 return Xml::encodeJsCall(
631 "( function( name, version, dependencies, group ) {\n\t$script\n} )",
632 array( $name, $version, $dependencies, $group ) );
633 }
634
635 /**
636 * Returns JS code which calls mediaWiki.loader.register with the given
637 * parameters. Has three calling conventions:
638 *
639 * - ResourceLoader::makeLoaderRegisterScript( $name, $version, $dependencies, $group ):
640 * Register a single module.
641 *
642 * - ResourceLoader::makeLoaderRegisterScript( array( $name1, $name2 ) ):
643 * Register modules with the given names.
644 *
645 * - ResourceLoader::makeLoaderRegisterScript( array(
646 * array( $name1, $version1, $dependencies1, $group1 ),
647 * array( $name2, $version2, $dependencies1, $group2 ),
648 * ...
649 * ) ):
650 * Registers modules with the given names and parameters.
651 *
652 * @param $name String: Module name
653 * @param $version Integer: Module version number as a timestamp
654 * @param $dependencies Array: List of module names on which this module depends
655 * @param $group String: group which the module is in.
656 */
657 public static function makeLoaderRegisterScript( $name, $version = null,
658 $dependencies = null, $group = null )
659 {
660 if ( is_array( $name ) ) {
661 return Xml::encodeJsCall( 'mediaWiki.loader.register', array( $name ) );
662 } else {
663 $version = (int) $version > 1 ? (int) $version : 1;
664 return Xml::encodeJsCall( 'mediaWiki.loader.register',
665 array( $name, $version, $dependencies, $group ) );
666 }
667 }
668
669 /**
670 * Returns JS code which runs given JS code if the client-side framework is
671 * present.
672 *
673 * @param $script String: JavaScript code
674 */
675 public static function makeLoaderConditionalScript( $script ) {
676 $script = str_replace( "\n", "\n\t", trim( $script ) );
677 return "if ( window.mediaWiki ) {\n\t$script\n}\n";
678 }
679
680 /**
681 * Returns JS code which will set the MediaWiki configuration array to
682 * the given value.
683 *
684 * @param $configuration Array: List of configuration values keyed by variable name
685 */
686 public static function makeConfigSetScript( array $configuration ) {
687 return Xml::encodeJsCall( 'mediaWiki.config.set', array( $configuration ) );
688 }
689
690 /**
691 * Determine whether debug mode was requested
692 * Order of priority is 1) request param, 2) cookie, 3) $wg setting
693 * @return bool
694 */
695 public static function inDebugMode() {
696 global $wgRequest, $wgResourceLoaderDebug;
697 static $retval = null;
698 if ( !is_null( $retval ) )
699 return $retval;
700 return $retval = $wgRequest->getFuzzyBool( 'debug',
701 $wgRequest->getCookie( 'resourceLoaderDebug', '', $wgResourceLoaderDebug ) );
702 }
703 }