MediaWiki:Gadget-diffhistory.js

// 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, ' . . ');

		if (mw.util.isIPAddress(rev.user) || mw.util.isTemporaryUser(rev.user)) {
			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();
	});
}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Kembali kehalaman sebelumnya