User:Ricordisamoa/TemplateLangUpdate.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/* <nowiki>
 * TemplateLangUpdate.js
 * adds a link to automatically update template langlinks with {{subst:lle}}
 * @author [[User:Ricordisamoa]]
*/
/* global $, mw */
$( function () {
	'use strict';

	if ( mw.config.get( 'wgNamespaceNumber' ) === 10 ) {
		$( mw.util.addPortletLink( 'p-cactions', '#', 'Update langlinks', 'TemplateLangUpdate', 'Automatically update template langlinks with {{subst:lle}}' ) )
		.click( function ( event ) {
			event.preventDefault();
			new mw.Api().postWithToken( 'csrf', {
				action: 'edit',
				text: '{{subst:lle}}',
				title: mw.config.get( 'wgPageName' ).split( '/' )[ 0 ] + '/lang',
				summary: '[[User:Ricordisamoa/TemplateLangUpdate|TemplateLangUpdate]]: updating language links with {{[[Template:Lle|subst:lle]]}}',
				minor: 1
			} )
			.done( function ( data ) {
				if ( data && data.edit && data.edit.result && data.edit.result === 'Success' ) {
					mw.notify( 'Translations updated!' );
				} else {
					mw.notify( 'The edit query returned an error.' );
				}
			} )
			.fail( function () {
				mw.notify( 'The ajax request failed.' );
			} );
		} );
	}
} );
// </nowiki>