Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 56 lines (48 sloc) 1.823 kB
b684133 @singpolyma Initial commit
authored
1 #!/usr/bin/ruby
2
3 require 'json'
4 require 'open-uri'
5 require 'cgi'
6 require 'time'
7
8 def an(v)
9 v || Class.new{def method_missing(*a);end;}.new
10 end
11
12 def get2commit(wiki,pageid,branch,authors={},rvstartid=nil,limit='max')
13 uri = "#{wiki}/w/api.php?action=query&prop=revisions&pageids=#{pageid.to_i}&rvprop=ids%7Cflags%7Ctimestamp%7Cuser%7Ccomment%7Ccontent&format=json&rvlimit=#{limit}&rvdir=newer"
14 uri += "&rvstartid=#{rvstartid.to_i}" if rvstartid
15 revisions = JSON::parse(open(uri).read)
16 an(an(revisions['query'])['pages']).each do |id,page|
17 page['revisions'].each do |rev|
18 time = Time.parse(rev['timestamp']).utc.to_i
19 user = authors[rev['user']] || "#{rev['user']} <>"
20 puts "commit #{branch}"
21 puts "mark :#{rev['revid']}"
22 puts "committer #{user} #{time} +0000"
23 puts "data #{rev['comment'] ? rev['comment'].length : 0}"
24 puts rev['comment'] if rev['comment'] and rev['comment'].length > 0
25 puts "from :#{rev['parentid']}" if rev['parentid']
26 puts "M 100644 inline #{page['title']}"
27 puts "data #{rev['*'] ? rev['*'].length : 0}"
28 puts rev['*'] if rev['*'] and rev['*'].length > 0
29 end
30 end
31 an(an(revisions['query-continue'])['revisions'])['rvstartid']
32 end
33
34 def all2commit(wiki,pageid,branch,authors={},rvstartid=nil)
35 while rvstartid = get2commit(wiki,pageid,branch,authors,rvstartid)
36 # Nothing
37 end
38 end
39
40 def somepages(wiki,apfrom=nil)
41 uri = "#{wiki}/w/api.php?action=query&list=allpages&aplimit=max&format=json"
42 uri += "&apfrom=#{CGI::escape(apfrom)}" if apfrom
43 pages = JSON::parse(open(uri).read)
44 (an(an(pages['query'])['allpages']).map{|v| v['pageid']} || []).each{|v| all2commit(wiki, v,'refs/heads/master')}
45 an(an(pages['query-continue'])['allpages'])['apfrom']
46 end
47
48 def allpages(wiki)
49 apfrom = nil
50 while apfrom = somepages(wiki,apfrom)
51 # Nothing
52 end
53 end
54
55 allpages(ARGV[0])
Something went wrong with that request. Please try again.