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

Content deleted Content added
test
apparently this is bad now
 
(10 intermediate revisions by 2 users not shown)
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(mw.config.get("wgPageName"), function (revision)
{
var regexResult = revision.content.match(/\{\{ *Peer[pP]eer review page *\| *topic *= *\w+ *\}\}/);
if (regexResult != null)
var regexResult = revision.content.match(/\{\{ *Peer review page *\| *topic *= *\w+ *\}\}/);
if (regexResult != null)
{
return {
text: revision.content.replace(regexResult[0], "{{OldClosed peer review" + regexResult[1] + "page}}"),
{
summary: "Closing peer review due to inactivity (via [[User:Writ Keeper/Scripts/peerReviewCloser.js|peerReviewCloser.js]])"
text: revision.content.replace(regexResult[0], "{{Old peer review" + regexResult[1] + "}}"),
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 also require cleanup.', { title: 'Peer review closing error' } );
{
title: 'Peer review closing error'
});
$("#ca-closepeer>a").text("error!");
return null;
}
}).done(function ()
{
api.edit(talkPageName, function (revision)
{
var regexResult = revision.content.match(/\{\{ *[pP]eer review *(\| *archive *= *\d+) *\}\}/);
if (regexResult != null && typeof regexResult[1] != "undefined")
{
return {
text: revision.content.replace(regexResult[0], "{{Oldsubst:Close peer review" + regexResult[1] + "}}"),
{
summary: "Closing peer review due to inactivity (via [[User:Writ Keeper/Scripts/peerReviewCloser.js|peerReviewCloser.js]])"
text: revision.content.replace(regexResult[0], "{{Old peer review" + regexResult[1] + "}}"),
summary: "Closing peer review due to inactivity (via [[User:Writ Keeper/Scripts/peerReviewCloser.js|peerReviewCloser.js]])"
};
}
{else
else if(revision.content.match(/\{\{ *[oO]ld peer review[^\}]+\}\}/)
{
if(typeof window.sessionStorage != "undefined")
mw.notify('Peer Review page updated. Error updating the article talk page; it may have already been closed there.',
{
window.sessionStorage.setItem("peerReviewCloserError","talkPageError");
title: 'Peer review closing error'
___location.reload();
return null;
}
);else
$("#ca-closepeer>a").text("error!");
return null;
}
else
{
mw.notify('Peer Review page updated. Error updating the article talk page; may require manual cleanup.',
{
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;
}
);
$("#ca-closepeer>a").text("error!");
return null;
}
})
.done(function ()
{
___location.reload();
Line 79 ⟶ 69:
}
 
 
mw.hook("wikipage.content").add(function ()
$(document).ready(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 Reviewreview page updated., but Errorerror updating the article talk page; it may haverequire alreadymanual been closed thereintervention.', { 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', '#', "Close peer review", "ca-closepeer", "close this peer review");
$("#ca-closepeer").click(function function(event)
{
event.preventDefault();
mw.loader.load( [ 'mediawiki.api.edit' ] ); //start loading, while the user is in the prompt
return closePeerReview();
});