From: Krinkle Date: Wed, 28 Sep 2011 22:08:08 +0000 (+0000) Subject: New OutputPage::addJsConfigVars() method (bug 31233) X-Git-Tag: 1.31.0-rc.0~27380 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=59953d58097084cee2a9f09ab4aaea5d5a9a9dfd;p=lhc%2Fweb%2Fwiklou.git New OutputPage::addJsConfigVars() method (bug 31233) * to make the output page specific mw.config map extendable. * fixes (bug 31233) Make OutputPage's mw.config array extendable internally instead of hard coded * fixes weird unfinished comment from r61690 --- diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 329274be61..08dc004a7c 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -69,6 +69,8 @@ production. * New common*.css files usable by skins instead of having to copy piles of generic styles from MonoBook or Vector's css. * Some deprecated presentational html attributes will now be automatically converted to css. +* (bug 31233) New OutputPage::addJsConfigVars() method to make the output page specific + mw.config map extendable. === Bug fixes in 1.19 === * $wgUploadNavigationUrl should be used for file redlinks if diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 7fd423fb83..6ea70b96b4 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -124,6 +124,7 @@ class OutputPage extends ContextSource { // @todo FIXME: Next variables probably comes from the resource loader var $mModules = array(), $mModuleScripts = array(), $mModuleStyles = array(), $mModuleMessages = array(); var $mResourceLoader; + var $mJsConfigVars = array(); /** @todo FIXME: Is this still used ?*/ var $mInlineMsg = array(); @@ -1330,7 +1331,7 @@ class OutputPage extends ContextSource { } /** - * Add wikitext with a custom Title object and + * Add wikitext with a custom Title object and tidy enabled. * * @param $text String: wikitext * @param $title Title object @@ -2606,11 +2607,29 @@ $distantTemplates } /** - * Get an array containing global JS variables + * Add one or more variables to be set in mw.config in JavaScript. * - * Do not add things here which can be evaluated in - * ResourceLoaderStartupScript - in other words, without state. - * You will only be adding bloat to the page and causing page caches to + * @param $key {String|Array} Key or array of key/value pars. + * @param $value {Mixed} Value of the configuration variable. + */ + public function addJsConfigVars( $keys, $value ) { + if ( is_array( $keys ) ) { + foreach ( $keys as $key => $value ) { + $this->mJsConfigVars[$key] = $value; + } + return; + } + + $this->mJsConfigVars[$keys] = $value; + } + + + /** + * Get an array containing the variables to be set in mw.config in JavaScript. + * + * Do not add things here which can be evaluated in ResourceLoaderStartupScript + * - in other words, page-indendent/site-wide variables (without state). + * You will only be adding bloat to the html page and causing page caches to * have to be purged on configuration changes. */ protected function getJSVars() { @@ -2654,10 +2673,14 @@ $distantTemplates $vars['wgIsMainPage'] = true; } - // Allow extensions to add their custom variables to the global JS variables + // Allow extensions to add their custom variables to the mw.config map. + // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not + // page-dependant but site-wide (without state). + // Alternatively, you may want to use OutputPage->addJsConfigVars() instead. wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars, &$this ) ); - return $vars; + // Merge in variables from addJsConfigVars last + return array_merge( $vars, $this->mJsConfigVars ); } /**