// MfD code follows <nowiki>
var MfD = {};
$(document).ready(function () {
MfD.$obj = $(".mbox-mfd").eq(0); //only add to first MfD tag in case of duplicate tags
MfD.target = $(MfD.$obj).find("b a").eq(1).attr("title"); // detect target of MfD
MfD.vote = function (vote) {
$('<div id="MfD-dialog"></div>').append('<p>Enter your argument below. MfD votes are weighted based on the strength of arguments, not based on number of votes. Cite relevant policies and guidelines where needed. See <a href="/wiki/Wikipedia:Polling_is_not_a_substitute_for_discussion">this page</a> and <a href="/wiki/Wikipedia:Arguments_to_avoid_in_deletion_discussions">this page</a> for more information.</p><form id="MfD-vote"><div><textarea id="MfD-vote-reason" placeholder="' + ((vote.toLowerCase() == "comment") ? 'Comment' : 'Reason to ' + vote.toLowerCase()) + '" height="5"></textarea></div>' + (vote.toLowerCase() == "delete" || vote.toLowerCase() == "keep" ? '<div>' : '<div style="display:none;">') + '<input type="checkbox" id="MfD-vote-speedy"><label for="MfD-vote-speedy">Speedy</label>' + "</div></form>" + '<div id="MfD-vote-preview"></div>').dialog({
buttons: [
{
text: "Proceed",
click: function () {
var comment = $("#MfD-vote-reason").val();
var speedy = $("#MfD-vote-speedy").is(":checked") ? true : false;
if (vote.toLowerCase() == "comment" && comment.length == 0) {
alert("Please add a comment.");
} else {
if (speedy) {
vote = "Speedy " + vote.toLowerCase();
}
$(".ui-dialog-buttonpane").eq($(".ui-dialog-buttonpane").length - 1).prepend('<div class="mw-spinner mw-spinner-small mw-spinner-inline" title="..." id="MfD-spinner"><div class="mw-spinner-container"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div></div>');
$(".ui-button").prop("disabled", true).addClass("ui-state-disabled");
$("#MfD-vote-reason").prop("disabled", true);
$("#MfD-vote-speedy").prop("disabled", true);
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "query",
format: "json",
meta: "tokens",
type: "csrf"
}).done(function (result) {
if (result.error) {
mw.notify($('<span class="error">' + result.error.info + '</span>'));
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-spinner").remove();
$("#MfD-vote-reason").prop("disabled", false);
$("#MfD-vote-speedy").prop("disabled", false);
} else {
var token = result.query.tokens.csrftoken;
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
prop: "wikitext",
format: "json",
page: MfD.target
}).done(function (result) {
if (result.error) {
mw.notify($('<span class="error">' + result.error.info + '</span>'));
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-spinner").remove();
$("#MfD-vote-reason").prop("disabled", false);
$("#MfD-vote-speedy").prop("disabled", false);
} else {
var wikitext = result.parse.wikitext["*"];
if (wikitext.includes('<div class="boilerplate mfd vfd xfd-closed""')) {
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-dialog").dialog("destroy").remove();
$('<table class="plainlinks plainlinks ombox ombox-content" role="presentation"><tbody><tr><td class="mbox-image"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/3/33/OOjs_UI_icon_clear-destructive.svg/40px-OOjs_UI_icon_clear-destructive.svg.png" decoding="async" width="40" height="40" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/3/33/OOjs_UI_icon_clear-destructive.svg/60px-OOjs_UI_icon_clear-destructive.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/3/33/OOjs_UI_icon_clear-destructive.svg/80px-OOjs_UI_icon_clear-destructive.svg.png 2x" data-file-width="20" data-file-height="20"></td><td class="mbox-text"><b>The MfD discussion appears to have been closed.</b><br><p>Please visit the MfD page to double-check.</p></td></tr></tbody></table>').dialog({
buttons: [{
text: "Visit MfD page",
click: function () {
window.location.href = "/wiki/" + MfD.target;
}
},
{
text: "OK",
click: function () {
$(this).dialog('destroy').remove();
}
}],
closeOnEscape: false,
modal: true,
title: "MfD Discussion Closed",
width: (0.50 * window.outerWidth > 300) ? 0.50 * window.outerWidth : 300
});
} else if ((wikitext.includes("<!--Vote cast using XFD voting tool by " + mw.config.get("wgUserName") + " -->") || wikitext.includes("<!--VCB " + mw.config.get("wgUserName") + "-->")) && vote.toLowerCase() != "comment") {
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-dialog").dialog("destroy").remove();
$('<table class="plainlinks plainlinks ombox ombox-content" role="presentation"><tbody><tr><td class="mbox-image"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/3/33/OOjs_UI_icon_clear-destructive.svg/40px-OOjs_UI_icon_clear-destructive.svg.png" decoding="async" width="40" height="40" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/3/33/OOjs_UI_icon_clear-destructive.svg/60px-OOjs_UI_icon_clear-destructive.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/3/33/OOjs_UI_icon_clear-destructive.svg/80px-OOjs_UI_icon_clear-destructive.svg.png 2x" data-file-width="20" data-file-height="20"></td><td class="mbox-text"><b>You\'ve already voted.</b> Please modify your existing vote on the MfD page rather than casting a new vote. If you have struck out your vote, please make sure to remove the "<!--Vote cast using XFD voting tool by ' + mw.config.get("wgUserName") + ' -->" or "<"!--VCB ' + mw.config.get("wgUserName") + '-->"code before trying again.</p></td></tr></tbody></table>').dialog({
buttons: [{
text: "Visit MfD page",
click: function () {
window.location.href = "/wiki/" + MfD.target;
}
},
{
text: "OK",
click: function () {
$(this).dialog('destroy').remove();
}
}],
closeOnEscape: false,
modal: true,
title: "You've already voted",
width: (0.50 * window.outerWidth > 300) ? 0.50 * window.outerWidth : 300
});
} else {
$.post(mw.config.get("wgScriptPath") + "/api.php", {
action: "edit",
format: "json",
appendtext: "\n* '''" + vote + "'''" + (comment ? ": " + comment : "") + " ~~~~" + ((vote.toLowerCase() != "comment") ? " <!--VCB " + mw.config.get("wgUserName") + "-->" : ""),
summary: ((vote.toLowerCase() == "comment") ? "Comment via [[User:Awesome Aasim/xfdvote|XFD Participation tool]]" : "!Vote via [[User:Awesome Aasim/xfdvote|XFD Participation tool]]"),
title: MfD.target,
nocreate: 1,
token: token
}).done(function (result) {
if (result.error) {
mw.notify($('<span class="error">' + result.error.info + '</span>'));
$("#MfD-vote-speedy").prop("disabled", false);
$("#MfD-vote-reason").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-spinner").remove();
} else {
window.location.href = "/wiki/" + MfD.target;
}
}).fail(function () {
$("#MfD-vote-reason").prop("disabled", false);
$("#MfD-vote-speedy").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-spinner").remove();
mw.notify($("<b>Try that again.</b><br>Could not cast your vote."));
});
}
}
}).fail(function () {
$("#MfD-vote-reason").prop("disabled", false);
$("#MfD-vote-speedy").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-spinner").remove();
mw.notify($("<b>Try that again.</b><br>Could not cast your vote."));
});
}
}).fail(function () {
$("#MfD-vote-reason").prop("disabled", false);
$("#MfD-vote-speedy").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#MfD-spinner").remove();
mw.notify($("<b>Try that again.</b><br>Could not cast your vote."));
});
}
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("destroy").remove();
$("#MfD-spinner").remove();
}
}
],
closeOnEscape: false,
modal: true,
title: (vote.toLowerCase() == "comment" ? "Comment on the nomination of " : "Vote to " + vote.toLowerCase()) + " \"" + mw.config.get("wgPageName") + "\"",
width: (0.50 * window.outerWidth > 300) ? 0.50 * window.outerWidth : 300
});
preview();
function preview() {
if ($("#MfD-dialog").length > 0) {
var comment = $("#MfD-vote-reason").val();
var speedy = $("#MfD-vote-speedy").is(":checked") ? true : false;
var temp = vote;
if (speedy) {
temp = "Speedy " + temp.toLowerCase();
}
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
title: MfD.target,
prop: "text",
pst: "1",
preview: "1",
text: "\n* '''" + temp + "'''" + (comment ? ": " + comment : "") + " ~~~~" + ((vote.toLowerCase() != "comment") ? " <!--VCB " + mw.config.get("wgUserName") + "-->" : "")
}).done(function (result) {
if (result.error) {
$("#MfD-vote-preview").html("<i>Could not load preview.</i>");
mw.notify($("<span class=\"error\">" + result.error.info + "</span>"));
} else {
$("#MfD-vote-preview").html("Preview: <br>" + result.parse.text["*"]);
}
}).fail(function () {
$("#MfD-vote-preview").html("<i>Could not load preview.</i>");
}).always(function () {
window.setTimeout(preview, 100);
});
}
}
$("#MfD-vote-reason").keypress(function (e) {
if (e.which == 13) {
e.preventDefault();
}
});
};
MfD.$keep = $('<button class="mw-ui-button mw-ui-progressive" id="MfD-vote-keep">Vote to keep</button>');
MfD.$keep.click(function (e) {
e.preventDefault();
MfD.vote("Keep");
}).css({ "margin-right": "5px", "margin-left": "1px" });
MfD.$delete = $('<button class="mw-ui-button mw-ui-destructive" id="MfD-vote-delete">Vote to delete</button>');
MfD.$delete.click(function (e) {
e.preventDefault();
MfD.vote("Delete");
}).css({ "margin-right": "5px", "margin-left": "1px" });
MfD.$merge = $('<button class="mw-ui-button" id="MfD-vote-merge">Vote to merge</button>');
MfD.$merge.click(function (e) {
e.preventDefault();
var target;
$('<div id="MfD-search"></div>').append('<p>Please enter a proposed target to merge this page with:</p><form><input list="MfD-search-results" id="MfD-search-box"><datalist id="MfD-search-results"></datalist></form>').dialog({
buttons: [
{
text: "Next",
click: function () {
target = $("#MfD-search-box").val();
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
prop: "text",
page: target
}).done(function (result) {
if (result.error) {
alert(result.error.info);
} else {
MfD.vote("Merge with " + (target ? "[[" + target + "]]" : "some other page"));
}
});
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("destroy").remove();
}
}
],
closeOnEscape: false,
modal: true,
title: "Enter a title",
width: (0.50 * window.outerWidth > 300) ? 0.50 * window.outerWidth : 300
});
$("#MfD-search-box").keyup(function () {
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "query",
list: "search",
srsearch: $("#MfD-search-box").val(),
format: "json"
}).done(function (result) {
if (result.error) {
} else {
$("#MfD-search-results").html('');
for (var i = 0; i < result.query.search.length; i++) {
if (result.query.search[i].title == mw.config.get("wgPageName").replace("_", " ")) {
continue;
}
$("#MfD-search-results").append('<option value="' + result.query.search[i].title + '">');
}
}
}).fail(function (result) {
})
});
}).css({ "margin-right": "5px", "margin-left": "1px" });
MfD.$redirect = $('<button class="mw-ui-button" id="MfD-vote-redirect">Vote to redirect</button>');
MfD.$redirect.click(function (e) {
e.preventDefault();
var target;
$('<div id="MfD-search"></div>').append('<p>Please enter a proposed target to redirect this page to:</p><form><input list="MfD-search-results" id="MfD-search-box"><datalist id="MfD-search-results"></datalist></form>').dialog({
buttons: [
{
text: "Next",
click: function () {
target = $("#MfD-search-box").val();
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
prop: "text",
page: target
}).done(function (result) {
if (result.error) {
alert(result.error.info);
} else {
MfD.vote("Redirect to " + (target ? "[[" + target + "]]" : "some other page"));
}
});
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("destroy").remove();
}
}
],
closeOnEscape: false,
modal: true,
title: "Enter a title",
width: (0.50 * window.outerWidth > 300) ? 0.50 * window.outerWidth : 300
});
$("#MfD-search-box").keyup(function () {
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "query",
list: "search",
srsearch: $("#MfD-search-box").val(),
format: "json"
}).done(function (result) {
if (result.error) {
} else {
$("#MfD-search-results").html('');
for (var i = 0; i < result.query.search.length; i++) {
if (result.query.search[i].title == mw.config.get("wgPageName").replace("_", " ")) {
continue;
}
$("#MfD-search-results").append('<option value="' + result.query.search[i].title + '">');
}
}
}).fail(function (result) {
})
});
}).css({ "margin-right": "5px", "margin-left": "1px" });
MfD.$comment = $('<button class="mw-ui-button" id="MfD-vote-comment">Leave a comment</button>');
MfD.$comment.click(function (e) {
e.preventDefault();
MfD.vote("Comment");
}).css({ "margin-right": "5px", "margin-left": "1px" });
MfD.$custom = $('<button class="mw-ui-button" id="MfD-vote-custom">Custom vote</button>');
MfD.$custom.click(function (e) {
e.preventDefault();
MfD.vote(prompt("Enter your custom vote here:"));
}).css({ "margin-right": "5px", "margin-left": "1px" });
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
page: MfD.target,
prop: "text"
}).done(function (result) {
if (result.error) {
MfD.$obj.find("tr .mbox-text").append('<hr>Deletion discussion actions:<div id="MfD-vote-buttons"></div>');
} else {
var $text = $(result.parse.text["*"]);
MfD.$obj.find("tr .mbox-text").append('<hr>Reason: ' + $text.find("p").eq(0).html() + '<hr>Deletion discussion actions:<div id="MfD-vote-buttons"></div>');
}
}).fail(function () {
MfD.$obj.find("tr .mbox-text").append('<hr>Deletion discussion actions:<div id="MfD-vote-buttons"></div>');
}).always(function () {
$("#MfD-vote-buttons").append(MfD.$keep).append(MfD.$delete).append(MfD.$merge).append(MfD.$redirect).append(MfD.$comment).append(MfD.$custom);
if (mw.config.get("wgPageName") == "Template:Mfd" || mw.config.get("wgPageName") == "Template:Mfdx") {
$("#MfD-vote-buttons").html("If this was a real MfD nomination, the buttons to vote on the nomination would appear here.");
}
});
});
// End of MfD code </nowiki>