| Index: trunk/phase3/RELEASE-NOTES-1.19 |
| — | — | @@ -69,6 +69,8 @@ |
| 70 | 70 | * New common*.css files usable by skins instead of having to copy piles |
| 71 | 71 | of generic styles from MonoBook or Vector's css. |
| 72 | 72 | * 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. |
| 73 | 75 | |
| 74 | 76 | === Bug fixes in 1.19 === |
| 75 | 77 | * $wgUploadNavigationUrl should be used for file redlinks if |
| Index: trunk/phase3/includes/OutputPage.php |
| — | — | @@ -124,6 +124,7 @@ |
| 125 | 125 | // @todo FIXME: Next variables probably comes from the resource loader |
| 126 | 126 | var $mModules = array(), $mModuleScripts = array(), $mModuleStyles = array(), $mModuleMessages = array(); |
| 127 | 127 | var $mResourceLoader; |
| | 128 | + var $mJsConfigVars = array(); |
| 128 | 129 | |
| 129 | 130 | /** @todo FIXME: Is this still used ?*/ |
| 130 | 131 | var $mInlineMsg = array(); |
| — | — | @@ -1330,7 +1331,7 @@ |
| 1331 | 1332 | } |
| 1332 | 1333 | |
| 1333 | 1334 | /** |
| 1334 | | - * Add wikitext with a custom Title object and |
| | 1335 | + * Add wikitext with a custom Title object and tidy enabled. |
| 1335 | 1336 | * |
| 1336 | 1337 | * @param $text String: wikitext |
| 1337 | 1338 | * @param $title Title object |
| — | — | @@ -2606,11 +2607,29 @@ |
| 2607 | 2608 | } |
| 2608 | 2609 | |
| 2609 | 2610 | /** |
| 2610 | | - * Get an array containing global JS variables |
| | 2611 | + * Add one or more variables to be set in mw.config in JavaScript. |
| 2611 | 2612 | * |
| 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 |
| 2615 | 2634 | * have to be purged on configuration changes. |
| 2616 | 2635 | */ |
| 2617 | 2636 | protected function getJSVars() { |
| — | — | @@ -2654,10 +2673,14 @@ |
| 2655 | 2674 | $vars['wgIsMainPage'] = true; |
| 2656 | 2675 | } |
| 2657 | 2676 | |
| 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. |
| 2659 | 2681 | wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars, &$this ) ); |
| 2660 | 2682 | |
| 2661 | | - return $vars; |
| | 2683 | + // Merge in variables from addJsConfigVars last |
| | 2684 | + return array_merge( $vars, $this->mJsConfigVars ); |
| 2662 | 2685 | } |
| 2663 | 2686 | |
| 2664 | 2687 | /** |