<commit_before>//__NOWYSIWYG__ <source lang="javascript">
//<nowiki>
/**
*
* Description:
* Updates file links in use on the wiki when image is renamed.
*
* @Author Foodbandlt
*
**/

// Options processing

if (typeof LIRoptions !== "undefined"){
	if (typeof (LIRoptions.bottomMessage) === "undefined"){
		LIRoptions.bottomMessage = "";
	}
	
	if (typeof LIRoptions.editSummary === "undefined"){
		LIRoptions.editSummary = "Updating file links (automatic)";
	}

	if (typeof LIRoptions.singleButtonText !== "undefined"){
		if (LIRoptions.singleButtonText === ""){
			LIRoptions.singleButtonText = "Rename and replace";
		}
	}else{
		LIRoptions.singleButtonText = "Rename and replace";
	}
	
	if (typeof LIRoptions.queueButtonText !== "undefined"){
		if (LIRoptions.queueButtonText === "" || LIRoptions.queueButtonText === "Rename and add to queue"){
			LIRoptions.queueButtonText = "Add to queue";
		}
	}else{
		LIRoptions.queueButtonText = "Add to queue";
	}
}else{		
	LIRoptions = {
		bottomMessage: "",
		editSummary: 'Updating file links (automatic)',
		singleButtonText: 'Rename and replace',
		queueButtonText: 'Add to queue'
	};
}
	
