Index: branches/wmf/1.18wmf1/includes/OutputPage.php |
— | — | @@ -118,6 +118,7 @@ |
119 | 119 | // @todo FIXME: Next variables probably comes from the resource loader |
120 | 120 | var $mModules = array(), $mModuleScripts = array(), $mModuleStyles = array(), $mModuleMessages = array(); |
121 | 121 | var $mResourceLoader; |
| 122 | + var $mJsConfigVars = array(); |
122 | 123 | |
123 | 124 | /** @todo FIXME: Is this still used ?*/ |
124 | 125 | var $mInlineMsg = array(); |
— | — | @@ -1314,7 +1315,7 @@ |
1315 | 1316 | } |
1316 | 1317 | |
1317 | 1318 | /** |
1318 | | - * Add wikitext with a custom Title object and |
| 1319 | + * Add wikitext with a custom Title object and tidy enabled. |
1319 | 1320 | * |
1320 | 1321 | * @param $text String: wikitext |
1321 | 1322 | * @param $title Title object |
— | — | @@ -2582,11 +2583,29 @@ |
2583 | 2584 | } |
2584 | 2585 | |
2585 | 2586 | /** |
2586 | | - * Get an array containing global JS variables |
| 2587 | + * Add one or more variables to be set in mw.config in JavaScript. |
2587 | 2588 | * |
2588 | | - * Do not add things here which can be evaluated in |
2589 | | - * ResourceLoaderStartupScript - in other words, without state. |
2590 | | - * You will only be adding bloat to the page and causing page caches to |
| 2589 | + * @param $key {String|Array} Key or array of key/value pars. |
| 2590 | + * @param $value {Mixed} Value of the configuration variable. |
| 2591 | + */ |
| 2592 | + public function addJsConfigVars( $keys, $value ) { |
| 2593 | + if ( is_array( $keys ) ) { |
| 2594 | + foreach ( $keys as $key => $value ) { |
| 2595 | + $this->mJsConfigVars[$key] = $value; |
| 2596 | + } |
| 2597 | + return; |
| 2598 | + } |
| 2599 | + |
| 2600 | + $this->mJsConfigVars[$keys] = $value; |
| 2601 | + } |
| 2602 | + |
| 2603 | + |
| 2604 | + /** |
| 2605 | + * Get an array containing the variables to be set in mw.config in JavaScript. |
| 2606 | + * |
| 2607 | + * Do not add things here which can be evaluated in ResourceLoaderStartupScript |
| 2608 | + * - in other words, page-indendent/site-wide variables (without state). |
| 2609 | + * You will only be adding bloat to the html page and causing page caches to |
2591 | 2610 | * have to be purged on configuration changes. |
2592 | 2611 | */ |
2593 | 2612 | protected function getJSVars() { |
— | — | @@ -2629,10 +2648,14 @@ |
2630 | 2649 | $vars['wgIsMainPage'] = true; |
2631 | 2650 | } |
2632 | 2651 | |
2633 | | - // Allow extensions to add their custom variables to the global JS variables |
| 2652 | + // Allow extensions to add their custom variables to the mw.config map. |
| 2653 | + // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not |
| 2654 | + // page-dependant but site-wide (without state). |
| 2655 | + // Alternatively, you may want to use OutputPage->addJsConfigVars() instead. |
2634 | 2656 | wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) ); |
2635 | 2657 | |
2636 | | - return $vars; |
| 2658 | + // Merge in variables from addJsConfigVars last |
| 2659 | + return array_merge( $vars, $this->mJsConfigVars ); |
2637 | 2660 | } |
2638 | 2661 | |
2639 | 2662 | /** |
Property changes on: branches/wmf/1.18wmf1/includes/OutputPage.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
2640 | 2663 | Merged /trunk/phase3/includes/OutputPage.php:r98374 |