mediawiki-butt 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,145 @@
1
+ module MediaWiki
2
+ module Query
3
+ module Lists
4
+ module Backlinks
5
+ # Gets an array of backlinks to a given title, like
6
+ # Special:WhatLinksHere.
7
+ # @param title [String] The page to get the backlinks of.
8
+ # @param limit [Int] The maximum number of pages to get. Defaults to
9
+ # 500, and cannot be greater than that unless the user is a bot. If
10
+ # the user is a bot, the limit cannot be greater than 5000.
11
+ # @see https://www.mediawiki.org/wiki/API:Backlinks MediaWiki Backlinks
12
+ # API Docs
13
+ # @since 0.1.0
14
+ # @return [Array<String>] All backlinks until the limit
15
+ def what_links_here(title, limit = 500)
16
+ params = {
17
+ action: 'query',
18
+ list: 'backlinks',
19
+ bltitle: title,
20
+ bllimit: get_limited(limit)
21
+ }
22
+
23
+ ret = []
24
+ response = post(params)
25
+ response['query']['backlinks'].each { |bl| ret << bl['title'] }
26
+
27
+ ret
28
+ end
29
+
30
+ # Gets interwiki backlinks by the prefix and title.
31
+ # @param prefix [String] The wiki prefix, e.g., "mcw".
32
+ # @param title [String] The title of the page on that wiki.
33
+ # @param limit [Int] See #what_links_here.
34
+ # @see https://www.mediawiki.org/wiki/API:Iwbacklinks MediaWiki
35
+ # Iwbacklinks API Docs
36
+ # @since 0.10.0
37
+ # @return [Array<String>] All interwiki backlinking page titles.
38
+ def get_interwiki_backlinks(prefix = nil, title = nil, limit = 500)
39
+ params = {
40
+ action: 'query',
41
+ list: 'iwbacklinks',
42
+ iwbllimit: get_limited(limit)
43
+ }
44
+ params[:iwblprefix] = prefix unless prefix.nil?
45
+ params[:iwbltitle] = title unless title.nil?
46
+
47
+ ret = []
48
+ response = post(params)
49
+ response['query']['iwbacklinks'].each { |bl| ret << bl['title'] }
50
+
51
+ ret
52
+ end
53
+
54
+ # Gets language backlinks by the language and title.
55
+ # @param language [String] The language code
56
+ # @param title [String] The page title.
57
+ # @param limit [Int] See {#what_links_here}
58
+ # @see https://www.mediawiki.org/wiki/API:Langlinks MediaWiki Langlinks
59
+ # API Docs
60
+ # @since 0.10.0
61
+ # @return [Array<String>] All pages that link to the language links.
62
+ def get_language_backlinks(language = nil, title = nil, limit = 500)
63
+ language.downcase! if language.match(/[^A-Z]*/)[0].size == 0
64
+ params = {
65
+ action: 'query',
66
+ list: 'langbacklinks',
67
+ lbltitle: get_limited(limit)
68
+ }
69
+ params[:lbllang] = language unless language.nil?
70
+ params[:lbltitle] = title unless title.nil?
71
+
72
+ ret = []
73
+ response = post(params)
74
+ response['query']['langbacklinks'].each { |bl| ret << bl['title'] }
75
+
76
+ ret
77
+ end
78
+
79
+ # Gets image backlinks, or the pages that use a given image.
80
+ # @param title [String] The image.
81
+ # @param list_redirects [Nil/Boolean] Set to nil to list redirects and
82
+ # non-redirects. Set to true to only list redirects. Set to false to
83
+ # only list non-redirects.
84
+ # @param thru_redirect [Boolean] Whether to list pages that link to a
85
+ # redirect of the image.
86
+ # @param limit [Int] See {#what_links_here}
87
+ # @see https://www.mediawiki.org/wiki/API:Imageusage MediaWiki
88
+ # Imageusage API Docs
89
+ # @since 0.10.0
90
+ # @return [Array<String>] All page titles that fit the requirements.
91
+ def get_image_backlinks(title, list_redirects = nil, thru_redir = false,
92
+ limit = 500)
93
+ params = {
94
+ action: 'query',
95
+ list: 'imageusage',
96
+ iutitle: title,
97
+ iulimit: get_limited(limit)
98
+ }
99
+
100
+ params[:iufilterredir] = list_redirects.nil? ? 'all' : list_redirects
101
+ params[:iuredirect] = '1' if thru_redir
102
+
103
+ response = post(params)
104
+ ret = []
105
+ response['query']['imageusage'].each { |bl| ret << bl['title'] }
106
+
107
+ ret
108
+ end
109
+
110
+ # Gets all external link page titles.
111
+ # @param url [String] The URL to get backlinks for.
112
+ # @param limit [Int] See {#what_links_here}
113
+ # @see https://www.mediawiki.org/wiki/API:Exturlusage MediaWiki
114
+ # Exturlusage API Docs
115
+ # @since 0.10.0
116
+ # @return [Array<String>] All pages that link to the given URL.
117
+ # @return [Array<Hash>] All pages that link to any external links.
118
+ def get_url_backlinks(url = nil, limit = 500)
119
+ params = {
120
+ action: 'query',
121
+ list: 'exturlusage',
122
+ eulimit: get_limited(limit)
123
+ }
124
+ params[:euquery] = url unless url.nil?
125
+
126
+ response = post(params)
127
+ ret = []
128
+ response['query']['exturlusage'].each do |bl|
129
+ if url.nil?
130
+ hash = {
131
+ url: bl['url'],
132
+ title: bl['title']
133
+ }
134
+ ret << hash
135
+ else
136
+ ret << bl['title']
137
+ end
138
+ end
139
+
140
+ ret
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,65 @@
1
+ module MediaWiki
2
+ module Query
3
+ module Lists
4
+ module Categories
5
+ # Returns an array of all page titles that belong to a given category.
6
+ # By default, it will only get the pages. Files and subcategories can
7
+ # be gotten through {#get_subcategories} and {#get_files_in_category}
8
+ # or setting the type parameter.
9
+ # @param category [String] The category title. It can include
10
+ # "Category:", or not, it doesn't really matter because we will add it
11
+ # if it is missing.
12
+ # @param limit [Int] The maximum number of members to get. Defaults to
13
+ # 500, and cannot be greater than that unless the user is a bot.
14
+ # If the user is a bot, the limit cannot be greater than 5000.
15
+ # @param type [String] The type of stuff to get. There are 3 valid
16
+ # values: page, file, and subcat. Separate these with a pipe
17
+ # character, e.g., 'page|file|subcat'.
18
+ # @see https://www.mediawiki.org/wiki/API:Categorymembers MediaWiki
19
+ # Category Members API Docs
20
+ # @since 0.1.0
21
+ # @return [Array] All category members until the limit
22
+ def get_category_members(category, limit = 500, type = 'page')
23
+ params = {
24
+ action: 'query',
25
+ list: 'categorymembers',
26
+ cmprop: 'title',
27
+ cmlimit: get_limited(limit),
28
+ cmtype: type
29
+ }
30
+
31
+ if category =~ /[Cc]ategory\:/
32
+ params[:cmtitle] = category
33
+ else
34
+ params[:cmtitle] = "Category:#{category}"
35
+ end
36
+ ret = []
37
+ response = post(params)
38
+ response['query']['categorymembers'].each { |cm| ret << cm['title'] }
39
+
40
+ ret
41
+ end
42
+
43
+ # Gets the subcategories of a given category.
44
+ # @param category [String] See {#get_category_members}
45
+ # @param limit [Int] See {#get_category_members}
46
+ # @see {#get_category_members}
47
+ # @since 0.9.0
48
+ # @return [Array<String>] All subcategories.
49
+ def get_subcategories(category, limit = 500)
50
+ get_category_members(category, limit, 'subcat')
51
+ end
52
+
53
+ # Gets all of the files in a given category.
54
+ # @param category [String] See {#get_category_members}
55
+ # @param limit [Int] See {#get_category_members}
56
+ # @see {#get_category_members}
57
+ # @since 0.9.0
58
+ # @return [Array<String>] All files in the category.
59
+ def get_files_in_category(category, limit = 500)
60
+ get_category_members(category, limit, 'file')
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../../constants'
2
+ require_relative '../query'
3
+ require_relative 'backlinks'
4
+ require_relative 'categories'
5
+ require_relative 'all'
6
+ require_relative 'search'
7
+ require_relative 'miscellaneous'
8
+ require_relative 'log/log'
9
+ require_relative 'recent_changes'
10
+ require_relative 'querypage'
11
+
12
+ module MediaWiki
13
+ module Query
14
+ module Lists
15
+ include MediaWiki::Query::Lists::Backlinks
16
+ include MediaWiki::Query::Lists::Categories
17
+ include MediaWiki::Query::Lists::All
18
+ include MediaWiki::Query::Lists::Search
19
+ include MediaWiki::Query::Lists::Miscellaneous
20
+ include MediaWiki::Query::Lists::Log
21
+ include MediaWiki::Query::Lists::RecentChanges
22
+ include MediaWiki::Query::Lists::QueryPage
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ require_relative '../../../constants'
2
+
3
+ module MediaWiki
4
+ module Query
5
+ module Lists
6
+ module Log
7
+ module Block
8
+ # Gets block/block logs.
9
+ # @param user [String] See {MediaWiki::Query::Lists::Log#get_log}
10
+ # @param title [String] See {MediaWiki::Query::Lists::Log#get_log}
11
+ # @param start [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
12
+ # @param stop [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
13
+ # @param limit [Int] See {MediaWiki::Query::Lists::Log#get_log}
14
+ # @see {MediaWiki::Query::Lists::Log#get_log}
15
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki
16
+ # Logevents API Docs
17
+ # @since 0.10.0
18
+ # @return [Array<Hash>] The events, containing the following keys: id,
19
+ # blocked, flags, duration, expiry, blocker, comment, timestamp.
20
+ def get_block_log(user = nil, title = nil, start = nil, stop = nil,
21
+ limit = 500)
22
+ response = get_log('block/block', user, title, start, stop, limit)
23
+
24
+ ret = []
25
+ response['query']['logevents'].each do |log|
26
+ ret << get_blockblock(log)
27
+ end
28
+
29
+ ret
30
+ end
31
+
32
+ # Gets block/reblock logs.
33
+ # @param user [String] See {MediaWiki::Query::Lists::Log#get_log}
34
+ # @param title [String] See {MediaWiki::Query::Lists::Log#get_log}
35
+ # @param start [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
36
+ # @param stop [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
37
+ # @param limit [Int] See {MediaWiki::Query::Lists::Log#get_log}
38
+ # @see {MediaWiki::Query::Lists::Log#get_log}
39
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki
40
+ # Logevents API Docs
41
+ # @since 0.10.0
42
+ # @return [Array<Hash>] The events, containing the following keys: id,
43
+ # blocked, flags, duration, expiry, blocker, comment, timestamp.
44
+ def get_reblock_log(user = nil, title = nil, start = nil, stop = nil,
45
+ limit = 500)
46
+ response = get_log('block/reblock', user, title, start, stop, limit)
47
+
48
+ ret = []
49
+ response['query']['logevents'].each do |log|
50
+ ret << get_blockreblock(log)
51
+ end
52
+
53
+ ret
54
+ end
55
+
56
+ # Gets block/unblock logs.
57
+ # @param user [String] See {MediaWiki::Query::Lists::Log#get_log}
58
+ # @param title [String] See {MediaWiki::Query::Lists::Log#get_log}
59
+ # @param start [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
60
+ # @param stop [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
61
+ # @param limit [Int] See {MediaWiki::Query::Lists::Log#get_log}
62
+ # @see {MediaWiki::Query::Lists::Log#get_log}
63
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki
64
+ # Logevents API Docs
65
+ # @since 0.10.0
66
+ # @return [Array<Hash>] The events, containing the following keys: id,
67
+ # blocked, blocker, comment, timestamp.
68
+ def get_unblock_log(user = nil, title = nil, start = nil, stop = nil,
69
+ limit = 500)
70
+ response = get_log('block/unblock', user, title, start, stop, limit)
71
+
72
+ ret = []
73
+ response['query']['logevents'].each do |log|
74
+ ret << get_blockunblock(log)
75
+ end
76
+
77
+ ret
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,59 @@
1
+ module MediaWiki
2
+ module Query
3
+ module Lists
4
+ module Log
5
+ # @todo delete/event
6
+ # @todo delete/revision
7
+ module Delete
8
+ # Gets delete/delete logs.
9
+ # @param user [String] See {MediaWiki::Query::Lists::Log#get_log}
10
+ # @param title [String] See {MediaWiki::Query::Lists::Log#get_log}
11
+ # @param start [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
12
+ # @param stop [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
13
+ # @param limit [Int] See {MediaWiki::Query::Lists::Log#get_log}
14
+ # @see {MediaWiki::Query::Lists::Log#get_log}
15
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki
16
+ # Logevents API Docs
17
+ # @since 0.10.0
18
+ # @return [Array<Hash>] The events, containing the following keys: id,
19
+ # title, user, comment, timestamp.
20
+ def get_delete_log(user = nil, title = nil, start = nil, stop = nil,
21
+ limit = 500)
22
+ response = get_log('delete/delete', user, title, start, stop, limit)
23
+
24
+ ret = []
25
+ response['query']['logevents'].each do |log|
26
+ ret << get_general(log)
27
+ end
28
+
29
+ ret
30
+ end
31
+
32
+ # Gets delete/restore logs.
33
+ # @param user [String] See {MediaWiki::Query::Lists::Log#get_log}
34
+ # @param title [String] See {MediaWiki::Query::Lists::Log#get_log}
35
+ # @param start [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
36
+ # @param stop [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
37
+ # @param limit [Int] See {MediaWiki::Query::Lists::Log#get_log}
38
+ # @see {MediaWiki::Query::Lists::Log#get_log}
39
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki
40
+ # Logevents API Docs
41
+ # @since 0.10.0
42
+ # @return [Array<Hash>] The events, containing the following keys: id,
43
+ # title, user, comment, timestamp.
44
+ def get_deletion_restore_log(user = nil, title = nil, start = nil,
45
+ stop = nil, limit = 500)
46
+ resp = get_log('delete/restore', user, title, start, stop, limit)
47
+
48
+ ret = []
49
+ resp['query']['logevents'].each do |log|
50
+ ret << get_general(log)
51
+ end
52
+
53
+ ret
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,57 @@
1
+ module MediaWiki
2
+ module Query
3
+ module Lists
4
+ module Log
5
+ module Import
6
+ # Gets import/interwiki logs.
7
+ # @param user [String] See {MediaWiki::Query::Lists::Log#get_log}
8
+ # @param title [String] See {MediaWiki::Query::Lists::Log#get_log}
9
+ # @param start [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
10
+ # @param stop [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
11
+ # @param limit [Int] See {MediaWiki::Query::Lists::Log#get_log}
12
+ # @see {MediaWiki::Query::Lists::Log#get_log}
13
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki
14
+ # Logevents API Docs
15
+ # @since 0.10.0
16
+ # @return [Array<Hash>] The events, containing the following keys: id,
17
+ # title, user, comment, timestamp, count, interwiki_title.
18
+ def get_interwiki_import_log(user = nil, title = nil, start = nil,
19
+ stop = nil, limit = 500)
20
+ resp = get_log('import/interwiki', user, title, start, stop, limit)
21
+
22
+ ret = []
23
+ resp['query']['logevents'].each do |log|
24
+ ret << get_importinterwiki(log)
25
+ end
26
+
27
+ ret
28
+ end
29
+
30
+ # Gets import/upload logs.
31
+ # @param user [String] See {MediaWiki::Query::Lists::Log#get_log}
32
+ # @param title [String] See {MediaWiki::Query::Lists::Log#get_log}
33
+ # @param start [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
34
+ # @param stop [DateTime] See {MediaWiki::Query::Lists::Log#get_log}
35
+ # @param limit [Int] See {MediaWiki::Query::Lists::Log#get_log}
36
+ # @see {MediaWiki::Query::Lists::Log#get_log}
37
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki
38
+ # Logevents API Docs
39
+ # @since 0.10.0
40
+ # @return [Array<Hash>] The events, containing the following keys: id,
41
+ # title, user, timestamp, comment.
42
+ def get_upload_import_log(user = nil, title = nil, start = nil,
43
+ stop = nil, limit = 500)
44
+ resp = get_log('import/upload', user, title, start, stop, limit)
45
+
46
+ ret = []
47
+ resp['query']['logevents'].each do |log|
48
+ ret << get_importupload(log)
49
+ end
50
+
51
+ ret
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,372 @@
1
+ require_relative '../../../constants'
2
+ require_relative 'block'
3
+ require_relative 'delete'
4
+ require_relative 'import'
5
+ require_relative 'merge'
6
+ require_relative 'move'
7
+ require_relative 'newusers'
8
+ require_relative 'patrol'
9
+ require_relative 'protect'
10
+ require_relative 'rights'
11
+ require_relative 'upload'
12
+
13
+ module MediaWiki
14
+ module Query
15
+ module Lists
16
+ module Log
17
+ include MediaWiki::Query::Lists::Log::Block
18
+ include MediaWiki::Query::Lists::Log::Delete
19
+ include MediaWiki::Query::Lists::Log::Import
20
+ include MediaWiki::Query::Lists::Log::Merge
21
+ include MediaWiki::Query::Lists::Log::Move
22
+ include MediaWiki::Query::Lists::Log::NewUsers
23
+ include MediaWiki::Query::Lists::Log::Patrol
24
+ include MediaWiki::Query::Lists::Log::Protect
25
+ include MediaWiki::Query::Lists::Log::Rights
26
+ include MediaWiki::Query::Lists::Log::Upload
27
+
28
+ # Gets the general log as seen in Special:Log. Since not every single
29
+ # log type possible can be supported, non-default MW logs will be
30
+ # represented exactly as provided by the API, with the :skipped key
31
+ # as true.
32
+ # @param user [String] See {#get_log}
33
+ # @param title [String] See {#get_log}
34
+ # @param start [DateTime] See {#get_log}
35
+ # @param stop [DateTime] See {#get_log}
36
+ # @param limit [Int] See {#get_log}
37
+ # @see {#get_log}
38
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki Logevents
39
+ # API Docs
40
+ # @since 0.10.0
41
+ # @return [Array<Hash>] All the log events.
42
+ def get_overall_log(user = nil, title = nil, start = nil, stop = nil,
43
+ limit = 500)
44
+ time_format = MediaWiki::Constants::TIME_FORMAT
45
+ params = {
46
+ action: 'query',
47
+ list: 'logevents',
48
+ lelimit: get_limited(limit)
49
+ }
50
+ params[:leuser] = user unless user.nil?
51
+ params[:letitle] = title unless title.nil?
52
+ params[:lestart] = start.strftime(time_format) unless start.nil?
53
+ params[:leend] = stop.strftime(time_format) unless stop.nil?
54
+ response = post(params)
55
+
56
+ ret = []
57
+ response['query']['logevents'].each do |log|
58
+ case log['type']
59
+ when 'block'
60
+ case log['action']
61
+ when 'block'
62
+ hash = get_blockblock(log)
63
+ when 'unblock'
64
+ hash = get_blockunblock(log)
65
+ when 'reblock'
66
+ hash = get_blockreblock(log)
67
+ end
68
+ when 'delete'
69
+ case log['action']
70
+ when 'delete', 'restore'
71
+ hash = get_deletedelete(log)
72
+ end
73
+ when 'import'
74
+ case log['action']
75
+ when 'interwiki'
76
+ hash = get_importinterwiki(log)
77
+ when 'upload'
78
+ hash = get_importupload(log)
79
+ end
80
+ when 'merge'
81
+ case log['action']
82
+ when 'merge'
83
+ hash = get_mergemerge(log)
84
+ end
85
+ when 'move'
86
+ case log['action']
87
+ when 'move', 'move_redir'
88
+ hash = get_move(log)
89
+ end
90
+ when 'newusers'
91
+ case log['action']
92
+ when 'autocreate', 'create', 'create2'
93
+ hash = get_user(log)
94
+ end
95
+ when 'patrol'
96
+ case log['action']
97
+ when 'patrol'
98
+ hash = get_patrol(log)
99
+ end
100
+ when 'protect'
101
+ case log['action']
102
+ when 'modify', 'protect'
103
+ hash = get_protect(log)
104
+ when 'move_prot'
105
+ hash = get_protectmoveprot(log)
106
+ when 'unprotect'
107
+ hash = get_protectunprotect(log)
108
+ end
109
+ when 'rights'
110
+ case log['action']
111
+ when 'autopromote'
112
+ hash = get_rightsautopromote(log)
113
+ when 'rights'
114
+ hash = get_rightsrights(log)
115
+ end
116
+ when 'upload'
117
+ case log['action']
118
+ when 'overwrite', 'upload'
119
+ hash = get_upload(log)
120
+ end
121
+ end
122
+
123
+ hash = log if hash.nil?
124
+
125
+ type = "#{log['type']}/#{log['action']}"
126
+
127
+ hash[:type] = type
128
+ hash[:skipped] = false unless hash.key(:skipped)
129
+
130
+ ret << hash
131
+ end
132
+
133
+ ret
134
+ end
135
+
136
+ private
137
+
138
+ # Gets log events.
139
+ # @param action [String] The action, e.g., block/block.
140
+ # @param user [String] The user to filter by.
141
+ # @param title [String] The title to filter by.
142
+ # @param start [DateTime] Where to start the log events at.
143
+ # @param stop [DateTime] Where to end the log events.
144
+ # @param limit [Int] The limit, maximum 500 for users or 5000 for bots.
145
+ # @see https://www.mediawiki.org/wiki/API:Logevents MediaWiki Logevents
146
+ # API Docs
147
+ # @since 0.10.0
148
+ # @return [JSON] The response json.
149
+ def get_log(action, user = nil, title = nil, start = nil, stop = nil,
150
+ limit = 500)
151
+ params = {
152
+ action: 'query',
153
+ list: 'logevents',
154
+ leaction: action,
155
+ lelimit: get_limited(limit)
156
+ }
157
+ params[:leuser] = user unless user.nil?
158
+ params[:letitle] = title unless title.nil?
159
+ params[:lestart] = start.strftime(MediaWiki::Constants::TIME_FORMAT) unless start.nil?
160
+ params[:leend] = stop.strftime(MediaWiki::Constants::TIME_FORMAT) unless stop.nil?
161
+ post(params)
162
+ end
163
+
164
+ def get_block(log)
165
+ {
166
+ id: log['logid'],
167
+ blocked: log['title'],
168
+ flags: log['block']['flags'],
169
+ duration: log['block']['duration'],
170
+ expiry: DateTime.strptime(log['block']['expiry'],
171
+ MediaWiki::Constants::TIME_FORMAT),
172
+ blocker: log['user'],
173
+ comment: log['comment'],
174
+ timestamp: DateTime.strptime(log['timestamp'],
175
+ MediaWiki::Constants::TIME_FORMAT)
176
+ }
177
+ end
178
+
179
+ def get_unblock(log)
180
+ {
181
+ id: log['logid'],
182
+ blocked: log['title'],
183
+ blocker: log['user'],
184
+ timestamp: DateTime.strptime(log['timestamp'],
185
+ MediaWiki::Constants::TIME_FORMAT),
186
+ comment: log['comment']
187
+ }
188
+ end
189
+
190
+ def get_importinterwiki(log)
191
+ {
192
+ id: log['logid'],
193
+ title: log['title'],
194
+ user: log['user'],
195
+ comment: log['comment'],
196
+ timestamp: DateTime.strptime(log['timestamp'],
197
+ MediaWiki::Constants::TIME_FORMAT),
198
+ count: log['params']['count'],
199
+ interwiki_title: log['params']['interwiki_title']
200
+ }
201
+ end
202
+
203
+ def get_general(log)
204
+ {
205
+ id: log['logid'],
206
+ title: log['title'],
207
+ user: log['user'],
208
+ timestamp: DateTime.strptime(log['timestamp'],
209
+ MediaWiki::Constants::TIME_FORMAT),
210
+ comment: log['comment']
211
+ }
212
+ end
213
+
214
+ def get_merge(log)
215
+ {
216
+ id: log['logid'],
217
+ title: log['title'],
218
+ user: log['user'],
219
+ comment: log['comment'],
220
+ destination_title: log['params']['dest_title'],
221
+ mergepoint: DateTime.strptime(log['params']['mergepoint'],
222
+ MediaWiki::Constants::TIME_FORMAT),
223
+ timestamp: DateTime.strptime(log['timestamp'],
224
+ MediaWiki::Constants::TIME_FORMAT)
225
+ }
226
+ end
227
+
228
+ def get_move(log)
229
+ hash = {
230
+ id: log['logid'],
231
+ timestamp: DateTime.strptime(log['timestamp'],
232
+ MediaWiki::Constants::TIME_FORMAT)
233
+ }
234
+
235
+ if log.key?('actionhidden')
236
+ hash[:hidden] = true
237
+ hash[:title] = nil
238
+ hash[:comment] = nil
239
+ hash[:suppressedredirect] = log.key('suppressed')
240
+ else
241
+ hash[:title] = log['title']
242
+ hash[:new_title] = log['move']['new_title']
243
+ hash[:user] = log['user']
244
+ hash[:comment] = log['comment']
245
+
246
+ hash[:suppressedredirect] = log['move'].key?('suppressedredirect')
247
+ end
248
+
249
+ hash
250
+ end
251
+
252
+ def get_user(log)
253
+ {
254
+ id: log['logid'],
255
+ new_user: log['title'],
256
+ user: log['user'],
257
+ comment: log['comment'],
258
+ timestamp: DateTime.strptime(log['timestamp'],
259
+ MediaWiki::Constants::TIME_FORMAT)
260
+ }
261
+ end
262
+
263
+ def get_patrol(log)
264
+ hash = {
265
+ id: log['logid'],
266
+ title: log['title'],
267
+ user: log['user'],
268
+ comment: log['comment'],
269
+ current_revision: log['patrol']['cur'],
270
+ previous_revision: log['patrol']['prev'],
271
+ timestamp: DateTime.strptime(log['timestamp'],
272
+ MediaWiki::Constants::TIME_FORMAT)
273
+ }
274
+ auto = log['patrol']['auto']
275
+ hash[:automatic] = auto == 1
276
+
277
+ hash
278
+ end
279
+
280
+ def get_protect(log)
281
+ time_format = MediaWiki::Constants::TIME_FORMAT
282
+ hash = {
283
+ id: log['logid'],
284
+ title: log['title'],
285
+ description: log['params']['description'],
286
+ user: log['user'],
287
+ comment: log['comment'],
288
+ timestamp: DateTime.strptime(log['timestamp'], time_format)
289
+ }
290
+
291
+ hash[:details] = []
292
+
293
+ log['params']['detail'].each do |detail|
294
+ details_hash = {
295
+ type: detail['type'],
296
+ level: detail['level']
297
+ }
298
+ expire = detail['expiry']
299
+ if expire != 'infinite'
300
+ details_hash[:expiry] = DateTime.strptime(expire, time_format)
301
+ end
302
+ hash[:details] << detail_hash
303
+ end
304
+
305
+ hash
306
+ end
307
+
308
+ def get_protectmoveprot(log)
309
+ {
310
+ id: log['logid'],
311
+ title: log['title'],
312
+ old_title: log['params']['oldtitle_title'],
313
+ user: log['user'],
314
+ comment: log['comment'],
315
+ timestamp: DateTime.strptime(log['timestamp'],
316
+ MediaWiki::Constants::TIME_FORMAT)
317
+ }
318
+ end
319
+
320
+ def get_protectunprotect(log)
321
+ {
322
+ id: log['logid'],
323
+ title: log['title'],
324
+ user: log['user'],
325
+ comment: log['comment'],
326
+ timestamp: DateTime.strptime(log['timestamp'],
327
+ MediaWiki::Constants::TIME_FORMAT)
328
+ }
329
+ end
330
+
331
+ def get_rightsautopromote(log)
332
+ {
333
+ id: log['logid'],
334
+ title: log['title'],
335
+ user: log['user'],
336
+ new_rights: log['rights']['new'].split(', '),
337
+ old_rights: log['rights']['old'].split(', '),
338
+ comment: log['comment'],
339
+ timestamp: DateTime.strptime(log['timestamp'],
340
+ MediaWiki::Constants::TIME_FORMAT)
341
+ }
342
+ end
343
+
344
+ def get_rightsrights(log)
345
+ {
346
+ id: log['logid'],
347
+ title: log['title'],
348
+ to: log['title'],
349
+ from: log['user'],
350
+ new_rights: log['rights']['new'].split(', '),
351
+ old_rights: log['rights']['old'].split(', '),
352
+ comment: log['comment'],
353
+ timestamp: DateTime.strptime(log['timestamp'],
354
+ MediaWiki::Constants::TIME_FORMAT)
355
+ }
356
+ end
357
+
358
+ def get_upload(log)
359
+ {
360
+ id: log['logid'],
361
+ title: log['title'],
362
+ user: log['user'],
363
+ sha: log['img_sha1'],
364
+ comment: log['comment'],
365
+ timestamp: DateTime.strptime(log['timestamp'],
366
+ MediaWiki::Constants::TIME_FORMAT)
367
+ }
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end