User:Incnis Mrsi/edithysteria.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Incnis Mrsi/edithysteria. |
// Ported from [[pl:MediaWiki:Gadget-edithysteria.js]], see there for authorship
window.editHysteriaGadget = {
version: 5,
init: function() {
if ( mw.config.get( 'wgNamespaceNumber' ) < 0 || mw.util.getParamValue('printable') === 'yes' ) {
return;
}
var that = this;
var request = {
action: 'query',
prop: 'revisions',
rvprop: 'user|ids',
format: 'json',
titles: mw.config.get( 'wgPageName' ),
rvlimit: 50,
requestid: new Date().getTime()
};
jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {
jQuery(document).ready(function() {
if (result) {
that.showResults(result);
}
});
});
},
userlink: function(name) {
var str = '<a href="' + mw.util.getUrl('User:' + name) + '">' + name + '</a> ' +
'(<a href="' + mw.util.getUrl('User talk:' + name) + '">talk</a>' +
' <b>·</b> <a href="' + mw.util.getUrl('Special:Contributions/' + name) + '">contribs</a>)';
// if ( jQuery.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) != -1 ) {
// str += ', <a href="' + mw.util.getUrl('Special:Blockip/' + name) + '">block</a>';
// }
//
// str += ')';
return str;
},
showResults: function(data) {
var page = data.query.pages[ mw.config.get( 'wgArticleId' ) ];
var firstHeading;
var headers = document.getElementsByTagName( 'h1' );
for ( var i = 0; i < headers.length; i++ ) {
var header = headers[i];
if(header.className == "firstHeading" || header.id == "firstHeading" || header.className == "pagetitle") {
firstHeading = header; break;
}
}
if( !firstHeading ) {
firstHeading = document.getElementById("section-0");
}
if( !firstHeading ) {
return;
}
var div = document.createElement("div");
div.style.cssText = "font-size:0.5em;line-height:1em";
div.className = 'plainlinks';
if ( mw.config.get( 'skin' ) == 'modern' ) {
div.style.marginLeft = "10px";
div.style.display = "inline-block";
}
firstHeading.appendChild(div);
var html = '';
if (! page) {
div.innerHTML = html + "Page not exists.";
div.style.color = "red";
return;
}
var topuser = page.revisions[0].user;
var ldiff;
var luser;
var count = 1;
for (var i = 1; i < page.revisions.length; i++) {
ldiff = page.revisions[i].revid;
luser = page.revisions[i].user;
if (luser != topuser)
break;
count++;
}
if (ldiff) {
html += 'Last <a href="'+ mw.util.getUrl( mw.config.get('wgPageName') ) + '?diff=cur&oldid=' + ldiff + '"/>edited</a>' +
' by ' + this.userlink(topuser) + ' (' + count + '×)';
if(luser !== "" && luser != topuser) {
html += ', previous edit by ' + this.userlink(luser);
}
html += '.';
div.innerHTML = html;
}
else if (topuser !== "") {
div.innerHTML = html + 'This is the only version by ' + this.userlink(topuser) + '.';
}
if ( mw.config.get('skin') == 'modern' ) {
var links = div.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
links[i].style.color = 'white';
links[i].style.textDecoration = 'underline';
}
}
}
};
editHysteriaGadget.init();