User:Yair rand/ControversialMoves.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Yair rand/ControversialMoves. |
// Adds a checkbox to the "Move page" special page, containing the content "Do you think this move might be controversial?"
// When checked, a move request is added to the talkpage, using the proper template.
mw.config.get( "wgCanonicalSpecialPageName" ) === "Movepage" &&
mw.config.get( "wgRelevantPageName" ).indexOf(":") === -1 && // mainspace only
$(function($){
var submitButton = $(".mw-submit > input"), submitText = submitButton.val();
function submitFunction( e ){
e.preventDefault();
var newTitle = $("#wpNewTitleMain").val();
if ( newTitle === mw.config.get( "wgRelevantPageName" ) || ! newTitle ) {
alert( "Please select a new page title." ); return;
}
submitButton.attr("disabled", "disabled");
$( "body" ).css("cursor", "wait");
$.ajax( { "url" : "/w/api.php", data : { "format" : "json", "action" : "tokens" }, "error" : cmError, success : function( t ){
$.ajax( { "url" : "/w/api.php", "type" : "POST", "data" : { "format" : "json", "action" : "edit", "title" : "Talk:" + mw.config.get( "wgRelevantPageName" ), "watchlist" : "watch", "section" : "new", "sectiontitle" : "Requested move \{\{subst:#time: d F Y | \{\{subst:CURRENTTIMESTAMP}} }}", appendtext : "\{\{subst:requested move|" + newTitle + "|reason = " + $("#wpReason").val() + "}}", "token" : t.tokens.edittoken }, "error" : cmError, "success" : function(){ location.href = "/wiki/Talk:" + mw.config.get( "wgRelevantPageName" ) + "#Requested_move" }})
}})
}
function cmError( q, w, e ){
$("#movepage").append( $("<span>").css("color","red").text("An error has occured: " + e ) );
}
submitButton.parent().parent().before(
$("<tr>").append(
$("<td>"),
$("<td>").append( $("<input>").attr({"type":"checkbox","id":"controversialMove"} ).click(function(){
var checked = $(this).attr("checked") === "checked";
submitButton.attr("value", checked ? "Propose moving the page" : submitText );
$("#wpMovetalk").attr("disabled", checked && "disabled" );
$("#movepage")[ checked ? "on" : "off" ]( "submit", submitFunction );
}), " ", $("<label>").attr("for", "controversialMove").text("Do you think this move might be controversial?") )
)
)
})