Ejemplo n.º 1
0
 /**
  * More minimal version of getHeadScripts from OutputPage
  *
  * @param OutputPage $out
  * @return string
  */
 protected function getHeadScripts(OutputPage $out)
 {
     $scripts = $out->makeResourceLoaderLink('startup', ResourceLoaderModule::TYPE_SCRIPTS, true, array('mobile' => true));
     $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript($out->getJSVars())));
     return $scripts;
 }
Ejemplo n.º 2
0
 /**
  * @param $data array
  * @return string
  */
 static function makeVariablesScript($data)
 {
     if ($data) {
         return Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript($data)));
     } else {
         return '';
     }
 }
Ejemplo n.º 3
0
 /**
  * JS stuff to put in the <head>. This is the startup module, config
  * vars and modules marked with position 'top'
  *
  * @param $sk Skin object to use
  * @return String: HTML fragment
  */
 function getHeadScripts(Skin $sk)
 {
     // Startup - this will immediately load jquery and mediawiki modules
     $scripts = $this->makeResourceLoaderLink($sk, 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true);
     // Load config before anything else
     $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript($this->getJSVars())));
     // Script and Messages "only" requests marked for top inclusion
     // Messages should go first
     $scripts .= $this->makeResourceLoaderLink($sk, $this->getModuleMessages(true, 'top'), ResourceLoaderModule::TYPE_MESSAGES);
     $scripts .= $this->makeResourceLoaderLink($sk, $this->getModuleScripts(true, 'top'), ResourceLoaderModule::TYPE_SCRIPTS);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the top
     $modules = $this->getModules(true, 'top');
     if ($modules) {
         $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(Xml::encodeJsCall('mw.loader.load', array($modules))));
     }
     return $scripts;
 }
Ejemplo n.º 4
0
 /**
  * Returns the HTML to add to the page for the toolbar
  *
  * @since 1.19
  * @param $context IContextSource
  * @return string
  */
 public static function getDebugHTML(IContextSource $context)
 {
     global $wgDebugComments;
     $html = '';
     if (self::$enabled) {
         MWDebug::log('MWDebug output complete');
         $debugInfo = self::getDebugInfo($context);
         // Cannot use OutputPage::addJsConfigVars because those are already outputted
         // by the time this method is called.
         $html = Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript(array('debugInfo' => $debugInfo))));
     }
     if ($wgDebugComments) {
         $html .= "<!-- Debug output:\n" . htmlspecialchars(implode("\n", self::$debug)) . "\n\n-->";
     }
     return $html;
 }
Ejemplo n.º 5
0
 /**
  * Generate self-sufficient JavaScript payload to run the tests elsewhere.
  *
  * Includes startup module to request modules from ResourceLoader.
  *
  * Note: This modifies the registry to replace 'jquery.qunit' with an
  * empty module to allow external environment to preload QUnit with any
  * neccecary framework adapters (e.g. Karma). Loading it again would
  * re-define QUnit and dereference event handlers from Karma.
  */
 private function exportQUnit()
 {
     $out = $this->getOutput();
     $out->disable();
     $rl = $out->getResourceLoader();
     $query = array('lang' => $this->getLanguage()->getCode(), 'skin' => $this->getSkin()->getSkinName(), 'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false');
     $embedContext = new ResourceLoaderContext($rl, new FauxRequest($query));
     $query['only'] = 'scripts';
     $startupContext = new ResourceLoaderContext($rl, new FauxRequest($query));
     $modules = $rl->getTestModuleNames('qunit');
     // The below is essentially a pure-javascript version of OutputPage::getHeadScripts.
     $startup = $rl->makeModuleResponse($startupContext, array('startup' => $rl->getModule('startup')));
     // Embed page-specific mw.config variables.
     // The current Special page shouldn't be relevant to tests, but various modules (which
     // are loaded before the test suites), reference mw.config while initialising.
     $code = ResourceLoader::makeConfigSetScript($out->getJSVars());
     // Embed private modules as they're not allowed to be loaded dynamically
     $code .= $rl->makeModuleResponse($embedContext, array('user.options' => $rl->getModule('user.options'), 'user.tokens' => $rl->getModule('user.tokens')));
     $code .= Xml::encodeJsCall('mw.loader.load', array($modules));
     header('Content-Type: text/javascript; charset=utf-8');
     header('Cache-Control: private, no-cache, must-revalidate');
     header('Pragma: no-cache');
     echo $startup;
     echo "\n";
     // Note: The following has to be wrapped in a script tag because the startup module also
     // writes a script tag (the one loading mediawiki.js). Script tags are synchronous, block
     // each other, and run in order. But they don't nest. The code appended after the startup
     // module runs before the added script tag is parsed and executed.
     echo Xml::encodeJsCall('document.write', array(Html::inlineScript($code)));
 }
