summaryrefslogtreecommitdiff
path: root/autopatrol.rb
blob: 6928bf67694fa85d895741936b89ffae9071e3b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

load 'mwapi.rb'
require 'yaml'

mw = MWApi.new('https://wiki.parabolagnulinux.org/api.php')
credentials = YAML.load_file('credentials.yml')
mw.login(credentials['username'], credentials['password'])

print "Finding autopatrol users...\n"
users = []
aufrom = ''
while not aufrom.nil? do
	audata = mw.query(
		:list => :allusers,
		:aurights => :autopatrol,
		:aulimit => 5000,
		:aufrom => aufrom)
	users.concat(audata['query']['allusers'])
	aufrom = (audata['query-continue'].nil?) ? nil : audata['query-continue']['allusers']['aufrom']
end

print "Finding unpatrolled edits by autopatrol users...\n"
changes = []
users.each do |user|
	print " -> #{user['name']}\n"
	rccontinue = ''
	while not rccontinue.nil?
		query = {
			:list => :recentchanges,
			:rcuser => user['name'],
			:rclimit => 5000,
			:rcshow => '!patrolled',
			:rctoken => :patrol,
		}
		if rccontinue.length > 0
			query.merge!({:rccontinue => rccontinue})
		end
		rcdata = mw.query(query)
		changes.concat(rcdata['query']['recentchanges'])
		rccontinue = (rcdata['query-continue'].nil?) ? nil : rcdata['query-continue']['recentchanges']['rccontinue']
	end
end

changes.each do |change|
	print "Patrolling change #{change['rcid']} to #{change['title']}\n"
	mw.patrol({:rcid => change['rcid'], :token => change['patroltoken']})
end