Lista haseł | Kategorie artykułów | Prześlij plik | Lista plików | Pomoc | Kontakt
Pnikut.net
Aby utworzyć nowe konto użytkownika należy postępować zgodnie z zaleceniami na stronie Tworzenie konta użytkownika.

MediaWiki:Gadget-diffhistory.js

Z Wiki.Pnikuczanie
Skocz do: nawigacji, wyszukiwania

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
  • Opera: Wyczyść pamięć podręczną w Narzędzia → Preferencje
// source: de:Benutzer:P.Copp/scripts/diffhistory.js
// Zeigt bei Diffs auf nachzusichtenden Seiten eine Übersicht über
// ungesichtete Versionen an.

var diffHistory = {
	maxrows : 10,
	addHistoryBox : function () {
		var d = diffHistory;
		//Check if old reviewed page
		if (!window.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').length === 0) return; //all revisions shown
		}
		//Create history box above the review form
		d.box = document.createElement('fieldset');
		var legend = d.el('legend','Nieprzejrzane wersje');
		legend.style.padding = 0;
		d.box.appendChild(legend);
		d.createToggle();
		d.box.appendChild(d.history = document.createElement('ul'));
		d.history.appendChild(d.el('li','Ładowanie historii...'));
		d.box.className = 'portlet pBody diffhistorybox';
		d.box.style.width = '95%';
		var nav = document.getElementById('jump-to-nav');
		nav.parentNode.insertBefore(d.box,nav.nextSibling);
		//Fetch history
		var url = wgScriptPath + '/api.php?format=json&callback=diffHistory.show&action=query'
			+ '&prop=revisions&rvprop=user|timestamp|size|flags|ids|comment&rvendid='
			+ (wgStableRevisionId + 1) + '&rvlimit=' + d.maxrows + '&pageids=' + wgArticleId;
		importScriptURI(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['query-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(wgPageName)
			+ '&diff=cur&oldid=' + rev.revid,') (');
		this.addLink(li,'poprz.','/w/index.php?title=' + encodeURIComponent(wgPageName)
			+ '&diff=prev&oldid=' + rev.revid,') . . ');
		this.addLink(li,diffHistory.tsToLocal(rev.timestamp),'/w/index.php?title='
			+ encodeURIComponent(wgPageName) + '&oldid=' + rev.revid,' . . ');
		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) {
			this.addLink(li,rev.user, wgArticlePath.replace(/\$1/g,'Special:Contributions/' + rev.user),' (');
			this.addLink(li,'dyskusja', wgArticlePath.replace(/\$1/g,'User talk:' + rev.user),') ');

		} else {
			this.addLink(li,rev.user, wgArticlePath.replace(/\$1/g,'User:' + rev.user),' (');
			this.addLink(li,'dyskusja', wgArticlePath.replace(/\$1/g,'User talk:' + rev.user),' | ');
			this.addLink(li,'edycje', wgArticlePath.replace(/\$1/g,'Special:Contributions/' + rev.user),') ');
		}
		if (rev.minor === '') {
			var span = this.el('span','K ');
			span.className = 'minor';
			li.appendChild(span);
		}
		if (rev.size) li.appendChild(document.createTextNode('(' + rev.size + ' bajtów) '));
		var span = this.el('span','(' + (rev.comment || '') + ')');
		span.className = 'comment';
		li.appendChild(span);
		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 (((wgAction == 'view') || (wgAction == 'historysubmit')) && location.search.indexOf('diff=') > -1) jQuery(diffHistory.addHistoryBox);