MediaWiki:Gadget-diffhistory.js: Różnice pomiędzy wersjami
Wygląd
Usunięta treść Dodana treść
m nie ma juz query-continue, jest samo continue |
mw.util.isIPAddress |
||
Linia 65: | Linia 65: | ||
}, |
}, |
||
addLink : function (node,text,target,postfix) { |
addLink : function (node,text,target,postfix) { |
||
var link = this.el('a',text); |
var link = this.el('a', text); |
||
link.href = target; |
link.href = target; |
||
node.appendChild(link); |
node.appendChild(link); |
||
Linia 72: | Linia 72: | ||
addEntry : function (rev) { |
addEntry : function (rev) { |
||
var li = this.el('li','('); |
var li = this.el('li','('); |
||
this.addLink(li,'bież.','/w/index.php?title=' + encodeURIComponent(this.conf.wgPageName) |
this.addLink(li, 'bież.','/w/index.php?title=' + encodeURIComponent(this.conf.wgPageName) |
||
+ '&diff=cur&oldid=' + rev.revid,') ('); |
+ '&diff=cur&oldid=' + rev.revid, ') ('); |
||
this.addLink(li,'poprz.','/w/index.php?title=' + encodeURIComponent(this.conf.wgPageName) |
this.addLink(li, 'poprz.','/w/index.php?title=' + encodeURIComponent(this.conf.wgPageName) |
||
+ '&diff=prev&oldid=' + rev.revid,') . . '); |
+ '&diff=prev&oldid=' + rev.revid, ') . . '); |
||
this.addLink(li,diffHistory.tsToLocal(rev.timestamp),'/w/index.php?title=' |
this.addLink(li, diffHistory.tsToLocal(rev.timestamp),'/w/index.php?title=' |
||
+ encodeURIComponent(this.conf.wgPageName) + '&oldid=' + rev.revid,' . . '); |
+ encodeURIComponent(this.conf.wgPageName) + '&oldid=' + rev.revid, ' . . '); |
||
var isIp = mw.util.isIPAddress(rev.user); |
|||
var isIp = rev.user.match(/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/); |
|||
if (isIp) { |
if (isIp) { |
||
this.addLink(li,rev.user, |
this.addLink(li, rev.user, mw.util.getUrl('Special:Contributions/' + rev.user), ' ('); |
||
this.addLink(li,'dyskusja', |
this.addLink(li, 'dyskusja', mw.util.getUrl('User talk:' + rev.user), ') '); |
||
} else { |
} else { |
||
this.addLink(li,rev.user, |
this.addLink(li, rev.user, mw.util.getUrl('User:' + rev.user), ' ('); |
||
this.addLink(li,'dyskusja', |
this.addLink(li, 'dyskusja', mw.util.getUrl('User talk:' + rev.user), ' | '); |
||
this.addLink(li,'edycje', |
this.addLink(li, 'edycje', mw.util.getUrl('Special:Contributions/' + rev.user), ') '); |
||
} |
} |
||
if (rev.minor === '') { |
if (rev.minor === '') { |
||
var |
var span_m = this.el('span','m '); |
||
span_m.className = 'minor'; |
|||
li.appendChild( |
li.appendChild(span_m); |
||
} |
} |
||
if (rev.size) li.appendChild(document.createTextNode('(' + rev.size + ' bajtów) ')); |
if (rev.size) li.appendChild(document.createTextNode('(' + rev.size + ' bajtów) ')); |
||
var |
var span_comment = this.el('span','(' + (rev.comment || '') + ')'); |
||
span_comment.className = 'comment'; |
|||
li.appendChild( |
li.appendChild(span_comment); |
||
this.history.appendChild(li); |
this.history.appendChild(li); |
||
}, |
}, |
||
Linia 115: | Linia 115: | ||
this.box.appendChild(span); |
this.box.appendChild(span); |
||
}, |
}, |
||
el : function (tag,text) { |
el : function (tag, text) { |
||
var el = document.createElement(tag); |
var el = document.createElement(tag); |
||
el.appendChild(document.createTextNode(text)); |
el.appendChild(document.createTextNode(text)); |
Aktualna wersja na dzień 23:17, 10 lut 2023
// source: de:Benutzer:P.Copp/scripts/diffhistory.js
// Zeigt bei Diffs auf nachzusichtenden Seiten eine Übersicht über
// ungesichtete Versionen an.
window.diffHistory = {
conf: mw.config.get([
'wgStableRevisionId',
'wgCurRevisionId',
'wgScriptPath',
'wgArticleId',
'wgPageName',
'wgArticlePath',
'wgAction'
]),
maxrows : 10,
addHistoryBox : function () {
//Check if old reviewed page
if (!this.conf.wgStableRevisionId || this.conf.wgStableRevisionId == this.conf.wgCurRevisionId) return;
var oldid = document.getElementById('mw-diff-otitle1').firstChild.firstChild.href.match(/&oldid=([^&]*)/)[1];
var curid = document.getElementById('mw-diff-ntitle1').firstChild.firstChild.href.match(/&oldid=([^&]*)/)[1];
if (this.conf.wgStableRevisionId == oldid && this.conf.wgCurRevisionId == curid) {
//Check if multi diff
if ($('table.diff td.diff-multi').length === 0) return; //all revisions shown
}
//Create history box above the review form
this.box = document.createElement('fieldset');
var legend = this.el('legend','Nieprzejrzane wersje');
legend.style.padding = 0;
this.box.appendChild(legend);
this.createToggle();
this.box.appendChild(this.history = document.createElement('ul'));
this.history.appendChild(this.el('li','Ładowanie historii...'));
this.box.className = 'portlet pBody diffhistorybox';
this.box.style.width = '95%';
var contentNode = document.getElementById('mw-content-text');
contentNode.parentNode.insertBefore(this.box, contentNode);
//Fetch history
var url = this.conf.wgScriptPath + '/api.php?format=json&callback=diffHistory.show&action=query'
+ '&prop=revisions&rvprop=user|timestamp|size|flags|ids|comment&rvendid='
+ (this.conf.wgStableRevisionId + 1) + '&rvlimit=' + this.maxrows + '&pageids=' + this.conf.wgArticleId;
mw.loader.load(url);
},
tsToLocal : function (ts) {
var m = ts.match(/^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/);
var d = new Date(Date.UTC(m[1],m[2]-1,m[3],m[4],m[5],m[6]));
var tzdiff = d.getTimezoneOffset() - (new Date()).getTimezoneOffset();
if (tzdiff) d.setTime(d.getTime() + tzdiff * 60 * 1000);
var hour = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
var min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
var month = ['stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia',
'września','października','listopada','grudnia'][d.getMonth()];
return d.getDate() + ' ' + month + ' ' + d.getFullYear() + ', ' + hour + ':' + min;
},
show : function (res) {
this.history.removeChild(this.history.firstChild);
try {
for (var i in res.query.pages) {
var p = res.query.pages[i];
if (p.revisions) for (j=0;j<p.revisions.length;j++)
this.addEntry(p.revisions[j]);
}
if (res['continue']) this.history.appendChild(this.el('li','...'));
}
catch (e) {this.history.appendChild(this.el('li','Błąd przy ładowaniu wersji.'));}
},
addLink : function (node,text,target,postfix) {
var link = this.el('a', text);
link.href = target;
node.appendChild(link);
node.appendChild(document.createTextNode(postfix));
},
addEntry : function (rev) {
var li = this.el('li','(');
this.addLink(li, 'bież.','/w/index.php?title=' + encodeURIComponent(this.conf.wgPageName)
+ '&diff=cur&oldid=' + rev.revid, ') (');
this.addLink(li, 'poprz.','/w/index.php?title=' + encodeURIComponent(this.conf.wgPageName)
+ '&diff=prev&oldid=' + rev.revid, ') . . ');
this.addLink(li, diffHistory.tsToLocal(rev.timestamp),'/w/index.php?title='
+ encodeURIComponent(this.conf.wgPageName) + '&oldid=' + rev.revid, ' . . ');
var isIp = mw.util.isIPAddress(rev.user);
if (isIp) {
this.addLink(li, rev.user, mw.util.getUrl('Special:Contributions/' + rev.user), ' (');
this.addLink(li, 'dyskusja', mw.util.getUrl('User talk:' + rev.user), ') ');
} else {
this.addLink(li, rev.user, mw.util.getUrl('User:' + rev.user), ' (');
this.addLink(li, 'dyskusja', mw.util.getUrl('User talk:' + rev.user), ' | ');
this.addLink(li, 'edycje', mw.util.getUrl('Special:Contributions/' + rev.user), ') ');
}
if (rev.minor === '') {
var span_m = this.el('span','m ');
span_m.className = 'minor';
li.appendChild(span_m);
}
if (rev.size) li.appendChild(document.createTextNode('(' + rev.size + ' bajtów) '));
var span_comment = this.el('span','(' + (rev.comment || '') + ')');
span_comment.className = 'comment';
li.appendChild(span_comment);
this.history.appendChild(li);
},
toggle : function () {
var t = this.history.style.display == 'none';
this.history.style.display = t ? 'block' : 'none';
this.togglelink.firstChild.nodeValue = t ? 'Ukryj' : 'Pokaż';
},
createToggle : function () {
var span = this.el('span','[');
this.togglelink = this.el('a','Ukryj');
this.togglelink.href = 'javascript:diffHistory.toggle()';
span.appendChild(this.togglelink);
span.appendChild(document.createTextNode(']'));
span.style.fontSize = 'x-small';
span.style.cssFloat = 'right';
span.style.styleFloat = 'right';
this.box.appendChild(span);
},
el : function (tag, text) {
var el = document.createElement(tag);
el.appendChild(document.createTextNode(text));
return el;
}
};
if (((diffHistory.conf.wgAction == 'view') || (diffHistory.conf.wgAction == 'historysubmit')) && location.search.indexOf('diff=') > -1) {
$(function() {
diffHistory.addHistoryBox();
});
}