From: Timo Tijhof Date: Fri, 14 Jun 2019 17:30:28 +0000 (+0100) Subject: specials: Combine small miscellaneous 'mediawiki.special.*' modules X-Git-Tag: 1.34.0-rc.0~1212 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=419849211e3a638884f13d9a7a7f43b898d1d2a4;p=lhc%2Fweb%2Fwiklou.git specials: Combine small miscellaneous 'mediawiki.special.*' modules The format for this would be cleaner if T225842 were solved. Bug: T193826 Bug: T219342 Change-Id: I9aaa52b567db254e1e79649b3b99260214da74b3 --- diff --git a/includes/specials/SpecialChangeCredentials.php b/includes/specials/SpecialChangeCredentials.php index 1d0ff21cf2..f899d76a35 100644 --- a/includes/specials/SpecialChangeCredentials.php +++ b/includes/specials/SpecialChangeCredentials.php @@ -141,9 +141,7 @@ class SpecialChangeCredentials extends AuthManagerSpecialPage { } if ( $any ) { - $this->getOutput()->addModules( [ - 'mediawiki.special.changecredentials.js' - ] ); + $this->getOutput()->addModules( 'mediawiki.misc-authed-ooui' ); } return $descriptor; diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 252df5be09..ecbbc25bca 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -147,7 +147,7 @@ class MovePageForm extends UnlistedSpecialPage { $out = $this->getOutput(); $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) ); $out->addModuleStyles( 'mediawiki.special' ); - $out->addModules( 'mediawiki.special.movePage' ); + $out->addModules( 'mediawiki.misc-authed-ooui' ); $this->addHelpLink( 'Help:Moving a page' ); $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ? diff --git a/includes/specials/SpecialPageLanguage.php b/includes/specials/SpecialPageLanguage.php index 7e41305bb1..c0f004ffa6 100644 --- a/includes/specials/SpecialPageLanguage.php +++ b/includes/specials/SpecialPageLanguage.php @@ -43,7 +43,7 @@ class SpecialPageLanguage extends FormSpecialPage { } protected function preText() { - $this->getOutput()->addModules( 'mediawiki.special.pageLanguage' ); + $this->getOutput()->addModules( 'mediawiki.misc-authed-ooui' ); return parent::preText(); } diff --git a/resources/Resources.php b/resources/Resources.php index 28b8793f3e..92b4fd4492 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -2092,11 +2092,27 @@ return [ ], 'targets' => [ 'desktop', 'mobile' ], ], - 'mediawiki.special.changecredentials.js' => [ - 'scripts' => 'resources/src/mediawiki.special.changecredentials.js', + // 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. + // - .. depend on oojs-ui-core. + // - .. contain UI intialisation code (e.g. no public module exports, because + // requiring or depending on this bundle is awkard) + 'mediawiki.misc-authed-ooui' => [ + 'localBasePath' => "$IP/resources/src/mediawiki.misc-authed-ooui", + 'remoteBasePath' => "$wgResourceBasePath/resources/src/mediawiki.misc-authed-ooui", + 'scripts' => [ + 'special.changecredentials.js', + 'special.movePage.js', + 'special.mute.js', + 'special.pageLanguage.js', + ], 'dependencies' => [ - 'mediawiki.api', - 'mediawiki.htmlform.ooui' + 'mediawiki.api', // Used by special.changecredentials.js + 'mediawiki.htmlform.ooui', // Used by special.changecredentials.js + 'mediawiki.widgets.visibleLengthLimit', // Used by special.movePage.js + 'mediawiki.widgets', // Used by special.movePage.js + 'oojs-ui-core', // Used by special.pageLanguage.js ], 'targets' => [ 'desktop', 'mobile' ], ], @@ -2145,22 +2161,6 @@ return [ 'mediawiki.special.import' => [ 'scripts' => 'resources/src/mediawiki.special.import.js', ], - 'mediawiki.special.movePage' => [ - 'scripts' => 'resources/src/mediawiki.special.movePage.js', - 'dependencies' => [ - 'mediawiki.widgets.visibleLengthLimit', - 'mediawiki.widgets', - ], - ], - 'mediawiki.special.pageLanguage' => [ - 'scripts' => [ - 'resources/src/mediawiki.special.mute.js', - 'resources/src/mediawiki.special.pageLanguage.js' - ], - 'dependencies' => [ - 'oojs-ui-core', - ], - ], 'mediawiki.special.preferences.ooui' => [ 'targets' => [ 'desktop', 'mobile' ], 'scripts' => [ diff --git a/resources/src/mediawiki.misc-authed-ooui/special.changecredentials.js b/resources/src/mediawiki.misc-authed-ooui/special.changecredentials.js new file mode 100644 index 0000000000..36ad252441 --- /dev/null +++ b/resources/src/mediawiki.misc-authed-ooui/special.changecredentials.js @@ -0,0 +1,55 @@ +/*! + * JavaScript for change credentials form. + */ +( function () { + mw.hook( 'htmlform.enhance' ).add( function ( $root ) { + var api = new mw.Api(); + + $root.find( '.mw-changecredentials-validate-password.oo-ui-fieldLayout' ).each( function () { + var currentApiPromise, + self = OO.ui.FieldLayout.static.infuse( $( this ) ); + + self.getField().setValidation( function ( password ) { + var d; + + if ( currentApiPromise ) { + currentApiPromise.abort(); + currentApiPromise = undefined; + } + + password = password.trim(); + + if ( password === '' ) { + self.setErrors( [] ); + return true; + } + + d = $.Deferred(); + currentApiPromise = api.post( { + action: 'validatepassword', + password: password, + formatversion: 2, + errorformat: 'html', + errorsuselocal: true, + uselang: mw.config.get( 'wgUserLanguage' ) + } ).done( function ( resp ) { + var pwinfo = resp.validatepassword, + good = pwinfo.validity === 'Good', + errors = []; + + currentApiPromise = undefined; + + if ( !good ) { + pwinfo.validitymessages.map( function ( m ) { + errors.push( new OO.ui.HtmlSnippet( m.html ) ); + } ); + } + self.setErrors( errors ); + d.resolve( good ); + } ).fail( d.reject ); + + return d.promise( { abort: currentApiPromise.abort } ); + } ); + } ); + } ); +}() ); diff --git a/resources/src/mediawiki.misc-authed-ooui/special.movePage.js b/resources/src/mediawiki.misc-authed-ooui/special.movePage.js new file mode 100644 index 0000000000..8004a44bae --- /dev/null +++ b/resources/src/mediawiki.misc-authed-ooui/special.movePage.js @@ -0,0 +1,19 @@ +/*! + * JavaScript for Special:MovePage + */ +( function () { + $( function () { + var summaryCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' ), + summaryByteLimit = mw.config.get( 'wgCommentByteLimit' ), + wpReason = OO.ui.infuse( $( '#wpReason' ) ); + + // Infuse for pretty dropdown + OO.ui.infuse( $( '#wpNewTitle' ) ); + // Limit to bytes or UTF-8 codepoints, depending on MediaWiki's configuration + if ( summaryCodePointLimit ) { + mw.widgets.visibleCodePointLimit( wpReason, summaryCodePointLimit ); + } else if ( summaryByteLimit ) { + mw.widgets.visibleByteLimit( wpReason, summaryByteLimit ); + } + } ); +}() ); diff --git a/resources/src/mediawiki.misc-authed-ooui/special.mute.js b/resources/src/mediawiki.misc-authed-ooui/special.mute.js new file mode 100644 index 0000000000..b9dcc21ab5 --- /dev/null +++ b/resources/src/mediawiki.misc-authed-ooui/special.mute.js @@ -0,0 +1,23 @@ +( function () { + 'use strict'; + + $( function () { + var $inputs = $( '#mw-specialmute-form input[type="checkbox"]' ), + saveButton, $saveButton = $( '#save' ); + + function isFormChanged() { + return $inputs.is( function () { + return this.checked !== this.defaultChecked; + } ); + } + + if ( $saveButton.length ) { + saveButton = OO.ui.infuse( $saveButton ); + saveButton.setDisabled( !isFormChanged() ); + + $inputs.on( 'change', function () { + saveButton.setDisabled( !isFormChanged() ); + } ); + } + } ); +}() ); diff --git a/resources/src/mediawiki.misc-authed-ooui/special.pageLanguage.js b/resources/src/mediawiki.misc-authed-ooui/special.pageLanguage.js new file mode 100644 index 0000000000..8538e955b5 --- /dev/null +++ b/resources/src/mediawiki.misc-authed-ooui/special.pageLanguage.js @@ -0,0 +1,13 @@ +/*! + * JavaScript module used on Special:PageLanguage + */ +( function () { + $( function () { + // Select the 'Language select' option if user is trying to select language + if ( $( '#mw-pl-languageselector' ).length ) { + OO.ui.infuse( $( '#mw-pl-languageselector' ) ).on( 'change', function () { + OO.ui.infuse( $( '#mw-pl-options' ) ).setValue( '2' ); + } ); + } + } ); +}() ); diff --git a/resources/src/mediawiki.special.changecredentials.js b/resources/src/mediawiki.special.changecredentials.js deleted file mode 100644 index 36ad252441..0000000000 --- a/resources/src/mediawiki.special.changecredentials.js +++ /dev/null @@ -1,55 +0,0 @@ -/*! - * JavaScript for change credentials form. - */ -( function () { - mw.hook( 'htmlform.enhance' ).add( function ( $root ) { - var api = new mw.Api(); - - $root.find( '.mw-changecredentials-validate-password.oo-ui-fieldLayout' ).each( function () { - var currentApiPromise, - self = OO.ui.FieldLayout.static.infuse( $( this ) ); - - self.getField().setValidation( function ( password ) { - var d; - - if ( currentApiPromise ) { - currentApiPromise.abort(); - currentApiPromise = undefined; - } - - password = password.trim(); - - if ( password === '' ) { - self.setErrors( [] ); - return true; - } - - d = $.Deferred(); - currentApiPromise = api.post( { - action: 'validatepassword', - password: password, - formatversion: 2, - errorformat: 'html', - errorsuselocal: true, - uselang: mw.config.get( 'wgUserLanguage' ) - } ).done( function ( resp ) { - var pwinfo = resp.validatepassword, - good = pwinfo.validity === 'Good', - errors = []; - - currentApiPromise = undefined; - - if ( !good ) { - pwinfo.validitymessages.map( function ( m ) { - errors.push( new OO.ui.HtmlSnippet( m.html ) ); - } ); - } - self.setErrors( errors ); - d.resolve( good ); - } ).fail( d.reject ); - - return d.promise( { abort: currentApiPromise.abort } ); - } ); - } ); - } ); -}() ); diff --git a/resources/src/mediawiki.special.movePage.js b/resources/src/mediawiki.special.movePage.js deleted file mode 100644 index 8004a44bae..0000000000 --- a/resources/src/mediawiki.special.movePage.js +++ /dev/null @@ -1,19 +0,0 @@ -/*! - * JavaScript for Special:MovePage - */ -( function () { - $( function () { - var summaryCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' ), - summaryByteLimit = mw.config.get( 'wgCommentByteLimit' ), - wpReason = OO.ui.infuse( $( '#wpReason' ) ); - - // Infuse for pretty dropdown - OO.ui.infuse( $( '#wpNewTitle' ) ); - // Limit to bytes or UTF-8 codepoints, depending on MediaWiki's configuration - if ( summaryCodePointLimit ) { - mw.widgets.visibleCodePointLimit( wpReason, summaryCodePointLimit ); - } else if ( summaryByteLimit ) { - mw.widgets.visibleByteLimit( wpReason, summaryByteLimit ); - } - } ); -}() ); diff --git a/resources/src/mediawiki.special.mute.js b/resources/src/mediawiki.special.mute.js deleted file mode 100644 index b9dcc21ab5..0000000000 --- a/resources/src/mediawiki.special.mute.js +++ /dev/null @@ -1,23 +0,0 @@ -( function () { - 'use strict'; - - $( function () { - var $inputs = $( '#mw-specialmute-form input[type="checkbox"]' ), - saveButton, $saveButton = $( '#save' ); - - function isFormChanged() { - return $inputs.is( function () { - return this.checked !== this.defaultChecked; - } ); - } - - if ( $saveButton.length ) { - saveButton = OO.ui.infuse( $saveButton ); - saveButton.setDisabled( !isFormChanged() ); - - $inputs.on( 'change', function () { - saveButton.setDisabled( !isFormChanged() ); - } ); - } - } ); -}() ); diff --git a/resources/src/mediawiki.special.pageLanguage.js b/resources/src/mediawiki.special.pageLanguage.js deleted file mode 100644 index 8538e955b5..0000000000 --- a/resources/src/mediawiki.special.pageLanguage.js +++ /dev/null @@ -1,13 +0,0 @@ -/*! - * JavaScript module used on Special:PageLanguage - */ -( function () { - $( function () { - // Select the 'Language select' option if user is trying to select language - if ( $( '#mw-pl-languageselector' ).length ) { - OO.ui.infuse( $( '#mw-pl-languageselector' ) ).on( 'change', function () { - OO.ui.infuse( $( '#mw-pl-options' ) ).setValue( '2' ); - } ); - } - } ); -}() );