Ejemplo n.º 6
0
 /**
  * @param array $data
  * @return string
  */
 static function makeVariablesScript($data)
 {
     if ($data) {
         return ResourceLoader::makeInlineScript(ResourceLoader::makeConfigSetScript($data));
     } else {
         return '';
     }
 }
 /**
  * Get all the kaltura defined modules from player config
  * */
 function outputKalturaModules()
 {
     $o = '';
     // Init modules array, always include MwEmbedSupport
     $moduleList = array('mw.MwEmbedSupport');
     // Check player config per plugin id mapping
     $kalturaSupportModules = (include 'KalturaSupport.php');
     $playerConfig = $this->getUiConfResult()->getPlayerConfig();
     foreach ($kalturaSupportModules as $name => $module) {
         if (isset($module['kalturaLoad']) && $module['kalturaLoad'] == 'always') {
             $moduleList[] = $name;
         }
         // Check if the module has a kalturaPluginName and load if set in playerConfig
         if (isset($module['kalturaPluginName'])) {
             if (is_array($module['kalturaPluginName'])) {
                 foreach ($module['kalturaPluginName'] as $subModuleName) {
                     if (isset($playerConfig['plugins'][$subModuleName])) {
                         $moduleList[] = $name;
                         continue;
                     }
                 }
             } else {
                 if (isset($playerConfig['plugins'][$module['kalturaPluginName']])) {
                     $moduleList[] = $name;
                 }
             }
         }
     }
     // Have all the kaltura related plugins listed in a configuration var for
     // implicte dependency mapping before embedding embedPlayer
     $o .= ResourceLoader::makeConfigSetScript(array('KalturaSupport.DepModuleList' => $moduleList));
     // Special cases: handle plugins that have more complex conditional load calls
     // always include mw.EmbedPlayer
     $moduleList[] = 'mw.EmbedPlayer';
     // Load all the known required libraries:
     $o .= ResourceLoader::makeLoaderConditionalScript(Xml::encodeJsCall('mw.loader.load', array($moduleList)));
     return $o;
 }
Ejemplo n.º 8
0
 /**
  * JS stuff to put in the "<head>". This is the startup module, config
  * vars and modules marked with position 'top'
  *
  * @return String: HTML fragment
  */
 function getHeadScripts()
 {
     global $wgResourceLoaderExperimentalAsyncLoading;
     // Startup - this will immediately load jquery and mediawiki modules
     $startupScript = $this->makeResourceLoaderLink('startup', ResourceLoaderModule::TYPE_SCRIPTS, true, array(), false);
     // AG added hook here to optionally replace the script link with an inline script
     wfRunHooks('HeadScriptsStartupScript', array($this, &$startupScript));
     $scripts = $startupScript;
     // Load config before anything else
     $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript($this->getJSVars())));
     // Load embeddable private modules before any loader links
     // This needs to be TYPE_COMBINED so these modules are properly wrapped
     // in mw.loader.implement() calls and deferred until mw.user is available
     $embedScripts = array('user.options', 'user.tokens');
     $scripts .= $this->makeResourceLoaderLink($embedScripts, ResourceLoaderModule::TYPE_COMBINED);
     // Script and Messages "only" requests marked for top inclusion
     // Messages should go first
     $scripts .= $this->makeResourceLoaderLink($this->getModuleMessages(true, 'top'), ResourceLoaderModule::TYPE_MESSAGES);
     $scripts .= $this->makeResourceLoaderLink($this->getModuleScripts(true, 'top'), ResourceLoaderModule::TYPE_SCRIPTS);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the top
     $modules = $this->getModules(true, 'top');
     if ($modules) {
         $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(Xml::encodeJsCall('mw.loader.load', array($modules))));
     }
     if ($wgResourceLoaderExperimentalAsyncLoading) {
         $scripts .= $this->getScriptsForBottomQueue(true);
     }
     return $scripts;
 }
