MediaWiki:Gadget-ConfirmRevert.js
Z Nonsensopedii, polskiej encyklopedii humoru
Uwaga: aby zobaczyć zmiany po zapisaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5 lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer: Przytrzymaj Ctrl jednocześnie klikając Odśwież lub naciśnij klawisze Ctrl+F5
- Konqueror: Kliknij polecenie Odśwież lub naciśnij klawisz F5
- Opera: Wyczyść pamięć podręczną w Narzędzia → Preferencje
// ConfirmRevert
// kod UI inspirowany gadżetem RollWithReason
// TODO: not works on middle (scroll) click - maybe this can be considered a feature? :P
// TODO: disable for specific time, not just until session end
var cookieString = "CRDisabled";
var ConfirmRevert = {};
ConfirmRevert.isEnabled = function()
{
var cookieIndex = document.cookie.indexOf(cookieString);
if (cookieIndex == -1)
{
return true;
}
else
{
return document.cookie.charAt(cookieIndex + String(cookieString).length + 1) == "0";
}
}
ConfirmRevert.disable = function()
{
document.cookie = cookieString + "=1";
}
ConfirmRevert.enable = function()
{
document.cookie = cookieString + "=0";
}
ConfirmRevert.init = function()
{
var lastClickedLink = "";
mw.loader.using(["oojs-ui-core", "oojs-ui-windows"], function()
{
function CRProcessDialog( config ) {
CRProcessDialog.super.call( this, config );
}
OO.inheritClass( CRProcessDialog, OO.ui.ProcessDialog );
CRProcessDialog.static.name = "CRProcessDialog";
CRProcessDialog.static.size = "medium";
CRProcessDialog.static.title = "Potwierdź rewert";
CRProcessDialog.static.actions =
[
{ action: "continue", label: "Zatwierdź", flags: ["progressive", "primary"] },
{ action: "cancel", label: "Anuluj", flags: "safe" },
]
var checkbox = new OO.ui.CheckboxInputWidget({ value: "enabled" });
checkbox.$element.on("click", function()
{
var selected = !checkbox.isSelected(); //if it will be selected after click event ends
if (selected)
{
ConfirmRevert.enable();
}
else
{
ConfirmRevert.disable();
}
});
CRProcessDialog.prototype.initialize = function ()
{
CRProcessDialog.super.prototype.initialize.apply( this, arguments );
this.panel = new OO.ui.PanelLayout
({
padded: true,
expanded: false
});
this.content = new OO.ui.FieldsetLayout({ label: "Potwierdź, że chcesz przeprowadzić rewert w artykule.", classes: ["CR-padding"] });
this.checkboxField = new OO.ui.FieldLayout(checkbox, { label: "Nie pytaj ponownie", align: "inline" });
this.content.addItems([ this.checkboxField ]);
this.panel.$element.append(this.content.$element);
this.$body.append( this.panel.$element );
};
CRProcessDialog.prototype.getActionProcess = function(action)
{
var dialog = this;
if (action == "continue")
{
return new OO.ui.Process ( function()
{
dialog.close();
document.location.href = lastClickedLink;
});
}
else if (action == "cancel")
{
return new OO.ui.Process ( function()
{
dialog.close();
});
}
}
CRProcessDialog.prototype.getSetupProcess = function(data)
{
return CRProcessDialog.super.prototype.getSetupProcess.call(this, data)
.next(function()
{
this.content.setLabel("Potwierdź, że chcesz przeprowadzić rewert w artykule " + data.artName + ".");
}, this);
};
var dialog = new CRProcessDialog();
var CRWindowManager = new OO.ui.WindowManager();
$(document.body).append(CRWindowManager.$element);
CRWindowManager.addWindows([dialog]);
$(".mw-rollback-link a[data-mw='interface']").click(function(event)
{
if (ConfirmRevert.isEnabled())
{
lastClickedLink = $(this).attr("href");
// ukradzione z MediaWiki:Gadget-RollWithReason.js
var n = $(this).attr('href').replace('/wiki/', '').replace('https://nonsa.pl', '');
n = decodeURIComponent(n.substring(0, n.indexOf("?"))).split("_").join(" ");
CRWindowManager.openWindow(dialog, { artName: n });
event.preventDefault();
}
})
});
}
$(ConfirmRevert.init);