מדיה ויקי:Gadget-rollBackSummary.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
(ניסוי)
(מספר שיפורים/תיקונים. פירוט בדף השיחה.)
שורה 3: שורה 3:
  * Written by [[:he:User:Yonidebest]] based on [[:en:User:Ilmari Karonen]]'s script.
  * Written by [[:he:User:Yonidebest]] based on [[:en:User:Ilmari Karonen]]'s script.
  * Translated to Hebrew by [[User:ברק שושני]]
  * Translated to Hebrew by [[User:ברק שושני]]
  * Rewritten by [[User:קיפודנחש]]
  * Rewritten by [[User:קיפודנחש]] and [[User:Guycn2]]
  *
  *
  */  
  */  
mw.hook( 'wikipage.content' ).add( function( content ) {
(function() {
var hist = mw.util.getParamValue( 'action' ) == 'history',
rollbackSummaryClass = 'rollback-summary-link';
"use strict";
if ($( '.' + rollbackSummaryClass ).length ) return;
$( 'span.mw-rollback-link', content )
function i18n(key) {
.append(' | ')
switch (mw.config.get("wgUserLanguage")) {
.append(
case "he":
$( '<a>', { href: '#', 'class': rollbackSummaryClass, title: 'שחזור מהיר עם תקציר', text: 'תקציר' })
switch (key) {
.click( function() {
case "summaryLinkTooltip":
var summary = $.trim( prompt( 'אנא הזינו תקציר לשחזור') || '' );
return "שחזור מהיר עם תקציר";
if ( summary )  
case "summaryLinkText":
$( this ).attr( 'href', $(this).siblings( 'a:first' ).attr( 'href' ) + '&summary=' + encodeURIComponent( summary ) );
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();
}
})();

גרסה מ־18:38, 23 באוקטובר 2020

/*
 * 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();
	}
	
})();