משתמש:Guycn2/rollbackSummary.js – הבדלי גרסאות

מתוך ויקיפדיה, האנציקלופדיה החופשית
תוכן שנמחק תוכן שנוסף
אין תקציר עריכה
אין תקציר עריכה
שורה 45: שורה 45:
function addSummaryLinks(content) {
function addSummaryLinks(content) {
console.log(content);
$(".mw-rollback-link", content).append(
$(".mw-rollback-link", content).append(
" | ",
" | ",

גרסה מ־21:14, 23 באוקטובר 2020

mw.loader.using(["oojs-ui-windows", "mediawiki.util", "mediawiki.user"], function() {
	
	"use strict";
	
	function i18n(key) {
		switch (mw.config.get("wgUserLanguage")) {
			case "he":
				switch (key) {
					case "summaryLinkTooltip":
						return "שחזור מהיר עם תקציר";
					case "summaryLinkText":
						return "תקציר";
					case "dialogText":
						return "נא להזין תקציר לשחזור:";
					case "notPerformed":
						return "השחזור לא בוצע";
					case "noRollbackUrl":
						return "כתוצאה משגיאה בלתי צפויה, לא ניתן היה לאתר את כתובת השחזור.";
					case "noSummary":
						return "לא הוזן תקציר.";
					case "actionCancelled":
						return "הפעולה בוטלה.";
				}
				break;
			default:
				switch (key) {
					case "summaryLinkTooltip":
						return "Rollback with summary";
					case "summaryLinkText":
						return "summary";
					case "dialogText":
						return "Please enter rollback summary:";
					case "notPerformed":
						return "Rollback was not performed";
					case "noRollbackUrl":
						return "Due to an unexpected error, the rollback URL could not be detected.";
					case "noSummary":
						return "No summary was entered.";
					case "actionCancelled":
						return "Action was cancelled.";
				}
		}
		return key;
	}
	
	function addSummaryLinks(content) {
		console.log(content);
		$(".mw-rollback-link", content).append(
			" | ",
			$("<a>", {
				"class": "rollback-summary-link",
				role: "button",
				href: "#",
				title: i18n("summaryLinkTooltip"),
				text: i18n("summaryLinkText"),
				click: rollbackWithSummary
			})
		);
	}
	
	function rollbackWithSummary(event) {
		event.preventDefault();
		var $summaryLink = $(event.target);
		var rollbackUrl = $summaryLink
							.siblings("a:first[href*='&action=rollback']")
							.attr("href");
		if (typeof rollbackUrl === "undefined") {
			rollbackUrl = $summaryLink
							.siblings(".jquery-confirmable-wrapper")
							.find("a:first[href*='&action=rollback']")
							.attr("href");
			if (typeof rollbackUrl === "undefined") {
				mw.notify(i18n("noRollbackUrl"), {
					title: i18n("notPerformed"),
					type: "error"
				});
				return;
			}
		}
		OO.ui.prompt(i18n("dialogText")).done(function(summary) {
			if (summary) {
				window.location.assign(
					rollbackUrl + "&summary=" + encodeURIComponent(summary) +
					"&usingRollbackSummaryGadget=1"
				);
			} else if (summary === "") {
				mw.notify(i18n("noSummary"), {
					title: i18n("notPerformed")
				});
			} else {
				mw.notify(i18n("actionCancelled"), {
					title: i18n("notPerformed")
				});
			}
		});
	}
	
	function bypassRollbackConfirmation() {
		// This function bypasses the confirmation message that shows up when performing
		// rollbacks, if the user has the "showrollbackconfirmation" option enabled
		if (mw.util.getParamValue("usingRollbackSummaryGadget") === "1") {
			if (mw.user.options.get("showrollbackconfirmation") === "1") {
				$("button[type='submit']", mw.util.$content).eq(0).click();
			}
		}
	}
	
	mw.hook("wikipage.content").add(addSummaryLinks);
	
	if (mw.config.get("wgAction") === "rollback") {
		bypassRollbackConfirmation();
	}
	
});