לדלג לתוכן

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

מתוך צפונות ויקי
מאין תקציר עריכה
מ 84 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-rollBackSummary.js יובאו
 
(33 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 1: שורה 1:
/** Collapsible tables *********************************************************
/*
* 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]]
  *
  *
  * Description: Allows tables to be collapsed, showing only the header. See
  */
*              [[Wikipedia:NavFrame]].
(function() {
*  Maintainers: [[User:R. Koot]]
*/
"use strict";
 
var autoCollapse = 2;
function i18n(key) {
var collapseCaption = ( wgUserLanguage == "he" ) ? "הסתרה": "Hide";
switch (mw.config.get("wgUserLanguage")) {
var expandCaption = ( wgUserLanguage == "he" ) ? "הצגה" : "Show";
case "he":
 
switch (key) {
function collapseTable( tableIndex )
case "summaryLinkTooltip":
{
return "שחזור מהיר עם תקציר";
    var Button = document.getElementById( "collapseButton" + tableIndex );
case "summaryLinkText":
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
return "תקציר";
    var allRows = Table.getElementsByTagName( "tr" );  
case "dialogText":
 
return "נא להזין תקציר לשחזור:";
    if ( !Table || !Button || allRows.length == 0 ) {
case "notPerformed":
        return;
return "השחזור לא בוצע";
    }
case "noRollbackUrl":
 
return "כתוצאה משגיאה בלתי צפויה, לא ניתן היה לאתר את כתובת השחזור.";
    var Rows = allRows[0].parentNode.childNodes;
case "noSummary":
 
return "לא הוזן תקציר.";
    if ( Button.firstChild.data == collapseCaption ) {
case "actionCancelled":
        for ( var i = 1; i < Rows.length; i++ ) {
return "הפעולה בוטלה.";
            if ( Rows[i].nodeType == 1 ) {
}
                Rows[i].style.display = "none";
break;
            }
default:
        }
switch (key) {
        Button.firstChild.data = expandCaption;
case "summaryLinkTooltip":
    } else {
return "Rollback with summary";
        for ( var i = 1; i < Rows.length; i++ ) {
case "summaryLinkText":
            if ( Rows[i].nodeType == 1 ) {
return "summary";
                Rows[i].style.display = "";
case "dialogText":
            }
return "Please enter rollback summary:";
        }
case "notPerformed":
        Button.firstChild.data = collapseCaption;
return "Rollback was not performed";
    }
case "noRollbackUrl":
}
return "Due to an unexpected error, the rollback URL could not be detected.";
 
case "noSummary":
function createCollapseButtons()
return "No summary was entered.";
{
case "actionCancelled":
    var tableIndex = 0;
return "Action was cancelled.";
    var NavigationBoxes = new Object();
}
    var Tables = document.getElementsByTagName( "table" );
}
 
return key;
    for ( var i = 0; i < Tables.length; i++ ) {
}
        if ( Tables[i].className.indexOf("collapsible") != -1 ) {
            NavigationBoxes[ tableIndex ] = Tables[i];
function addSummaryLinks(content) {
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
$(".mw-rollback-link", content).append(
 
" | ",
            var Button    = document.createElement( "span" );
$("<a>", {
            var ButtonLink = document.createElement( "a" );
"class": "rollback-summary-link",
            var ButtonText = document.createTextNode( collapseCaption );
role: "button",
 
href: "#",
            Button.style.styleFloat = "left";
title: i18n("summaryLinkTooltip"),
            Button.style.cssFloat = "left";
text: i18n("summaryLinkText"),
            Button.style.fontWeight = "normal";
click: rollbackWithSummary
            Button.style.textAlign = "left";
})
            Button.style.width = "6em";
);
 
}
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
function rollbackWithSummary(event) {
            ButtonLink.appendChild( ButtonText );
event.preventDefault();
 
var $summaryLink = $(event.target);
            Button.appendChild( document.createTextNode( "[" ) );
var rollbackUrl = $summaryLink
            Button.appendChild( ButtonLink );
.siblings("a:first[href*='&action=rollback']")
            Button.appendChild( document.createTextNode( "]" ) );
.attr("href");
 
if (typeof rollbackUrl === "undefined") {
            var Header;
rollbackUrl = $summaryLink
            if (Tables[i].className.indexOf("otherrow") != -1)
.siblings(".jquery-confirmable-wrapper")
                Header = getElementsByClassName(Tables[i], "TD", "headerrow")[0];
.find("a:first[href*='&action=rollback']")
            else
.attr("href");
                Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
if (typeof rollbackUrl === "undefined") {
            /* only add button and increment count if there is a header row to work with */
mw.notify(i18n("noRollbackUrl"), {
            if (Header) {
title: i18n("notPerformed"),
                Header.insertBefore( Button, Header.childNodes[0] );
type: "error"
                tableIndex++;
});
            }
return;
        }
}
    }
}
 
OO.ui.prompt(i18n("dialogText")).done(function(summary) {
    for ( var i = 0; i < tableIndex; i++ ) {
if (summary) {
        if ( NavigationBoxes[i].className.indexOf("collapsed") != -1 || ( tableIndex >= autoCollapse && NavigationBoxes[i].className.indexOf("autocollapse") != -1 ) ) {
window.location.assign(
            collapseTable( i );
rollbackUrl + "&summary=" + encodeURIComponent(summary) +
        }
"&usingRollbackSummaryGadget=1"
    }
);
}
} else if (summary === "") {
 
mw.notify(i18n("noSummary"), {
addOnloadHook(createCollapseButtons);
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();
}
})();

גרסה אחרונה מ־13:10, 5 בדצמבר 2022

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