„Benutzer:Fomafix/diffhistory.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
Umgestellt auf #mw-fr-diff-headeritems, da #contentSub und #jump-to-nav nicht auf allen Skins vorhanden ist. width = 'auto' statt die willkürlichen width = '95%'. Hinweis auf rev:108343 |
Alle Funktionen nach mw:ResourceLoader/JavaScript Deprecations ersetzt. Teilweise auf jQuery umgestellt: AJAX statt JSONP. |
||
Zeile 5: | Zeile 5: | ||
maxrows : 10, |
maxrows : 10, |
||
addHistoryBox : function () { |
addHistoryBox : function () { |
||
var d = diffHistory |
var d = diffHistory, |
||
wgStableRevisionId = mw.config.get( 'wgStableRevisionId' ), |
|||
wgCurRevisionId = mw.config.get( 'wgCurRevisionId' ), |
|||
wgArticleId = mw.config.get( 'wgArticleId' ); |
|||
//Check if old reviewed page |
//Check if old reviewed page |
||
if (! |
if (!wgStableRevisionId || wgStableRevisionId == wgCurRevisionId) return; |
||
var oldid = document.getElementById('mw-diff-otitle1').firstChild.firstChild.href.match(/&oldid=([^&]*)/)[1]; |
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]; |
var curid = document.getElementById('mw-diff-ntitle1').firstChild.firstChild.href.match(/&oldid=([^&]*)/)[1]; |
||
if (wgStableRevisionId == oldid && wgCurRevisionId == curid) { |
if (wgStableRevisionId == oldid && wgCurRevisionId == curid) { |
||
//Check if multi diff |
//Check if multi diff |
||
if (! $( 'table.diff td.diff-multi' )[0] ) return; //all revisions shown |
|||
var multi = getElementsByClassName(table, 'td', 'diff-multi')[0]; |
|||
if (!multi) return; //all revisions shown |
|||
} |
} |
||
//Create history box above the review form |
//Create history box above the review form |
||
Zeile 29: | Zeile 30: | ||
contentSub.parentNode.insertBefore(d.box, contentSub); |
contentSub.parentNode.insertBefore(d.box, contentSub); |
||
//Fetch history |
//Fetch history |
||
$.getJSON( |
|||
var url = mw.util.wikiScript( 'api' ) + '?format=json&callback=diffHistory.show&action=query' |
|||
mw.util.wikiScript( 'api' ), { |
|||
⚫ | |||
format: 'json', |
|||
+ (wgStableRevisionId + 1) + '&rvlimit=' + d.maxrows + '&pageids=' + wgArticleId; |
|||
action: 'query', |
|||
importScriptURI(url); |
|||
prop: 'revisions', |
|||
⚫ | |||
rvendid: wgStableRevisionId + 1, |
|||
rvlimit: d.maxrows, |
|||
pageids: wgArticleId |
|||
}, diffHistory.show ); |
|||
}, |
}, |
||
tsToLocal : function (ts) { |
tsToLocal : function (ts) { |
||
Zeile 46: | Zeile 53: | ||
show : function (res) { |
show : function (res) { |
||
var i, j, p; |
var i, j, p; |
||
diffHistory.history.removeChild(diffHistory.history.firstChild); |
|||
try { |
try { |
||
for (i in res.query.pages) { |
for (i in res.query.pages) { |
||
p = res.query.pages[i]; |
p = res.query.pages[i]; |
||
if (p.revisions) for (j=0; j<p.revisions.length; j++) |
if (p.revisions) for (j=0; j<p.revisions.length; j++) |
||
diffHistory.addEntry(p.revisions[j]); |
|||
} |
} |
||
if (res['query-continue']) { |
if (res['query-continue']) { |
||
diffHistory.history.appendChild(diffHistory.el('li', '...')); |
|||
} |
} |
||
} |
} |
||
catch (e) { |
catch (e) { |
||
diffHistory.history.appendChild(diffHistory.el('li', 'Fehler beim Laden der Versionen.')); |
|||
} |
} |
||
}, |
}, |
||
addLink : function (node, text, target, postfix) { |
addLink : function (node, text, target, postfix) { |
||
var link = |
var link = diffHistory.el('a', text); |
||
link.href = target; |
link.href = target; |
||
node.appendChild(link); |
node.appendChild(link); |
||
Zeile 68: | Zeile 75: | ||
}, |
}, |
||
addEntry : function (rev) { |
addEntry : function (rev) { |
||
var li = |
var li = diffHistory.el('li', '('); |
||
diffHistory.addLink(li, 'Aktuell', mw.config.get( 'wgScript' ) + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) |
|||
+ '&diff=cur&oldid=' + rev.revid, ') ('); |
+ '&diff=cur&oldid=' + rev.revid, ') ('); |
||
diffHistory.addLink(li, 'Vorherige', mw.config.get( 'wgScript' ) + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) |
|||
+ '&diff=prev&oldid=' + rev.revid, ') . . '); |
+ '&diff=prev&oldid=' + rev.revid, ') . . '); |
||
diffHistory.addLink(li, diffHistory.tsToLocal(rev.timestamp), mw.config.get( 'wgScript' ) + '?title=' |
|||
+ mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) + '&oldid=' + rev.revid, ' . . '); |
+ mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) + '&oldid=' + rev.revid, ' . . '); |
||
diffHistory.addLink(li, rev.user, mw.config.get( 'wgArticlePath' ).replace(/\$1/g, 'User:' + rev.user), ' ('); |
|||
diffHistory.addLink(li, 'Diskussion', mw.config.get( 'wgArticlePath' ).replace(/\$1/g, 'User talk:' + rev.user), ' | '); |
|||
diffHistory.addLink(li, 'Beiträge', mw.config.get( 'wgArticlePath' ).replace(/\$1/g, 'Special:Contributions/' + rev.user), ') '); |
|||
if (rev.minor === '') { |
if (rev.minor === '') { |
||
var span = |
var span = diffHistory.el('span', 'K '); |
||
span.className = 'minor'; |
span.className = 'minor'; |
||
li.appendChild(span); |
li.appendChild(span); |
||
} |
} |
||
if (rev.size) li.appendChild(document.createTextNode('(' + rev.size + ' Bytes) ')); |
if (rev.size) li.appendChild(document.createTextNode('(' + rev.size + ' Bytes) ')); |
||
var span = |
var span = diffHistory.el('span', '(' + (rev.comment || '') + ')'); |
||
span.className = 'comment'; |
span.className = 'comment'; |
||
li.appendChild(span); |
li.appendChild(span); |
||
diffHistory.history.appendChild(li); |
|||
}, |
}, |
||
toggle : function () { |
toggle : function () { |
||
var t = |
var t = diffHistory.history.style.display == 'none'; |
||
diffHistory.history.style.display = t ? 'block' : 'none'; |
|||
diffHistory.togglelink.firstChild.nodeValue = mw.msg ( t ? 'collapsible-collapse' : 'collapsible-expand' ); |
|||
return false; |
|||
}, |
}, |
||
createToggle : function () { |
createToggle : function () { |
||
var span = |
var span = diffHistory.el('span', '['); |
||
diffHistory.togglelink = diffHistory.el('a', mw.msg ( 'collapsible-collapse' ) ); |
|||
diffHistory.togglelink.href = '#'; |
|||
diffHistory.togglelink.onclick = diffHistory.toggle; |
|||
span.appendChild(diffHistory.togglelink); |
|||
span.appendChild(document.createTextNode(']')); |
span.appendChild(document.createTextNode(']')); |
||
span.style.fontSize = 'x-small'; |
span.style.fontSize = 'x-small'; |
||
span.style.cssFloat = 'right'; |
span.style.cssFloat = 'right'; |
||
span.style.styleFloat = 'right'; |
span.style.styleFloat = 'right'; |
||
diffHistory.box.appendChild(span); |
|||
}, |
}, |
||
el : function (tag, text) { |
el : function (tag, text) { |
||
Zeile 113: | Zeile 122: | ||
if ( ( mw.config.get( 'wgAction' ) === 'view' |
if ( ( mw.config.get( 'wgAction' ) === 'view' |
||
|| mw.config.get( 'wgAction' ) === 'historysubmit' ) // Kann |
|| mw.config.get( 'wgAction' ) === 'historysubmit' ) // Kann entfallen, wenn [[rev:108343]] live ist. |
||
&& mw.util.getParamValue( 'diff' ) !== null ) { |
&& mw.util.getParamValue( 'diff' ) !== null ) { |
||
jQuery( document ).ready( diffHistory.addHistoryBox ); |
jQuery( document ).ready( diffHistory.addHistoryBox ); |
Version vom 12. Januar 2012, 12:15 Uhr
// Zeigt bei Diffs auf nachzusichtenden Seiten eine Übersicht über
// ungesichtete Versionen an.
var diffHistory = {
maxrows : 10,
addHistoryBox : function () {
var d = diffHistory,
wgStableRevisionId = mw.config.get( 'wgStableRevisionId' ),
wgCurRevisionId = mw.config.get( 'wgCurRevisionId' ),
wgArticleId = mw.config.get( 'wgArticleId' );
//Check if old reviewed page
if (!wgStableRevisionId || wgStableRevisionId == 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 (wgStableRevisionId == oldid && wgCurRevisionId == curid) {
//Check if multi diff
if (! $( 'table.diff td.diff-multi' )[0] ) return; //all revisions shown
}
//Create history box above the review form
d.box = document.createElement('fieldset');
var legend = d.el('legend', 'Ungesichtete Versionen');
legend.style.padding = 0;
d.box.appendChild(legend);
d.createToggle();
d.box.appendChild(d.history = document.createElement('ul'));
d.history.appendChild(d.el('li', 'Lade Versionsgeschichte …'));
d.box.className = 'portlet pBody diffhistorybox';
d.box.style.width = 'auto';
var contentSub = document.getElementById('mw-fr-diff-headeritems');
contentSub.parentNode.insertBefore(d.box, contentSub);
//Fetch history
$.getJSON(
mw.util.wikiScript( 'api' ), {
format: 'json',
action: 'query',
prop: 'revisions',
rvprop: 'user|timestamp|size|flags|ids|comment',
rvendid: wgStableRevisionId + 1,
rvlimit: d.maxrows,
pageids: wgArticleId
}, diffHistory.show );
},
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 = ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'][d.getMonth()];
return d.getDate() + '. ' + month + '. ' + d.getFullYear() + ', ' + hour + ':' + min;
},
show : function (res) {
var i, j, p;
diffHistory.history.removeChild(diffHistory.history.firstChild);
try {
for (i in res.query.pages) {
p = res.query.pages[i];
if (p.revisions) for (j=0; j<p.revisions.length; j++)
diffHistory.addEntry(p.revisions[j]);
}
if (res['query-continue']) {
diffHistory.history.appendChild(diffHistory.el('li', '...'));
}
}
catch (e) {
diffHistory.history.appendChild(diffHistory.el('li', 'Fehler beim Laden der Versionen.'));
}
},
addLink : function (node, text, target, postfix) {
var link = diffHistory.el('a', text);
link.href = target;
node.appendChild(link);
node.appendChild(document.createTextNode(postfix));
},
addEntry : function (rev) {
var li = diffHistory.el('li', '(');
diffHistory.addLink(li, 'Aktuell', mw.config.get( 'wgScript' ) + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) )
+ '&diff=cur&oldid=' + rev.revid, ') (');
diffHistory.addLink(li, 'Vorherige', mw.config.get( 'wgScript' ) + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) )
+ '&diff=prev&oldid=' + rev.revid, ') . . ');
diffHistory.addLink(li, diffHistory.tsToLocal(rev.timestamp), mw.config.get( 'wgScript' ) + '?title='
+ mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) + '&oldid=' + rev.revid, ' . . ');
diffHistory.addLink(li, rev.user, mw.config.get( 'wgArticlePath' ).replace(/\$1/g, 'User:' + rev.user), ' (');
diffHistory.addLink(li, 'Diskussion', mw.config.get( 'wgArticlePath' ).replace(/\$1/g, 'User talk:' + rev.user), ' | ');
diffHistory.addLink(li, 'Beiträge', mw.config.get( 'wgArticlePath' ).replace(/\$1/g, 'Special:Contributions/' + rev.user), ') ');
if (rev.minor === '') {
var span = diffHistory.el('span', 'K ');
span.className = 'minor';
li.appendChild(span);
}
if (rev.size) li.appendChild(document.createTextNode('(' + rev.size + ' Bytes) '));
var span = diffHistory.el('span', '(' + (rev.comment || '') + ')');
span.className = 'comment';
li.appendChild(span);
diffHistory.history.appendChild(li);
},
toggle : function () {
var t = diffHistory.history.style.display == 'none';
diffHistory.history.style.display = t ? 'block' : 'none';
diffHistory.togglelink.firstChild.nodeValue = mw.msg ( t ? 'collapsible-collapse' : 'collapsible-expand' );
return false;
},
createToggle : function () {
var span = diffHistory.el('span', '[');
diffHistory.togglelink = diffHistory.el('a', mw.msg ( 'collapsible-collapse' ) );
diffHistory.togglelink.href = '#';
diffHistory.togglelink.onclick = diffHistory.toggle;
span.appendChild(diffHistory.togglelink);
span.appendChild(document.createTextNode(']'));
span.style.fontSize = 'x-small';
span.style.cssFloat = 'right';
span.style.styleFloat = 'right';
diffHistory.box.appendChild(span);
},
el : function (tag, text) {
var el = document.createElement(tag);
el.appendChild(document.createTextNode(text));
return el;
}
};
if ( ( mw.config.get( 'wgAction' ) === 'view'
|| mw.config.get( 'wgAction' ) === 'historysubmit' ) // Kann entfallen, wenn [[rev:108343]] live ist.
&& mw.util.getParamValue( 'diff' ) !== null ) {
jQuery( document ).ready( diffHistory.addHistoryBox );
}