User:Writ Keeper/Scripts/peerReviewCloser.js: Difference between revisions

Content deleted Content added
caps
test
Line 1:
function closePeerReview()
{
mw.loader.using("mediawiki.api").done( function ()
{
$("#ca-closepeer>a").text("Closing...");
Line 7:
var talkPage = $("a:contains('Article talk')").attr("href");
var talkPageName = "";
if (talkPage != null)
{
talkPage = talkPage.match(/\/wiki\/(\w+:.+)/);
if (talkPage != null)
{
talkPageName = talkPage[1];
Line 16:
}
var api = new mw.Api();
 
api.edit(talkPageNamemw.config.get("wgPageName"), function (revision)
{
var regexResult = revision.content.match(/\{\{ *Peer review *(\| *archive *= *\d+) *\}\}/);
if(var regexResult != nullrevision.content.match(/\{\{ &&*Peer typeofreview regexResult[1]page !*\| *topic *= "undefined"*\w+ *\}\}/);
if (regexResult != null)
{
return {
{
text: revision.content.replace(regexResult[0], "{{Old peer review" + regexResult[1] + "}}"),
text: revision.content.replace(regexResult[0], "{{Ombox|text='''This [[WP:PR|peer review]] discussion has been closed.'''}} <noinclude>[[Category:November 2018 peer reviews]]</noinclude>"),
summary: "Closing peer review due to inactivity (via [[User:Writ Keeper/Scripts/peerReviewCloser.js|peerReviewCloser.js]])"
};
}
else
{
mw.notify( 'Error updating the Peer Review page; article talk page.', {might title:also 'Peerrequire review closing errorcleanup.' } );,
{
title: 'Peer review closing error'
});
$("#ca-closepeer>a").text("error!");
return null;
}
}).done(function ()
{
api.edit(mw.config.get("wgPageName")talkPageName, function (revision)
{
var regexResult = revision.content.match(/\{\{ *Peer[pP]eer review page *(\| *topicarchive *= *\wd+) *\}\}/);
if (regexResult != null && typeof regexResult[1] != "undefined")
{
return {
{
text: revision.content.replace(regexResult[0], "{{Ombox|text='''This [[WP:PR|peer review]] discussion has been closed.'''}} <noinclude>[[Category:November 2018 peer reviews]]</noinclude>"),
summarytext: revision.content.replace(regexResult[0], "Closing{{Old peer review" due+ toregexResult[1] inactivity+ "}}"),
summary: "Closing peer review due to inactivity (via [[User:Writ Keeper/Scripts/peerReviewCloser.js|peerReviewCloser.js]])"
};
}
var regexResult = else if(revision.content.match(/\{\{ *Peer[oO]ld peer review *([^\| *archive *= *\d}]+) *\}\}/);
{
mw.notify('Peer Review page updated. Error updating the article talk page; it may have already been closed there.',
{
title: 'Peer review closing error'
}
);
$("#ca-closepeer>a").text("error!");
return null;
}
else
{
mw.notify('Peer Review page updated. 'Error updating the Peer Review page; article talk page; mightmay require manual cleanup.', { title: 'Peer review closing error' } );
{
title: 'Peer review closing error'
}
);
$("#ca-closepeer>a").text("error!");
return null;
}
}).done(function ()
{
___location.reload();
Line 59 ⟶ 79:
}
 
mw.hook("wikipage.content").add(function ()
 
 
mw.hook("wikipage.content").add(function()
{
if (mw.config.get("wgCategories").indexOf("Current peer reviews") >= 0)
{
mw.loader.using("mediawiki.util").done( function ()
{
mw.util.addPortletLink('p-cactions', '#', "Close peer review", "ca-closepeer", "close this peer review");
$("#ca-closepeer").click( function (event)
{
event.preventDefault();
mw.loader.load( [ 'mediawiki.api.edit' ] ); //start loading, while the user is in the prompt
return closePeerReview();
});