Użytkownik:Expert3222/quickPatrol.js: Różnice pomiędzy wersjami
Z Nondanych
m |
m |
||
(Nie pokazano 91 pośrednich wersji utworzonych przez tego samego użytkownika) | |||
Linia 5: | Linia 5: | ||
*/ |
*/ |
||
mw.loader.load('/wiki/Użytkownik:Expert3222/patrolModule.js?action=raw&ctype=text/javascript'); |
|||
// TODO: $(this) na $this (do zmiennej), lepsza wydajność będzie |
|||
var patrolSuccessCode = "<span style='color: green;' class='patrolButtonClicked'><img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> zrobione</span>"; |
|||
var spinnerCode = "<div class='mw-spinner mw-spinner-small mw-spinner-inline' title='...'></div>"; |
|||
var patrolFailureCode = "<span style='color: red;' class='patrolButtonClicked'><img src='https://nonsa.pl/images/a/a8/Przeciw.svg.png' width='15px' height='15px' /> błąd</span>"; |
|||
var tryAgainText = "spróbuj ponownie"; |
|||
var RCPatrolSuccessCode = "<img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='patrolButtonClicked'>zrobione</span>"; |
|||
var RCPatrolFailureCode = "<img src='https://nonsa.pl/images/a/a8/Przeciw.svg.png' width='15px' height='15px' /> <span style='color: red;' class='patrolButtonClicked'>błąd</span>"; |
|||
var RCMultiplePatrolSuccessCode = "<img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='multiplePatrolButtonClicked'>zrobione</span>"; |
|||
var RCMultiplePatrolFailureCode = "<img src='https://nonsa.pl/images/a/a8/Przeciw.svg.png' width='15px' height='15px' /> <span style='color: red;' class='multiplePatrolButtonClicked'>błąd</span>"; |
|||
$(document).ready(function() |
$(document).ready(function() |
||
{ |
{ |
||
mw.loader.using(["jquery.spinner", "mediawiki.notification"], function() |
|||
if (mw.config.get("wgCanonicalSpecialPageName") === "Recentchanges") |
|||
{ |
{ |
||
if (mw.config.get("wgCanonicalSpecialPageName") === "Recentchanges") |
|||
makePatrolLinks(); |
|||
/*if (!!$('.mw-rcfilters-enabled').length) //wzięte od Polskacafe z gadżetu RollWithReason |
|||
{ |
{ |
||
makePatrolLinks(); |
|||
if (!!$('.mw-rcfilters-enabled').length) //wzięte od Polskacafe z gadżetu RollWithReason |
|||
}*/ |
|||
{ |
|||
} |
|||
setInterval(makePatrolLinks, 2000); |
|||
else if (mw.config.get("wgCanonicalSpecialPageName") == "Newpages") |
|||
} |
|||
{ |
|||
} |
|||
makeNewpagesPatrolLinks(); |
|||
else if (mw.config.get("wgCanonicalSpecialPageName") == "Newpages") |
|||
} |
|||
{ |
|||
else if (mw.util.getParamValue("diff") !== null) |
|||
var $buttons = $(".patrollink-page a"); |
|||
{ |
|||
$buttons.click(function() |
|||
makeDiffPagePatrolButtons(); |
|||
{ |
|||
processPagePatrol($(this).parent()); |
|||
//setInterval(makeDiffPagePatrolButton, 2000); //"przeglądaj historię interaktywnie" na górze |
|||
}); |
|||
} |
|||
} |
|||
else if (mw.config.get("wgCanonicalSpecialPageName") == "MobileDiff") |
|||
else if (mw.util.getParamValue("diff") !== null) |
|||
{ |
|||
{ |
|||
makeDiffPagePatrolLinks(); |
|||
/*var oldid = mw.util.getParamValue("oldid", $("#mw-mf-diff-info a").attr("href")); |
|||
setInterval(makeDiffPagePatrolLinks, 2000); //"przeglądaj historię interaktywnie" na górze |
|||
alert("oldid = " + oldid); |
|||
} |
|||
var urlArray = window.location.href.split("/"); |
|||
else if ($(".patrollink").length > 0) //footer |
|||
{ |
|||
alert("curid = " + curid); |
|||
$(".patrollink-page a").off("click").click(function(event) //remove default click handler and attach our own |
|||
{ |
|||
var title = $("#mw-mf-diff-info a").text(); |
|||
event.preventDefault(); |
|||
makeDiffViewRevidsList(oldid, curid, title);*/ |
|||
event.stopImmediatePropagation(); |
|||
} |
|||
processPagePatrol($(this).parent()); |
|||
}); |
|||
} |
|||
else if (mw.config.get("wgCanonicalSpecialPageName") == "MobileDiff") |
|||
{ |
|||
//TODO |
|||
/*var oldid = mw.util.getParamValue("oldid", $("#mw-mf-diff-info a").attr("href")); |
|||
alert("oldid = " + oldid); |
|||
var urlArray = window.location.href.split("/"); |
|||
var curid = urlArray[urlArray.length - 1]; |
|||
alert("curid = " + curid); |
|||
var title = $("#mw-mf-diff-info a").text(); |
|||
makeDiffViewRevidsList(oldid, curid, title);*/ |
|||
} |
|||
}); |
|||
}); |
}); |
||
function makePatrolLinks() |
function makePatrolLinks() |
||
{ |
{ |
||
$(".patrollink- |
$(".patrollink-range a").each(function() |
||
{ |
{ |
||
$ |
var $link = $(this); |
||
if (!isEventBound($link)) |
|||
var lines = $tbody.find("tr"); |
|||
var firstLine = $(lines).first(); |
|||
if (lines.length >= 2 && $(firstLine).hasClass("mw-changeslist-reviewstatus-unpatrolled") && |
|||
$(firstLine).find(".patrollink-page a").length === 1 && $(firstLine).find(".multiplePatrolButtonClicked").length === 0) |
|||
{ |
{ |
||
var $tbody = getParentTag($link, "tbody"); |
|||
$(firstLine).find(".patrollink-page a").on("click", function() |
|||
$link.on("click", function() |
|||
{ |
{ |
||
processMultipleChangeRCPatrol($tbody); |
processMultipleChangeRCPatrol($tbody); |
||
Linia 67: | Linia 77: | ||
}); |
}); |
||
$(".patrollink-single a"). |
$(".patrollink-single a").each(function() |
||
{ |
{ |
||
var $button = $(this); |
|||
if (!isEventBound($button)) |
|||
processRCChangePatrol($(this).parent()); |
|||
{ |
|||
$button.on("click", function() |
|||
{ |
|||
processRCChangePatrol($(this).parent(), true); |
|||
}); |
|||
} |
|||
}); |
}); |
||
} |
} |
||
//helper function to process multiple change RC patrol, including spinner etc. |
|||
function makeNewpagesPatrolLinks() |
|||
function processMultipleChangeRCPatrol($tbody) |
|||
{ |
{ |
||
var $button = $tbody.find(".patrollink-range"), |
|||
$("li.not-patrolled").each(function() |
|||
$patrolLink = $button.find("a"), |
|||
$singlePatrolLinks = $tbody.find(".patrollink-single a"), |
|||
$spinner = $.createSpinner({ size: 'small', type: 'inline' }), |
|||
$patrolAgainBrackets = $patrolLink.parent().find(".patrolAgainBracket"); |
|||
$patrolLink.hide(); |
|||
$patrolAgainBrackets.hide(); |
|||
$patrolLink.after($spinner); |
|||
$patrolLink.parent().find(".patrolButtonClicked").remove(); |
|||
patrolModule.patrolRangeOfChanges($patrolLink.attr("data-revision-max")).done(function(data) |
|||
{ |
{ |
||
removeSpinner($button); |
|||
if (typeof $(this).find(".mw-newpages-oldtitle") == "undefined") |
|||
$patrolLink.after(patrolSuccessCode); |
|||
$patrolLink.remove(); |
|||
$patrolAgainBrackets.remove(); |
|||
var title = new mw.Title(data["fmod-patrol"].title); |
|||
mw.notify( mw.msg( 'markedaspatrollednotifymulti', title.toText() ) ); |
|||
//replace single buttons with success text |
|||
$singlePatrolLinks.replaceWith(patrolSuccessCode); |
|||
//remove patrol exclamation marks |
|||
$tbody.find("abbr.unpatrolled").replaceWith(" "); |
|||
}).fail(function() { |
|||
removeSpinner($button); |
|||
if ($patrolAgainBrackets.length === 0) |
|||
{ |
{ |
||
$patrolLink.before(patrolFailureCode); |
|||
var oldid = $(this).attr("data-mw-revid"); |
|||
$patrolLink.before("<span class='patrolAgainBracket'> (</span>"); |
|||
$(this).find("span.mw-newpages-history a").after(" • <span class='patrolButton' title='Oznacz tę stronę jako sprawdzoną' data-diff='" + oldid + "'><a>patrol</a></span>"); |
|||
$patrolLink.after("<span class='patrolAgainBracket'>)</span>"); |
|||
} |
} |
||
else |
else |
||
{ |
{ |
||
$patrolAgainBrackets.first().before(patrolFailureCode); |
|||
var api = new mw.Api(), |
|||
$patrolAgainBrackets.show(); |
|||
elem = $(this), |
|||
pageName = $(this).find(".mw-newpages-pagename").attr("title"); |
|||
api.post( |
|||
{ |
|||
action: 'query', |
|||
format: 'json', |
|||
formatversion: '2', |
|||
prop: 'revisions', |
|||
titles: pageName, |
|||
rvprop: 'ids', |
|||
rvlimit: '1', |
|||
rvdir: 'newer' |
|||
}).done(function(data) |
|||
{ |
|||
var oldid = data.query.pages[0].revisions[0].revid; |
|||
$(elem).find("span.mw-newpages-history a").after(" • <span class='patrolButton' title='Oznacz tę stronę jako sprawdzoną' data-diff='" + oldid + "'><a>patrol</a></span>"); |
|||
$(elem).find(".patrolButton").on("click", function() |
|||
{ |
|||
patrolChange(oldid, false, false); |
|||
}); |
|||
}).fail(function(error) |
|||
{ |
|||
console.log(error); |
|||
}); |
|||
} |
} |
||
$patrolLink.text(tryAgainText); |
|||
}); |
|||
$patrolLink.show(); |
|||
$(".patrolButton").on("click", function() |
|||
mw.notify( mw.msg( 'markedaspatrollederrornotify' ), { type: 'error' } ); |
|||
{ |
|||
resetLastClick(); |
|||
patrolChange($(this).attr("data-diff"), false, false); |
|||
}); |
}); |
||
} |
} |
||
//helper function to process |
//helper function to process one RC link including spinner etc. |
||
function |
function processRCChangePatrol($button) |
||
{ |
{ |
||
var |
var $patrolLink = $button.find("a"), |
||
revid = $patrolLink.attr("data-revision"), |
|||
failureCount = 0, |
|||
$spinner = $.createSpinner({ size: 'small', type: 'inline' }), |
|||
successCount = 0, |
|||
$patrolAgainBrackets = $button.find(".patrolAgainBracket"); |
|||
$buttons = $tbody.find(".patrollink-single"), |
|||
buttonsCount = buttons.length; |
|||
$patrolLink.hide(); |
|||
multiplePatrolButton.find("a").replaceWith(spinnerCode); |
|||
$patrolAgainBrackets.hide(); |
|||
$buttons.each(function() |
|||
$patrolLink.after($spinner); |
|||
$patrolLink.parent().find(".patrolButtonClicked").remove(); |
|||
patrolModule.resetLastClick(); |
|||
patrolModule.patrolChange(revid).done(function(data) |
|||
{ |
{ |
||
removeSpinner($button); |
|||
processRCChangePatrol($(this)) |
|||
.done(function() |
|||
$patrolLink.after(patrolSuccessCode); |
|||
$patrolLink.remove(); |
|||
$patrolAgainBrackets.remove(); |
|||
getParentTag($button, "tr").find("abbr.unpatrolled").replaceWith(" "); |
|||
var title = new mw.Title(data["fmod-patrol"].title); |
|||
mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) ); |
|||
}).fail(function() |
|||
{ |
|||
removeSpinner($button); |
|||
if ($patrolAgainBrackets.length === 0) |
|||
{ |
{ |
||
$patrolLink.before(patrolFailureCode); |
|||
++successCount; |
|||
$patrolLink.before("<span class='patrolAgainBracket'> (</span>"); |
|||
}).fail(function() |
|||
$patrolLink.after("<span class='patrolAgainBracket'>)</span>"); |
|||
{ |
|||
} |
|||
++failureCount; |
|||
else |
|||
}).always(function() |
|||
{ |
{ |
||
$patrolAgainBrackets.first().before(patrolFailureCode); |
|||
if (successCount == buttonsCount) //wszystkie wywołania AJAX do patrolowania zakończyły się pomyślnie |
|||
$patrolAgainBrackets.show(); |
|||
{ |
|||
} |
|||
deferred.resolve(successCount, failureCount); |
|||
$patrolLink.text(tryAgainText); |
|||
$patrolLink.show(); |
|||
multiplePatrolButton.find("a").replaceWith(RCMultiplePatrolSuccessCode); |
|||
$tbody.find("tr:first-child abbr.unpatrolled").replaceWith(" "); |
|||
mw.notify( mw.msg( 'markedaspatrollederrornotifychange' ), { type: 'error' } ); |
|||
} |
|||
else if (successCount + failureCount == buttonsCount) //wszystkie zakończyły się, niekoniecznie pomyślnie |
|||
{ |
|||
deferred.reject(successCount, failureCount); |
|||
multiplePatrolButton.find("a").replaceWith(RCMultiplePatrolFailureCode); |
|||
} |
|||
}); |
|||
}); |
}); |
||
/*if (buttonsCount == 0) |
|||
{ |
|||
multiplePatrolButton.replaceWith("<span><img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='multiplePatrolButtonClicked'>zrobione</span></span>"); |
|||
$tbody.find("tr:first-child abbr.unpatrolled").replaceWith(" "); |
|||
}*/ |
|||
return deferred.promise(); |
|||
} |
} |
||
function processPagePatrol($button) |
|||
//helper function to process one RC link including spinner etc. |
|||
function processRCChangePatrol($button) |
|||
{ |
{ |
||
//diff page, new pages and any new page on the bottom |
|||
var deferred = $.Deferred(); |
|||
var |
var pageid = $button.find("a").attr("data-pageid"), |
||
$patrolLink = $button.find("a"), |
|||
$spinner = $.createSpinner({ size: 'small', type: 'inline' }), |
|||
resetLastClick(); |
|||
$patrolAgainBrackets = $button.find(".patrolAgainBracket"); |
|||
patrolChange(revid).done(function() |
|||
$patrolLink.hide(); |
|||
$patrolAgainBrackets.hide(); |
|||
$patrolLink.after($spinner); |
|||
$patrolLink.parent().find(".patrolButtonClicked").remove(); |
|||
patrolModule.resetLastClick(); |
|||
patrolModule.patrolPage(pageid).done(function(data) |
|||
{ |
{ |
||
removeSpinner($button); |
|||
$button.find("div").replaceWith(RCPatrolSuccessCode); |
|||
goUpUntilTag($button, "tr").find("abbr.unpatrolled").replaceWith(" "); |
|||
$patrolLink.after(patrolSuccessCode); |
|||
deferred.resolve(); |
|||
$patrolLink.remove(); |
|||
$patrolAgainBrackets.remove(); |
|||
// if we are on diff page remove range patrol button, because we just patrolled all page revisions |
|||
$(".patrollink-range a").replaceWith(patrolSuccessCode); |
|||
//if we are on Special:Newpages change background to match patrolled |
|||
if (mw.config.get("wgCanonicalSpecialPageName") == "Newpages") |
|||
{ |
|||
getParentTag($button, "li").removeClass("not-patrolled"); |
|||
} |
|||
var title = new mw.Title(data["fmod-patrol"].title); |
|||
mw.notify( mw.msg( 'markedaspatrollednotifypage', title.toText() ) ); |
|||
}).fail(function() |
}).fail(function() |
||
{ |
{ |
||
removeSpinner($button); |
|||
$button.find("div").replaceWith(RCPatrolFailureCode); |
|||
deferred.reject(); |
|||
if ($patrolAgainBrackets.length === 0) |
|||
{ |
|||
$patrolLink.before(patrolFailureCode); |
|||
$patrolLink.before("<span class='patrolAgainBracket'> (</span>"); |
|||
$patrolLink.after("<span class='patrolAgainBracket'>)</span>"); |
|||
} |
|||
else |
|||
{ |
|||
$patrolAgainBrackets.first().before(patrolFailureCode); |
|||
$patrolAgainBrackets.show(); |
|||
} |
|||
$patrolLink.text(tryAgainText); |
|||
$patrolLink.show(); |
|||
mw.notify( mw.msg( 'markedaspatrollederrornotifypage' ), { type: 'error' } ); |
|||
}); |
}); |
||
return deferred.promise(); |
|||
} |
} |
||
function |
function makeDiffPagePatrolLinks() |
||
{ |
{ |
||
$(".patrollink-range a") |
var $button = $(".patrollink-range a"); |
||
if (!isEventBound($button)) |
|||
{ |
{ |
||
$button.click(function() |
|||
processDiffPageRangePatrol(); |
|||
{ |
|||
}); |
|||
processDiffPageRangePatrol(); |
|||
}); |
|||
} |
|||
$(".patrollink-page a") |
$button = $(".patrollink-page a"); |
||
if (!isEventBound($button)) |
|||
{ |
{ |
||
$button.click(function() |
|||
processDiffPageFullPatrol(); |
|||
{ |
|||
}); |
|||
processPagePatrol($button.parent()); |
|||
}); |
|||
} |
|||
} |
} |
||
Linia 204: | Linia 268: | ||
function processDiffPageRangePatrol() |
function processDiffPageRangePatrol() |
||
{ |
{ |
||
var $button = $(".patrollink-range") |
var $button = $(".patrollink-range"), |
||
$patrolLink = $button.find("a"), |
|||
$spinner = $.createSpinner({ size: 'small', type: 'inline' }), |
|||
$patrolAgainBrackets = $button.find(".patrolAgainBracket"), |
|||
to = $patrolLink.attr("data-revision-max"), |
|||
from = $patrolLink.attr("data-revision-min"); |
|||
$patrolLink.hide(); |
|||
$button.find("a").replaceWith(spinnerCode); |
|||
$patrolAgainBrackets.hide(); |
|||
$patrolLink.after($spinner); |
|||
$patrolLink.parent().find(".patrolButtonClicked").remove(); |
|||
patrolModule.resetLastClick(); |
|||
var to = mw.util.getParamValue("oldid", $("#mw-diff-ntitle-1 strong a").attr("href")); |
|||
patrolModule.patrolRangeOfChanges(to, from).done(function(data) |
|||
var from = mw.util.getParamValue("oldid", $("#mw-diff-otitle-1 strong a").attr("href")) + 1; |
|||
patrolRangeOfChanges(to, from).done(function() |
|||
{ |
{ |
||
removeSpinner($button); |
|||
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
|||
}).fail(function(error) |
|||
$patrolLink.after(patrolSuccessCode); |
|||
$patrolLink.remove(); |
|||
$patrolAgainBrackets.remove(); |
|||
var title = new mw.Title(data["fmod-patrol"].title); |
|||
mw.notify( mw.msg( 'markedaspatrollednotifymulti', title.toText() ) ); |
|||
}).fail(function() |
|||
{ |
{ |
||
removeSpinner($button); |
|||
console.log(error); |
|||
$button.find("div").replaceWith(RCMultipleFailureSuccessCode); |
|||
if ($patrolAgainBrackets.length === 0) |
|||
{ |
|||
$patrolLink.before(patrolFailureCode); |
|||
$patrolLink.before("<span class='patrolAgainBracket'> (</span>"); |
|||
$patrolLink.after("<span class='patrolAgainBracket'>)</span>"); |
|||
} |
|||
else |
|||
{ |
|||
$patrolAgainBrackets.first().before(patrolFailureCode); |
|||
$patrolAgainBrackets.show(); |
|||
} |
|||
$patrolLink.text(tryAgainText); |
|||
$patrolLink.show(); |
|||
mw.notify( mw.msg( 'markedaspatrollederrornotifypage' ), { type: 'error' } ); |
|||
}); |
}); |
||
} |
} |
||
function |
function getParentTag($anchor, tag) |
||
{ |
{ |
||
tag = tag.toUpperCase(); |
|||
var $button = $(".patrollink-page"); |
|||
var $a = $anchor; |
|||
while ($a.prop("tagName") != tag && $a.prop("tagName") != "BODY") |
|||
var pageid = $button.find("a").attr("data-pageid"); |
|||
$button.find("a").replaceWith(spinnerCode); |
|||
patrolPage(pageid).done(function() |
|||
{ |
|||
$button.find("div").replaceWith(RCMultiplePatrolSuccessCode); |
|||
}).fail(function(error) |
|||
{ |
{ |
||
$a = $a.parent(); |
|||
} |
|||
$button.find("div").replaceWith(RCMultipleFailureSuccessCode); |
|||
return $a; |
|||
}); |
|||
} |
} |
||
function isEventBound($element) |
|||
function processGroupMarksAndButtons($anchor) //usuwa grupowy wykrzyknik i przycisk patrolowania, jak zajdzie potrzeba |
|||
{ |
{ |
||
if ($element == null || $element.length == 0) |
|||
var $parent = $anchor; |
|||
while ($parent.prop("tagName") != "TABLE" && $parent.prop("tagName") != "BODY") |
|||
{ |
{ |
||
return false; |
|||
$parent = $parent.parent(); |
|||
} |
|||
//wszystkie rozwijalne zmiany/pliki spatrolowane, drugi warunek po to, |
|||
//zeby nie ignorowalo sytuacji, gdy zmiany nie udalo sie spatrolowac |
|||
if ($parent.find(".patrolButton").length === 0 && $parent.find("abbr.unpatrolled").length == 1) |
|||
{ |
|||
$parent.find("abbr.unpatrolled").replaceWith(" "); |
|||
$parent.find(".multiplePatrolButton").replaceWith("<span><img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> <span style='color: green;' class='multiplePatrolButtonClicked'>zrobione</span></span>"); |
|||
} |
} |
||
var events = $._data($element.get(0), "events"); |
|||
return events != null; |
|||
} |
} |
||
function |
function removeSpinner($node) |
||
{ |
{ |
||
$node.find("div.mw-spinner").remove(); |
|||
tag = tag.toUpperCase(); |
|||
while ($anchor.prop("tagName") != tag && $anchor.prop("tagName") != "BODY") |
|||
{ |
|||
$anchor = $anchor.parent(); |
|||
} |
|||
return $anchor; |
|||
} |
} |
Aktualna wersja na dzień 17:25, 28 maj 2020
/*
* gadżet do szybkiego oznaczania wersji jako sprawdzonych na OZ, nowych stronach i widoku diffów
* autor: Expert3222
* drobne modyfikacje, backend: Ostrzyciel
*/
mw.loader.load('/wiki/Użytkownik:Expert3222/patrolModule.js?action=raw&ctype=text/javascript');
var patrolSuccessCode = "<span style='color: green;' class='patrolButtonClicked'><img src='https://nonsa.pl/images/2/26/Za.svg.png' width='15px' height='15px' /> zrobione</span>";
var patrolFailureCode = "<span style='color: red;' class='patrolButtonClicked'><img src='https://nonsa.pl/images/a/a8/Przeciw.svg.png' width='15px' height='15px' /> błąd</span>";
var tryAgainText = "spróbuj ponownie";
$(document).ready(function()
{
mw.loader.using(["jquery.spinner", "mediawiki.notification"], function()
{
if (mw.config.get("wgCanonicalSpecialPageName") === "Recentchanges")
{
makePatrolLinks();
if (!!$('.mw-rcfilters-enabled').length) //wzięte od Polskacafe z gadżetu RollWithReason
{
setInterval(makePatrolLinks, 2000);
}
}
else if (mw.config.get("wgCanonicalSpecialPageName") == "Newpages")
{
var $buttons = $(".patrollink-page a");
$buttons.click(function()
{
processPagePatrol($(this).parent());
});
}
else if (mw.util.getParamValue("diff") !== null)
{
makeDiffPagePatrolLinks();
setInterval(makeDiffPagePatrolLinks, 2000); //"przeglądaj historię interaktywnie" na górze
}
else if ($(".patrollink").length > 0) //footer
{
$(".patrollink-page a").off("click").click(function(event) //remove default click handler and attach our own
{
event.preventDefault();
event.stopImmediatePropagation();
processPagePatrol($(this).parent());
});
}
else if (mw.config.get("wgCanonicalSpecialPageName") == "MobileDiff")
{
//TODO
/*var oldid = mw.util.getParamValue("oldid", $("#mw-mf-diff-info a").attr("href"));
alert("oldid = " + oldid);
var urlArray = window.location.href.split("/");
var curid = urlArray[urlArray.length - 1];
alert("curid = " + curid);
var title = $("#mw-mf-diff-info a").text();
makeDiffViewRevidsList(oldid, curid, title);*/
}
});
});
function makePatrolLinks()
{
$(".patrollink-range a").each(function()
{
var $link = $(this);
if (!isEventBound($link))
{
var $tbody = getParentTag($link, "tbody");
$link.on("click", function()
{
processMultipleChangeRCPatrol($tbody);
});
}
});
$(".patrollink-single a").each(function()
{
var $button = $(this);
if (!isEventBound($button))
{
$button.on("click", function()
{
processRCChangePatrol($(this).parent(), true);
});
}
});
}
//helper function to process multiple change RC patrol, including spinner etc.
function processMultipleChangeRCPatrol($tbody)
{
var $button = $tbody.find(".patrollink-range"),
$patrolLink = $button.find("a"),
$singlePatrolLinks = $tbody.find(".patrollink-single a"),
$spinner = $.createSpinner({ size: 'small', type: 'inline' }),
$patrolAgainBrackets = $patrolLink.parent().find(".patrolAgainBracket");
$patrolLink.hide();
$patrolAgainBrackets.hide();
$patrolLink.after($spinner);
$patrolLink.parent().find(".patrolButtonClicked").remove();
patrolModule.patrolRangeOfChanges($patrolLink.attr("data-revision-max")).done(function(data)
{
removeSpinner($button);
$patrolLink.after(patrolSuccessCode);
$patrolLink.remove();
$patrolAgainBrackets.remove();
var title = new mw.Title(data["fmod-patrol"].title);
mw.notify( mw.msg( 'markedaspatrollednotifymulti', title.toText() ) );
//replace single buttons with success text
$singlePatrolLinks.replaceWith(patrolSuccessCode);
//remove patrol exclamation marks
$tbody.find("abbr.unpatrolled").replaceWith(" ");
}).fail(function() {
removeSpinner($button);
if ($patrolAgainBrackets.length === 0)
{
$patrolLink.before(patrolFailureCode);
$patrolLink.before("<span class='patrolAgainBracket'> (</span>");
$patrolLink.after("<span class='patrolAgainBracket'>)</span>");
}
else
{
$patrolAgainBrackets.first().before(patrolFailureCode);
$patrolAgainBrackets.show();
}
$patrolLink.text(tryAgainText);
$patrolLink.show();
mw.notify( mw.msg( 'markedaspatrollederrornotify' ), { type: 'error' } );
});
}
//helper function to process one RC link including spinner etc.
function processRCChangePatrol($button)
{
var $patrolLink = $button.find("a"),
revid = $patrolLink.attr("data-revision"),
$spinner = $.createSpinner({ size: 'small', type: 'inline' }),
$patrolAgainBrackets = $button.find(".patrolAgainBracket");
$patrolLink.hide();
$patrolAgainBrackets.hide();
$patrolLink.after($spinner);
$patrolLink.parent().find(".patrolButtonClicked").remove();
patrolModule.resetLastClick();
patrolModule.patrolChange(revid).done(function(data)
{
removeSpinner($button);
$patrolLink.after(patrolSuccessCode);
$patrolLink.remove();
$patrolAgainBrackets.remove();
getParentTag($button, "tr").find("abbr.unpatrolled").replaceWith(" ");
var title = new mw.Title(data["fmod-patrol"].title);
mw.notify( mw.msg( 'markedaspatrollednotify', title.toText() ) );
}).fail(function()
{
removeSpinner($button);
if ($patrolAgainBrackets.length === 0)
{
$patrolLink.before(patrolFailureCode);
$patrolLink.before("<span class='patrolAgainBracket'> (</span>");
$patrolLink.after("<span class='patrolAgainBracket'>)</span>");
}
else
{
$patrolAgainBrackets.first().before(patrolFailureCode);
$patrolAgainBrackets.show();
}
$patrolLink.text(tryAgainText);
$patrolLink.show();
mw.notify( mw.msg( 'markedaspatrollederrornotifychange' ), { type: 'error' } );
});
}
function processPagePatrol($button)
{
//diff page, new pages and any new page on the bottom
var pageid = $button.find("a").attr("data-pageid"),
$patrolLink = $button.find("a"),
$spinner = $.createSpinner({ size: 'small', type: 'inline' }),
$patrolAgainBrackets = $button.find(".patrolAgainBracket");
$patrolLink.hide();
$patrolAgainBrackets.hide();
$patrolLink.after($spinner);
$patrolLink.parent().find(".patrolButtonClicked").remove();
patrolModule.resetLastClick();
patrolModule.patrolPage(pageid).done(function(data)
{
removeSpinner($button);
$patrolLink.after(patrolSuccessCode);
$patrolLink.remove();
$patrolAgainBrackets.remove();
// if we are on diff page remove range patrol button, because we just patrolled all page revisions
$(".patrollink-range a").replaceWith(patrolSuccessCode);
//if we are on Special:Newpages change background to match patrolled
if (mw.config.get("wgCanonicalSpecialPageName") == "Newpages")
{
getParentTag($button, "li").removeClass("not-patrolled");
}
var title = new mw.Title(data["fmod-patrol"].title);
mw.notify( mw.msg( 'markedaspatrollednotifypage', title.toText() ) );
}).fail(function()
{
removeSpinner($button);
if ($patrolAgainBrackets.length === 0)
{
$patrolLink.before(patrolFailureCode);
$patrolLink.before("<span class='patrolAgainBracket'> (</span>");
$patrolLink.after("<span class='patrolAgainBracket'>)</span>");
}
else
{
$patrolAgainBrackets.first().before(patrolFailureCode);
$patrolAgainBrackets.show();
}
$patrolLink.text(tryAgainText);
$patrolLink.show();
mw.notify( mw.msg( 'markedaspatrollederrornotifypage' ), { type: 'error' } );
});
}
function makeDiffPagePatrolLinks()
{
var $button = $(".patrollink-range a");
if (!isEventBound($button))
{
$button.click(function()
{
processDiffPageRangePatrol();
});
}
$button = $(".patrollink-page a");
if (!isEventBound($button))
{
$button.click(function()
{
processPagePatrol($button.parent());
});
}
}
//helper function to process diff page range patrol including spinner etc.
function processDiffPageRangePatrol()
{
var $button = $(".patrollink-range"),
$patrolLink = $button.find("a"),
$spinner = $.createSpinner({ size: 'small', type: 'inline' }),
$patrolAgainBrackets = $button.find(".patrolAgainBracket"),
to = $patrolLink.attr("data-revision-max"),
from = $patrolLink.attr("data-revision-min");
$patrolLink.hide();
$patrolAgainBrackets.hide();
$patrolLink.after($spinner);
$patrolLink.parent().find(".patrolButtonClicked").remove();
patrolModule.resetLastClick();
patrolModule.patrolRangeOfChanges(to, from).done(function(data)
{
removeSpinner($button);
$patrolLink.after(patrolSuccessCode);
$patrolLink.remove();
$patrolAgainBrackets.remove();
var title = new mw.Title(data["fmod-patrol"].title);
mw.notify( mw.msg( 'markedaspatrollednotifymulti', title.toText() ) );
}).fail(function()
{
removeSpinner($button);
if ($patrolAgainBrackets.length === 0)
{
$patrolLink.before(patrolFailureCode);
$patrolLink.before("<span class='patrolAgainBracket'> (</span>");
$patrolLink.after("<span class='patrolAgainBracket'>)</span>");
}
else
{
$patrolAgainBrackets.first().before(patrolFailureCode);
$patrolAgainBrackets.show();
}
$patrolLink.text(tryAgainText);
$patrolLink.show();
mw.notify( mw.msg( 'markedaspatrollederrornotifypage' ), { type: 'error' } );
});
}
function getParentTag($anchor, tag)
{
tag = tag.toUpperCase();
var $a = $anchor;
while ($a.prop("tagName") != tag && $a.prop("tagName") != "BODY")
{
$a = $a.parent();
}
return $a;
}
function isEventBound($element)
{
if ($element == null || $element.length == 0)
{
return false;
}
var events = $._data($element.get(0), "events");
return events != null;
}
function removeSpinner($node)
{
$node.find("div.mw-spinner").remove();
}