Ejemplo n.º 9
0
 /**
  * JS stuff to put in the <head>. This is the startup module, config
  * vars and modules marked with position 'top'
  *
  * @return String: HTML fragment
  */
 function getHeadScripts()
 {
     global $wgResourceLoaderExperimentalAsyncLoading;
     // Startup - this will immediately load jquery and mediawiki modules
     $scripts = $this->makeResourceLoaderLink('startup', ResourceLoaderModule::TYPE_SCRIPTS, true);
     // Load config before anything else
     $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript($this->getJSVars())));
     // Wikia change - begin - @author: wladek
     $scripts = $this->topScripts . $scripts;
     // Wikia change - end
     /* Wikia change begin - @author: Macbre */
     /* allow old skins to inject JS code before files from MW core (BugId:960) */
     wfRunHooks('SkinGetHeadScripts', array(&$scripts));
     /* Wikia change end */
     // Load embeddable private modules before any loader links
     // This needs to be TYPE_COMBINED so these modules are properly wrapped
     // in mw.loader.implement() calls and deferred until mw.user is available
     $embedScripts = array('user.options', 'user.tokens');
     $scripts .= $this->makeResourceLoaderLink($embedScripts, ResourceLoaderModule::TYPE_COMBINED);
     // Script and Messages "only" requests marked for top inclusion
     // Messages should go first
     $scripts .= $this->makeResourceLoaderLink($this->getModuleMessages(true, 'top'), ResourceLoaderModule::TYPE_MESSAGES);
     $scripts .= $this->makeResourceLoaderLink($this->getModuleScripts(true, 'top'), ResourceLoaderModule::TYPE_SCRIPTS);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the top
     $modules = $this->getModules(true, 'top');
     if ($modules) {
         $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(Xml::encodeJsCall('mw.loader.load', array($modules))));
     }
     if ($wgResourceLoaderExperimentalAsyncLoading) {
         $scripts .= $this->getScriptsForBottomQueue(true);
     }
     return $scripts;
 }
Ejemplo n.º 10
0
 /**
  * JS stuff to put at the bottom of the `<body>`. These are modules with position 'bottom',
  * legacy scripts ($this->mScripts), and user JS.
  *
  * @return string|WrappedStringList HTML
  */
 public function getBottomScripts()
 {
     $chunks = [];
     $chunks[] = $this->getRlClient()->getBodyHtml();
     // Legacy non-ResourceLoader scripts
     $chunks[] = $this->mScripts;
     // Exempt 'user' module
     // - May need excludepages for live preview. (T28283)
     // - Must use TYPE_COMBINED so its response is handled by mw.loader.implement() which
     //   ensures execution is scheduled after the "site" module.
     // - Don't load if module state is already resolved as "ready".
     if ($this->rlUserModuleState === 'loading') {
         if ($this->isUserJsPreview()) {
             $chunks[] = $this->makeResourceLoaderLink('user', ResourceLoaderModule::TYPE_COMBINED, ['excludepage' => $this->getTitle()->getPrefixedDBkey()]);
             $chunks[] = ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.using', [['user', 'site'], new XmlJsCode('function () {' . Xml::encodeJsCall('$.globalEval', [$this->getRequest()->getText('wpTextbox1')]) . '}')]));
             // FIXME: If the user is previewing, say, ./vector.js, his ./common.js will be loaded
             // asynchronously and may arrive *after* the inline script here. So the previewed code
             // may execute before ./common.js runs. Normally, ./common.js runs before ./vector.js.
             // Similarly, when previewing ./common.js and the user module does arrive first,
             // it will arrive without common.js and the inline script runs after.
             // Thus running common after the excluded subpage.
         } else {
             // Load normally
             $chunks[] = $this->makeResourceLoaderLink('user', ResourceLoaderModule::TYPE_COMBINED);
         }
     }
     if ($this->limitReportData) {
         $chunks[] = ResourceLoader::makeInlineScript(ResourceLoader::makeConfigSetScript(['wgPageParseReport' => $this->limitReportData], true));
     }
     return self::combineWrappedStrings($chunks);
 }
