_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:DannyS712 test/FWTH/PageMoverClosure.js

The User:DannyS712 test/FWTH/PageMoverClosure.js topic has been the subject of debate and controversy throughout history. From its origins to the present day, User:DannyS712 test/FWTH/PageMoverClosure.js has played a vital role in various aspects of society. In this article, we will explore different facets and perspectives on User:DannyS712 test/FWTH/PageMoverClosure.js, analyzing its impact on culture, politics, economics and other areas. Additionally, we will examine current trends related to User:DannyS712 test/FWTH/PageMoverClosure.js and its influence on the contemporary world. Through an exhaustive analysis, we aim to shed light on the importance and relevance of User:DannyS712 test/FWTH/PageMoverClosure.js in the current context, providing a comprehensive and updated vision on this very relevant topic.
// closeRM by ], modified as PageMoverClosure by ]
// Copied to User:DannyS712/PageMoverClosure.js after FWTH retired, who took over as maintainer
// Install with:
// <code><nowiki>		{{subst:Iusc|User:DannyS712/PageMoverClosure.js}}																</nowiki></code>
// or with
// <code><nowiki>		importScript( 'User:DannyS712/PageMoverClosure.js' ); // Backlink: ]		</nowiki></code> 
//
// If forking this script, please give all of us credit
//<nowiki>

$(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("Closing statement for requested move:");
		if (closeStr === null || closeStr === '') {
			alert("Invalid closing statement. Aborted.");
			return;
		}

		var editform = document.editform, t = editform.wpTextbox1;
		var lines = t.value.split('\n');
		var submitform = document.editform.submit();

		var inReqMoveTemplate = false;
		var foundReqMoveTemplate = false;
		var acc = '';
		for (var idx in lines) {
			if (lines.toLowerCase().includes("{{requested move/dated")) {
				acc += '{{subst' + ':RM top|' + closeStr + ' {{subst' + ':pnac}}}}';
				inReqMoveTemplate = !lines.includes("}}");
				foundReqMoveTemplate = true;
			} else if (foundReqMoveTemplate && inReqMoveTemplate) {
				inReqMoveTemplate = !lines.includes("}}");
			} else {
				acc += lines + '\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 answered by another editor earlier.");
			return;
		}

		t.value = acc + "{{subst:" + "RM bottom}}";
		editform.wpSummary.value += "Closing RM discussion" + " " + 'using ]';
		document.editform.submit();
	}
	
	mw.loader.using( 'mediawiki.util' ).then( function(){
		var portletLink = mw.util.addPortletLink("p-cactions", "#", "Close RM", "ca-rmclose", "Close a requested move discussion section");
		$( portletLink ).click( rmClick );
	} );
});
//</nowiki>