示例#1
0
 /**
  * Core resourceLoader driver:
  *
  * 	get request key
  *  builds javascript string
  *  optionally gzips the output
  *  checks for errors
  *  sends the headers
  *  outputs js
  */
 function doResourceLoader()
 {
     global $wgResourceLoaderNamedPaths, $IP, $wgUseFileCache;
     // Load the resource paths:
     require_once realpath(dirname(__FILE__)) . "/includes/NamedResourceLoader.php";
     try {
         NamedResourceLoader::loadResourcePaths();
     } catch (Exception $e) {
         $this->errorMsg .= "loadResourcePaths:" . $e->getMessage();
     }
     // Reset the requestKey:
     $this->requestKey = '';
     // Do the post proc request with configuration vars:
     $this->postProcRequestVars();
     // Update the filename (if gzip is on)
     $this->sFileCache->getCacheFileName();
     // Setup script loader header ( to easy identify file data )
     if ($this->outputFormat == 'js') {
         $this->output .= 'var mwResourceLoaderDate = "' . xml::escapeJsString(date('c')) . '";' . "\n";
         $this->output .= 'var mwResourceLoaderRequestKey = "' . xml::escapeJsString($this->requestKey) . '";' . "\n";
     }
     // Build the output
     // Swap in the appropriate language per js_file
     foreach ($this->namedFileList as $resourceName => $filePath) {
         // Check if we are exclusively getting messages
         if ($this->outputFormat == 'messages') {
             // Get only the message code
             $this->output .= $this->getResourceMessageJS($resourceName);
         } else {
             // Process the full class
             $this->output .= $this->getLocalizedScriptText($resourceName);
         }
         // MwEmbed is a core component so it includes loaders and other styles
         if ($resourceName == 'mwEmbed' && $this->outputFormat != 'messages') {
             // Output core components ( parts of core mwEmbed that are in different files )
             $coreComponentsList = NamedResourceLoader::getComponentsList();
             foreach ($coreComponentsList as $componentClassName) {
                 // Output the core component via the script loader:
                 $this->output .= $this->getLocalizedScriptText($componentClassName);
             }
             // Output the loaders js
             $loaderJS = NamedResourceLoader::getCombinedLoaderJs();
             // Transform the loader text to remove debug statements and
             // update language msgs if any are present
             $this->output .= $this->transformScriptText($loaderJS, 'mwEmbed');
             // Output the current language resource js
             $this->output .= NamedResourceLoader::getLanguageJs($this->langCode);
             // Output the localSettings.js
             $localSettingsJsPath = realpath(dirname(__FILE__)) . '/localSettings.js';
             if (is_file($localSettingsJsPath)) {
                 wfSuppressWarnings();
                 $this->output .= file_get_contents($localSettingsJsPath);
                 wfRestoreWarnings();
             }
             // Add the required core mwEmbed style sheets
             // removed for now because when creating stand alone packages js package with css
             // the paths get messed up.
             /*if( !isset( $this->namedFileList[ 'mw.style.mwCommon' ] ) ) {
             			$this->output .= $this->getResourceText( 'mw.style.mwCommon' );
             		}*/
             // Output "special" IE comment tag to support "special" mwEmbed tags.
             $this->notMinifiedTopOutput .= '/*@cc_on@if(@_jscript_version<9){\'video audio source itext playlist\'.replace(/\\w+/g,function(n){document.createElement(n)})}@end@*/' . "\n";
         }
     }
     /**
      * Add a mw.loadDone resource callback if there was no "error" in getting any of the classes
      */
     if ($this->errorMsg == '' && $this->outputFormat == 'js') {
         $this->output .= self::getOnDoneCallback();
     }
     // Check if we should minify the whole thing:
     if (!$this->debug && $this->outputFormat == 'js') {
         $this->output = self::getMinifiedJs($this->output, $this->requestKey);
         $this->output = $this->notMinifiedTopOutput . $this->output;
     }
     // Save to the file cache
     if ($wgUseFileCache && !$this->debug) {
         $status = $this->sFileCache->saveToFileCache($this->output);
         if ($status !== true) {
             $this->errorMsg .= "Could not save file to cache::" . $status;
         }
     }
     // Check for an error msg
     if ($this->errorMsg != '') {
         //just set the content type (don't send cache header)
         header('Content-Type: text/javascript');
         echo 'if( typeof console !=\'undefined\' && console.log)console.log(\'Error With ResourceLoader ::' . str_replace("\n", '\'+"\\n"+' . "\n'", xml::escapeJsString($this->errorMsg)) . '\');' . "\n";
         echo trim($this->output);
     } else {
         // All good, let's output "cache" headers
         $this->outputJsWithHeaders();
     }
 }