From: Timo Tijhof Date: Fri, 19 Dec 2014 04:39:33 +0000 (+0000) Subject: EditPage: Optimise loading of mediawiki.toolbar module X-Git-Tag: 1.31.0-rc.0~12894^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/wiki/supprimer.php?a=commitdiff_plain;h=1dd14dcec0dfb69a8e9763b380e2b151e0da9634;p=lhc%2Fweb%2Fwiklou.git EditPage: Optimise loading of mediawiki.toolbar module 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 --- diff --git a/includes/EditPage.php b/includes/EditPage.php index c73792066f..7f5a9c0463 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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' ); } diff --git a/resources/Resources.php b/resources/Resources.php index e5332df734..ccb842ded6 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -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', ), diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.js b/resources/src/mediawiki.action/mediawiki.action.edit.js index f88b83667d..01a25f3b85 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.js @@ -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; + } ); + } +} );