Ejemplo n.º 11
0
 /**
  * Returns the HTML to add to the page for the toolbar
  *
  * @param $context IContextSource
  * @return string
  */
 public static function getDebugHTML(IContextSource $context)
 {
     if (!self::$enabled) {
         return '';
     }
     global $wgVersion, $wgRequestTime;
     MWDebug::log('MWDebug output complete');
     $request = $context->getRequest();
     $debugInfo = array('mwVersion' => $wgVersion, 'phpVersion' => PHP_VERSION, 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $_SERVER['REQUEST_METHOD'], 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage()), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage()), 'includes' => self::getFilesIncluded($context));
     // Cannot use OutputPage::addJsConfigVars because those are already outputted
     // by the time this method is called.
     $html = Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript(array('debugInfo' => $debugInfo))));
     return $html;
 }
Ejemplo n.º 12
0
 /**
  * The order of elements in the head is as follows:
  * - Inline scripts.
  * - Stylesheets.
  * - Async external script-src.
  *
  * Reasons:
  * - Script execution may be blocked on preceeding stylesheets.
  * - Async scripts are not blocked on stylesheets.
  * - Inline scripts can't be asynchronous.
  * - For styles, earlier is better.
  *
  * @return string|WrappedStringList HTML
  */
 public function getHeadHtml()
 {
     $data = $this->getData();
     $chunks = [];
     // Change "client-nojs" class to client-js. This allows easy toggling of UI components.
     // This happens synchronously on every page view to avoid flashes of wrong content.
     // See also #getDocumentAttributes() and /resources/src/startup.js.
     $chunks[] = Html::inlineScript('document.documentElement.className = document.documentElement.className' . '.replace( /(^|\\s)client-nojs(\\s|$)/, "$1client-js$2" );');
     // Inline RLQ: Set page variables
     if ($this->config) {
         $chunks[] = ResourceLoader::makeInlineScript(ResourceLoader::makeConfigSetScript($this->config));
     }
     // Inline RLQ: Initial module states
     $states = array_merge($this->exemptStates, $data['states']);
     if ($states) {
         $chunks[] = ResourceLoader::makeInlineScript(ResourceLoader::makeLoaderStateScript($states));
     }
     // Inline RLQ: Embedded modules
     if ($data['embed']['general']['top']) {
         $chunks[] = $this->getLoad($data['embed']['general']['top'], ResourceLoaderModule::TYPE_COMBINED);
     }
     // Inline RLQ: Load general modules
     if ($data['general']['top']) {
         $chunks[] = ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.load', [$data['general']['top']]));
     }
     // Inline RLQ: Load only=scripts
     if ($data['scripts']['top']) {
         $chunks[] = $this->getLoad($data['scripts']['top'], ResourceLoaderModule::TYPE_SCRIPTS);
     }
     // External stylesheets
     if ($data['styles']) {
         $chunks[] = $this->getLoad($data['styles'], ResourceLoaderModule::TYPE_STYLES);
     }
     // Inline stylesheets (embedded only=styles)
     if ($data['embed']['styles']) {
         $chunks[] = $this->getLoad($data['embed']['styles'], ResourceLoaderModule::TYPE_STYLES);
     }
     // Async scripts. Once the startup is loaded, inline RLQ scripts will run.
     // Pass-through a custom target from OutputPage (T143066).
     $startupQuery = $this->target ? ['target' => $this->target] : [];
     $chunks[] = $this->getLoad('startup', ResourceLoaderModule::TYPE_SCRIPTS, $startupQuery);
     return WrappedStringList::join("\n", $chunks);
 }
	/**
	 * In main namespace, display the proofreading status of transcluded pages.
	 *
	 * @param $out Object: OutputPage object
	 */
	private static function prepareArticle( $out ) {
		global $wgUser;

		$id = $out->getTitle()->mArticleID;
		if( $id == -1 ) {
			return true;
		}
		list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace();
		$page_ns_index = MWNamespace::getCanonicalIndex( strtolower( str_replace( ' ', '_', $page_namespace ) ) );
		$index_ns_index = MWNamespace::getCanonicalIndex( strtolower( str_replace( ' ', '_', $index_namespace ) ) );
		if( $page_ns_index == null || $index_ns_index == null ) {
			return true;
		}

		$dbr = wfGetDB( DB_SLAVE );

		// find the index page
		$indextitle = null;
		$res = $dbr->select(
			array( 'templatelinks' ),
			array( 'tl_title AS title' ),
			array( 'tl_from' => $id, 'tl_namespace' => $page_ns_index ),
			__METHOD__,
			array( 'LIMIT' => 1 )
		);
		if( $res && $dbr->numRows( $res ) > 0 ) {
			$row = $dbr->fetchObject( $res );
			$res2 = $dbr->select(
				array( 'pagelinks', 'page' ),
				array( 'page_title AS title' ),
				array(
					'pl_title' => $row->title,
					'pl_namespace' => $page_ns_index,
					'page_namespace' => $index_ns_index
				),
				__METHOD__,
				array( 'LIMIT' => 1 ),
				array( 'page' => array( 'LEFT JOIN', 'page_id=pl_from' ) )
			);
			if( $res2 && $dbr->numRows( $res2 ) > 0 ) {
				$row = $dbr->fetchObject( $res2 );
				$indextitle = $row->title;
			}
		}

		if( isset( $out->is_toc ) && $out->is_toc ) {
			if ( $indextitle ) {
				$res = $dbr->select(
					array( 'pr_index', 'page' ),
					array( 'pr_count', 'pr_q0', 'pr_q1', 'pr_q2', 'pr_q3', 'pr_q4' ),
					array( 'page_title' => $indextitle, 'page_namespace' => $index_ns_index ),
					__METHOD__,
					null,
					array( 'page' => array( 'LEFT JOIN', 'page_id=pr_page_id' ) )
				);
				$row = $dbr->fetchObject( $res );
				if( $row ) {
					$n0 = $row->pr_q0;
					$n1 = $row->pr_q1;
					$n2 = $row->pr_q2;
					$n3 = $row->pr_q3;
					$n4 = $row->pr_q4;
					$n = $row->pr_count;
					$ne = $n - ( $n0 + $n1 + $n2 + $n3 + $n4 );
				}
			}
		} else {
			// count transclusions from page namespace
			$res = $dbr->select(
				array( 'templatelinks', 'page' ),
				array( 'COUNT(page_id) AS count' ),
				array( 'tl_from' => $id, 'tl_namespace' => $page_ns_index ),
				__METHOD__,
				null,
				array( 'page' => array( 'LEFT JOIN', 'page_title=tl_title AND page_namespace=tl_namespace' ) )
			);
			if( $res && $dbr->numRows( $res ) > 0 ) {
				$row = $dbr->fetchObject( $res );
				$n = $row->count;
			}

			// find the proofreading status of transclusions
			$queryArr = array(
				'tables' => array( 'templatelinks', 'page', 'categorylinks' ),
				'fields' => array( 'COUNT(page_id) AS count' ),
				'conds' => array( 'tl_from' => $id, 'tl_namespace' => $page_ns_index, 'cl_to' => '' ),
				'joins' => array(
					'page' => array( 'LEFT JOIN', 'page_title=tl_title AND page_namespace=tl_namespace' ),
					'categorylinks' => array( 'LEFT JOIN', 'cl_from=page_id' ),
				)
			);

			$n0 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality0_category' );
			$n2 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality2_category' );
			$n3 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality3_category' );
			$n4 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality4_category' );
			// quality1 is the default value
			$n1 = $n - $n0 - $n2 - $n3 - $n4;
			$ne = 0;
		}

		if( $n == 0 ) {
			return true;
		}

		if( $indextitle ) {
			$sk = $wgUser->getSkin();
			$nt = Title::makeTitleSafe( $index_ns_index, $indextitle );
			$indexlink = $sk->link( $nt, wfMsg( 'proofreadpage_source' ),
						array( 'title' => wfMsg( 'proofreadpage_source_message' ) ) );
			$out->addInlineScript( ResourceLoader::makeConfigSetScript( array( 'proofreadpage_source_href' => $indexlink ) ) );
			$out->addModules( 'ext.proofreadpage.article' );
		}

		$q0 = $n0 * 100 / $n;
		$q1 = $n1 * 100 / $n;
		$q2 = $n2 * 100 / $n;
		$q3 = $n3 * 100 / $n;
		$q4 = $n4 * 100 / $n;
		$qe = $ne * 100 / $n;
		$void_cell = $ne ? "<td align=center style='border-style:dotted;border-width:1px;' width=\"{$qe}\"></td>" : '';
		$output = "<table class=\"pr_quality\" style=\"line-height:40%;\" border=0 cellpadding=0 cellspacing=0 ><tr>
<td align=center >&#160;</td>
<td align=center class='quality4' width=\"$q4\"></td>
<td align=center class='quality3' width=\"$q3\"></td>
<td align=center class='quality2' width=\"$q2\"></td>
<td align=center class='quality1' width=\"$q1\"></td>
<td align=center class='quality0' width=\"$q0\"></td>
$void_cell
</tr></table>";
		$out->setSubtitle( $out->getSubtitle() . $output );
		return true;
	}
