r98374 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98373‎ | r98374 | r98375 >
Date:22:08, 28 September 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -69,6 +69,8 @@
7070 * New common*.css files usable by skins instead of having to copy piles
7171 of generic styles from MonoBook or Vector's css.
7272 * Some deprecated presentational html attributes will now be automatically converted to css.
 73+* (bug 31233) New OutputPage::addJsConfigVars() method to make the output page specific
 74+ mw.config map extendable.
7375
7476 === Bug fixes in 1.19 ===
7577 * $wgUploadNavigationUrl should be used for file redlinks if
Index: trunk/phase3/includes/OutputPage.php
@@ -124,6 +124,7 @@
125125 // @todo FIXME: Next variables probably comes from the resource loader
126126 var $mModules = array(), $mModuleScripts = array(), $mModuleStyles = array(), $mModuleMessages = array();
127127 var $mResourceLoader;
 128+ var $mJsConfigVars = array();
128129
129130 /** @todo FIXME: Is this still used ?*/
130131 var $mInlineMsg = array();
@@ -1330,7 +1331,7 @@
13311332 }
13321333
13331334 /**
1334 - * Add wikitext with a custom Title object and
 1335+ * Add wikitext with a custom Title object and tidy enabled.
13351336 *
13361337 * @param $text String: wikitext
13371338 * @param $title Title object
@@ -2606,11 +2607,29 @@
26072608 }
26082609
26092610 /**
2610 - * Get an array containing global JS variables
 2611+ * Add one or more variables to be set in mw.config in JavaScript.
26112612 *
2612 - * Do not add things here which can be evaluated in
2613 - * ResourceLoaderStartupScript - in other words, without state.
2614 - * You will only be adding bloat to the page and causing page caches to
 2613+ * @param $key {String|Array} Key or array of key/value pars.
 2614+ * @param $value {Mixed} Value of the configuration variable.
 2615+ */
 2616+ public function addJsConfigVars( $keys, $value ) {
 2617+ if ( is_array( $keys ) ) {
 2618+ foreach ( $keys as $key => $value ) {
 2619+ $this->mJsConfigVars[$key] = $value;
 2620+ }
 2621+ return;
 2622+ }
 2623+
 2624+ $this->mJsConfigVars[$keys] = $value;
 2625+ }
 2626+
 2627+
 2628+ /**
 2629+ * Get an array containing the variables to be set in mw.config in JavaScript.
 2630+ *
 2631+ * Do not add things here which can be evaluated in ResourceLoaderStartupScript
 2632+ * - in other words, page-indendent/site-wide variables (without state).
 2633+ * You will only be adding bloat to the html page and causing page caches to
26152634 * have to be purged on configuration changes.
26162635 */
26172636 protected function getJSVars() {
@@ -2654,10 +2673,14 @@
26552674 $vars['wgIsMainPage'] = true;
26562675 }
26572676
2658 - // Allow extensions to add their custom variables to the global JS variables
 2677+ // Allow extensions to add their custom variables to the mw.config map.
 2678+ // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not
 2679+ // page-dependant but site-wide (without state).
 2680+ // Alternatively, you may want to use OutputPage->addJsConfigVars() instead.
26592681 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars, &$this ) );
26602682
2661 - return $vars;
 2683+ // Merge in variables from addJsConfigVars last
 2684+ return array_merge( $vars, $this->mJsConfigVars );
26622685 }
26632686
26642687 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r98379clean up Html::inlineScript usage...krinkle22:47, 28 September 2011
r98769Fix comment in r98374catrope14:59, 3 October 2011
r99981After merging r98374 into REL1_18 in r99980, move RELEASE-NOTES to 1.18reedy22:14, 16 October 2011
r99983MFT r98374demon22:17, 16 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r61690Step two in fixing OutputPage's documentation, more or less the same as r61647ialex21:32, 29 January 2010

Comments

#Comment by Catrope (talk | contribs)   15:23, 3 October 2011

Tagging 1.18 because r98379, which is a bugfix, requires it.

Status & tagging log