resources: Merge dblClickEdit and rightClickEdit JS code

Both are rare preferences that are off by default and have no active steward.

They are small enough that it isn't worth creating and registering public bundle
for on all page views for all users. Instead, combine them into a single module.

Bug: T233676
Change-Id: I21a492ad8b6005c1bd9257599cd19b594fc3d263
This commit is contained in:
Timo Tijhof 2019-11-05 16:22:13 -05:00
parent 1876680167
commit c656980498
5 changed files with 51 additions and 46 deletions

View file

@ -238,23 +238,18 @@ abstract class Skin extends ContextSource {
$modules['styles']['content'][] = 'mediawiki.toc.styles';
}
// Add various resources if required
$prefMgr = MediaWikiServices::getInstance()->getPermissionManager();
if ( $user->isLoggedIn()
&& MediaWikiServices::getInstance()
->getPermissionManager()
->userHasAllRights( $user, 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
&& $prefMgr->userHasAllRights( $user, 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
&& $this->getRelevantTitle()->canExist()
) {
$modules['watch'][] = 'mediawiki.page.watch.ajax';
}
if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
$modules['user'][] = 'mediawiki.action.view.rightClickEdit';
}
// Crazy edit-on-double-click stuff
if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
$modules['user'][] = 'mediawiki.action.view.dblClickEdit';
if ( $user->getBoolOption( 'editsectiononrightclick' )
|| ( $out->isArticle() && $user->getOption( 'editondblclick' ) )
) {
$modules['user'][] = 'mediawiki.misc-authed-pref';
}
if ( $out->isSyndicated() ) {

View file

@ -1313,13 +1313,6 @@ return [
],
'targets' => [ 'desktop', 'mobile' ],
],
'mediawiki.action.view.dblClickEdit' => [
'scripts' => 'resources/src/mediawiki.action/mediawiki.action.view.dblClickEdit.js',
'dependencies' => [
'mediawiki.util',
'user.options',
],
],
'mediawiki.action.view.metadata' => [
'styles' => 'resources/src/mediawiki.action/mediawiki.action.view.metadata.css',
'scripts' => 'resources/src/mediawiki.action/mediawiki.action.view.metadata.js',
@ -1359,9 +1352,6 @@ return [
'targets' => [ 'desktop', 'mobile' ],
'styles' => 'resources/src/mediawiki.action/mediawiki.action.view.redirectPage.css',
],
'mediawiki.action.view.rightClickEdit' => [
'scripts' => 'resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js',
],
'mediawiki.action.edit.editWarning' => [
'targets' => [ 'desktop', 'mobile' ],
'scripts' => 'resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js',
@ -2018,8 +2008,8 @@ return [
'targets' => [ 'desktop', 'mobile' ],
],
// This bundles various small (under 5 KB?) JavaScript files that:
// - .. are not loaded on when viewing or editing wiki pages.
// - .. are used by logged-in users only.
// - .. are never loaded when viewing or editing wiki pages.
// - .. are only used by logged-in users.
// - .. depend on oojs-ui-core.
// - .. contain UI intialisation code (e.g. no public module exports, because
// requiring or depending on this bundle is awkard)
@ -2041,6 +2031,22 @@ return [
],
'targets' => [ 'desktop', 'mobile' ],
],
// This bundles various small (under 2 KB?) JavaScript files that:
// - .. are only used by logged-in users when a non-default preference was enabled.
// - .. may be loaded in the critical path for those users on page views.
// - .. do NOT depend on OOUI.
// - .. contain only UI intialisation code (e.g. no public exports)
'mediawiki.misc-authed-pref' => [
'localBasePath' => "$IP/resources/src/mediawiki.misc-authed-pref",
'remoteBasePath' => "$wgResourceBasePath/resources/src/mediawiki.misc-authed-pref",
'scripts' => [
'rightClickEdit.js',
'dblClickEdit.js',
],
'dependencies' => [
'user.options',
],
],
'mediawiki.special.changeslist' => [
'styles' => [
'resources/src/mediawiki.special.changeslist/changeslist.less'

View file

@ -1,20 +0,0 @@
/*!
* Enables double-click-to-edit functionality.
*/
( function () {
$( function () {
mw.util.$content.on( 'dblclick', function ( e ) {
var $a;
// Recheck preference so extensions can do a hack to disable this code.
if ( parseInt( mw.user.options.get( 'editondblclick' ), 10 ) ) {
// Trigger native HTMLElement click instead of opening URL (T45052)
$a = $( '#ca-edit a' );
// Not every page has an edit link (T59713)
if ( $a.length ) {
e.preventDefault();
$a.get( 0 ).click();
}
}
} );
} );
}() );

View file

@ -0,0 +1,19 @@
/*!
* Enable double-click-to-edit functionality.
*/
( function () {
if ( !parseInt( mw.user.options.get( 'editondblclick' ), 10 ) ) {
return;
}
$( function () {
$( '#mw-content-text' ).on( 'dblclick', function ( e ) {
// Trigger native HTMLElement click instead of opening URL (T45052)
var $a = $( '#ca-edit a' );
// Not every page has an edit link (T59713)
if ( $a.length ) {
e.preventDefault();
$a.get( 0 ).click();
}
} );
} );
}() );

View file

@ -1,9 +1,14 @@
/*!
* JavaScript to enable right click edit functionality.
* When the user right-clicks in a heading, it will open the
* edit screen.
* Enable right-click-to-edit functionality.
*
* When the user right-clicks in a content heading, it will open the
* edit section link.
*/
( function () {
if ( !parseInt( mw.user.options.get( 'editsectiononrightclick' ), 10 ) ) {
return;
}
// Trigger this when a contextmenu click on the page targets an h1-h6 element.
// This uses a delegate handler which 1) starts immediately instead of blocking
// response on dom-ready, and 2) selects and binds once instead of N times.