mediawiki-butt 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/lib/mediawiki/administration.rb +0 -2
- data/lib/mediawiki/butt.rb +8 -2
- data/lib/mediawiki/edit.rb +4 -4
- data/lib/mediawiki/query/lists.rb +388 -0
- data/lib/mediawiki/query/meta/filerepoinfo.rb +90 -0
- data/lib/mediawiki/query/meta/meta.rb +13 -0
- data/lib/mediawiki/query/meta/siteinfo.rb +196 -0
- data/lib/mediawiki/query/meta/userinfo.rb +111 -0
- data/lib/mediawiki/query/properties.rb +107 -0
- data/lib/mediawiki/query/query.rb +11 -0
- metadata +9 -3
- data/lib/mediawiki/query.rb +0 -789
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediawiki-butt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-10-
|
12
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: string-utility
|
@@ -55,7 +55,13 @@ files:
|
|
55
55
|
- lib/mediawiki/constants.rb
|
56
56
|
- lib/mediawiki/edit.rb
|
57
57
|
- lib/mediawiki/exceptions.rb
|
58
|
-
- lib/mediawiki/query.rb
|
58
|
+
- lib/mediawiki/query/lists.rb
|
59
|
+
- lib/mediawiki/query/meta/filerepoinfo.rb
|
60
|
+
- lib/mediawiki/query/meta/meta.rb
|
61
|
+
- lib/mediawiki/query/meta/siteinfo.rb
|
62
|
+
- lib/mediawiki/query/meta/userinfo.rb
|
63
|
+
- lib/mediawiki/query/properties.rb
|
64
|
+
- lib/mediawiki/query/query.rb
|
59
65
|
homepage: https://github.com/ftb-gamepedia/mediawiki-butt-ruby
|
60
66
|
licenses:
|
61
67
|
- CC-BY-NC-ND-4.0
|
data/lib/mediawiki/query.rb
DELETED
@@ -1,789 +0,0 @@
|
|
1
|
-
require 'string-utility'
|
2
|
-
require_relative 'constants'
|
3
|
-
|
4
|
-
module MediaWiki
|
5
|
-
module Query
|
6
|
-
module Meta
|
7
|
-
module SiteInfo
|
8
|
-
# Gets wiki information. This method should rarely be used by
|
9
|
-
# normal users.
|
10
|
-
# @param prop [String] The siprop parameter.
|
11
|
-
# @return [Response] Parsed full response.
|
12
|
-
def get_siteinfo(prop)
|
13
|
-
params = {
|
14
|
-
action: 'query',
|
15
|
-
meta: 'siteinfo',
|
16
|
-
siprop: prop
|
17
|
-
}
|
18
|
-
|
19
|
-
post(params)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Gets the statistics for the wiki.
|
23
|
-
# @return [Hash] The statistics and their according values.
|
24
|
-
def get_statistics
|
25
|
-
response = get_siteinfo('statistics')
|
26
|
-
ret = {}
|
27
|
-
response['query']['statistics'].each { |k, v| ret[k] = v }
|
28
|
-
ret
|
29
|
-
end
|
30
|
-
|
31
|
-
# Gets the general information for the wiki.
|
32
|
-
# @return [Hash] The general info and their according values.
|
33
|
-
def get_general
|
34
|
-
response = get_siteinfo('general')
|
35
|
-
ret = {}
|
36
|
-
response['query']['general'].each { |k, v| ret[k] = v }
|
37
|
-
ret
|
38
|
-
end
|
39
|
-
|
40
|
-
# Gets all extensions installed on the wiki.
|
41
|
-
# @return [Array] All extension names.
|
42
|
-
def get_extensions
|
43
|
-
response = get_siteinfo('extensions')
|
44
|
-
ret = []
|
45
|
-
response['query']['extensions'].each { |e| ret.push(e['name']) }
|
46
|
-
ret
|
47
|
-
end
|
48
|
-
|
49
|
-
# Gets all languages and their codes.
|
50
|
-
# @return [Hash] All languages. Hash key value pair formatted as
|
51
|
-
# code => name.
|
52
|
-
def get_languages
|
53
|
-
response = get_siteinfo('languages')
|
54
|
-
ret = {}
|
55
|
-
response['query']['languages'].each { |l| ret[l['code']] = l['*'] }
|
56
|
-
ret
|
57
|
-
end
|
58
|
-
|
59
|
-
# Gets all namespaces on the wiki and their IDs. Different from the
|
60
|
-
# Namespaces module.
|
61
|
-
# @return [Hash] All namespaces, formatted as ID => Name.
|
62
|
-
def get_namespaces
|
63
|
-
response = get_siteinfo('namespaces')
|
64
|
-
ret = {}
|
65
|
-
response['query']['namespaces'].each do |id, hash|
|
66
|
-
idid = response['query']['namespaces'][id]['id']
|
67
|
-
name = response['query']['namespaces'][id]['*']
|
68
|
-
ret[idid] = name
|
69
|
-
end
|
70
|
-
ret
|
71
|
-
end
|
72
|
-
|
73
|
-
# Gets all namespace aliases and their IDs.
|
74
|
-
# @return [Hash] All aliases, formatted as ID => Alias.
|
75
|
-
def get_namespace_aliases
|
76
|
-
response = get_siteinfo('namespacealiases')
|
77
|
-
ret = {}
|
78
|
-
response['query']['namespacealiases'].each do |a|
|
79
|
-
ret[i['id']] = i['*']
|
80
|
-
end
|
81
|
-
ret
|
82
|
-
end
|
83
|
-
|
84
|
-
# Gets all special page aliases.
|
85
|
-
# @return [Hash] All aliases, formatted as RealName => Alias.
|
86
|
-
def get_special_page_aliases
|
87
|
-
response = get_siteinfo('specialpagealiases')
|
88
|
-
ret = {}
|
89
|
-
response['query']['specialpagealiases'].each do |a|
|
90
|
-
ret[i['realname']] = i['aliases']
|
91
|
-
end
|
92
|
-
ret
|
93
|
-
end
|
94
|
-
|
95
|
-
# Gets all magic words and their aliases.
|
96
|
-
# @return [Hash] All magic words, formatted as Name => Alias.
|
97
|
-
def get_magic_words
|
98
|
-
response = get_siteinfo('magicwords')
|
99
|
-
ret = {}
|
100
|
-
response['query']['magicwords'].each do |w|
|
101
|
-
ret[w['name']] = w['aliases']
|
102
|
-
end
|
103
|
-
ret
|
104
|
-
end
|
105
|
-
|
106
|
-
# Gets all user groups total.
|
107
|
-
# @return [Hash] All groups, formatted as Name => [Rights].
|
108
|
-
def get_all_usergroups
|
109
|
-
response = get_siteinfo('usergroups')
|
110
|
-
ret = {}
|
111
|
-
response['query']['usergroups'].each do |g|
|
112
|
-
ret[g['name']] = g['rights']
|
113
|
-
end
|
114
|
-
ret
|
115
|
-
end
|
116
|
-
|
117
|
-
# Gets all file extensions that are allowed to be uploaded.
|
118
|
-
# @return [Array] All file extensions.
|
119
|
-
def get_allowed_file_extensions
|
120
|
-
response = get_siteinfo('fileextensions')
|
121
|
-
ret = []
|
122
|
-
response['query']['fileextensions'].each do |e|
|
123
|
-
ret.push(e['ext'])
|
124
|
-
end
|
125
|
-
ret
|
126
|
-
end
|
127
|
-
|
128
|
-
# Gets the response for the restrictions siteinfo API. Not really for
|
129
|
-
# use by users, mostly for the other two restriction methods.
|
130
|
-
def get_restrictions_data
|
131
|
-
response = get_siteinfo('restrictions')
|
132
|
-
return response['query']['restrictions']
|
133
|
-
end
|
134
|
-
|
135
|
-
# Gets all restriction/protection types.
|
136
|
-
# @return [Array] All protection types.
|
137
|
-
def get_restriction_types
|
138
|
-
restrictions = get_restrictions_data
|
139
|
-
ret = []
|
140
|
-
restrictions['types'].each { |t| ret.push(t) }
|
141
|
-
ret
|
142
|
-
end
|
143
|
-
|
144
|
-
# Gets all restriction/protection levels.
|
145
|
-
# @return [Array] All protection levels.
|
146
|
-
def get_restriction_levels
|
147
|
-
restrictions = get_restrictions_data
|
148
|
-
ret = []
|
149
|
-
restrictions['levels'].each { |l| ret.push(l) }
|
150
|
-
ret
|
151
|
-
end
|
152
|
-
|
153
|
-
# Gets all skins and their codes.
|
154
|
-
# @return [Hash] All skins, formatted as Code => Name
|
155
|
-
def get_skins
|
156
|
-
response = get_siteinfo('skins')
|
157
|
-
ret = {}
|
158
|
-
response['query']['skins'].each do |s|
|
159
|
-
ret[s['code']] = s['*']
|
160
|
-
end
|
161
|
-
ret
|
162
|
-
end
|
163
|
-
|
164
|
-
# Gets all HTML tags added by installed extensions.
|
165
|
-
# @return [Array] All extension tags.
|
166
|
-
def get_extension_tags
|
167
|
-
response = get_siteinfo('extensiontags')
|
168
|
-
ret = []
|
169
|
-
response['query']['extensiontags'].each do |t|
|
170
|
-
ret.push(t)
|
171
|
-
end
|
172
|
-
ret
|
173
|
-
end
|
174
|
-
|
175
|
-
# Gets all function hooks.
|
176
|
-
# @return [Array] All function hooks.
|
177
|
-
def get_function_hooks
|
178
|
-
response = get_siteinfo('functionhooks')
|
179
|
-
ret = []
|
180
|
-
response['query']['functionhooks'].each do |h|
|
181
|
-
ret.push(h)
|
182
|
-
end
|
183
|
-
ret
|
184
|
-
end
|
185
|
-
|
186
|
-
# Gets all variables that are usable on the wiki, such as NUMBEROFPAGES.
|
187
|
-
# @return [Array] All variable string values.
|
188
|
-
def get_variables
|
189
|
-
response = get_siteinfo('variables')
|
190
|
-
ret = []
|
191
|
-
response['query']['variables'].each do |v|
|
192
|
-
ret.push(v)
|
193
|
-
end
|
194
|
-
ret
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
module FileRepoInfo
|
199
|
-
# Gets FileRepoInfo for the property.
|
200
|
-
# @param prop [String] The friprop to get.
|
201
|
-
# @return [Response] The full parsed response.
|
202
|
-
def get_filerepoinfo(prop)
|
203
|
-
params = {
|
204
|
-
action: 'query',
|
205
|
-
meta: 'filerepoinfo',
|
206
|
-
friprop: prop
|
207
|
-
}
|
208
|
-
|
209
|
-
post(params)
|
210
|
-
end
|
211
|
-
|
212
|
-
# Returns an array of all the wiki's file repository names.
|
213
|
-
# @return [Array] All wiki's file repository names.
|
214
|
-
def get_filerepo_names
|
215
|
-
response = get_filerepoinfo('name|displayname')
|
216
|
-
ret = {}
|
217
|
-
response['query']['repos'].each { |n, dn| ret[n] = dn }
|
218
|
-
ret
|
219
|
-
end
|
220
|
-
|
221
|
-
# Gets the root URLs for the file repositories.
|
222
|
-
# @return [Hash] A hash containing keys of the names, and values of the
|
223
|
-
# root URLs.
|
224
|
-
def get_filerepo_rooturls
|
225
|
-
response = get_filerepoinfo('name|rootUrl')
|
226
|
-
ret = {}
|
227
|
-
response['query']['repos'].each { |n, r| ret[n] = r }
|
228
|
-
ret
|
229
|
-
end
|
230
|
-
|
231
|
-
# Gets an array containing all local repositories.
|
232
|
-
# @return [Array] All repositories that are marked as local.
|
233
|
-
def get_local_filerepos
|
234
|
-
response = get_filerepoinfo('name|local')
|
235
|
-
ret = []
|
236
|
-
response['query']['repos'].each do |n, l|
|
237
|
-
ret.push(n) if l == 'true'
|
238
|
-
end
|
239
|
-
|
240
|
-
ret
|
241
|
-
end
|
242
|
-
|
243
|
-
# Gets an array containing all repositories that aren't local.
|
244
|
-
# @return [Array] All repositories that are not marked as local.
|
245
|
-
def get_nonlocal_filerepos
|
246
|
-
response = get_filerepoinfo('name|local')
|
247
|
-
ret = []
|
248
|
-
response['query']['repos'].each do |n, l|
|
249
|
-
ret.push(n) if l == 'false'
|
250
|
-
end
|
251
|
-
|
252
|
-
ret
|
253
|
-
end
|
254
|
-
|
255
|
-
# Gets the repository names and their according URLs.
|
256
|
-
# @return [Hash] Names as the keys, with their URLs as the values.
|
257
|
-
def get_filerepo_urls
|
258
|
-
response = get_filerepoinfo('name|url')
|
259
|
-
ret = {}
|
260
|
-
response['query']['repos'].each { |n, u| ret[n] = u }
|
261
|
-
ret
|
262
|
-
end
|
263
|
-
|
264
|
-
# Gets the repository names and their accoring thumbnail URLs.
|
265
|
-
# @return [Hash] Names as the keys, with their URLs as the values.
|
266
|
-
def get_filerepo_thumburls
|
267
|
-
response = get_filerepoinfo('name|thumbUrl')
|
268
|
-
ret = {}
|
269
|
-
response['query']['repos'].each { |n, u| ret[n] = u }
|
270
|
-
ret
|
271
|
-
end
|
272
|
-
|
273
|
-
# Gets the repository names and their according favicon URLs.
|
274
|
-
# @return [Hash] Names as the keys, with their favicons as the values.
|
275
|
-
def get_filerepo_favicons
|
276
|
-
response = get_filerepoinfo('name|favicon')
|
277
|
-
ret = {}
|
278
|
-
response['query']['repos'].each { |n, f| ret[n] = f }
|
279
|
-
ret
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
module UserInfo
|
284
|
-
# Gets meta information for the currently logged in user.
|
285
|
-
# @param prop [String] The uiprop to get. Optional.
|
286
|
-
# @return [Response/Boolean] Either a full, parsed response, or false if
|
287
|
-
# not logged in.
|
288
|
-
def get_current_user_meta(prop = nil)
|
289
|
-
if @logged_in
|
290
|
-
params = {
|
291
|
-
action: 'query',
|
292
|
-
meta: 'userinfo',
|
293
|
-
uiprop: prop
|
294
|
-
}
|
295
|
-
|
296
|
-
post(params)
|
297
|
-
else
|
298
|
-
return false
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
# Gets the current user's username.
|
303
|
-
# @return [String/Boolean] Returns the username, or false.
|
304
|
-
def get_current_user_name
|
305
|
-
if !@name.nil?
|
306
|
-
return @name
|
307
|
-
else
|
308
|
-
name = get_current_user_meta
|
309
|
-
if name != false
|
310
|
-
name = name['query']['userinfo']['name']
|
311
|
-
end
|
312
|
-
|
313
|
-
name
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
# Returns whether or not the currently logged in user has any unread
|
318
|
-
# messages on their talk page.
|
319
|
-
# @return [Boolean] True if they have unreads, else false.
|
320
|
-
def current_user_hasmsg?
|
321
|
-
response = get_current_user_meta('hasmsg')
|
322
|
-
if response != false
|
323
|
-
if !response['query']['userinfo']['messages'] == ''
|
324
|
-
return false
|
325
|
-
else
|
326
|
-
return true
|
327
|
-
end
|
328
|
-
else
|
329
|
-
return false
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
# Gets a hash-of-arrays containing all the groups the user can add and
|
334
|
-
# remove people from.
|
335
|
-
# @return [Boolean/Hash] False if get_current_user_meta is false, else
|
336
|
-
# a hash containing arrays of all the groups the user can add/remove
|
337
|
-
# people from.
|
338
|
-
def get_changeable_groups
|
339
|
-
response = get_current_user_meta('changeablegroups')
|
340
|
-
if response != false
|
341
|
-
ret = {}
|
342
|
-
add = []
|
343
|
-
remove = []
|
344
|
-
addself = []
|
345
|
-
removeself = []
|
346
|
-
changeablegroups = response['query']['userinfo']['changeablegroups']
|
347
|
-
puts changeablegroups
|
348
|
-
changeablegroups['add'].each { |g| puts g; add.push(g) }
|
349
|
-
changeablegroups['remove'].each { |g| puts g; remove.push(g) }
|
350
|
-
changeablegroups['add-self'].each { |g| puts g; addself.push(g) }
|
351
|
-
changeablegroups['remove-self'].each { |g| puts g; removeself.push(g) }
|
352
|
-
ret['add'] = add
|
353
|
-
ret['remove'] = remove
|
354
|
-
ret['addself'] = addself
|
355
|
-
ret['removeself'] = removeself
|
356
|
-
return ret
|
357
|
-
else
|
358
|
-
return false
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
# Gets the currently logged in user's real name.
|
363
|
-
# @return [String/Nil] Nil if they don't have a real name set, or their
|
364
|
-
# real name.
|
365
|
-
def get_realname
|
366
|
-
response = get_current_user_meta('realname')
|
367
|
-
if response['query']['userinfo']['realname'] == ''
|
368
|
-
return nil
|
369
|
-
else
|
370
|
-
return response['query']['userinfo']['realname']
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
|
-
# Gets the currently logged in user's email address.
|
375
|
-
# @return [String/Nil] Nil if their email is not set, or their email.
|
376
|
-
def get_email_address
|
377
|
-
response = get_current_user_meta('email')
|
378
|
-
if response['query']['userinfo']['email'] == ''
|
379
|
-
return nil
|
380
|
-
else
|
381
|
-
return response['query']['userinfo']['email']
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
def get_current_user_options
|
386
|
-
response = get_current_user_meta('options')
|
387
|
-
ret = {}
|
388
|
-
response['query']['userinfo']['options'].each { |k, v| ret[k] = v }
|
389
|
-
end
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
module Properties
|
394
|
-
# Gets the wiki text for the given page. Returns nil if it for some
|
395
|
-
# reason cannot get the text, for example, if the page does not exist.
|
396
|
-
# @param title [String] The page title
|
397
|
-
# @return [String/nil] String containing page contents, or nil
|
398
|
-
def get_text(title)
|
399
|
-
params = {
|
400
|
-
action: 'query',
|
401
|
-
prop: 'revisions',
|
402
|
-
rvprop: 'content',
|
403
|
-
titles: title
|
404
|
-
}
|
405
|
-
|
406
|
-
response = post(params)
|
407
|
-
revid = nil
|
408
|
-
response['query']['pages'].each { |r, _| revid = r }
|
409
|
-
|
410
|
-
if response['query']['pages'][revid]['missing'] == ''
|
411
|
-
return nil
|
412
|
-
else
|
413
|
-
return response['query']['pages'][revid]['revisions'][0]['*']
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
# Gets the revision ID for the given page.
|
418
|
-
# @param title [String] The page title
|
419
|
-
# @return [Int/nil] the ID or nil
|
420
|
-
def get_id(title)
|
421
|
-
params = {
|
422
|
-
action: 'query',
|
423
|
-
prop: 'revisions',
|
424
|
-
rvprop: 'content',
|
425
|
-
titles: title
|
426
|
-
}
|
427
|
-
|
428
|
-
response = post(params)
|
429
|
-
response['query']['pages'].each do |revid, _|
|
430
|
-
if revid != '-1'
|
431
|
-
return revid.to_i
|
432
|
-
else
|
433
|
-
return nil
|
434
|
-
end
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
# Gets the token for the given type. This method should rarely be
|
439
|
-
# used by normal users.
|
440
|
-
# @param type [String] The type of token.
|
441
|
-
# @param title [String] The page title for the token. Optional.
|
442
|
-
# @return [String] The token. If the butt isn't logged in, it returns
|
443
|
-
# with '+\\'.
|
444
|
-
def get_token(type, title = nil)
|
445
|
-
if @logged_in == true
|
446
|
-
# There is some weird thing with MediaWiki where you must pass a valid
|
447
|
-
# inprop parameter in order to get any response at all. This is why
|
448
|
-
# there is a displaytitle inprop as well as gibberish in the titles
|
449
|
-
# parameter. And to avoid normalization, it's capitalized.
|
450
|
-
params = {
|
451
|
-
action: 'query',
|
452
|
-
prop: 'info',
|
453
|
-
inprop: 'displaytitle',
|
454
|
-
intoken: type
|
455
|
-
}
|
456
|
-
|
457
|
-
title = 'Somegibberish' if title.nil?
|
458
|
-
params[:titles] = title
|
459
|
-
response = post(params)
|
460
|
-
revid = nil
|
461
|
-
response['query']['pages'].each { |r, _| revid = r }
|
462
|
-
|
463
|
-
# URL encoding is not needed for some reason.
|
464
|
-
return response['query']['pages'][revid]["#{type}token"]
|
465
|
-
else
|
466
|
-
return '+\\'
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
module Lists
|
472
|
-
using StringUtility
|
473
|
-
|
474
|
-
# Gets an array of backlinks to a given title.
|
475
|
-
# @param title [String] The page to get the backlinks of.
|
476
|
-
# @param limit [Int] The maximum number of pages to get. Defaults to 500,
|
477
|
-
# and cannot be greater than that unless the user is a bot. If the user
|
478
|
-
# is a bot, the limit cannot be greater than 5000.
|
479
|
-
# @return [Array] All backlinks until the limit
|
480
|
-
def what_links_here(title, limit = 500)
|
481
|
-
params = {
|
482
|
-
action: 'query',
|
483
|
-
bltitle: title
|
484
|
-
}
|
485
|
-
|
486
|
-
if limit > 500
|
487
|
-
if is_user_bot? == true
|
488
|
-
if limit > 5000
|
489
|
-
params[:bllimit] = 5000
|
490
|
-
else
|
491
|
-
params[:bllimit] = limit
|
492
|
-
end
|
493
|
-
else
|
494
|
-
params[:bllimit] = 500
|
495
|
-
end
|
496
|
-
else
|
497
|
-
params[:bllimit] = limit
|
498
|
-
end
|
499
|
-
|
500
|
-
ret = []
|
501
|
-
response = post(params)
|
502
|
-
response['query']['backlinks'].each { |bl| ret.push(bl['title']) }
|
503
|
-
|
504
|
-
ret
|
505
|
-
end
|
506
|
-
|
507
|
-
# Returns an array of all page titles that belong to a given category.
|
508
|
-
# @param category [String] The category title. It can include "Category:",
|
509
|
-
# or not, it doesn't really matter because we will add it if it is
|
510
|
-
# missing.
|
511
|
-
# @param limit [Int] The maximum number of members to get. Defaults to
|
512
|
-
# 500, and cannot be greater than that unless the user is a bot.
|
513
|
-
# If the user is a bot, the limit cannot be greater than 5000.
|
514
|
-
# @return [Array] All category members until the limit
|
515
|
-
def get_category_members(category, limit = 500)
|
516
|
-
params = {
|
517
|
-
action: 'query',
|
518
|
-
list: 'categorymembers',
|
519
|
-
cmprop: 'title'
|
520
|
-
}
|
521
|
-
|
522
|
-
if category =~ /[Cc]ategory\:/
|
523
|
-
params[:cmtitle] = category
|
524
|
-
else
|
525
|
-
params[:cmtitle] = "Category:#{category}"
|
526
|
-
end
|
527
|
-
|
528
|
-
if limit > 500
|
529
|
-
if is_user_bot?
|
530
|
-
if limit > 5000
|
531
|
-
params[:cmlimit] = 5000
|
532
|
-
else
|
533
|
-
params[:cmlimit] = limit
|
534
|
-
end
|
535
|
-
else
|
536
|
-
params[:cmlimit] = 500
|
537
|
-
end
|
538
|
-
else
|
539
|
-
params[:cmlimit] = limit
|
540
|
-
end
|
541
|
-
|
542
|
-
ret = []
|
543
|
-
response = post(params)
|
544
|
-
response['query']['categorymembers'].each { |cm| ret.push(cm['title']) }
|
545
|
-
|
546
|
-
ret
|
547
|
-
end
|
548
|
-
|
549
|
-
# Returns an array of random pages titles.
|
550
|
-
# @param number_of_pages [Int] The number of articles to get.
|
551
|
-
# Defaults to 1. Cannot be greater than 10 for normal users,
|
552
|
-
# or 20 for bots.
|
553
|
-
# @param namespace [Int] The namespace ID. Defaults to
|
554
|
-
# 0 (the main namespace).
|
555
|
-
# @return [Array] All members
|
556
|
-
def get_random_pages(number_of_pages = 1, namespace = 0)
|
557
|
-
params = {
|
558
|
-
action: 'query',
|
559
|
-
list: 'random'
|
560
|
-
}
|
561
|
-
|
562
|
-
if $namespaces.value?(namespace)
|
563
|
-
params[:rnnamespace] = namespace
|
564
|
-
else
|
565
|
-
params[:rnnamespace] = 0
|
566
|
-
end
|
567
|
-
|
568
|
-
if number_of_pages > 10
|
569
|
-
if is_user_bot?
|
570
|
-
if limit > 20
|
571
|
-
params[:rnlimit] = 20
|
572
|
-
else
|
573
|
-
params[:rnlimit] = limit
|
574
|
-
end
|
575
|
-
else
|
576
|
-
params[:rnlimit] = 10
|
577
|
-
end
|
578
|
-
else
|
579
|
-
params[:rnlimit] = number_of_pages
|
580
|
-
end
|
581
|
-
|
582
|
-
ret = []
|
583
|
-
responce = post(params)
|
584
|
-
responce['query']['random'].each { |a| ret.push(a['title']) }
|
585
|
-
|
586
|
-
ret
|
587
|
-
end
|
588
|
-
|
589
|
-
# Gets user information. This method should rarely be used by
|
590
|
-
# normal users.
|
591
|
-
# @param prop [String] The usprop parameter.
|
592
|
-
# @param username [String] The username to get info for. Optional.
|
593
|
-
# Defaults to the currently logged in user if ommitted.
|
594
|
-
# @return [String/Nil] Parsed full response if successful, nil if
|
595
|
-
# the username is nil and the Butt is not logged in.
|
596
|
-
def get_userlists(prop, username = nil)
|
597
|
-
if username.nil?
|
598
|
-
if @logged_in
|
599
|
-
response = get_current_user_meta(prop)
|
600
|
-
else
|
601
|
-
return false
|
602
|
-
end
|
603
|
-
else
|
604
|
-
params = {
|
605
|
-
action: 'query',
|
606
|
-
list: 'users',
|
607
|
-
usprop: prop,
|
608
|
-
ususers: username
|
609
|
-
}
|
610
|
-
|
611
|
-
response = post(params)
|
612
|
-
end
|
613
|
-
|
614
|
-
response
|
615
|
-
end
|
616
|
-
|
617
|
-
# Gets an array of all the user's groups.
|
618
|
-
# @param username [String] The username to get groups of. Optional.
|
619
|
-
# Defaults to the currently logged in user.
|
620
|
-
# @return [Array/Boolean] All of the user's groups, or false if username
|
621
|
-
# is nil and Butt is not logged in.
|
622
|
-
def get_usergroups(username = nil)
|
623
|
-
ret = []
|
624
|
-
if username.nil?
|
625
|
-
if @logged_in
|
626
|
-
info = get_userlists('groups')
|
627
|
-
info['query']['userinfo']['groups'].each { |i| ret.push(i) }
|
628
|
-
else
|
629
|
-
return false
|
630
|
-
end
|
631
|
-
else
|
632
|
-
info = get_userlists('groups', username)
|
633
|
-
info['query']['users'].each do |i|
|
634
|
-
i['groups'].each { |g| ret.push(g) }
|
635
|
-
end
|
636
|
-
end
|
637
|
-
|
638
|
-
ret
|
639
|
-
end
|
640
|
-
|
641
|
-
# Gets the user rights for the user.
|
642
|
-
# @param username [String] The user to get the rights for. Optional.
|
643
|
-
# Defaults to the currently logged in user.
|
644
|
-
# @return [Array/Boolean] All of the user's groups, or false if username
|
645
|
-
# is nil and Butt is not logged in.
|
646
|
-
def get_userrights(username = nil)
|
647
|
-
ret = []
|
648
|
-
if username.nil?
|
649
|
-
if @logged_in
|
650
|
-
info = get_userlists('rights')
|
651
|
-
info['query']['userinfo']['rights'].each { |i| ret.push(i) }
|
652
|
-
else
|
653
|
-
return false
|
654
|
-
end
|
655
|
-
else
|
656
|
-
info = get_userlists('rights', username)
|
657
|
-
info['query']['users'].each do |i|
|
658
|
-
i['rights'].each do |g|
|
659
|
-
ret.push(g)
|
660
|
-
end
|
661
|
-
end
|
662
|
-
end
|
663
|
-
|
664
|
-
ret
|
665
|
-
end
|
666
|
-
|
667
|
-
# Gets contribution count for the user.
|
668
|
-
# @param username [String] The username to get the contribution count of.
|
669
|
-
# Optional. Defaults to the currently logged in user.
|
670
|
-
# @param autoparse [Boolean] Whether to automatically format the string
|
671
|
-
# with commas using string-utility. Defaults to true.
|
672
|
-
# @return [Boolean/Int/String] False if username is nil and Butt is not
|
673
|
-
# logged in. An integer value of the contribution count if autoparse is
|
674
|
-
# false. A formatted string version of the contribution count if
|
675
|
-
# autoparse is true.
|
676
|
-
def get_contrib_count(username = nil, autoparse = true)
|
677
|
-
count = nil
|
678
|
-
if username.nil?
|
679
|
-
if @logged_in
|
680
|
-
info = get_userlists('editcount')
|
681
|
-
count = info['query']['userinfo']['editcount']
|
682
|
-
else
|
683
|
-
return false
|
684
|
-
end
|
685
|
-
else
|
686
|
-
info = get_userlists('editcount', username)
|
687
|
-
info['query']['users'].each { |i| count = i['editcount'] }
|
688
|
-
end
|
689
|
-
|
690
|
-
if autoparse
|
691
|
-
countstring = count.to_s.separate
|
692
|
-
return countstring
|
693
|
-
end
|
694
|
-
|
695
|
-
count
|
696
|
-
end
|
697
|
-
|
698
|
-
# Gets when the user registered.
|
699
|
-
# @param username [String] The username to get the registration date and
|
700
|
-
# time of. Optional. Defaults to the currently logged in user.
|
701
|
-
# @return [DateTime] The registration date and time as a DateTime object.
|
702
|
-
def get_registration_time(username = nil)
|
703
|
-
time = nil
|
704
|
-
# Do note that in Userinfo, registration is called registrationdate.
|
705
|
-
if username.nil?
|
706
|
-
if @logged_in
|
707
|
-
info = get_userlists('registrationdate')
|
708
|
-
time = info['query']['userinfo']['registrationdate']
|
709
|
-
else
|
710
|
-
return false
|
711
|
-
end
|
712
|
-
else
|
713
|
-
info = get_userlists('registration', username)
|
714
|
-
info['query']['users'].each { |i| time = i['registration'] }
|
715
|
-
end
|
716
|
-
|
717
|
-
# %Y: Year including century
|
718
|
-
# %m: Month num
|
719
|
-
# %d: day of month
|
720
|
-
# %T: Time as HH:MM:SS
|
721
|
-
timeformat = '%Y-%m-%dT%T'
|
722
|
-
time = DateTime.strptime(time, timeformat)
|
723
|
-
|
724
|
-
time
|
725
|
-
end
|
726
|
-
|
727
|
-
# Gets the gender for the provded user.
|
728
|
-
# @param username [String] The user.
|
729
|
-
# @return [String] The gender. 'male', 'female', or 'unknown'.
|
730
|
-
def get_user_gender(username)
|
731
|
-
gender = nil
|
732
|
-
info = get_userlists('gender', username)
|
733
|
-
info['query']['users'].each { |i| gender = i['gender'] }
|
734
|
-
|
735
|
-
|
736
|
-
gender
|
737
|
-
end
|
738
|
-
|
739
|
-
# Gets the amount of results for the search value.
|
740
|
-
# @param search_value [String] The thing to search for.
|
741
|
-
# @param namespace [Int] The namespace to search in.
|
742
|
-
# Defaults to 0 (the main namespace).
|
743
|
-
# @return [Int] The number of pages that matched the search.
|
744
|
-
def get_search_result_amount(search_value, namespace = 0)
|
745
|
-
params = {
|
746
|
-
action: 'query',
|
747
|
-
list: 'search',
|
748
|
-
srsearch: search_value
|
749
|
-
}
|
750
|
-
|
751
|
-
if $namespaces.value?(namespace)
|
752
|
-
params[:srnamespace] = namespace
|
753
|
-
else
|
754
|
-
params[:srnamespace] = 0
|
755
|
-
end
|
756
|
-
|
757
|
-
response = post(params)
|
758
|
-
|
759
|
-
response['query']['searchinfo']['totalhits']
|
760
|
-
end
|
761
|
-
|
762
|
-
# Gets an array containing page titles that matched the search.
|
763
|
-
# @param search_value [String] The thing to search for.
|
764
|
-
# @param namespace [Int] The namespace to search in.
|
765
|
-
# Defaults to 0 (the main namespace).
|
766
|
-
# @return [Array] The page titles that matched the search.
|
767
|
-
def get_search_results(search_value, namespace = 0)
|
768
|
-
params = {
|
769
|
-
action: 'query',
|
770
|
-
list: 'search',
|
771
|
-
srsearch: search_value
|
772
|
-
}
|
773
|
-
|
774
|
-
if $namespaces.value?(namespace)
|
775
|
-
params[:srnamespace] = namespace
|
776
|
-
else
|
777
|
-
params[:srnamespace] = 0
|
778
|
-
end
|
779
|
-
|
780
|
-
response = post(params)
|
781
|
-
|
782
|
-
ret = []
|
783
|
-
response['query']['search'].each { |search| ret.push(search['title']) }
|
784
|
-
|
785
|
-
ret
|
786
|
-
end
|
787
|
-
end
|
788
|
-
end
|
789
|
-
end
|