Ejemplo n.º 14
0
 /**
  * <script>...</script> tags to put in "<head>".
  *
  * @return string HTML fragment
  */
 function getInlineHeadScripts()
 {
     $links = array();
     // Client profile classes for <html>. Allows for easy hiding/showing of UI components.
     // Must be done synchronously on every page to avoid flashes of wrong content.
     // Note: This class distinguishes MediaWiki-supported JavaScript from the rest.
     // The "rest" includes browsers that support JavaScript but not supported by our runtime.
     // For the performance benefit of the majority, this is added unconditionally here and is
     // then fixed up by the startup module for unsupported browsers.
     $links[] = Html::inlineScript('document.documentElement.className = document.documentElement.className' . '.replace( /(^|\\s)client-nojs(\\s|$)/, "$1client-js$2" );');
     // Load config before anything else
     $links[] = ResourceLoader::makeInlineScript(ResourceLoader::makeConfigSetScript($this->getJSVars()));
     // Load embeddable private modules before any loader links
     // This needs to be TYPE_COMBINED so these modules are properly wrapped
     // in mw.loader.implement() calls and deferred until mw.user is available
     $embedScripts = array('user.options');
     $links[] = $this->makeResourceLoaderLink($embedScripts, ResourceLoaderModule::TYPE_COMBINED);
     // Separate user.tokens as otherwise caching will be allowed (T84960)
     $links[] = $this->makeResourceLoaderLink('user.tokens', ResourceLoaderModule::TYPE_COMBINED);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the top
     $modules = $this->getModules(true, 'top');
     if ($modules) {
         $links[] = ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.load', array($modules)));
     }
     // "Scripts only" modules marked for top inclusion
     $links[] = $this->makeResourceLoaderLink($this->getModuleScripts(true, 'top'), ResourceLoaderModule::TYPE_SCRIPTS);
     return self::getHtmlFromLoaderLinks($links);
 }
 /**
  * Generate self-sufficient JavaScript payload to run the tests elsewhere.
  *
  * Includes startup module to request modules from ResourceLoader.
  *
  * Note: This modifies the registry to replace 'jquery.qunit' with an
  * empty module to allow external environment to preload QUnit with any
  * neccecary framework adapters (e.g. Karma). Loading it again would
  * re-define QUnit and dereference event handlers from Karma.
  */
 private function exportQUnit()
 {
     $out = $this->getOutput();
     $out->disable();
     $rl = $out->getResourceLoader();
     $query = array('lang' => $this->getLanguage()->getCode(), 'skin' => $this->getSkin()->getSkinName(), 'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false', 'target' => 'test');
     $embedContext = new ResourceLoaderContext($rl, new FauxRequest($query));
     $query['only'] = 'scripts';
     $startupContext = new ResourceLoaderContext($rl, new FauxRequest($query));
     $query['raw'] = true;
     $modules = $rl->getTestModuleNames('qunit');
     // Disable autostart because we load modules asynchronously. By default, QUnit would start
     // at domready when there are no tests loaded and also fire 'QUnit.done' which then instructs
     // Karma to end the run before the tests even started.
     $qunitConfig = 'QUnit.config.autostart = false;' . 'if (window.__karma__) {' . 'window.__karma__.loaded = function () {};' . '}';
     // The below is essentially a pure-javascript version of OutputPage::getHeadScripts.
     $startup = $rl->makeModuleResponse($startupContext, array('startup' => $rl->getModule('startup')));
     // Embed page-specific mw.config variables.
     // The current Special page shouldn't be relevant to tests, but various modules (which
     // are loaded before the test suites), reference mw.config while initialising.
     $code = ResourceLoader::makeConfigSetScript($out->getJSVars());
     // Embed private modules as they're not allowed to be loaded dynamically
     $code .= $rl->makeModuleResponse($embedContext, array('user.options' => $rl->getModule('user.options'), 'user.tokens' => $rl->getModule('user.tokens')));
     // Catch exceptions (such as "dependency missing" or "unknown module") so that we
     // always start QUnit. Re-throw so that they are caught and reported as global exceptions
     // by QUnit and Karma.
     $code .= '(function () {' . 'var start = window.__karma__ ? window.__karma__.start : QUnit.start;' . 'try {' . 'mw.loader.using( ' . Xml::encodeJsVar($modules) . ' ).always( start );' . '} catch ( e ) { start(); throw e; }' . '}());';
     header('Content-Type: text/javascript; charset=utf-8');
     header('Cache-Control: private, no-cache, must-revalidate');
     header('Pragma: no-cache');
     echo $qunitConfig;
     echo $startup;
     // The following has to be deferred via RLQ because the startup module is asynchronous.
     echo ResourceLoader::makeLoaderConditionalScript($code);
 }
