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

Content deleted Content added
fx
apparently this is bad now
 
(19 intermediate revisions by 2 users not shown)
Line 1:
function closePeerReview()
{
mw.loader.using("mediawiki.api.edit").done( function ()
{
$("#ca-closepeer>a").text("closingClosing...");
$("#ca-closepeer").off("click");
var talkPage = $("a:contains('Article talk')").attr("href");
var talkPageName = "";
if(talkPage != null)
{
talkPage = talkPage.match(/\/wiki\/(\w+:\w.+)/);
if(talkPage != null)
{
Line 16 ⟶ 17:
var api = new mw.Api();
api.edit(talkPageNamemw.config.get("wgPageName"), function(revision)
{
var regexResult = revision.content.match(/\{\Peer{ *[pP]eer review( page *\|archive *topic *= *\d)w+ *\}\}/);
if(regexResult != null && typeof regexResult[1] != "undefined")
{
return {
text: revision.content.replace("{{peer review" + regexResult[10] + "}}", "{{OldClosed peer review" + regexResult[1] + "page}}"),
summary: "Closing peer review due to inactivity (via [[User:Writ Keeper/Scripts/peerReviewCloser|peerReviewCloser.js]])"
};
}
else
{
alertmw.notify(" 'Error updating the Peer Review page; article talk page might also require cleanup."', { 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*(\|topic *archive *= *\wd+) *\}\}/);
if(regexResult != null && typeof regexResult[1] != "undefined")
{
return {
text: revision.content.replace(/\{\{Peer review page\|topic=\w+\}\}/regexResult[0], "{{Ombox|text='''Thissubst:Close [[WP:PR|peer review]]" discussion+ hasregexResult[1] been+ closed.'''"}} <noinclude>[[Category:November 2018 peer reviews]]</noinclude>"),
summary: "Closing peer review due to inactivity (via [[User:Writ Keeper/Scripts/peerReviewCloser|peerReviewCloser.js]])"
};
}
else
{
if(typeof window.sessionStorage != "undefined")
alert("Error updating the Peer Review page.");
return null;{
window.sessionStorage.setItem("peerReviewCloserError","talkPageError");
___location.reload();
return null;
}
else
{
mw.notify( 'Peer review page updated, but error updating the article talk page; it may require manual intervention.', { title: 'Peer review closing error' } );
$("#ca-closepeer>a").text("error!");
return null;
}
}
})
.done(function()
{
___location.reload();
Line 57 ⟶ 70:
 
 
$(document).ready(function()
 
mw.hook("wikipage-content").add(function()
{
if(typeof window.sessionStorage != "undefined")
if(mw.config.get("wgCategories").indexOf("Current peer reviews") >= 0)
{
if(window.sessionStorage.getItem("peerReviewCloserError") == "talkPageError")
{
mw.notify( 'Peer review page updated, but error updating the article talk page; it may require manual intervention.', { title: 'Peer review closing error' } );
window.sessionStorage.removeItem("peerReviewCloserError");
}
}
if(mw.config.get("wgCategories",[]).indexOf("Current peer reviews") >= 0)
{
mw.loader.using("mediawiki.util").done( function ()
{
mw.util.addPortletLink('p-cactions', '#', "closeClose peer review", "ca-closepeer", "close this peer review");
$("#ca-closepeer").click( function(event)
{