From: Brion Vibber Date: Fri, 6 Jan 2012 01:38:26 +0000 (+0000) Subject: Fix a race condition in classic edit toolbar setup X-Git-Tag: 1.31.0-rc.0~25494 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=749ebf43165b406cfee840632ac79418d637be6e;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/EditPage.php b/includes/EditPage.php index 487f2e885f..eee290a13f 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2671,7 +2671,7 @@ HTML ) ); - $script = ''; + $script = 'mw.loader.using("mediawiki.action.edit", function() {'; foreach ( $toolarray as $tool ) { if ( !$tool ) { continue; @@ -2692,6 +2692,14 @@ HTML $script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params ); } + + // This used to be called on DOMReady from mediawiki.action.edit, which + // ended up causing race conditions with the setup code above. + $script .= "\n" . + "// Create button bar\n" . + "$(function() { mw.toolbar.init(); } );\n"; + + $script .= '});'; $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) ); $toolbar = '
'; diff --git a/resources/mediawiki.action/mediawiki.action.edit.js b/resources/mediawiki.action/mediawiki.action.edit.js index 497a424826..06fe100694 100644 --- a/resources/mediawiki.action/mediawiki.action.edit.js +++ b/resources/mediawiki.action/mediawiki.action.edit.js @@ -82,9 +82,6 @@ }; scrollEditBox(); - // Create button bar - mw.toolbar.init(); - $( 'textarea, input:text' ).focus( function() { currentFocused = $(this); });