Jump to content
Wikipedia The Free Encyclopedia

User:Sam Sailor/Scripts/MoveToDraft.js

From Wikipedia, the free encyclopedia
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:Sam Sailor/Scripts/MoveToDraft.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
 /***************************************************************************************************
  A fork of
  MoveToDraft as it looked in [[Special:PermaLink/852307914]]
  with the ns0 limitation removed.
  -------------
  Version 2.2.2-sandbox
  -------------
  A script to move unsourced articles to draft space, including cleanup and author notification.
  - Moves page to draftspace
  - Checks if any files used are non-free
  - Checks if any redirects pointed to the page
  - Comments out non-free files, turn categories into links, add afc draft template, add redirects
  - Adds notification message on author talk page
  - Updates talk page banners
  - Logs draftification in user subpage

 ***************************************************************************************************/
 // <nowiki>
 $(function($){

 varmoveToDraft=functionmoveToDraft(){

 /* ========== Config ============================================================================ */
 varconfig={};
 // Script info
 config.script={
 // Advert to append to edit summaries
 advert:' ([[User:Evad37/MoveToDraft.js|via script]])',
 version:'2.2.2'
 };
 // MediaWiki configuration values
 config.mw=mw.config.get([
 'wgArticleId',
 'wgPageName',
 'wgUserGroups',
 'wgUserName',
 'wgMonthNames'
 ]);
 // Wikitext strings
 config.wikitext={
 'rationale':window.m2d_rationale||'Undersourced, incubate in draftspace',
 'editsummary':window.m2d_rationale||'[[WP:AFC|AFC]] draft',
 'notification_heading':'[[Draft:1ドル|1ドル]] moved to draftspace',
 'notification':window.m2d_notification||"An article you recently created, [[Draft:1ドル|1ドル]], does not have enough sources and citations as written to remain published. It needs more citations from [[WP:RS|reliable]], [[WP:IS|independent sources]]. <small>([[WP:42|?]])</small> Information that can't be referenced should be removed ([[WP:V|verifiability]] is of [[WP:5|central importance]] on Wikipedia). I've moved your draft to [[Wikipedia:Draftspace|draftspace]] (with a prefix of \"<code>Draft:</code>\" before the article title) where you can incubate the article with minimal disruption. When you feel the article meets Wikipedia's [[WP:GNG|general notability guideline]] and thus is ready for mainspace, please click on the \"Submit your draft for review!\" button at the top of the page. ~~~~",
 'logMsg':'#[[1ドル]] moved to [[2ドル]] at ~~~~~'
 };
 // Page data -- to be retreived later from api
 config.pagedata={};

 // Helper functions
 // - prettify an encoded page title (or at least replace underscores with spaces)
 vargetPageText=function(p){
 vart=mw.Title.newFromText(decodeURIComponent(p));
 if(t){
 returnt.getPrefixedText();
 }else{
 returnp.replace(/_/g," ");
 }
 };

 /* ========== API =============================================================================== */
 varAPI=newmw.Api({
 ajax:{
 headers:{
 'Api-User-Agent':'MoveToDraft/'+config.script.version+
 ' ( https://en.wikipedia.org/wiki/User:Evad37/MoveToDraft )'
 }
 }
 });

 /* ========== Tasks ============================================================================= */

 // Grab page data - initial author, current wikitext, any redirects, if Draft: page already exists
 vargrabPageData=function(){

 varpatt_isRedirect=/^\s*#redirect/i;

 varcheckedPageTriageStatus=false;

 // Function to check if all done
 varcheckPageData=function(){
 if(
 config.pagedata.author!=null&&
 config.pagedata.oldwikitext!=null&&
 config.pagedata.redirects!=null&&
 checkedPageTriageStatus
 ){
 //all done - go to next screen
 screen1();
 }
 };

 /* ---------- Initial author ---------------------------------------------------------------- */

 /* Try making an api call for just the first revision - but if that is a redirect, then get 'max'
 	 number of revisions, and look for first non-redirect revision - use this as the initial author,
 	 not the creator of the redirect.
 	*/
 varprocessMaxRvAuthorQuery=function(result){
 varrevisions=result.query.pages[config.mw.wgArticleId].revisions;
 for(vari=1;i<revisions.length;i++){
 if(!patt_isRedirect.test(revisions[i]['*'])){
 config.pagedata.author=revisions[i].user;
 break;
 }
 }
 //Check that we actually found an author (i.e. not all revisions were redirects
 if(config.pagedata.author==null){
 API.abort();
 varretry=confirm("Could not retrieve page author:\n"+extraJs.makeErrorMsg(c,r)+"\n\nTry again?");
 if(retry){
 screen0();
 }else{
 $("#M2D-modal").remove();
 }
 }

 checkPageData();
 };

 varprocessAuthorQuery=function(result){
 // Check if page is currently a redirect
 if(result.query.pages[config.mw.wgArticleId].redirect){
 API.abort();
 alert("Error: "+config.mw.wgPageName+" is a redirect");
 return;
 }
 // Check if first revision is a redirect
 rvwikitext=result.query.pages[config.mw.wgArticleId].revisions[0]['*'];
 if(patt_isRedirect.test(rvwikitext)){
 // query to look for first non-redirect revision
 API.get({
 action:'query',
 pageids:config.mw.wgArticleId,
 prop:'revisions',
 rvprop:['user','content'],
 rvlimit:'max',
 rvdir:'newer'
 })
 .done(processMaxRvAuthorQuery)
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 API.abort();
 varretry=confirm("Could not retrieve page author:\n"+extraJs.makeErrorMsg(c,r)+"\n\nTry again?");
 if(retry){
 screen0();
 }else{
 $("#M2D-modal").remove();
 }
 });
 return;
 }

 config.pagedata.author=result.query.pages[config.mw.wgArticleId].revisions[0].user;
 checkPageData();
 };

 //Get author
 API.get({
 action:'query',
 pageids:config.mw.wgArticleId,
 prop:['revisions','info'],
 rvprop:['user','content'],
 rvlimit:1,
 rvdir:'newer'
 })
 .done(processAuthorQuery)
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 API.abort();
 varretry=confirm("Could not retrieve page author:\n"+extraJs.makeErrorMsg(c,r)+"\n\nTry again?");
 if(retry){
 screen0();
 }else{
 $("#M2D-modal").remove();
 }
 });

 /* ---------- Current wikitext -------------------------------------------------------------- */

 API.get({
 action:'query',
 pageids:config.mw.wgArticleId,
 prop:'revisions',
 rvprop:'content'
 })
 .done(function(result){
 config.pagedata.oldwikitext=result.query.pages[config.mw.wgArticleId].revisions[0]['*'];
 checkPageData();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 API.abort();
 varretry=confirm("Could not retrieve page wikitext:\n"+extraJs.makeErrorMsg(c,r)+"\n\nTry again?");
 if(retry){
 screen0();
 }else{
 $("#M2D-modal").remove();
 }
 });

 //TODO(?): also get proposed Draft: page (to check if it is empty or not)

 /* ---------- Redirects --------------------------------------------------------------------- */
 varredirectTitles=[];

 varprocessRedirectsQuery=function(result){
 if(!result.query||!result.query.pages){
 // No results
 config.pagedata.redirects=false;
 checkPageData();
 return;
 }
 // Gather redirect titles into array
 $.each(result.query.pages,function(_id,info){
 redirectTitles.push(info.title);
 });
 // Continue query if needed
 if(result.continue){
 doRedirectsQuery($.extend(redirectsQuery,result.continue));
 return;
 }

 // Check if redirects were found
 if(redirectTitles.length===0){
 config.pagedata.redirects=false;
 checkPageData();
 return;
 }

 // Set redirects
 config.pagedata.redirects=(redirectTitles.length===0)?false:redirectTitles;
 checkPageData();
 };

 varredirectsQuery={
 action:'query',
 pageids:config.mw.wgArticleId,
 generator:'redirects',
 grdlimit:500
 };
 vardoRedirectsQuery=function(q){
 API.get(q)
 .done(processRedirectsQuery)
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 API.abort();
 varretry=confirm("Could not retrieve redirects:\n"+extraJs.makeErrorMsg(c,r)+
 "\n\nTry again? (or Cancel to skip)");
 if(retry){
 screen0();
 }else{
 config.pagedata.redirects=false;
 checkPageData();
 }
 });
 };
 doRedirectsQuery(redirectsQuery);

 /* ---------- Review (Page Triage) status ----------------------------------------------------------------- */

 API.get({
 action:'pagetriagelist',
 page_id:config.mw.wgArticleId
 })
 .done(function(result){
 if(!result.pagetriagelist.pages.length){
 varkeepGoing=confirm('WARNING: Page has already been reviewed by a New Page Patroller. Are you sure you want to draftify this page?');
 if(!keepGoing){
 API.abort();
 $("#M2D-modal").remove();
 return;
 }
 }
 checkedPageTriageStatus=true;
 checkPageData();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 API.abort();
 varretry=confirm("Could not retrieve page wikitext:\n"+extraJs.makeErrorMsg(c,r)+"\n\nTry again?");
 if(retry){
 screen0();
 }else{
 $("#M2D-modal").remove();
 }
 });

 };

 //Move page
 varmovePage=function(){
 $("#M2D-task0").css({"color":"#00F","font-weight":"bold"});
 $("#M2D-status0").html("...");

 API.postWithToken('csrf',{
 action:'move',
 fromid:config.mw.wgArticleId,
 to:config.inputdata.newTitle,
 movetalk:1,
 noredirect:1,
 reason:config.inputdata.rationale+config.script.advert
 })
 .done(function(){
 if(
 -1===$.inArray('sysop',config.mw.wgUserGroups)&&
 -1===$.inArray('extendedmover',config.mw.wgUserGroups)
 ){
 // Newly created redirect to be tagged for speedy deletion
 tagRedrect();
 return;
 }
 $("#M2D-task0").css({"color":"#000","font-weight":""});
 $("#M2D-status0").html("Done!");
 getImageInfo();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not move page:\n"+extraJs.makeErrorMsg(c,r)+"\n\nTry again?");
 if(retry){
 movePage();
 }else{
 $("#M2D-modal").remove();
 }
 });
 };

 vartagRedrect=function(){
 $("#M2D-status0").html("Done,<br/>Tagging redirect for speedy deletion...");
 API.postWithToken('csrf',{
 action:'edit',
 title:config.mw.wgPageName,
 prependtext:'{{Db-r2}}\n',
 summary:'[[WP:R2|R2]] speedy deletion request (article moved to draftspace)'+config.script.advert
 })
 .done(function(){
 $("#M2D-task0").css({"color":"#000","font-weight":""});
 $("#M2D-status0").append(" Done!");
 getImageInfo();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not tag redirect for speedy deletion:\n"+
 extraJs.makeErrorMsg(c,r)+"\n\nTry again?");
 if(retry){
 tagRedrect();
 }else{
 $("#M2D-task0").css({"color":"#F00","font-weight":""});
 $("#M2D-status0").append(" Skipped");
 getImageInfo();
 }
 });
 };

 //Find which images are non-free
 vargetImageInfo=function(){
 $("#M2D-task1").css({"color":"#00F","font-weight":"bold"});
 $("#M2D-status1").html("...");

 processImageInfo=function(result){
 varnonfreefiles=[];
 if(result&&result.query){
 $.each(result.query.pages,function(id,page){
 if(id>0&&page.categories){
 nonfreefiles.push(page.title);
 }
 });
 }
 editWikitext(nonfreefiles);
 };

 API.get({
 action:'query',
 pageids:config.mw.wgArticleId,
 generator:'images',
 gimlimit:'max',
 prop:'categories',
 cllimit:'max',
 clcategories:'Category:All non-free media',
 })
 .done(function(result){
 $("#M2D-task1").css({"color":"#000","font-weight":""});
 $("#M2D-status1").html("Done!");
 processImageInfo(result);
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not find if there are non-free files:\n"+extraJs.makeErrorMsg(c,r)+"\n\n[Okay] to try again, or [Cancel] to skip");
 if(retry){
 getImageInfo();
 }else{
 $("#M2D-task1").css({"color":"#F00","font-weight":""});
 $("#M2D-status1").html("Skipped");
 editWikitext([]);
 }
 });

 };


 //Comment out non-free files, turn categories into links, add afc draft template, list any redirects
 vareditWikitext=function(nonfreefiles){
 $("#M2D-task2").css({"color":"#00F","font-weight":"bold"});
 $("#M2D-status2").html("...");

 varredirectsList=(!config.pagedata.redirects)?'':'\n'+
 '<!-- Note: The following pages were redirects to [['+config.mw.wgPageName+
 ']] before draftification:\n'+
 '*[['+config.pagedata.redirects.join(']]\n*[[')+']]\n-->\n';

 varwikitext="{{subst:AFC draft|"+config.inputdata.authorName+"}}\n"+redirectsList+
 config.pagedata.oldwikitext.replace(/\[\[\s*[Cc]ategory\s*:/g,"[[:Category:");

 // non-free files
 // (derived from [[WP:XFDC]] - https://en.wikipedia.org/wiki/User:Evad37/XFDcloser.js )
 if(nonfreefiles.length>0){
 // Start building regex strings
 normal_regex_str="(";
 gallery_regex_str="(";
 free_regex_str="(";
 for(vari=0;i<nonfreefiles.length;i++){
 // Take off namespace prefix
 filename=nonfreefiles[i].replace(/^.*?:/,"");
 // For regex matching: first character can be either upper or lower case, special
 // characters need to be escaped, spaces can be either spaces or underscores
 filename_regex_str="["+mw.RegExp.escape(filename.slice(0,1).toUpperCase())+
 mw.RegExp.escape(filename.slice(0,1).toLowerCase())+"]"+
 mw.RegExp.escape(filename.slice(1)).replace(/ /g,"[ _]");
 // Add to regex strings
 normal_regex_str+="\\[\\[\\s*(?:[Ii]mage|[Ff]ile)\\s*:\\s*"+filename_regex_str+
 "\\s*\\|?.*?(?:(?:\\[\\[.*?\\]\\]).*?)*\\]\\]";
 gallery_regex_str+="^\\s*(?:[Ii]mage|[Ff]ile):\\s*"+filename_regex_str+".*?$";
 free_regex_str+="\\|\\s*(?:[\\w\\s]+\\=)?\\s*(?:(?:[Ii]mage|[Ff]ile):\\s*)?"+
 filename_regex_str;

 if(i+1===nonfreefiles.length){
 normal_regex_str+=")(?![^<]*?-->)";
 gallery_regex_str+=")(?![^<]*?-->)";
 free_regex_str+=")(?![^<]*?-->)";
 }else{
 normal_regex_str+="|";
 gallery_regex_str+="|";
 free_regex_str+="|";
 }
 }

 // Check for normal file usage, i.e. [[File:Foobar.png|...]]
 varnormal_regex=newRegExp(normal_regex_str,"g");
 wikitext=wikitext.replace(normal_regex,"<!-- Commented out: 1ドル -->");

 // Check for gallery usage, i.e. instances that must start on a new line, eventually
 // preceded with some space, and must include File: or Image: prefix
 vargallery_regex=newRegExp(gallery_regex_str,"mg");
 wikitext=wikitext.replace(gallery_regex,"<!-- Commented out: 1ドル -->");

 // Check for free usages, for example as template argument, might have the File: or Image:
 // prefix excluded, but must be preceeded by an |
 varfree_regex=newRegExp(free_regex_str,"mg");
 wikitext=wikitext.replace(free_regex,"<!-- Commented out: 1ドル -->");
 }

 API.postWithToken('csrf',{
 action:'edit',
 pageid:config.mw.wgArticleId,
 text:wikitext,
 summary:config.wikitext.editsummary+config.script.advert
 })
 .done(function(){
 $("#M2D-task2").css({"color":"#000","font-weight":""});
 $("#M2D-status2").html("Done!");
 notifyAuthor();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not edit draft artice:\n"+extraJs.makeErrorMsg(c,r)+"\n\n[Okay] to try again, or [Cancel] to skip");
 if(retry){
 editWikitext(nonfreefiles);
 }else{
 $("#M2D-task2").css({"color":"#F00","font-weight":""});
 $("#M2D-status2").html("Skipped");
 notifyAuthor();
 }
 });

 };

 varnotifyAuthor=function(){
 $("#M2D-task3").css({"color":"#00F","font-weight":"bold"});
 $("#M2D-status3").html("...");

 API.postWithToken('csrf',{
 action:'edit',
 title:'User talk:'+config.inputdata.authorName,
 section:'new',
 sectiontitle:config.inputdata.notifyMsgHead,
 text:config.inputdata.notifyMsg,
 })
 .done(function(){
 $("#M2D-task3").css({"color":"#000","font-weight":""});
 $("#M2D-status3").html("Done!");
 updateTalk();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not edit author talk page:\n"+extraJs.makeErrorMsg(c,r)+"\n\n[Okay] to try again, or [Cancel] to skip");
 if(retry){
 notifyAuthor();
 }else{
 $("#M2D-task3").css({"color":"#F00","font-weight":""});
 $("#M2D-status3").html("Skipped");
 updateTalk();
 }
 });
 };

 varupdateTalk=function(){
 $("#M2D-task4").css({"color":"#00F","font-weight":"bold"});
 $("#M2D-status4").html("...");

 //if page exists, do a regex search/repace for class/importances parameters
 varprocessTalkWikitext=function(result){
 vartalk_id=result.query.pageids[0];
 if(talk_id<0){
 $("#M2D-task4").css({"color":"#000","font-weight":""});
 $("#M2D-status4").html("Done (talk page does not exist)");
 draftifyLog();
 return;
 }
 varold_talk_wikitext=result.query.pages[talk_id].revisions[0]['*'];
 varnew_talk_wikitext=old_talk_wikitext.replace(/(\|\s*(?:class|importance)\s*=\s*)[^\|}]*(?=[^}]*}})/g,"1ドル");
 if(new_talk_wikitext===old_talk_wikitext){
 $("#M2D-task4").css({"color":"#000","font-weight":""});
 $("#M2D-status4").html("Done (no changes needed)");
 draftifyLog();
 return;
 }

 API.postWithToken('csrf',{
 action:'edit',
 pageid:talk_id,
 section:'0',
 text:new_talk_wikitext,
 summary:'Remove class/importance from project banners'+config.script.advert
 })
 .done(function(){
 $("#M2D-task4").css({"color":"#000","font-weight":""});
 $("#M2D-status4").html("Done!");
 draftifyLog();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not edit draft's talk page:\n"+extraJs.makeErrorMsg(c,r)+"\n\n[Okay] to try again, or [Cancel] to skip");
 if(retry){
 updateTalk();
 }else{
 $("#M2D-task4").css({"color":"#F00","font-weight":""});
 $("#M2D-status4").html("Skipped");
 draftifyLog();
 }
 });

 };

 //get talk page wikitext (section 0)
 API.get({
 action:'query',
 titles:config.inputdata.newTitle.replace("Draft:","Draft talk:"),
 prop:'revisions',
 rvprop:'content',
 rvsection:'0',
 indexpageids:1
 })
 .done(processTalkWikitext)
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not find draft's talk page:\n"+extraJs.makeErrorMsg(c,r)+"\n\n[Okay] to try again, or [Cancel] to skip");
 if(retry){
 updateTalk();
 }else{
 $("#M2D-task4").css({"color":"#F00","font-weight":""});
 $("#M2D-status4").html("Skipped");
 draftifyLog();
 }
 });

 };

 vardraftifyLog=function(){
 $("#M2D-task5").css({"color":"#00F","font-weight":"bold"});
 $("#M2D-status5").html("...");

 varlogpage='User:'+config.mw.wgUserName+'/Draftify_log';
 varmonthNames=config.mw.wgMonthNames.slice(1);
 varnow=newDate();
 varheading='== '+monthNames[now.getUTCMonth()]+' '+now.getUTCFullYear()+' ==';
 varheadingPatt=RegExp(heading);

 varprocessLogWikitext=function(result){
 varlogpage_wikitext='';

 varid=result.query.pageids[0];
 if(id<0){
 varcreatelog=confirm('Log draftification (at '+logpage+') ?');
 if(!createlog){
 $("#M2D-task5").css({"color":"#F00","font-weight":""});
 $("#M2D-status5").empty().append("Skipped");
 $("#M2D-finished, #M2D-abort").toggle();
 return;
 }
 logpage_wikitext='This is a log of pages moved to draftspace using the [[User:Evad37/MoveToDraft|MoveToDraft]] script.';
 }else{
 logpage_wikitext=result.query.pages[id].revisions[0]['*'].trim();
 }

 if(!headingPatt.test(logpage_wikitext)){
 logpage_wikitext+='\n\n'+heading;
 }
 logpage_wikitext+='\n'+config.inputdata.logMsg;

 API.postWithToken('csrf',{
 action:'edit',
 title:logpage,
 text:logpage_wikitext,
 summary:'Logging [['+config.inputdata.newTitle+']]'+config.script.advert
 })
 .done(function(){
 $("#M2D-task5").css({"color":"#000","font-weight":""});
 $("#M2D-status5").html("Done!");
 $("#M2D-finished, #M2D-abort").toggle();
 })
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not edit log page:\n"+extraJs.makeErrorMsg(c,r)+"\n\n[Okay] to try again, or [Cancel] to skip");
 if(retry){
 draftifyLog();
 }else{
 $("#M2D-task5").css({"color":"#F00","font-weight":""});
 $("#M2D-status5").html("Skipped");
 $("#M2D-finished, #M2D-abort").toggle();
 }
 });
 };

 //get log page wikitext
 API.get({
 action:'query',
 titles:logpage,
 prop:'revisions',
 rvprop:'content',
 indexpageids:1
 })
 .done(processLogWikitext)
 .fail(function(c,r){
 if(r.textStatus==='abort'){return;}

 varretry=confirm("Could not find log page:\n"+extraJs.makeErrorMsg(c,r)+"\n\n[Okay] to try again, or [Cancel] to skip");
 if(retry){
 draftifyLog();
 }else{
 $("#M2D-task5").css({"color":"#F00","font-weight":""});
 $("#M2D-status5").html("Skipped");
 $("#M2D-finished, #M2D-abort").toggle();
 }
 });
 };

 // --- Interface screens ---
 //0) Initial screen
 varscreen0=function(){
 $("#M2D-interface-header, #M2D-interface-content, #M2D-interface-footer").empty();
 $("#M2D-interface-header").text("Move To Draft...");
 $("#M2D-interface-content").text("Loading...");
 grabPageData();
 };

 //1) User inputs
 varscreen1=function(){
 $("#M2D-interface-header, #M2D-interface-content, #M2D-interface-footer").empty();
 $("#M2D-interface-header").text("Move To Draft: options");

 $("#M2D-interface-content").append(
 $('<div>').css('margin-bottom','0.5em').append(
 $('<label>').attr('for','M2D-option-newtitle').append(
 'Move to ',
 $('<b>').text('Draft:')
 ),
 $('<input>').attr({'type':'text','name':'M2D-option-newtitle','id':'M2D-option-newtitle'})
 ),

 $('<div>').css('margin-bottom','0.5em').append(
 $('<label>').attr({'for':'M2D-option-movelog','id':'M2D-option-movelog-label'})
 .css('display','block').text('Move log reason:'),
 $('<textarea>').attr({'rows':'1','name':'M2D-option-movelog','id':'M2D-option-movelog'})
 .css('width','99%')
 ),

 $('<div>').css('margin-bottom','0.5em').append(
 $('<label>').attr({'for':'M2D-option-author','id':'M2D-option-author-label'}).text('Author:'),
 $('<input>').attr({'type':'text','name':'M2D-option-author','id':'M2D-option-author'})
 ),

 $('<label>').attr({'for':'M2D-option-message-head','id':'M2D-option-message-head-label'})
 .css('display','block').text('Notification heading'),
 $('<textarea>').attr({'id':'M2D-option-message-head','rows':'1'})
 .css({'width':'99%','margin-bottom':'0.5em'}),
 $('<label>').attr({'for':'M2D-option-message','id':'M2D-option-message-label'})
 .css('display','block').text('Notification message:'),
 $('<textarea>').attr({'id':'M2D-option-message','rows':'6'})
 .css('width','99%')
 );

 $('#M2D-option-movelog').val(config.wikitext.rationale);
 $('#M2D-option-newtitle').val(getPageText(config.mw.wgPageName)).change(function(){
 $('#M2D-option-message-head').val(
 $('#M2D-option-message-head').val().trim()
 .replace(/\[\[Draft\:.*?\|/,"[[Draft:"+$('#M2D-option-newtitle').val().trim()+"|")
 );
 $('#M2D-option-message').val(
 $('#M2D-option-message').val().trim()
 .replace(/\[\[Draft\:.*?\|/,"[[Draft:"+$('#M2D-option-newtitle').val().trim()+"|")
 );
 });
 $('#M2D-option-author').val(config.pagedata.author);
 $('#M2D-option-message-head').val(config.wikitext.notification_heading.replace(/\1ドル/g,getPageText(config.mw.wgPageName)));
 $('#M2D-option-message').val(config.wikitext.notification.replace(/\1ドル/g,getPageText(config.mw.wgPageName)));

 $("#M2D-interface-footer").append(
 $('<button>').attr('id','M2D-next').text('Continue'),
 $('<button>').attr('id','M2D-cancel').css('margin-left','3em').text('Cancel')
 );

 $("#M2D-cancel").click(function(){
 $("#M2D-modal").remove();
 });


 $("#M2D-next").click(function(){
 //Gather inputs
 config.inputdata={
 rationale:$('#M2D-option-movelog').val().trim(),
 newTitle:"Draft:"+$('#M2D-option-newtitle').val().trim(),
 authorName:$('#M2D-option-author').val().trim(),
 notifyMsgHead:$('#M2D-option-message-head').val().trim(),
 notifyMsg:$('#M2D-option-message').val().trim()
 };
 config.inputdata.logMsg=config.wikitext.logMsg
 .replace(/\1ドル/g,getPageText(config.mw.wgPageName))
 .replace(/\2ドル/g,config.inputdata.newTitle);

 //Verify inputs
 varerrors=[];
 if(config.inputdata.newTitle.length===0){
 errors.push("Invalid draft title");
 }
 if(config.inputdata.authorName.length===0){
 errors.push("Invalid user name");
 }
 if(config.inputdata.rationale.length===0){
 errors.push("Move log reason is empty");
 }
 if(config.inputdata.notifyMsgHead.length===0){
 errors.push("Notification heading is empty");
 }
 if(config.inputdata.notifyMsg.length===0){
 errors.push("Notification message is empty");
 }
 if(errors.length>=1){
 alert("Error:\n\n"+errors.join(";\n"));
 return;
 }

 //start process off
 screen2();
 });

 };

 //2) Progress indicators	
 varscreen2=function(){
 $("#M2D-interface-header, #M2D-interface-content, #M2D-interface-footer").empty();
 $("#M2D-interface-header").text("Move To Draft: In progress...");
 $("#M2D-interface-content").append(
 $('<ul>').attr('id','M2D-tasks').css("color","#888").append(
 $('<li>').attr('id','M2D-task0').append(
 'Moving page... ',
 $('<span>').attr('id','M2D-status0').text('waiting')
 ),
 $('<li>').attr('id','M2D-task1').append(
 'Checking images... ',
 $('<span>').attr('id','M2D-status1').text('waiting')
 ),
 $('<li>').attr('id','M2D-task2').append(
 'Editing page wikitext... ',
 $('<span>').attr('id','M2D-status2').text('waiting')
 ),
 $('<li>').attr('id','M2D-task3').append(
 'Notifying author... ',
 $('<span>').attr('id','M2D-status3').text('waiting')
 ),
 $('<li>').attr('id','M2D-task4').append(
 'Updating talk page banners... ',
 $('<span>').attr('id','M2D-status4').text('waiting')
 ),
 $('<li>').attr('id','M2D-task5').append(
 'Logging... ',
 $('<span>').attr('id','M2D-status5').text('waiting')
 )
 )
 );

 $("#M2D-interface-footer").append(
 $('<button>').attr('id','M2D-abort').text('Abort uncompleted tasks'),
 $('<span>').attr('id','M2D-finished').hide().append(
 'Finished!',
 $('<button>').attr('id','M2D-close').text('Close')
 )
 );

 $("#M2D-close").click(function(){
 $("#M2D-modal").remove();
 window.location.reload();
 });
 $("M2D-abort").click(function(){
 API.abort();
 $("#M2D-modal").remove();
 window.location.reload();
 });

 //Start task 0. The rest are done sequentially as each task is completed (or skipped).
 movePage();
 };

 // --- Add link to 'More' menu (or user-specified portlet) which starts everything ---
 mw.util.addPortletLink((window.m2d_portlet||'p-cactions'),'#','Move to draft','ca-m2d',null,null,"#ca-move");
 $('#ca-m2d').on('click',function(e){
 e.preventDefault();
 // Add interface shell
 $('body').prepend('<div id="M2D-modal">'+
 '<div id="M2D-interface">'+
 '<h4 id="M2D-interface-header"></h4>'+
 '<hr>'+
 '<div id="M2D-interface-content"></div>'+
 '<hr>'+
 '<div id="M2D-interface-footer"></div>'+
 '</div>'+
 '</div>');

 // Interface styling
 $("#M2D-modal").css({
 "position":"fixed",
 "z-index":"1",
 "left":"0",
 "top":"0",
 "width":"100%",
 "height":"100%",
 "overflow":"auto",
 "background-color":"rgba(0,0,0,0.4)"
 });
 $("#M2D-interface").css({
 "background-color":"#f0f0f0",
 "margin":"15% auto",
 "padding":"2px 20px",
 "border":"1px solid #888",
 "width":"80%",
 "max-width":"60em",
 "font-size":"90%"
 });
 $("#M2D-interface-content").css("min-height","7em");
 $("#M2D-interface-footor").css("min-height","3em");

 // Initial interface content
 screen0();
 });


 // End of function moveToDraft
 };

 /* ========== Setup ============================================================================= */
 // Only operate for existing pages
 if(mw.config.get('wgCurRevisionId')===0){
 return;
 }
 /* 
 // Load Morebits gadget if not already available
 if ( window.Morebits == null ) {
 	importScript('MediaWiki:Gadget-morebits.js');
 	importStylesheet( 'MediaWiki:Gadget-morebits.css' );
 }
 */
 // Load extra.js if not already available
 if(window.extraJs==null){
 importScript('User:Evad37/extra.js');
 }
 // Load resource loader modules
 mw.loader.using(['mediawiki.util','mediawiki.api','mediawiki.Title','mediawiki.RegExp'],moveToDraft());


 });
 // </nowiki>

AltStyle によって変換されたページ (->オリジナル) /