mediawiki-butt 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/mediawiki/constants.rb +212 -211
- data/lib/mediawiki/query.rb +167 -23
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbd268a2d756469fbc632169feaeaa48b2eaabea
|
4
|
+
data.tar.gz: dad624c4add5afefe4a0dd5bcbcd9b09dbc203d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc460415bd8589e103c3956c5c24cb4754aef9c0a0395a6b9f5e534a878d68606395797e75f0cb0aa0460eb51fdd72e5fd950209708b316144d478fb2b9afd59
|
7
|
+
data.tar.gz: b7cfec3633270b2374c7e219166e6ce917a8632b7605df9d1af34cb7a7233d00601c398a2e08719ce002e54753f07a43016e09808f0f0d501e5575b80367ab68
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
## Version 0
|
3
|
+
### Version 0.4.0
|
4
|
+
* New get_userrights method for getting an array of all user rights that user has.
|
5
|
+
* New get_user_gender method for getting the gender of the provided user.
|
6
|
+
* New get_current_user_meta for getting userlists about the currently logged in user. Essentially the equivalent of get_userlists for logged in users.
|
7
|
+
* Fix all userlist methods to work without supplying a username.
|
8
|
+
* New get_registration_time method to get when the user registered.
|
9
|
+
* Update to work with latest version of string-utility.
|
10
|
+
* Namespaces are now in a hash instead of just a bunch of variables.
|
11
|
+
* Namespace parameters are now actually limited to the valid namespaces constant. It will default to the main namespace (0) if the integer provided is not in the namespaces hash.
|
12
|
+
* get_random_pages no longer wrongly sets the rnlimit to the namespaces argument rather than the namespace argument.
|
13
|
+
|
3
14
|
### Version 0.3.1
|
4
15
|
* Fix edit and create_page NoMethodErrors.
|
5
16
|
* Remove dependency for JSON as the version we use is included in the Ruby standard library.
|
data/lib/mediawiki/constants.rb
CHANGED
@@ -2,217 +2,218 @@ module MediaWiki
|
|
2
2
|
module Constants
|
3
3
|
# Constants Namespace IDs. Taken from https://www.mediawiki.org/wiki/Extension_default_namespaces
|
4
4
|
module Namespaces
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
5
|
+
$namespaces = {
|
6
|
+
"MAIN": 0,
|
7
|
+
"TALK": 1,
|
8
|
+
"USER": 2,
|
9
|
+
"USER_TALK": 3,
|
10
|
+
"PROJECT": 4,
|
11
|
+
"PROJECT_TALK": 5,
|
12
|
+
"FILE": 6,
|
13
|
+
"FILE_TALK": 7,
|
14
|
+
"MEDIAWIKI": 8,
|
15
|
+
"MEDIAWIKI_TALK": 9,
|
16
|
+
"TEMPLATE": 10,
|
17
|
+
"TEMPLATE_TALK": 11,
|
18
|
+
"HELP": 12,
|
19
|
+
"HELP_TALK": 13,
|
20
|
+
"CATEGORY": 14,
|
21
|
+
"CATEGORY_TALK": 15,
|
22
|
+
"SPECIAL": -1,
|
23
|
+
"MEDIA": -2,
|
24
|
+
|
25
|
+
# Extension:LiquidThreads
|
26
|
+
"LQT_THREAD": 90,
|
27
|
+
"LQT_THREAD_TALK": 91,
|
28
|
+
"LQT_SUMMARY": 92,
|
29
|
+
"LQT_SUMMARY_TALK": 93,
|
30
|
+
|
31
|
+
# Extension:Semantic MediaWiki / Extension:Semantic Forms
|
32
|
+
"SMW_RELATION": 100,
|
33
|
+
"SMW_RELATION_TALK": 101,
|
34
|
+
"SMW_PROPERTY": 102,
|
35
|
+
"SMW_PROPERTY_TALK": 103,
|
36
|
+
"SMW_TYPE": 104,
|
37
|
+
"SMW_TYPE_TALK": 105,
|
38
|
+
"SMW_FORM": 106,
|
39
|
+
"SMW_FORM_TALK": 107,
|
40
|
+
"SF_CONCEPT": 108,
|
41
|
+
"SF_CONCEPT_TALK": 109,
|
42
|
+
|
43
|
+
# Extension:DPLforum
|
44
|
+
"DPLF_FORUM": 110,
|
45
|
+
"DPLF_FORUM_TAlK": 111,
|
46
|
+
|
47
|
+
# Extension:RefHelper
|
48
|
+
"RFH_CITE": 120,
|
49
|
+
"RFH_CITE_TALK": 121,
|
50
|
+
|
51
|
+
# Extension:SemanticAccessControl
|
52
|
+
"ACL_USERGROUP": 160,
|
53
|
+
"ACL_ACL": 162,
|
54
|
+
|
55
|
+
# Extension:Semantic Drilldown
|
56
|
+
"SED_FILTER": 170,
|
57
|
+
"SED_FILTER_TALK": 171,
|
58
|
+
|
59
|
+
# Extension:SocialProfile
|
60
|
+
"SCP_USERWIKI": 200,
|
61
|
+
"SCP_USERWIKI_TALK": 201,
|
62
|
+
"SCP_USERPROFILE": 202,
|
63
|
+
"SCP_USERPROFILE_TALK": 203,
|
64
|
+
|
65
|
+
# Extension:Proofread Page
|
66
|
+
"PRP_PAGE": 250,
|
67
|
+
"PRP_PAGE_TALK": 251,
|
68
|
+
"PRP_INDEX": 252,
|
69
|
+
"PRP_INDEX_TALK": 253,
|
70
|
+
|
71
|
+
# Extension:TrustedMath
|
72
|
+
"TRM_MATH": 262,
|
73
|
+
"TRM_MATH_TALK": 263,
|
74
|
+
|
75
|
+
# Extension:Widgets
|
76
|
+
"WID_WIDGET": 274,
|
77
|
+
"WID_WIDGET_TALK": 275,
|
78
|
+
|
79
|
+
# Extension:EmbedScript
|
80
|
+
"EMS_JSAPPLET": 280,
|
81
|
+
"EMS_JSAPPLET_TALK": 281,
|
82
|
+
|
83
|
+
# Extension:PollNY
|
84
|
+
"PLN_POLL": 300,
|
85
|
+
"PLN_POLL_TALK": 301,
|
86
|
+
|
87
|
+
# Extension:Semantic Image Annotator
|
88
|
+
"SIA_IMAGE_ANNOTATOR": 380,
|
89
|
+
|
90
|
+
# Extension:Wiki2LaTeX
|
91
|
+
"WTL_WIKI2LATEX": 400,
|
92
|
+
"WTL_WIKI2LATEX_TALK": 401,
|
93
|
+
|
94
|
+
# Extension:Workflow
|
95
|
+
"WRF_WORKFLOW": 410,
|
96
|
+
"WRF_WORKFLOW_TALK": 411,
|
97
|
+
|
98
|
+
# Extension:Maps
|
99
|
+
"MAP_LAYER": 420,
|
100
|
+
"MAP_LAYER_TALK": 421,
|
101
|
+
|
102
|
+
# Extension:QuizTabulate
|
103
|
+
"QTB_QUIZ": 430,
|
104
|
+
"QTB_QUIZ_TALK": 431,
|
105
|
+
|
106
|
+
# Extension:Education Program
|
107
|
+
"EDP_EDUCATION_PROGRAM": 446,
|
108
|
+
"EDP_EDUCATION_PROGRAM_TALK": 447,
|
109
|
+
|
110
|
+
# Extension:BoilerRoom
|
111
|
+
"BLR_BOILERPLATE": 450,
|
112
|
+
"BLR_BOILERPLATE_TALK": 451,
|
113
|
+
|
114
|
+
# Extension:UploadWizard
|
115
|
+
"UPW_CAMPAIGN": 460,
|
116
|
+
"UPW_CAMPAIGN_TALK": 461,
|
117
|
+
|
118
|
+
# Extension:EventLogging
|
119
|
+
"ELG_SCHEMA": 470,
|
120
|
+
"ELG_SCHEMA_TALK": 471,
|
121
|
+
|
122
|
+
# Extension:ZeroBanner
|
123
|
+
"ZRB_ZERO": 480,
|
124
|
+
"ZRB_ZERO_TALK": 481,
|
125
|
+
|
126
|
+
# Extension:JsonConfig
|
127
|
+
"JSC_CONFIG": 482,
|
128
|
+
"JSC_CONFIG_TALK": 483,
|
129
|
+
"JSC_DATA": 486,
|
130
|
+
"JSC_DATA_TALK": 487,
|
131
|
+
|
132
|
+
# Extension:Graph
|
133
|
+
"GRP_GRAPH": 484,
|
134
|
+
"GRP_GRAPH_TALK": 485,
|
135
|
+
|
136
|
+
# Extension:OpenStackManager
|
137
|
+
"OSM_NOVA_RESOURCE": 488,
|
138
|
+
"OSM_NOVA_RESOURCE_TALK": 489,
|
139
|
+
|
140
|
+
# Extension:GWToolset
|
141
|
+
"GWT_GWTOOLSET": 490,
|
142
|
+
"GWT_GWTOOLSET_TALK": 491,
|
143
|
+
|
144
|
+
# Extension:BlogPage
|
145
|
+
"BLP_BLOG": 500,
|
146
|
+
"BLP_BLOG_TALK": 501,
|
147
|
+
|
148
|
+
# Extension:XMLContentExtension
|
149
|
+
"XCE_XML": 580,
|
150
|
+
"XCE_XML_TALK": 581,
|
151
|
+
"XCE_SCHEMA": 582,
|
152
|
+
"XCE_SCHEMA_TALK": 583,
|
153
|
+
|
154
|
+
# Extension:FanBoxes
|
155
|
+
"FNB_USERBOX": 600,
|
156
|
+
"FNB_USERBOX_TALK": 601,
|
157
|
+
|
158
|
+
# Extension:LinkFilter
|
159
|
+
"LFT_LINK": 700,
|
160
|
+
"LFT_LINK_TALK": 701,
|
161
|
+
|
162
|
+
# Extension:TimedMediaHandler
|
163
|
+
"TMH_TIMEDTEXT": 710,
|
164
|
+
"TMH_TIMEDTEXT_TALK": 711,
|
165
|
+
|
166
|
+
# Extension:QPoll
|
167
|
+
"QPL_INTERPRETATION": 800,
|
168
|
+
"QPL_INTERPRETATION_TALK": 801,
|
169
|
+
|
170
|
+
# Extension:SemanticMustacheFormat :3,
|
171
|
+
"SMF_MUSTACHE": 806,
|
172
|
+
"SMF_MUSTACHE_TALK": 807,
|
173
|
+
|
174
|
+
# Extension:R
|
175
|
+
"R_R": 814,
|
176
|
+
"R_R_TALK": 815,
|
177
|
+
|
178
|
+
# Extension:Scribunto
|
179
|
+
"SCR_MODULE": 828,
|
180
|
+
"SCR_MODULE_TALK": 829,
|
181
|
+
|
182
|
+
# Extension:SecurePoll
|
183
|
+
"SEP_SECUREPOLL": 830,
|
184
|
+
"SEP_SECUREPOLL_TALK": 831,
|
185
|
+
|
186
|
+
# Extension:CentralNotice
|
187
|
+
"CNT_CNBANNER": 866,
|
188
|
+
"CNT_CNBANNER_TALK": 867,
|
189
|
+
|
190
|
+
# Extension:Translate
|
191
|
+
"TRN_TRANSLATIONS": 1198,
|
192
|
+
"TRN_TRANSLATIOTALK": 1199,
|
193
|
+
|
194
|
+
# Extension:PackageForce
|
195
|
+
"PKF_PACKAGEFORCE": 1300,
|
196
|
+
"PKF_PACKAGEFORCE_TALK": 1301,
|
197
|
+
|
198
|
+
# Extension:BlueSpice
|
199
|
+
"BLS_BLOG": 1502,
|
200
|
+
"BLS_BLOG_TALK": 1503,
|
201
|
+
"BLS_BOOK": 1504,
|
202
|
+
"BLS_BOOK_TALK": 1505,
|
203
|
+
|
204
|
+
# Extension:Gadgets
|
205
|
+
"GDG_GADGET": 2300,
|
206
|
+
"GDG_GADGET_TALK": 2301,
|
207
|
+
"GDG_GADGET_DEFININTION": 2302,
|
208
|
+
"GDG_GADGET_DEFININTION_TALK": 2303,
|
209
|
+
|
210
|
+
# Extension:VisualEditor
|
211
|
+
"VSE_VISUALEDITOR": 2500,
|
212
|
+
"VSE_VISUALEDITOR_TALK": 2501,
|
213
|
+
|
214
|
+
# Extension:Flow
|
215
|
+
"FLW_TOPIC": 2600
|
216
|
+
}
|
216
217
|
end
|
217
218
|
end
|
218
219
|
end
|
data/lib/mediawiki/query.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'string-utility'
|
2
|
+
require_relative 'constants'
|
2
3
|
|
3
4
|
module MediaWiki
|
4
5
|
module Query
|
5
6
|
#TODO: Actually decide on a good way to deal with meta information queries.
|
6
7
|
# The metainformation could probably be handled in a much less verbose way.
|
8
|
+
# Perhaps we should get hashes instead?
|
7
9
|
module Meta
|
8
10
|
|
9
11
|
# Returns an array of all the wiki's file repository names.
|
@@ -23,6 +25,25 @@ module MediaWiki
|
|
23
25
|
end
|
24
26
|
return ret
|
25
27
|
end
|
28
|
+
|
29
|
+
# Gets meta information for the currently logged in user.
|
30
|
+
# @param prop [String] The uiprop to get.
|
31
|
+
# @return [Response/Boolean] Either a full, parsed response, or false if not logged in.
|
32
|
+
def get_current_user_meta(prop)
|
33
|
+
if @logged_in == true
|
34
|
+
params = {
|
35
|
+
action: 'query',
|
36
|
+
meta: 'userinfo',
|
37
|
+
uiprop: prop,
|
38
|
+
format: 'json'
|
39
|
+
}
|
40
|
+
|
41
|
+
response = post(params)
|
42
|
+
return response
|
43
|
+
else
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
end
|
26
47
|
end
|
27
48
|
|
28
49
|
module Properties
|
@@ -100,6 +121,7 @@ module MediaWiki
|
|
100
121
|
end
|
101
122
|
|
102
123
|
module Lists
|
124
|
+
using StringUtility
|
103
125
|
|
104
126
|
# Gets an array of backlinks to a given title.
|
105
127
|
# @param title [String] The page to get the backlinks of.
|
@@ -185,9 +207,13 @@ module MediaWiki
|
|
185
207
|
format: 'json'
|
186
208
|
}
|
187
209
|
|
188
|
-
|
210
|
+
if $namespaces.has_value?(namespace)
|
211
|
+
params[:rnnamespace] = namespace
|
212
|
+
else
|
213
|
+
params[:rnnamespace] = 0
|
214
|
+
end
|
189
215
|
|
190
|
-
if
|
216
|
+
if number_of_pages > 10
|
191
217
|
if is_user_bot? == true
|
192
218
|
if limit > 20
|
193
219
|
params[:rnlimit] = 20
|
@@ -198,7 +224,7 @@ module MediaWiki
|
|
198
224
|
params[:rnlimit] = 10
|
199
225
|
end
|
200
226
|
else
|
201
|
-
params[:rnlimit] =
|
227
|
+
params[:rnlimit] = number_of_pages
|
202
228
|
end
|
203
229
|
|
204
230
|
ret = Array.new
|
@@ -214,47 +240,76 @@ module MediaWiki
|
|
214
240
|
# @param username [String] The username to get info for. Optional. Defaults to the currently logged in user if ommitted.
|
215
241
|
# @return [String/Nil] Parsed full response if successful, nil if the username is nil and the Butt is not logged in.
|
216
242
|
def get_userlists(prop, username = nil)
|
217
|
-
params = {
|
218
|
-
action: 'query',
|
219
|
-
list: 'users',
|
220
|
-
usprop: prop,
|
221
|
-
format: 'json'
|
222
|
-
}
|
223
|
-
|
224
243
|
if username.nil?
|
225
244
|
if @logged_in == true
|
226
|
-
response =
|
245
|
+
response = get_current_user_meta(prop)
|
227
246
|
else
|
228
|
-
return
|
247
|
+
return false
|
229
248
|
end
|
230
249
|
else
|
231
|
-
params
|
250
|
+
params = {
|
251
|
+
action: 'query',
|
252
|
+
list: 'users',
|
253
|
+
usprop: prop,
|
254
|
+
ususers: username,
|
255
|
+
format: 'json'
|
256
|
+
}
|
257
|
+
|
232
258
|
response = post(params)
|
233
259
|
end
|
234
260
|
|
235
261
|
return response
|
236
262
|
end
|
237
263
|
|
238
|
-
# Gets an array of all the
|
264
|
+
# Gets an array of all the user's groups.
|
239
265
|
# @param username [String] The username to get groups of. Optional. Defaults to the currently logged in user.
|
240
266
|
# @return [Array/Boolean] All of the user's groups, or false if username is nil and Butt is not logged in.
|
241
267
|
def get_usergroups(username = nil)
|
268
|
+
ret = Array.new
|
242
269
|
if username.nil?
|
243
270
|
if @logged_in == true
|
244
271
|
info = get_userlists('groups')
|
272
|
+
info["query"]["userinfo"]["groups"].each do |i|
|
273
|
+
ret.push(i)
|
274
|
+
end
|
245
275
|
else
|
246
276
|
return false
|
247
277
|
end
|
248
278
|
else
|
249
279
|
info = get_userlists('groups', username)
|
280
|
+
info["query"]["users"].each do |i|
|
281
|
+
i["groups"].each do |g|
|
282
|
+
ret.push(g)
|
283
|
+
end
|
284
|
+
end
|
250
285
|
end
|
251
286
|
|
287
|
+
return ret
|
288
|
+
end
|
289
|
+
|
290
|
+
# Gets the user rights for the user.
|
291
|
+
# @param username [String] The user to get the rights for. Optional. Defaults to the currently logged in user.
|
292
|
+
# @return [Array/Boolean] All of the user's groups, or false if username is nil and Butt is not logged in.
|
293
|
+
def get_userrights(username = nil)
|
252
294
|
ret = Array.new
|
253
|
-
|
254
|
-
|
255
|
-
|
295
|
+
if username.nil?
|
296
|
+
if @logged_in == true
|
297
|
+
info = get_userlists('rights')
|
298
|
+
info["query"]["userinfo"]["rights"].each do |i|
|
299
|
+
ret.push(i)
|
300
|
+
end
|
301
|
+
else
|
302
|
+
return false
|
303
|
+
end
|
304
|
+
else
|
305
|
+
info = get_userlists('rights', username)
|
306
|
+
info["query"]["users"].each do |i|
|
307
|
+
i["rights"].each do |g|
|
308
|
+
ret.push(g)
|
309
|
+
end
|
256
310
|
end
|
257
311
|
end
|
312
|
+
|
258
313
|
return ret
|
259
314
|
end
|
260
315
|
|
@@ -263,27 +318,116 @@ module MediaWiki
|
|
263
318
|
# @param autoparse [Boolean] Whether to automatically format the string with commas. Defaults to true.
|
264
319
|
# @return [Boolean/Int/String] False if username is nil and Butt is not logged in. An integer value of the contribution count if autoparse is false. A formatted string version of the contribution count if autoparse is true.
|
265
320
|
def get_contrib_count(username = nil, autoparse = true)
|
321
|
+
count = nil
|
266
322
|
if username.nil?
|
267
323
|
if @logged_in == true
|
268
324
|
info = get_userlists('editcount')
|
325
|
+
count = info["query"]["userinfo"]["editcount"]
|
269
326
|
else
|
270
327
|
return false
|
271
328
|
end
|
272
329
|
else
|
273
330
|
info = get_userlists('editcount', username)
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
info["query"]["users"].each do |i|
|
278
|
-
count = i["editcount"]
|
331
|
+
info["query"]["users"].each do |i|
|
332
|
+
count = i["editcount"]
|
333
|
+
end
|
279
334
|
end
|
280
335
|
|
281
336
|
if autoparse == true
|
282
|
-
countstring =
|
337
|
+
countstring = count.to_s.separate
|
283
338
|
return countstring
|
284
339
|
end
|
285
340
|
return count
|
286
341
|
end
|
342
|
+
|
343
|
+
# Gets when the user registered.
|
344
|
+
# @param username [String] The username to get the registration date and time of. Optional. Defaults to the currently logged in user.
|
345
|
+
# @return [DateTime] The registration date and time as a DateTime object.
|
346
|
+
def get_registration_time(username = nil)
|
347
|
+
time = nil
|
348
|
+
# Do note that in Userinfo, registration is called registrationdate.
|
349
|
+
if username.nil?
|
350
|
+
if @logged_in == true
|
351
|
+
info = get_userlists('registrationdate')
|
352
|
+
time = info["query"]["userinfo"]["registrationdate"]
|
353
|
+
else
|
354
|
+
return false
|
355
|
+
end
|
356
|
+
else
|
357
|
+
info = get_userlists('registration', username)
|
358
|
+
info["query"]["users"].each do |i|
|
359
|
+
time = i["registration"]
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
# %Y: Year including century, %m: Month num, %d day of month, %T Time as H:M:S
|
364
|
+
timeformat = "%Y-%m-%dT%T"
|
365
|
+
time = DateTime.strptime(time, timeformat)
|
366
|
+
return time
|
367
|
+
end
|
368
|
+
|
369
|
+
# Gets the gender for the provded user.
|
370
|
+
# @param username [String] The user.
|
371
|
+
# @return [String] The gender. "male", "female", or "unknown".
|
372
|
+
def get_user_gender(username)
|
373
|
+
gender = nil
|
374
|
+
info = get_userlists('gender', username)
|
375
|
+
info["query"]["users"].each do |i|
|
376
|
+
gender = i["gender"]
|
377
|
+
end
|
378
|
+
|
379
|
+
return gender
|
380
|
+
end
|
381
|
+
|
382
|
+
# Gets the amount of results for the search value.
|
383
|
+
# @param search_value [String] The thing to search for.
|
384
|
+
# @param namespace [Int] The namespace to search in. Defaults to the main namespace.
|
385
|
+
# @return [Int] The number of pages that matched the search.
|
386
|
+
def get_search_result_amount(search_value, namespace = 0)
|
387
|
+
params = {
|
388
|
+
action: 'query',
|
389
|
+
list: 'search',
|
390
|
+
srsearch: search_value,
|
391
|
+
format: 'json'
|
392
|
+
}
|
393
|
+
|
394
|
+
if $namespaces.has_value?(namespace)
|
395
|
+
params[:srnamespace] = namespace
|
396
|
+
else
|
397
|
+
params[:srnamespace] = 0
|
398
|
+
end
|
399
|
+
|
400
|
+
response = post(params)
|
401
|
+
|
402
|
+
return response["query"]["searchinfo"]["totalhits"]
|
403
|
+
end
|
404
|
+
|
405
|
+
# Gets an array containing page titles that matched the search.
|
406
|
+
# @param search_value [String] The thing to search for.
|
407
|
+
# @param namespace [Int] The namespace to search in. Defaults to the main namespace.
|
408
|
+
# @return [Array] The page titles that matched the search.
|
409
|
+
def get_search_results(search_value, namespace = 0)
|
410
|
+
params = {
|
411
|
+
action: 'query',
|
412
|
+
list: 'search',
|
413
|
+
srsearch: search_value,
|
414
|
+
format: 'json'
|
415
|
+
}
|
416
|
+
|
417
|
+
if $namespaces.has_value?(namespace)
|
418
|
+
params[:srnamespace] = namespace
|
419
|
+
else
|
420
|
+
params[:srnamespace] = 0
|
421
|
+
end
|
422
|
+
|
423
|
+
response = post(params)
|
424
|
+
|
425
|
+
ret = Array.new
|
426
|
+
response["query"]["search"].each do |search|
|
427
|
+
ret.push(search["title"])
|
428
|
+
end
|
429
|
+
return ret
|
430
|
+
end
|
287
431
|
end
|
288
432
|
end
|
289
433
|
end
|
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.4.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-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: string-utility
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 2.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 2.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: httpclient
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|