if (typeof LIR === "undefined"){

	if (typeof localStorage.LIRQueuedUpdates === "undefined"){
		localStorage.LIRQueuedUpdates = 0;
		localStorage.LIRQueuedUpdatesPos = 1;
	}
	
	if (typeof localStorage[wgUserName + "_LIRNamespaceSelection"] === "undefined"){
		localStorage[wgUserName + "_LIRNamespaceSelection"] = "";
	}

	LIR = {
		started: false,
		
		updateStatus: function(gifDisplay, message){
			if ($("#queueStatus").length == 0) return false;
		
			if (typeof gifDisplay === "string"){
				message = gifDisplay;
			}else if (typeof gifDisplay === "boolean"){
				if (gifDisplay == false){
					displayValue = "none";
				}else{
					displayValue = "inline-block";
				}
				document.getElementById("liveLoader").style.display = displayValue;
			}else{
				return false;
			}
			
			if (typeof message === "string"){
				$("#queueStatus").html(" " + message);
			}
			return true;
		},
		
		start: function(type){
			if (!Storage){
				return false;
			}
			
			/* Checks if function has already started */
			if (LIR.started == true && typeof LIR.queuePosition === "undefined"){
				return false;
			}
			
			/* Checks whether renaming single image or adding to queue */
			if (typeof(type) !== "undefined"){
				if (type == "single"){
					LIR.started = true;
					LIR.updateStatus(true, "Processing");
					LIR.type = "single";
				}else if (type == "multi"){
					LIR.started = true;
					
					if (typeof LIR.queuePosition === "undefined"){
						LIR.queuePosition = ++localStorage.LIRQueuedUpdates;
						LIR.updateStatus(true);
					}
					
					if (LIR.queuePosition != localStorage.LIRQueuedUpdatesPos){
						LIR.updateStatus("Number " + (LIR.queuePosition - localStorage.LIRQueuedUpdatesPos) + " on wait list to add to queue");
						setTimeout(function(){LIR.start(type);}, 500);
						return false;
					}
					
					LIR.updateStatus("Processing");
					LIR.type = "multi";
				}else{
					if (console) console.log("Incorrect type specified");
					return false;
				}
			}else{
				LIR.started = true;
				LIR.updateStatus(true, "Processing");
				LIR.type = "single";
			}
			
			/* Retrieves queue, or resets variables if doesn't exist */
			if (typeof (localStorage[wgUserName + "_LIRQueueData"]) !== "undefined"){
				LIR.queueData = JSON.parse(localStorage[wgUserName + "_LIRQueueData"]);
			}else{
				LIR.queueData = [];
			}

			/* Sets variables used by the function */
			var oldImageName = $('input[name="wpOldTitle"]').val().slice(5),
				newImageName = document.getElementById("wpNewTitleMain").value,
				reason = $("#wpReason").val();
			LIR.pageKey = [];
			
			/* Checks if old or new file name is currently part of the queue */
			for (i=0; i<LIR.queueData.length; i++){
				if (LIR.queueData[i].newImage == oldImageName || LIR.queueData[i].newImage == newImageName || LIR.queueData[i].oldImage == oldImageName){
					LIR.started = false;
					if (typeof LIR.queuePosition !== "undefined"){
						localStorage.LIRQueuedUpdatesPos++;
						delete LIR.queuePosition;
					}
					LIR.updateStatus(false, "File already added to queue, or destination name is already queued to be used.");
					return false;
				}
			}
			
			/* Checks if destination file name is the same as file being renamed (since Wikia's server-sided code usually validates this) */
			if (oldImageName.lastIndexOf(".") == oldImageName.length-4 && oldImageName.slice(oldImageName.length-4) != newImageName.slice(newImageName.length-4)){
				LIR.started = false;
				if (typeof LIR.queuePosition !== "undefined"){
					localStorage.LIRQueuedUpdatesPos++;
					delete LIR.queuePosition;
				}
				LIR.updateStatus(false, "Invalid file extension");
				return false;
			}
			
			if (localStorage[wgUserName + "_LIRNamespaceSelection"] == false){
				var namespaceSelection = "&blnamespace=0";
			}else{
				var namespaceSelection = "";
			}
			
			/* Check if destination file name is in use */<commit_msg>Filename extension error<commit_after>//__NOWYSIWYG__ <source lang="javascript">
//<nowiki>
/**
*
* Description:
* Updates file links in use on the wiki when image is renamed.
*
* @Author Foodbandlt
*
**/

// Options processing

if (typeof LIRoptions !== "undefined"){
	if (typeof (LIRoptions.bottomMessage) === "undefined"){
		LIRoptions.bottomMessage = "";
	}
	
	if (typeof LIRoptions.editSummary === "undefined"){
		LIRoptions.editSummary = "Updating file links (automatic)";
	}

	if (typeof LIRoptions.singleButtonText !== "undefined"){
		if (LIRoptions.singleButtonText === ""){
			LIRoptions.singleButtonText = "Rename and replace";
		}
	}else{
		LIRoptions.singleButtonText = "Rename and replace";
	}
	
	if (typeof LIRoptions.queueButtonText !== "undefined"){
		if (LIRoptions.queueButtonText === "" || LIRoptions.queueButtonText === "Rename and add to queue"){
			LIRoptions.queueButtonText = "Add to queue";
		}
	}else{
		LIRoptions.queueButtonText = "Add to queue";
	}
}else{		
	LIRoptions = {
		bottomMessage: "",
		editSummary: 'Updating file links (automatic)',
		singleButtonText: 'Rename and replace',
		queueButtonText: 'Add to queue'
	};
}
	
if (typeof LIR === "undefined"){

	if (typeof localStorage.LIRQueuedUpdates === "undefined"){
		localStorage.LIRQueuedUpdates = 0;
		localStorage.LIRQueuedUpdatesPos = 1;
	}
	
	if (typeof localStorage[wgUserName + "_LIRNamespaceSelection"] === "undefined"){
		localStorage[wgUserName + "_LIRNamespaceSelection"] = "";
	}

	LIR = {
		started: false,
		
		updateStatus: function(gifDisplay, message){
			if ($("#queueStatus").length == 0) return false;
		
			if (typeof gifDisplay === "string"){
				message = gifDisplay;
			}else if (typeof gifDisplay === "boolean"){
				if (gifDisplay == false){
					displayValue = "none";
				}else{
					displayValue = "inline-block";
				}
				document.getElementById("liveLoader").style.display = displayValue;
			}else{
				return false;
			}
			
			if (typeof message === "string"){
				$("#queueStatus").html(" " + message);
			}
			return true;
		},
		
		start: function(type){
			if (!Storage){
				return false;
			}
			
			/* Checks if function has already started */
			if (LIR.started == true && typeof LIR.queuePosition === "undefined"){
				return false;
			}
			
			/* Checks whether renaming single image or adding to queue */
			if (typeof(type) !== "undefined"){
				if (type == "single"){
					LIR.started = true;
					LIR.updateStatus(true, "Processing");
					LIR.type = "single";
				}else if (type == "multi"){
					LIR.started = true;
					
					if (typeof LIR.queuePosition === "undefined"){
						LIR.queuePosition = ++localStorage.LIRQueuedUpdates;
						LIR.updateStatus(true);
					}
					
					if (LIR.queuePosition != localStorage.LIRQueuedUpdatesPos){
						LIR.updateStatus("Number " + (LIR.queuePosition - localStorage.LIRQueuedUpdatesPos) + " on wait list to add to queue");
						setTimeout(function(){LIR.start(type);}, 500);
						return false;
					}
					
					LIR.updateStatus("Processing");
					LIR.type = "multi";
				}else{
					if (console) console.log("Incorrect type specified");
					return false;
				}
			}else{
				LIR.started = true;
				LIR.updateStatus(true, "Processing");
				LIR.type = "single";
			}
			
			/* Retrieves queue, or resets variables if doesn't exist */
			if (typeof (localStorage[wgUserName + "_LIRQueueData"]) !== "undefined"){
				LIR.queueData = JSON.parse(localStorage[wgUserName + "_LIRQueueData"]);
			}else{
				LIR.queueData = [];
			}

			/* Sets variables used by the function */
			var oldImageName = $('input[name="wpOldTitle"]').val().slice(5),
				newImageName = document.getElementById("wpNewTitleMain").value,
				reason = $("#wpReason").val();
			LIR.pageKey = [];
			
			/* Checks if old or new file name is currently part of the queue */
			for (i=0; i<LIR.queueData.length; i++){
				if (LIR.queueData[i].newImage == oldImageName || LIR.queueData[i].newImage == newImageName || LIR.queueData[i].oldImage == oldImageName){
					LIR.started = false;
					if (typeof LIR.queuePosition !== "undefined"){
						localStorage.LIRQueuedUpdatesPos++;
						delete LIR.queuePosition;
					}
					LIR.updateStatus(false, "File already added to queue, or destination name is already queued to be used.");
					return false;
				}
			}
			
			/* Checks if destination file name is the same as file being renamed (since Wikia's server-sided code usually validates this) */
			if (oldImageName.lastIndexOf(".") == oldImageName.length-4 && oldImageName.slice(oldImageName.length-4).toLowerCase() != newImageName.slice(newImageName.length-4).toLowerCase()){
				LIR.started = false;
				if (typeof LIR.queuePosition !== "undefined"){
					localStorage.LIRQueuedUpdatesPos++;
					delete LIR.queuePosition;
				}
				LIR.updateStatus(false, "Invalid file extension");
				return false;
			}
			
			if (localStorage[wgUserName + "_LIRNamespaceSelection"] == false){
				var namespaceSelection = "&blnamespace=0";
			}else{
				var namespaceSelection = "";
			}
			
			/* Check if destination file name is in use */
{'fraction_non_alphanumeric': 0.14512785072563925, 'fraction_numerical': 0.0023694342975614574, 'mean_word_length': 3.47635881573133, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5973844', 'n_tokens_mistral': 3934, 'n_tokens_neox': 3137, 'n_words': 764}