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