// CfD code follows <nowiki>
var CfD = {};
$(document).ready(function () {
CfD.$obj = $(".mbox-cfd").eq(0); //only add to first CfD tag in case of duplicate tags
CfD.target = $(CfD.$obj).find('b a:contains("this category\'s entry")').eq(0).attr("title"); // detect target of CfD
CfD.vote = function (vote) {
$('<div id="CfD-dialog"></div>').append('<p>Enter your argument below. CfD 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="CfD-vote"><div><textarea id="CfD-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="CfD-vote-speedy"><label for="CfD-vote-speedy">Speedy</label>' + "</div></form>" + '<div id="CfD-vote-preview"></div>').dialog({
buttons: [
{
text: "Proceed",
click: function () {
var comment = $("#CfD-vote-reason").val();
var speedy = $("#CfD-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="CfD-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");
$("#CfD-vote-reason").prop("disabled", true);
$("#CfD-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");
$("#CfD-spinner").remove();
$("#CfD-vote-reason").prop("disabled", false);
$("#CfD-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: CfD.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");
$("#CfD-spinner").remove();
$("#CfD-vote-reason").prop("disabled", false);
$("#CfD-vote-speedy").prop("disabled", false);
} else {
var wikitext = result.parse.wikitext["*"];
if ((wikitext.includes("<!--VCB " + mw.config.get("wgUserName") + " " + $(CfD.$obj).find("b a").eq(1).attr("href").split("#")[1].split("_").join(" ") + "-->")) && vote.toLowerCase() != "comment") {
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#CfD-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 CfD 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 or similar before trying again.</p></td></tr></tbody></table>').dialog({
buttons: [{
text: "Visit CfD page",
click: function () {
window.location.href = "/wiki/" + CfD.target + "#" + $(CfD.$obj).find("b a").eq(1).attr("href").split("#")[1].split("_").join(" ");
}
},
{
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 {
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
prop: "text",
format: "json",
page: CfD.target
}).done(function (result) {
var section;
$(result.parse.text["*"]).find(".mw-headline").each(function (i) {
if ($(this).text() == $(CfD.$obj).find('b a:contains("this category\'s entry")').eq(0).attr("href").split("#")[1].split("_").join(" ")) {
section = i + 1;
}
});
$.post(mw.config.get("wgScriptPath") + "/api.php", {
action: "edit",
format: "json",
section: section,
appendtext: "\n* '''" + vote + "'''" + (comment ? ": " + comment : "") + " ~~~~" + ((vote.toLowerCase() != "comment") ? " <!--VCB " + mw.config.get("wgUserName") + " " + $(CfD.$obj).find("b a").eq(1).attr("href").split("#")[1].split("_").join(" ") + "-->" : ""),
summary: "/* " + $(CfD.$obj).find("b a").eq(1).attr("href").split("#")[1].split("_").join(" ") + "*/ " + ((vote.toLowerCase() == "comment") ? "Comment via [[User:Awesome Aasim/xfdvote|XFD Participation tool]]" : "!Vote via [[User:Awesome Aasim/xfdvote|XFD Participation tool]]"),
title: CfD.target,
nocreate: 1,
token: token
}).done(function (result) {
if (result.error) {
mw.notify($('<span class="error">' + result.error.info + '</span>'));
$("#CfD-vote-speedy").prop("disabled", false);
$("#CfD-vote-reason").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#CfD-spinner").remove();
} else {
window.location.href = "/wiki/" + CfD.target + "#" + $(CfD.$obj).find("b a").eq(1).attr("href").split("#")[1].split("_").join(" ");
}
}).fail(function () {
$("#CfD-vote-reason").prop("disabled", false);
$("#CfD-vote-speedy").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#CfD-spinner").remove();
mw.notify($("<b>Try that again.</b><br>Could not cast your vote."));
});
}).fail(function (result) {
$("#CfD-vote-reason").prop("disabled", false);
$("#CfD-vote-speedy").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#CfD-spinner").remove();
mw.notify($("<b>Try that again.</b><br>Could not cast your vote."));
});
}
}
}).fail(function () {
$("#CfD-vote-reason").prop("disabled", false);
$("#CfD-vote-speedy").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#CfD-spinner").remove();
mw.notify($("<b>Try that again.</b><br>Could not cast your vote."));
});
}
}).fail(function () {
$("#CfD-vote-reason").prop("disabled", false);
$("#CfD-vote-speedy").prop("disabled", false);
$(".ui-button").prop("disabled", false).removeClass("ui-state-disabled");
$("#CfD-spinner").remove();
mw.notify($("<b>Try that again.</b><br>Could not cast your vote."));
});
}
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("destroy").remove();
$("#CfD-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 ($("#CfD-dialog").length > 0) {
var comment = $("#CfD-vote-reason").val();
var speedy = $("#CfD-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: CfD.target,
prop: "text",
pst: "1",
preview: "1",
text: "\n* '''" + temp + "'''" + (comment ? ": " + comment : "") + " ~~~~"
}).done(function (result) {
if (result.error) {
$("#CfD-vote-preview").html("<i>Could not load preview.</i>");
mw.notify($("<span class=\"error\">" + result.error.info + "</span>"));
} else {
$("#CfD-vote-preview").html("Preview: <br>" + result.parse.text["*"]);
}
}).fail(function () {
$("#CfD-vote-preview").html("<i>Could not load preview.</i>");
}).always(function () {
window.setTimeout(preview, 100);
});
}
}
$("#CfD-vote-reason").keypress(function (e) {
if (e.which == 13) {
e.preventDefault();
}
});
};
CfD.$keep = $('<button class="mw-ui-button mw-ui-progressive" id="CfD-vote-keep">Vote to keep</button>');
CfD.$keep.click(function (e) {
e.preventDefault();
CfD.vote("Keep");
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$delete = $('<button class="mw-ui-button mw-ui-destructive" id="CfD-vote-delete">Vote to delete</button>');
CfD.$delete.click(function (e) {
e.preventDefault();
CfD.vote("Delete");
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$article = $('<button class="mw-ui-button" id="CfD-vote-article">Vote to convert to article</button>');
CfD.$article.click(function (e) {
e.preventDefault();
var target;
$('<div id="CfD-search"></div>').append('<p>Please enter a proposed article name:</p><form><input id="CfD-search-box"></form>').dialog({
buttons: [
{
text: "Next",
click: function () {
target = $("#CfD-search-box").val();
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
prop: "text",
page: target
}).done(function (result) {
if (result.error) {
CfD.vote("Convert to article" + (target ? " [[" + target + "]]" : ""));
} else {
alert("That article already exists!");
}
});
}
},
{
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
});
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$rename = $('<button class="mw-ui-button" id="CfD-vote-rename">Vote to rename</button>');
CfD.$rename.click(function (e) {
e.preventDefault();
var target;
$('<div id="CfD-search"></div>').append('<p>Please enter a proposed category name:</p><form><input id="CfD-search-box"></form>').dialog({
buttons: [
{
text: "Next",
click: function () {
target = $("#CfD-search-box").val();
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
prop: "text",
page: target
}).done(function (result) {
if (result.error) {
CfD.vote("Rename" + (target ? " to category [[:Category:" + target + "]]" : ""));
} else {
alert("That category already exists!");
}
});
}
},
{
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
});
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$list = $('<button class="mw-ui-button" id="CfD-vote-list">Vote to listify</button>');
CfD.$list.click(function (e) {
e.preventDefault();
CfD.vote("Listify");
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$merge = $('<button class="mw-ui-button" id="CfD-vote-merge">Vote to merge</button>');
CfD.$merge.click(function (e) {
e.preventDefault();
var target;
$('<div id="CfD-search"></div>').append('<p>Please enter a proposed target to merge this page with:</p><form><input list="CfD-search-results" id="CfD-search-box"><datalist id="CfD-search-results"></datalist></form>').dialog({
buttons: [
{
text: "Next",
click: function () {
target = $("#CfD-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 {
CfD.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
});
$("#CfD-search-box").keyup(function () {
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "query",
list: "search",
srsearch: $("#CfD-search-box").val(),
format: "json"
}).done(function (result) {
if (result.error) {
} else {
$("#CfD-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;
}
$("#CfD-search-results").append('<option value="' + result.query.search[i].title + '">');
}
}
}).fail(function (result) {
})
});
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$split = $('<button class="mw-ui-button" id="CfD-vote-split">Vote to split</button>');
CfD.$split.click(function (e) {
e.preventDefault();
var i = 3;
$('<div id="CfD-split"></div>').append('<p>Please enter two proposed split titles:</p><form><input id="CfD-split1" placeholder="First title"><br><input id="CfD-split2" placeholder="Second title"><div id="CfD-additional"></div></form>').dialog({
buttons: [
{
text: "Next",
click: function () {
var targetstring = "";
for (var j = 1; j < i; j++) {
if ($("#CfD-split" + j).val() != "") {
if (j != 1) {
targetstring += ", "
}
targetstring += "[[:Category:" + $("#CfD-split" + j).val() + "]]";
}
}
CfD.vote("Split" + (targetstring ? " into " + targetstring : ""));
}
},
{
text: "Add another category",
click: function () {
$("#CfD-additional").append('<span id="CfD-split-field' + i + '"><input placeholder="title..." id="CfD-split' + i + '"><br></span>');
i++;
}
},
{
text: "Remove last category",
click: function () {
try {
i--;
$("#CfD-split-field" + i).remove();
if (i < 3) {
i = 3;
}
} catch (error) {
console.error(error);
i++;
}
}
},
{
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
});
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$comment = $('<button class="mw-ui-button" id="CfD-vote-comment">Comment</button>');
CfD.$comment.click(function (e) {
e.preventDefault();
CfD.vote("Comment");
}).css({ "margin-right": "5px", "margin-left": "1px" });
CfD.$custom = $('<button class="mw-ui-button" id="CfD-vote-custom">Custom vote</button>');
CfD.$custom.click(function (e) {
e.preventDefault();
CfD.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: CfD.target,
prop: "text"
}).done(function (result) {
if (result.error) {
CfD.$obj.find("tr .mbox-text").append('<hr>Deletion discussion actions:<div id="CfD-vote-buttons"></div>');
} else {
var section;
$(result.parse.text["*"]).find(".mw-headline").each(function (i) {
if ($(this).text() == $(CfD.$obj).find('b a:contains("this category\'s entry")').eq(0).attr("href").split("#")[1].split("_").join(" ")) {
section = i + 1;
}
});
$.get(mw.config.get("wgScriptPath") + "/api.php", {
action: "parse",
format: "json",
page: CfD.target,
prop: "text",
section: section
}).done(function (result) {
if (result.error) {
CfD.$obj.find("tr .mbox-text").append('<hr>Deletion discussion actions:<div id="CfD-vote-buttons"></div>');
} else {
var $text = $(result.parse.text["*"]);
CfD.$obj.find("tr .mbox-text").append("<hr>" + $text.find("dd").eq(1).html() + '<hr>Deletion discussion actions:<div id="CfD-vote-buttons"></div>');
}
}).fail(function () {
CfD.$obj.find("tr .mbox-text").append('<hr>Deletion discussion actions:<div id="CfD-vote-buttons"></div>');
}).always(function () {
$("#CfD-vote-buttons").append(CfD.$keep).append(CfD.$delete).append(CfD.$article).append(CfD.$rename).append(CfD.$list).append(CfD.$merge).append(CfD.$split).append(CfD.$comment).append(CfD.$custom);
if (mw.config.get("wgNamespaceNumber") != 14) {
$("#CfD-vote-buttons").html("If this was a real CfD nomination, the buttons to vote on the nomination would appear here.");
}
});
}
}).fail(function () {
CfD.$obj.find("tr .mbox-text").append('<hr>Deletion discussion actions:<div id="CfD-vote-buttons"></div>');
}).always(function () {
$("#CfD-vote-buttons").append(CfD.$keep).append(CfD.$delete).append(CfD.$article).append(CfD.$rename).append(CfD.$list).append(CfD.$merge).append(CfD.$split).append(CfD.$comment).append(CfD.$custom);
if (mw.config.get("wgNamespaceNumber") != 14) {
$("#CfD-vote-buttons").html("If this was a real CfD nomination, the buttons to vote on the nomination would appear here.");
}
});
});
// End of CfD code </nowiki>