// 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?") )
)
)
})