r91089 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91088‎ | r91089 | r91090 >
Date:18:06, 29 June 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT r85616, r85617. This required meticulous conflict resolution due to differences in RL between 1.17wmf1 and trunk, mainly the TYPE_* and ORIGIN_* stuff
Modified paths:
  • /branches/wmf/1.17wmf1/includes/OutputPage.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/Skin.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/resourceloader/ResourceLoaderFileModule.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/resourceloader/ResourceLoaderModule.php (modified) (history)
  • /branches/wmf/1.17wmf1/resources/Resources.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/OutputPage.php
@@ -228,12 +228,37 @@
229229 }
230230
231231 /**
 232+ * Filter an array of modules to remove modules
 233+ * which are no longer registered (eg a page is cached before an extension is disabled)
 234+ * @param $modules Array
 235+ * @param $position String if not null, only return modules with this position
 236+ * @return Array
 237+ */
 238+ protected function filterModules( $modules, $position = null ){
 239+ $resourceLoader = $this->getResourceLoader();
 240+ $filteredModules = array();
 241+ foreach( $modules as $val ){
 242+ $module = $resourceLoader->getModule( $val );
 243+ if( $module instanceof ResourceLoaderModule
 244+ && ( is_null( $position ) || $module->getPosition() == $position ) )
 245+ {
 246+ $filteredModules[] = $val;
 247+ }
 248+ }
 249+ return $filteredModules;
 250+ }
 251+
 252+ /**
232253 * Get the list of modules to include on this page
233254 *
 255+ * @param $position String if not null, only return modules with this position
234256 * @return Array of module names
235257 */
236 - public function getModules() {
237 - return array_values( array_unique( $this->mModules ) );
 258+ public function getModules( $filter = false, $position = null, $param = 'mModules' ) {
 259+ $modules = array_values( array_unique( $this->$param ) );
 260+ return $filter
 261+ ? $this->filterModules( $modules, $position )
 262+ : $modules;
238263 }
239264
240265 /**
@@ -251,8 +276,8 @@
252277 * Get the list of module JS to include on this page
253278 * @return array of module names
254279 */
255 - public function getModuleScripts() {
256 - return array_values( array_unique( $this->mModuleScripts ) );
 280+ public function getModuleScripts( $filter = false, $position = null ) {
 281+ return $this->getModules( $filter, $position, 'mModuleScripts' );
257282 }
258283
259284 /**
@@ -271,8 +296,8 @@
272297 *
273298 * @return Array of module names
274299 */
275 - public function getModuleStyles() {
276 - return array_values( array_unique( $this->mModuleStyles ) );
 300+ public function getModuleStyles( $filter = false, $position = null ) {
 301+ return $this->getModules( $filter, $position, 'mModuleStyles' );
277302 }
278303
279304 /**
@@ -291,8 +316,8 @@
292317 *
293318 * @return Array of module names
294319 */
295 - public function getModuleMessages() {
296 - return array_values( array_unique( $this->mModuleMessages ) );
 320+ public function getModuleMessages( $filter = false, $position = null ) {
 321+ return $this->getModules( $filter, $position, 'mModuleMessages' );
297322 }
298323
299324 /**
@@ -2257,6 +2282,7 @@
22582283 $ret .= implode( "\n", array(
22592284 $this->getHeadLinks( $sk ),
22602285 $this->buildCssLinks( $sk ),
 2286+ $this->getHeadScripts( $sk ),
22612287 $this->getHeadItems()
22622288 ) );
22632289
@@ -2458,32 +2484,59 @@
24592485 }
24602486
24612487 /**
2462 - * Gets the global variables and mScripts; also adds userjs to the end if
2463 - * enabled. Despite the name, these scripts are no longer put in the
2464 - * <head> but at the bottom of the <body>
 2488+ * JS stuff to put in the <head>. This is the startup module, config
 2489+ * vars and modules marked with position 'top'
24652490 *
24662491 * @param $sk Skin object to use
24672492 * @return String: HTML fragment
24682493 */
24692494 function getHeadScripts( Skin $sk ) {
2470 - global $wgUser, $wgRequest, $wgUseSiteJs;
2471 -
24722495 // Startup - this will immediately load jquery and mediawiki modules
24732496 $scripts = $this->makeResourceLoaderLink( $sk, 'startup', 'scripts', true );
2474 -
2475 - // Configuration -- This could be merged together with the load and go, but
2476 - // makeGlobalVariablesScript returns a whole script tag -- grumble grumble...
 2497+
 2498+ // Load config before anything else
24772499 $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
 2500+
 2501+ // Script and Messages "only" requests marked for top inclusion
 2502+ // Messages should go first
 2503+ $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages( true, 'top' ), 'messages' );
 2504+ $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts( true, 'top' ), 'scripts' );
24782505
2479 - // Script and Messages "only" requests
2480 - $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts(), 'scripts' );
2481 - $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' );
 2506+ // Modules requests - let the client calculate dependencies and batch requests as it likes
 2507+ // Only load modules that have marked themselves for loading at the top
 2508+ $modules = $this->getModules( true, 'top' );
 2509+ if ( $modules ) {
 2510+ $scripts .= Html::inlineScript(
 2511+ ResourceLoader::makeLoaderConditionalScript(
 2512+ Xml::encodeJsCall( 'mediaWiki.loader.load', array( $modules ) ) .
 2513+ Xml::encodeJsCall( 'mediaWiki.loader.go', array() )
 2514+ )
 2515+ ) . "\n";
 2516+ }
24822517
 2518+ return $scripts;
 2519+ }
 2520+
 2521+ /**
 2522+ * JS stuff to put at the bottom of the <body>: modules marked with position 'bottom',
 2523+ * legacy scripts ($this->mScripts), user preferences, site JS and user JS
 2524+ */
 2525+ function getBottomScripts( Skin $sk ) {
 2526+ global $wgUseSiteJs, $wgAllowUserJs, $wgUser, $wgRequest;
 2527+
 2528+ // Script and Messages "only" requests marked for bottom inclusion
 2529+ // Messages should go first
 2530+ $scripts = $this->makeResourceLoaderLink( $sk, $this->getModuleMessages( true, 'bottom' ), 'messages' );
 2531+ $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts( true, 'bottom' ), 'scripts' );
 2532+
24832533 // Modules requests - let the client calculate dependencies and batch requests as it likes
2484 - if ( $this->getModules() ) {
 2534+ // Only load modules that have marked themselves for loading at the bottom
 2535+ $modules = $this->getModules( true, 'bottom' );
 2536+ if ( $modules ) {
24852537 $scripts .= Html::inlineScript(
24862538 ResourceLoader::makeLoaderConditionalScript(
2487 - Xml::encodeJsCall( 'mediaWiki.loader.load', array( $this->getModules() ) ) .
 2539+ Xml::encodeJsCall( 'mediaWiki.loader.load', array( $modules ) ) .
 2540+ // the go() call is unnecessary if we inserted top modules, but we don't know for sure that we did
24882541 Xml::encodeJsCall( 'mediaWiki.loader.go', array() )
24892542 )
24902543 ) . "\n";
Property changes on: branches/wmf/1.17wmf1/includes/OutputPage.php
___________________________________________________________________
Modified: svn:mergeinfo
24912544 Merged /trunk/phase3/includes/OutputPage.php:r85616-85617
Index: branches/wmf/1.17wmf1/includes/resourceloader/ResourceLoaderFileModule.php
@@ -78,6 +78,8 @@
7979 protected $messages = array();
8080 /** String: Name of group to load this module in */
8181 protected $group;
 82+ /** String: Position on the page to load this module at */
 83+ protected $position = 'bottom';
8284 /** Boolean: Link to raw files in debug mode */
8385 protected $debugRaw = true;
8486 /**
@@ -137,6 +139,8 @@
138140 * 'messages' => [array of message key strings],
139141 * // Group which this module should be loaded together with
140142 * 'group' => [group name string],
 143+ * // Position on the page to load this module at
 144+ * 'position' => ['bottom' (default) or 'top']
141145 * )
142146 */
143147 public function __construct( $options = array(), $localBasePath = null,
@@ -187,6 +191,7 @@
188192 break;
189193 // Single strings
190194 case 'group':
 195+ case 'position':
191196 case 'localBasePath':
192197 case 'remoteBasePath':
193198 $this->{$member} = (string) $option;
@@ -293,6 +298,10 @@
294299 public function getGroup() {
295300 return $this->group;
296301 }
 302+
 303+ public function getPosition() {
 304+ return $this->position;
 305+ }
297306
298307 /**
299308 * Gets list of names of modules this module depends on.
Index: branches/wmf/1.17wmf1/includes/resourceloader/ResourceLoaderModule.php
@@ -107,6 +107,15 @@
108108 // Stub, override expected
109109 return null;
110110 }
 111+
 112+ /**
 113+ * Where on the HTML page should this module's JS be loaded?
 114+ * 'top': in the <head>
 115+ * 'bottom': at the bottom of the <body>
 116+ */
 117+ public function getPosition() {
 118+ return 'bottom';
 119+ }
111120
112121 /**
113122 * Get the loader JS for this module, if set.
Property changes on: branches/wmf/1.17wmf1/includes/resourceloader/ResourceLoaderModule.php
___________________________________________________________________
Modified: svn:mergeinfo
114123 Merged /trunk/phase3/includes/resourceloader/ResourceLoaderModule.php:r85616-85617
Index: branches/wmf/1.17wmf1/includes/Skin.php
@@ -928,7 +928,10 @@
929929 * @return String HTML-wrapped JS code to be put before </body>
930930 */
931931 function bottomScripts( $out ) {
932 - $bottomScriptText = "\n" . $out->getHeadScripts( $this );
 932+ // TODO and the suckage continues. This function is really just a wrapper around
 933+ // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
 934+ // up at some point
 935+ $bottomScriptText = $out->getBottomScripts( $this );
933936 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
934937
935938 return $bottomScriptText;
Property changes on: branches/wmf/1.17wmf1/includes/Skin.php
___________________________________________________________________
Modified: svn:mergeinfo
936939 Merged /trunk/phase3/includes/Skin.php:r85616-85617
Index: branches/wmf/1.17wmf1/resources/Resources.php
@@ -454,6 +454,7 @@
455455 'remoteBasePath' => $GLOBALS['wgStylePath'],
456456 'localBasePath' => "{$GLOBALS['IP']}/skins",
457457 'dependencies' => 'mediawiki.legacy.wikibits',
 458+ 'position' => 'top',
458459 ),
459460 'mediawiki.legacy.edit' => array(
460461 'scripts' => 'common/edit.js',
Property changes on: branches/wmf/1.17wmf1/resources/Resources.php
___________________________________________________________________
Modified: svn:mergeinfo
461462 Merged /trunk/phase3/resources/Resources.php:r85616-85617

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85616For bug 27488: move the startup script, jquery+mediawiki and the mw.config.se...catrope12:07, 7 April 2011
r85617Fix copypaste fail in r85616catrope13:14, 7 April 2011

Status & tagging log