מדיה ויקי: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]] | ||
* | * | ||
*/ | */ | ||
(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(); | |||
} | |||
})(); |
גרסה מ־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();
}
})();