Ejemplo n.º 16
0
 /**
  * JS stuff to put in the "<head>". This is the startup module, config
  * vars and modules marked with position 'top'
  *
  * @return string HTML fragment
  */
 function getHeadScripts()
 {
     // Startup - this will immediately load jquery and mediawiki modules
     $links = array();
     $links[] = $this->makeResourceLoaderLink('startup', ResourceLoaderModule::TYPE_SCRIPTS, true);
     // Load config before anything else
     $links[] = ResourceLoader::makeInlineScript(ResourceLoader::makeConfigSetScript($this->getJSVars()));
     // Load embeddable private modules before any loader links
     // This needs to be TYPE_COMBINED so these modules are properly wrapped
     // in mw.loader.implement() calls and deferred until mw.user is available
     $embedScripts = array('user.options');
     $links[] = $this->makeResourceLoaderLink($embedScripts, ResourceLoaderModule::TYPE_COMBINED);
     // Separate user.tokens as otherwise caching will be allowed (T84960)
     $links[] = $this->makeResourceLoaderLink('user.tokens', ResourceLoaderModule::TYPE_COMBINED);
     // Scripts and messages "only" requests marked for top inclusion
     $links[] = $this->makeResourceLoaderLink($this->getModuleScripts(true, 'top'), ResourceLoaderModule::TYPE_SCRIPTS);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the top
     $modules = $this->getModules(true, 'top');
     if ($modules) {
         $links[] = ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.load', array($modules)));
     }
     if ($this->getConfig()->get('ResourceLoaderExperimentalAsyncLoading')) {
         $links[] = $this->getScriptsForBottomQueue(true);
     }
     return self::getHtmlFromLoaderLinks($links);
 }
 public function getScript(ResourceLoaderContext $context)
 {
     $config = $context->getResourceLoader()->getConfig();
     return ResourceLoader::makeConfigSetScript(['wgUploadDialog' => $config->get('UploadDialog')]);
 }