Fix a race condition in classic edit toolbar setup
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 6 Jan 2012 01:38:26 +0000 (01:38 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 6 Jan 2012 01:38:26 +0000 (01:38 +0000)
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.

includes/EditPage.php
resources/mediawiki.action/mediawiki.action.edit.js

index 487f2e8..eee290a 100644 (file)
@@ -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 = '<div id="toolbar"></div>';
index 497a424..06fe100 100644 (file)
@@ -82,9 +82,6 @@
                };
                scrollEditBox();
 
-               // Create button bar
-               mw.toolbar.init();
-
                $( 'textarea, input:text' ).focus( function() {
                        currentFocused = $(this);
                });