User:Void/testing.js: Difference between revisions

From TestWiki
Content deleted Content added
further testing
upd current progress
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
// <nowiki>
/*
if( mw.config.get('wgPageName') === 'TestWiki:Request_permissions' ) {
* Simple script designed to mass undelete pages deleted by a user.
var headings = $('.mw-headline'), i = 0;
* You are responsible for any and all actions you take using this tool. PLEASE be careful.
for( ; i < headings.length; i++) {
*/
if(/Status: (Open|Done)/.test(headings[i].innerText)) {

headings[i].nextSibling.lastChild.id = 'edit-' + i;
//Add link
$('#edit-' + i).before('| <a id="resp-click-' + i + '">respond</a>');
var user = mw.config.get( 'wgRelevantUserName' );
}
if( user !== null ){
}
var unNuke = mw.util.addPortletLink(
'p-tb',
for( ; i >= 0; i--) {
attach('#resp-click-' + i, i);
'#',
}
'un-Nuke',
'pt-unnuke',
'Undelete all pages deleted by this user.'
);
}
}


$( unNuke ).click( function () {
function makeResponse(num) {
console.log(num);
$.getJSON(
//Get deletions
mw.util.wikiScript('api'),
{
format: 'json',
action: 'query',
list: 'logevents',
leprop: 'title',
leaction: 'delete/delete',
leuser: user,
lelimit: 500 //Going all out
}
).done( function ( data ) {
try {
var titles = [];
for( i = 0; i < data.query.logevents.length; i++ ) {
titles.push( data.query.logevents[i].title );
}
for( i = 0; i < titles.length; i++){
undelete( titles[i] );
}
}
catch ( e ) {
console.log( "Content request error: " + e.message );
console.log( "Content request response: " + JSON.stringify( data ) );
}
} ).fail( function () {
console.log( "While getting the userlist, there was an AJAX error." );
} );
});

function undelete( pageTitle ) {
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'undelete',
title: pageTitle,
reason: 'Mass undeletion of pages',
token: mw.user.tokens.get( 'csrfToken' ),
}
} ).done(console.log( "Undeleted page: " + pageTitle )
).fail( function ( e, data ){
console.log( e.message );
console.log( JSON.stringify( data ) );
});
}
}
function attach(id, num) {

$(id).click(function(){makeResponse(num)});
//Add link
if( user !== null ){
var unMove = mw.util.addPortletLink(
'p-tb',
'#',
'un-move',
'pt-un-move',
'Unmove all pages moved by this user.'
);
}
}


// </nowiki>
$( unMove ).click( function () {
$.getJSON(
//Get deletions
mw.util.wikiScript('api'),
{
format: 'json',
action: 'query',
list: 'logevents',
leprop: 'title|details',
leaction: 'move/move',
leuser: user,
lelimit: 500 //Going all out
}
).done( function ( data ) {
try {
var fromTitles = [];
var toTitles = [];
for( i = 0; i < data.query.logevents.length; i++ ) {
fromTitles.push( data.query.logevents[i].title );
toTitles.push( data.query.logevents[i].params.target_title );
}
for( i = 0; i < fromTitles.length; i++){
unmove( fromTitles[i], toTitles[i] );
}
}
catch ( e ) {
console.log( "Content request error: " + e.message );
console.log( "Content request response: " + JSON.stringify( data ) );
}
} ).fail( function () {
console.log( "While getting the userlist, there was an AJAX error." );
} );
});

function unmove( fromTitle, toTitle ) {
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'move',
title: fromTitle,
to: toTitle,
reason: 'Reverting page moves',
token: mw.user.tokens.get( 'csrfToken' ),
}
} ).done(console.log( "Moved page " + fromTitle + " to " + toTitle )
).fail( function ( e, data ){
console.log( e.message );
console.log( JSON.stringify( data ) );
});
}

Latest revision as of 23:11, 11 September 2017

// <nowiki>
if( mw.config.get('wgPageName') === 'TestWiki:Request_permissions' ) {
	var headings = $('.mw-headline'), i = 0;
	for( ; i < headings.length; i++) {
		if(/Status: (Open|Done)/.test(headings[i].innerText)) {
			headings[i].nextSibling.lastChild.id = 'edit-' + i;
			$('#edit-' + i).before('| <a id="resp-click-' + i + '">respond</a>');
		}
	}
	for( ; i >= 0; i--) {
		attach('#resp-click-' + i, i);
	}
}

function makeResponse(num) {
	console.log(num);
}
function attach(id, num) {
	$(id).click(function(){makeResponse(num)});
}

// </nowiki>