summaryrefslogtreecommitdiff
blob: 8050d8152def508c7b65fa86bbe9479f194ab043 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Enhance Special:CheckUser's block form with a link to CentralAuth's
 * Special:MultiLock (if installed)
 */
( function () {
	var $userCheckboxes,
		centralURL = mw.config.get( 'wgCUCAMultiLockCentral' );

	if ( !centralURL ) {
		// Ignore. Either this isn't a block form, or CentralAuth isn't setup.
		return;
	}

	// Initialize the link
	$( '#checkuserblock fieldset' ).append(
		$( '<a>' ).attr( {
			id: 'cacu-multilock-link',
			href: centralURL
		} ).text( mw.msg( 'checkuser-centralauth-multilock' ) )
	);

	// Change the URL of the link when a checkbox's state is changed
	$userCheckboxes = $( '#checkuserresults li [type=checkbox]' );
	$userCheckboxes.on( 'change', function () {
		var names = [];
		$userCheckboxes.serializeArray().forEach( function ( obj ) {
			if ( obj.name && obj.name === 'users[]' ) {
				// Only registered accounts (not IPs) can be locked
				if ( !mw.util.isIPAddress( obj.value ) ) {
					names.push( obj.value );
				}
			}
		} );

		// Update the href of the link with the latest change
		$( '#cacu-multilock-link' ).prop(
			'href',
			centralURL + '?wpTarget=' + encodeURIComponent( names.join( '\n' ) )
		);
	} );

}() );