User:Xain36/Non-adminClosure.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. |
This user script seems to have a documentation page at User:Xain36/Non-adminClosure. |
// <syntaxhighlight lang="javascript">
// Non-admin Closure by [[User:Xain36]]
// 4.3.2019 v.1.0
// based on [[User:Armbrust/closemrv.js]] and [[User:Andy M. Wang/closeRM.js]]
// If forking this script, please give all of us credit
$(document).ready(function() {
"use strict";
// Add only when editing section
// Assumes Requested move has a level 2 header, ends at end of section
if ((document.title.indexOf("Editing ") === -1)
|| (document.title.indexOf("(section)") === -1)) {
return;
}
function rmClick(e) {
e.preventDefault();
var closeStr = prompt("The discussion may be closed 7 days after being opened, if consensus has been reached.\n"
+ "Closing statement/Result for requested move:");
if (closeStr === null || closeStr === '') {
alert("Aborted or canceled by the user.");
return;
}
var editform = document.editform, t = editform.wpTextbox1;
var lines = t.value.split('\n');
var inReqMoveTemplate = false;
var foundReqMoveTemplate = false;
var acc = '';
for (var idx in lines) {
if (lines[idx].toLowerCase().includes("{{requested move/dated")) {
acc += '{{subst:RM top|' + closeStr + " {{subst:RMnac}}}}";
inReqMoveTemplate = !lines[idx].includes("}}");
foundReqMoveTemplate = true;
} else if (foundReqMoveTemplate && inReqMoveTemplate) {
inReqMoveTemplate = !lines[idx].includes("}}");
} else {
acc += lines[idx] + '\n';
}
}
if (!foundReqMoveTemplate) {
alert("{{requested move/dated}} NOT FOUND. Wikitext not updated\n\n"
+ "Possible reasons:\n"
+ "1. This edited section is not a requested move discussion.\n"
+ "2. The discussion was alraedy closed by another editor.\n"
+ "What to do?:\n"
+ "1. Please reload the page and try again.\n"
+ "2. Check your Internet connection.\n"
+ "3. If somebody closed the discussion, then do not modify it. ");
return;
}
t.value = acc + "{{subst:" + "RM bottom" + "}}";
editform.wpSummary.value += "Closing a Requested move discussion: " + closeStr.replace(
/\{\{subst\:rmnac\}\}|\'\'\'/gi,'').substring(0, 140)
+ (closeStr.length > 140 ? ' ...' : '')
+ ' ([[User:Xain36/Non-adminClosure|Non-admin Closure]])';
}
mw.loader.using( 'mediawiki.util' ).then( function(){
var portletLink = mw.util.addPortletLink("p-cactions", "#", "Non-admin Closure",
"ca-rmclose", "Close a requested move discussion section");
$( portletLink ).click( rmClick );
} );
});
// </syntaxhighlight>