r108191 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108190‎ | r108191 | r108192 >
Date:01:38, 6 January 2012
Author:brion
Status:ok
Tags:
Comment:
Fix a race condition in classic edit toolbar setup

mediawiki.action.edit used to call mw.toolbar.init on its own during DOMReady -- this required that the module already be loaded *before* DOMReady, *and* that it be fully loaded before the immedate-execution code that sets up the default toolbar items (output from EditPage.php).
This failed since we've gone fully async in the bottom-loading items, and could result in failed calls to mw.toolbar.addButton.

Wrapped those immediate calls in a mediawiki.loader.using call to ensure they're run after the module is loaded, and moved the mw.toolbar.init call into that section so we guarantee it gets run first.
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -2671,7 +2671,7 @@
26722672 )
26732673 );
26742674
2675 - $script = '';
 2675+ $script = 'mw.loader.using("mediawiki.action.edit", function() {';
26762676 foreach ( $toolarray as $tool ) {
26772677 if ( !$tool ) {
26782678 continue;
@@ -2692,6 +2692,14 @@
26932693
26942694 $script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params );
26952695 }
 2696+
 2697+ // This used to be called on DOMReady from mediawiki.action.edit, which
 2698+ // ended up causing race conditions with the setup code above.
 2699+ $script .= "\n" .
 2700+ "// Create button bar\n" .
 2701+ "$(function() { mw.toolbar.init(); } );\n";
 2702+
 2703+ $script .= '});';
26962704 $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
26972705
26982706 $toolbar = '<div id="toolbar"></div>';
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js
@@ -82,9 +82,6 @@
8383 };
8484 scrollEditBox();
8585
86 - // Create button bar
87 - mw.toolbar.init();
88 -
8986 $( 'textarea, input:text' ).focus( function() {
9087 currentFocused = $(this);
9188 });

Status & tagging log