מדיה ויקי:Gadget-rollBackSummary.js

מתוך ויקיטקסט, מאגר הטקסטים החופשי

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/*
 * Adds option to add summary to rollback revets.
 * Written by [[:he:User:Yonidebest]] based on [[:en:User:Ilmari Karonen]]'s script.
 * Translated to Hebrew by [[User:ברק שושני]]
 * Rewritten by [[User:קיפודנחש]] and [[User:Guycn2]]
 *
 */ 
(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) {
		$(".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();
	}
	
})();