EditPage: Optimise loading of mediawiki.toolbar module
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 19 Dec 2014 04:39:33 +0000 (04:39 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 19 Dec 2014 22:53:49 +0000 (22:53 +0000)
Follows-up b3830611c4.

Unlike getEditToolbar(), which only runs if the user preference
is enabled, the loading of mediawiki.action.edit is unconditional.

As mediawiki.toolbar has already been separated from mediawiki.action.edit,
it's easy to load it conditionally instead of via a dependency
(mediawiki.action.edit doesn't depend on it for anything else).

Also:
* Remove odd 'false' values passed to User::getOption(). These
  options are part of MediaWiki core and always exist. The default
  value 'false' was ignored.
* Remove redundant closure. The domready callback already provides
  a closure and 'mw' is not used here (similar to jquery.mw-jump).

Change-Id: Ib2f4633b328cf8090df43b8d286cfcd77f95c5ea

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

index c737920..7f5a9c0 100644 (file)
@@ -2118,11 +2118,19 @@ class EditPage {
                $wgOut->addModules( 'mediawiki.action.edit' );
                $wgOut->addModuleStyles( 'mediawiki.action.edit.styles' );
 
-               if ( $wgUser->getOption( 'uselivepreview', false ) ) {
+               if ( $wgUser->getOption( 'showtoolbar' ) ) {
+                       // The addition of default buttons is handled by getEditToolbar() which
+                       // has its own dependency on this module. The call here ensures the module
+                       // is loaded in time (it has position "top") for other modules to register
+                       // buttons (e.g. extensions, gadgets, user scripts).
+                       $wgOut->addModules( 'mediawiki.toolbar' );
+               }
+
+               if ( $wgUser->getOption( 'uselivepreview' ) ) {
                        $wgOut->addModules( 'mediawiki.action.edit.preview' );
                }
 
-               if ( $wgUser->getOption( 'useeditwarning', false ) ) {
+               if ( $wgUser->getOption( 'useeditwarning' ) ) {
                        $wgOut->addModules( 'mediawiki.action.edit.editWarning' );
                }
 
index e5332df..ccb842d 100644 (file)
@@ -1011,6 +1011,7 @@ return array(
                'class' => 'ResourceLoaderEditToolbarModule',
                'scripts' => 'resources/src/mediawiki.toolbar/toolbar.js',
                'styles' => 'resources/src/mediawiki.toolbar/toolbar.less',
+               'position' => 'top',
        ),
 
        /* MediaWiki Action */
@@ -1020,7 +1021,6 @@ return array(
                'styles' => 'resources/src/mediawiki.action/mediawiki.action.edit.css',
                'dependencies' => array(
                        'mediawiki.action.edit.styles',
-                       'mediawiki.toolbar',
                        'jquery.textSelection',
                        'jquery.byteLimit',
                ),
index f88b836..01a25f3 100644 (file)
@@ -1,27 +1,23 @@
 /*!
- * Scripts for action=edit
+ * Scripts for action=edit at domready
  */
-( function ( mw, $ ) {
+jQuery( function ( $ ) {
+       var editBox, scrollTop, $editForm;
 
-       $( function () {
-               var editBox, scrollTop, $editForm;
+       // Make sure edit summary does not exceed byte limit
+       $( '#wpSummary' ).byteLimit( 255 );
 
-               // Make sure edit summary does not exceed byte limit
-               $( '#wpSummary' ).byteLimit( 255 );
-
-               // Restore the edit box scroll state following a preview operation,
-               // and set up a form submission handler to remember this state.
-               editBox = document.getElementById( 'wpTextbox1' );
-               scrollTop = document.getElementById( 'wpScrolltop' );
-               $editForm = $( '#editform' );
-               if ( $editForm.length && editBox && scrollTop ) {
-                       if ( scrollTop.value ) {
-                               editBox.scrollTop = scrollTop.value;
-                       }
-                       $editForm.submit( function () {
-                               scrollTop.value = editBox.scrollTop;
-                       } );
+       // Restore the edit box scroll state following a preview operation,
+       // and set up a form submission handler to remember this state.
+       editBox = document.getElementById( 'wpTextbox1' );
+       scrollTop = document.getElementById( 'wpScrolltop' );
+       $editForm = $( '#editform' );
+       if ( $editForm.length && editBox && scrollTop ) {
+               if ( scrollTop.value ) {
+                       editBox.scrollTop = scrollTop.value;
                }
-       } );
-
-}( mediaWiki, jQuery ) );
+               $editForm.submit( function () {
+                       scrollTop.value = editBox.scrollTop;
+               } );
+       }
+} );