User:Void/testing.js: Difference between revisions
Content deleted Content added
update comment |
upd current progress |
||
(25 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 swap the titles of two pages. Does not seem to work, use at your own risk! |
|||
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 roundRobin = mw.util.addPortletLink( |
|||
} |
|||
'p-cactions', |
|||
} |
|||
'#', |
|||
for( ; i >= 0; i--) { |
|||
'roundRobin', |
|||
attach('#resp-click-' + i, i); |
|||
'pt-roundrobin', |
|||
'Swap the page titles of the current page and another.', |
|||
null |
|||
); |
|||
$( roundRobin ).click( function () { |
|||
var newTitle = prompt("What is the title of the other page?"); |
|||
var curTitle = mw.config.get("wgPageName"); |
|||
var moveReason = prompt("Why is this move being done?"); |
|||
var goAhead = confirm( "Move " + curTitle + " to " + newTitle + ", with reason " + moveReason + "?" ); |
|||
if (goAhead){ |
|||
robinMove( newTitle, curTitle, moveReason ); |
|||
} |
} |
||
}); |
|||
function robinMove ( newTitle, curTitle, moveReason ) { |
|||
var robinReason = moveReason + "; moving page " + curTitle + " to existing page " + newTitle + " (see [[WP:SWAP]])"; |
|||
var useTitle = newTitle + "/temp"; |
|||
movePage ( newTitle, useTitle, robinReason ); |
|||
movePage ( curTitle, newTitle, robinReason ); |
|||
movePage ( useTitle, curTitle, robinReason ); |
|||
alert("Page move completed, please be sure to update any relevant information."); |
|||
} |
} |
||
function makeResponse(num) { |
|||
function movePage ( curTitle, newTitle, moveReason ){ |
|||
⚫ | |||
$.ajax( { |
|||
url: mw.util.wikiScript( 'api' ), |
|||
type: 'POST', |
|||
dataType: 'json', |
|||
data: { |
|||
format: 'json', |
|||
action: 'move', |
|||
from: curTitle, |
|||
to: newTitle, |
|||
reason: moveReason, |
|||
movetalk: 1, |
|||
noredirect: 1, |
|||
token: mw.user.tokens.get( 'csrfToken' ), |
|||
} |
|||
} ).done(console.log( "Moved page " + curTitle + " to location " + newTitle ) |
|||
).fail( function ( e, data ){ |
|||
⚫ | |||
console.log( JSON.stringify( data ) ); |
|||
}); |
|||
} |
} |
||
function attach(id, num) { |
|||
$(id).click(function(){makeResponse(num)}); |
|||
} |
|||
// </nowiki> |
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>