( function( mw, $ ) {
	'use strict';

	function expandContribs() {
		var urlMatch = /Speciale:Contributi\/(.+?)(&|$)/.exec( window.location.href );
		if ( !urlMatch ) {
			return;
		}
		var target = urlMatch,
			button;
		if ( mw.util.isIPv6Address( target ) ) {
			button = new OO.ui.ButtonWidget( {
				label: 'Vai ai contributi del /64',
				flags: 
			} );
			button.on( 'click', function() {
				window.location.href = window.location.href.replace( target, target + '/64' );
			} );
			$( '.mw-contributions-user-tools' ).after( button.$element );
		}
	}
	
	function adjustBlock() {
		var $targetField = $( 'input' ),
			target = $targetField.val(),
			button;

		if ( mw.util.isIPv6Address( target ) ) {
			button = new OO.ui.ButtonWidget( {
				label: 'Inserisci il /64',
				flags: 
			} );
			button.on( 'click', function() {
				$targetField.val( target + '/64' );
			} );
			$( '#mw-htmlform-target' ).append( button.$element );
		}
	}

	$( function () {
		var cb;
		if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Block' ) {
			cb = adjustBlock;
		} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Contributions' ) {
			cb = expandContribs;
		}

		if ( cb ) {
			mw.loader.using( 'mediawiki.util' )
				.done( cb )
				.fail( function() { console.error( 'Impossibile avviare script IPv6' ); } );
		}
	} );
}( mediaWiki, jQuery ) );