Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Alexander Monk, 2014-08-05
function buildGBlockForm () {
var $durationInput = $( '<input>' )
.attr( 'name', 'gblockDuration' )
.attr( 'id', 'gblockDuration' )
.attr( 'type', 'text' ),
$reasonInput = $( '<input>' )
.attr( 'name', 'gblockReason' )
.attr( 'id', 'gblockReason' )
.attr( 'type', 'text' ),
$form = $( '<form>' )
.css( 'font-size', '10pt' )
.append(
$( '<legend>' ).text( 'GBlock data' ),
$( '<table>' ).append(
$( '<tr>' ).append(
$( '<td>' ).text( 'Duration:' ),
$( '<td>' ).append( $durationInput )
),
$( '<tr>' ).append(
$( '<td>' ).text( 'Reason:' ),
$( '<td>' ).append( $reasonInput )
),
$( '<tr>' ).append(
$( '<td>' ).append(
$( '<input>' )
.attr( 'type', 'submit' )
)
)
)
);
$form.submit( function () {
var text = "\{\{subst:User:Rjd0060/blocknotice\|" +
$reasonInput.val() + "\|" +
$durationInput.val() + "\}\}";
 
mw.loader.using( 'mediawiki.api.edit', function () {
new mw.Api().postWithEditToken( {
action: 'edit',
minor: 'true',
title: mw.config.get( 'wgPageName' ),
appendtext: text,
summary: "You have been blocked from editing."
} ).done( function () {
window.location.reload();
} ).fail( function ( code, result ) {
$( '#contentSub' ).html( "Failure!<br>" + code + "<br>" + result );
} );
} );
 
return false;
} );
$( '#contentSub' ).html( $form );
};
$( function () {
if ( mw.config.get( 'wgNamespaceNumber' ) == 3 ) {
mw.util.addPortletLink( 'p-tb', 'javascript:buildGBlockForm()', 'GBlock', 't-gblock' );
}
} );