User:Saftzie/Sandbox

ShoutWiki — express yourself and be heard!
Jump to navigation Jump to search

usrchk

Crystal Clear action info.svgCrystal Clear app error.svgCrystal Clear action stop.png
Nuvola apps atlantik.png

Spam user pages?[edit | edit source]

Source 
// find user pages
// 1. with only the original revision
// 2. not created by the user
(function (mw, $) {
	'use strict';

	var
		urlAPI = mw.config.get('wgScriptPath') + '/api.php',
		ta = $('<textarea rows="8" readonly="readonly"></textarea>')[0],
		opts = {
			format: 'json',
			action: 'query',
			prop: 'revisions',
			rvprop: 'ids|user',
			generator: 'allpages',
			gapnamespace: 2,
			gaplimit: 500
		};

	$('#mw-content-text').empty().append(ta);
	(function loop() {
		$.post(urlAPI, opts).done(function (data) {
			var
				c = data && data['continue'],
				p = data && data.query && data.query.pages,
				count = 0,
				i, r, m, t;

			if (p) {
				for (i in p) {
					if (p.hasOwnProperty(i) &&
						((r = p[i].revisions[0]).parentid === 0) &&
						((t = p[i].title).search('/') === -1)) {
						m = t.match(/:(.+)$/);
						if (m && (m[1] !== r.user)) {
							ta.value += '* [[' + t + ']]\n';
							++count;
						}
					}
				}
			}
			if (c) {
				$.extend(opts, c);
				loop();
			} else {
				console.log(count);
			}
		});
	}());
}(mediaWiki, jQuery));