// Core taken from [[WP:US/G]]
// the line "text: info.text," will cause the call
// to replace entire page content with supplied data.
// alternatively, one can append or prepend the data to the page, by using
// "appendtext: info.text," or "prependtext: info.text," instead.
// when using "appendtext", it is possible to append the text to a specific section,
// by setting the optional field "section".
function editPageToAddLinks( info ) {
$.ajax({
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'edit',
title: info.title,
appendtext: info.text,
summary: info.summary,
token: mw.user.tokens.get( 'csrfToken' )
}
})
.then (function( data ) {
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
mw.notify('Added.' );
} else
{
alert('There was an error requesting the page edit. Code: ' + data);
}
}).fail(function(data) {
alert('There was an error using AJAX to edit the page. Error: ' + data);
});
}
// Make sure the utilities module is loaded (will only load if not already)
mw.loader.using( 'mediawiki.util', function () {
// Wait for the page to be parsed
$( document ).ready( function () {
// 'More' tab in vector skin
var link = mw.util.addPortletLink( 'p-cactions', '#', 'Add to list', 'ca-addtolist', 'Add the current page to User:Qwerfjkl/pages');
$( link ).click( function ( event ) {
event.preventDefault();
editPageToAddLinks({
title: 'User:Qwerfjkl/pages',
text: '\n* [['+mw.config.get('wgPageName').replace(/_/g, ' ')+']]',
summary: '+1'
});
} );
} );
} );