মিডিয়াউইকি:Gadget-Adiutor-BDM.js

লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।

  • ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
  • ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
  • অপেরা: Ctrl-F5 টিপুন।
/* Adiutor: Enhancing Wikipedia Editing Through a Comprehensive Set of Versatile Tools and Modules.
 * Author: Vikipolimer
 * Learn more at: https://meta.wikimedia.org/wiki/Adiutor
 * License: Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
<nowiki> */
var api = new mw.Api();
var mwConfig = mw.config.get(["skin", "wgAction", "wgArticleId", "wgPageName", "wgNamespaceNumber", "wgTitle", "wgUserGroups", "wgUserName", "wgUserEditCount", "wgUserRegistration", "wgCanonicalNamespace"]);
var wikiId = mw.config.get('wgWikiID');
var adiutorUserOptions = JSON.parse(mw.user.options.get('userjs-adiutor-' + wikiId));
var batchDeletionList = [];
var selectedOptions;
var selectedReason;
// Fetch JSON data containing speedy deletion reasons
api.get({
	action: 'query',
	prop: 'revisions',
	titles: 'MediaWiki:Gadget-Adiutor-CSD.json',
	rvprop: 'content',
	formatversion: 2
}).done(function(data) {
	// Extract speedy deletion reasons from the retrieved JSON data
	var content = data.query.pages[0].revisions[0].content;
	var jsonData = JSON.parse(content);
	var speedyDeletionReasons = jsonData.speedyDeletionReasons;
	var csdCategoryForBatchDeletion = jsonData.csdCategoryForBatchDeletion;
	var apiPostSummaryforTalkPage = jsonData.apiPostSummaryforTalkPage;
	// Fetch list of pages to be considered for batch deletion from a specific category
	api.get({
		action: 'query',
		list: 'categorymembers',
		cmtitle: csdCategoryForBatchDeletion,
		cmsort: 'timestamp',
		cmdir: 'desc',
		format: 'json'
	}).done(function(data) {
		// Process the retrieved pages and create CheckboxMultioptionWidgets for each
		var members = data.query.categorymembers;
		members.sort(function(a, b) {
			return a.title.localeCompare(b.title);
		});
		members.forEach(function(page) {
			batchDeletionList.push(new OO.ui.CheckboxMultioptionWidget({
				data: page.title,
				selected: false,
				label: new OO.ui.HtmlSnippet(page.title + '<a style="margin-left:10px" target="_blank" href="' + page.title + '">→ ' + mw.msg('see') + '</a>')
			}));
		});
		// Create a CheckboxMultiselectWidget to display the list of pages
		var multiselectInput = new OO.ui.CheckboxMultiselectWidget({
			items: batchDeletionList,
		});
		multiselectInput.$element.css({
			'margin-top': '10px'
		});
		// Create a "Select All" button to select all checkboxes at once
		var selectAllButton = new OO.ui.ButtonWidget({
			label: mw.msg('select-all'),
			flags: ['progressive']
		});
		// Create a "Clear Selection" button to clear all checkboxes at once
		var clearSelectionButton = new OO.ui.ButtonWidget({
			label: mw.msg('uncheck-selected')
		});
		// Event handler for the "Select All" button
		selectAllButton.on('click', function() {
			batchDeletionList.forEach(function(option) {
				option.setSelected(true);
			});
			printSelectedOptions();
		});
		// Event handler for the "Clear Selection" button
		clearSelectionButton.on('click', function() {
			batchDeletionList.forEach(function(option) {
				option.setSelected(false);
			});
			printSelectedOptions();
		});
		// Event handler for checkbox changes
		batchDeletionList.forEach(function(option) {
			option.on('change', function() {
				printSelectedOptions();
			});
		});
		// Function to update the selectedOptions array and clear console
		function printSelectedOptions() {
			selectedOptions = batchDeletionList.filter(function(option) {
				return option.isSelected();
			}).map(function(option) {
				return option.data;
			});
			console.clear();
		}
		// Define a class for the Batch Deletion Dialog
		function batchDeletionDialog(config) {
			batchDeletionDialog.super.call(this, config);
		}
		// Inherit from the ProcessDialog class
		OO.inheritClass(batchDeletionDialog, OO.ui.ProcessDialog);
		// Set the dialog's name and title
		batchDeletionDialog.static.name = 'batchDeletionDialog';
		batchDeletionDialog.static.title = mw.msg('batch-deletion');
		// Define the dialog's actions (Save and Cancel)
		batchDeletionDialog.static.actions = [{
			action: 'save',
			label: new OO.ui.deferMsg('confirm-action'),
			flags: ['primary', 'destructive']
		}, {
			label: new OO.ui.deferMsg('cancel'),
			flags: 'safe'
		}];
		// Initialize the dialog
		batchDeletionDialog.prototype.initialize = function() {
			batchDeletionDialog.super.prototype.initialize.apply(this, arguments);
			// Create a notice message for header
			var headerTitle = new OO.ui.MessageWidget({
				type: 'notice',
				inline: true,
				label: mw.msg('batch-deletion-warning')
			});
			headerTitle.$element.css({
				'margin-bottom': '20px',
				'font-weight': '300'
			});
			// Construct options for the speedy deletion reasons dropdown
			var dropdownOptions = [];
			speedyDeletionReasons.forEach(function(reasonGroup) {
				dropdownOptions.push({
					"optgroup": reasonGroup.name
				});
				reasonGroup.reasons.forEach(function(reason) {
					dropdownOptions.push({
						"data": reason.data,
						"label": reason.label
					});
				});
			});
			// Create a dropdown input for selecting deletion reasons
			var reasonDropdown = new OO.ui.DropdownInputWidget({
				options: dropdownOptions,
				icon: 'dropdown',
				value: null // Set the initial selected value to null
			});
			reasonDropdown.on('change', function(value) {
				selectedReason = value;
			});
			reasonDropdown.$element.css({
				'margin-top': '20px',
				'margin-bottom': '10px'
			});
			// Create an input field for additional rationale
			otherRationaleInput = new OO.ui.TextInputWidget({
				placeholder: mw.msg('other-reason'),
				value: '',
			});
			otherRationaleInput.$element.css({
				'margin-bottom': '20px',
			});
			// Create a layout for the "Select All" and "Clear Selection" buttons
			var buttonsLayout = new OO.ui.HorizontalLayout({
				items: [selectAllButton, clearSelectionButton]
			});
			var secondHeader = new OO.ui.FieldsetLayout({
				label: mw.msg('pages-to-be-deleted'),
				items: [buttonsLayout]
			});
			buttonsLayout.$element.css({
				'display': 'contents',
			});
			secondHeader.$element.css({
				'margin-bottom': '10px',
			});
			// Create the content layout for the dialog
			this.content = new OO.ui.PanelLayout({
				padded: true,
				expanded: false
			});
			this.content.$element.append(headerTitle.$element, reasonDropdown.$element, otherRationaleInput.$element, secondHeader.$element, multiselectInput.$element);
			this.$body.append(this.content.$element);
		};
		// Define the action process for the dialog
		batchDeletionDialog.prototype.getActionProcess = function(action) {
			var dialog = this;
			if(action) {
				return new OO.ui.Process(function() {
					var deletionSummary = '';
					if(selectedReason) {
						deletionSummary = selectedReason;
						if(otherRationaleInput.value) {
							deletionSummary += ' | ';
						}
					}
					if(otherRationaleInput.value) {
						deletionSummary += otherRationaleInput.value;
					}
					selectedOptions.forEach(function(pageTitle) {
						// Perform batch deletion for selected pages
						api.postWithToken('csrf', {
							action: 'delete',
							title: pageTitle,
							reason: deletionSummary,
							tags: 'Adiutor',
							format: 'json'
						}).done(function() {
							// Delete corresponding talk pages
							api.postWithToken('csrf', {
								action: 'delete',
								title: "Tartışma:" + pageTitle,
								reason: apiPostSummaryforTalkPage,
								tags: 'Adiutor',
								format: 'json'
							}).done(function() {});
							// Close the dialog and display success notification
							dialog.close({
								action: action
							});
							mw.notify(mw.msg('batch-deletion-success'), {
								title: mw.msg('operation-completed'),
								type: 'success'
							});
						});
					});
				});
			}
			return batchDeletionDialog.super.prototype.getActionProcess.call(this, action);
		};
		// Create an instance of WindowManager to manage dialog windows
		var windowManager = new OO.ui.WindowManager();
		$(document.body).append(windowManager.$element);
		// Create and open the Batch Deletion Dialog
		var dialog = new batchDeletionDialog();
		windowManager.addWindows([dialog]);
		windowManager.openWindow(dialog);
	});
});
/* </nowiki> */