User:Kangaroopower/userhist.js

/** * Based off of userHist by Ale jrb * @author Kangaroopower * Lets you filter out the edits made by a user on a certain page */ $(function {	function userHistMain {		var me = this,			conf = {				page: mw.config.get('wgPageName'),				action: mw.config.get('wgAction')			};

this.displayBox = function (user) { // if user is set, this name will automatically be displayed on load user = user == null ? '' : user.replace(/(_|%20)/gi, ' ').replace (/(%3A)/gi, ':');

var box = $(' ', {				id: 'userhist-isolate',				type: 'text'			}).val(user).css('width', (window.histwidth || 200) + 'px'); var button = $(' ', {				id: 'userhist-ibutton',				type: 'button'			}).val('Isolate history').css('margin-left', '4px');

var span = $(' ').css('margin-left', '20px').append(box).append(button);

$(button).click(function {				me.getUserHist($('#userhist-isolate').val);			}); $('#mw-history-search').append(span);

$('#userhist-isolate').keydown(function(e) {				if(e.keyCode === 13) {					e.preventDefault;					me.getUserHist($('#userhist-isolate').val);				}			}); };		this.getUserHist = function (user) { if (typeof user === 'undefined' || !user) return false; user = user.replace(/ /g, '_').replace(/User(:|%3A)/gi, ''); // remove useless interface $('#mw-history-compare').html(' isolating edits by ' + user + ' - please wait... '); var apiLink = '?action=query&prop=revisions&titles='+conf.page+'&rvprop=ids|timestamp|flags|comment|user|size&rvlimit=500&indexpageids=1&rvuser='+user;

Flash('question').load(apiLink).wait(function (data) {				me.data = data.query.pages[data.query.pageids[0]];				me.showUserHist;			}).run; };		this.showUserHist = function { var data = this.data; if (typeof data.revisions === 'undefined') { this.showError('That user has never edited this page.'); return false; }			// get output var output = []; for (var i = 0; i < data.revisions.length; i++) { var info = data.revisions[i], minor = typeof info.minor === "undefined" ? false : (info.minor === ""); output[i] = [info.revid, info.user, info.timestamp, info.comment, info.size, minor]; }			// build our own interface var newInt = ' ', url = mw.util.wikiScript('index') + '?title='+ conf.page;

for (var j = 0; j < output.length; j++) { var timestamp = me.convertTimestamp(output[j][2]), comment = me.parseComment(output[j][3]), m = '';

if (output[j][5]) m = ' m '; newInt += '(cur | prev)'; newInt += ' '+timestamp+' '; newInt += ' '+output[j][1]+' '; newInt += m + ' ('+output[j][4]+' bytes) '+comment+''; }

newInt += ''; $('#mw-history-compare').html(newInt); };		this.showError = function( errorMessage ) { $('#mw-history-compare').html(' userhist error: ' + errorMessage + ' '); };		this.convertTimestamp = function (timestamp) { var d = new Date(timestamp), dStr = d.toGMTString.split(" "), arr = [ dStr[4].substring(0, dStr[4].lastIndexOf(":")), dStr.slice(1, 4).join(" ") ];			return arr[0] + ', ' + arr[1]; };		this.parseComment = function (comment) { if (comment === ) return ; comment = comment.replace('/*', ' →'); comment = comment.replace('*/', ' '); comment = comment.replace(/\[\[(.+?)(#.+?)?(?:\|(.+?))\]\]/g, "$3"); comment = comment.replace(/\[\[(.+?)(#.+?)?\]\]/g, "$1"); comment = '( ' + comment + ' )'; return comment; };		this.init = function { if (conf.action === 'history') { var user = '', l = window.location.href + ""; if (l.indexOf('&isolate=') > -1 && l.indexOf('&offset=') === -1 && l.indexOf('&limit=') === -1) { user = l.substr(l.indexOf('&isolate=') + 9); me.getUserHist(user); }				me.displayBox(user); }		};	}

if (typeof mw.loader.moduleRegistry.Flash === "undefined") { mw.loader.implement('Flash', [			mw.util.wikiScript('index') + '?title=User:Kangaroopower/Flash.js&action=raw&ctype=text/javascript'		], {}, {}); }

mw.loader.using(['Flash'], function {		var userHist = new userHistMain;		userHist.init;	}); });