mediawiki-butt 3.0.0 → 4.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7716798bbc8877e9a116dfde230ca4a4db7a9914
4
- data.tar.gz: 75fa4f657ee01443634762697672f8142d0c9387
2
+ SHA256:
3
+ metadata.gz: 175a073830204042dc379d9052239791398ff93a793d7546db1c92da3d30ced8
4
+ data.tar.gz: c08d9cb85b4e7492c9cf74882ccc38236bedf248f6e41bb24c14d461624d8e89
5
5
  SHA512:
6
- metadata.gz: af78a66c15e2ba113cbb140037d1ca1294aa740d93e5a089dc2881228a3c087cb293aaa61fa574441217afe295affe93a6aa35055ebd7f31921a1032b9bd270e
7
- data.tar.gz: 45e1c4885a3cf8e7ba01523573d60899b246b03ec49471efd98e8911275ab84496190adba89037e80216d2dc39a10de2e43716d856e6d6d5a13bcc4883ba730f
6
+ metadata.gz: 29377d587605d49389ff50bb14c5a762126ef3e83700cc3ebf39ae8885da286aa66222c5b7adc943ffa33ac56c65bdbef9c2dd0990dd91d78110c1983fe894cc
7
+ data.tar.gz: 5b7888432084599c4c7de6a0bf6ce1427d8a2d5f17cc45f63c9f01a0feebab53c1f8e0025a36385fba6247c04890a7a512426cf1a63629874eb46293ac496d76
@@ -1,4 +1,49 @@
1
1
  # Changelog
2
+ ## Version 4
3
+ ### Version 4.0.1
4
+ * Yank 4.0.0, fix gem build.
5
+
6
+ ### Version 4.0.0
7
+ **Breaking changes!**
8
+ * Add support for searching text (NCC-Gnisha) (#69, #77).
9
+ * Replace HTTPClient with Patron (#71).
10
+ * Fix limiting on `get_tags`.
11
+ * Implement token caching (#75).
12
+ * Change log hash formatting methods from `get_[type]` to `loghash_[type]` to fix `NoMethodError`s in log queries (#35).
13
+ * Fixes overlapping methods, such as `get_general` from siteinfo and `get_general` from log.
14
+ * Is more accurate as a descriptor, because no new data is being "gotten" from these methods, they only format data.
15
+ * Affected methods:
16
+ * `get_block` -> `loghash_block`
17
+ * `get_unblock` -> `loghash_unblock`
18
+ * `get_importinterwiki` -> `loghash_importinterwiki`
19
+ * `get_general` -> `loghash_general`
20
+ * `get_merge` -> `loghash_merge`
21
+ * `get_move` -> `loghash_move`
22
+ * `get_user` -> `loghash_user`
23
+ * `get_patrol` -> `loghash_patrol`
24
+ * `get_protect` -> `loghash_protect`
25
+ * `get_protectmoveprot` -> `loghash_protectmoveprot`
26
+ * `get_unprotect` -> `loghash_unprotect`
27
+ * `get_rightsautopromote` -> `loghash_rightsautopromote`
28
+ * `get_rightsrights` -> `loghash_rightsrights`
29
+ * `get_upload` -> `loghash_upload`
30
+ * Fix broken log hash keys causing `NoMethodError`s (#35):
31
+ * `loghash_block`: `flags`, `duration`, and `expiry`
32
+ * `loghash_move`: `new_title`, and `suppressredirect`
33
+ * `loghash_patrol`: `current_revision`, and `previous_revision`; remove `automatic`
34
+ * `loghash_protect`: `details` (`type`, `expiry`, `level`) is not present in older protection logs; getting protection logs will no longer error on older entries without `details`
35
+ * `loghash_rightsautopromote`: `new_rights`, `old_rights`
36
+ * `loghash_rightsrights`: `new_rights`, `old_rights`
37
+ * Fix missing log hash methods causing `NoMethodError`s (#35):
38
+ * `get_reblock_log`
39
+ * `get_unblock_log`
40
+ * `get_overall_log`
41
+ * `get_merge_log`
42
+ * Returned log hash in move logs no longer has `title` key, it is now called `old_title`.
43
+ * Rights log hashes no longer have `title` key because they were not useful.
44
+ * Update minitest
45
+ * Implement patrol API support. Patrol edits with the `patrol` method, which if errors will raise a `PatrolError` (#76).
46
+
2
47
  ## Version 3
3
48
  ### Version 3.0.0
4
49
  **Breaking changes!**
@@ -5,7 +5,7 @@ require_relative 'edit'
5
5
  require_relative 'administration'
6
6
  require_relative 'watch'
7
7
  require_relative 'purge'
8
- require 'httpclient'
8
+ require 'patron'
9
9
  require 'json'
10
10
 
11
11
  module MediaWiki
@@ -43,11 +43,20 @@ module MediaWiki
43
43
  def initialize(url, opts = {})
44
44
  @url = url =~ /api.php$/ ? url : "#{url}/api.php"
45
45
  @query_limit_default = opts[:query_limit_default] || 'max'
46
- @client = HTTPClient.new
47
- @uri = URI.parse(@url)
48
- @logged_in = false
49
46
  @custom_agent = opts[:custom_agent]
47
+ @session = Patron::Session.new
48
+ @session.timeout = 60
49
+ @session.handle_cookies
50
+ @session.headers['User-Agent'] = @custom_agent if @custom_agent
51
+ @logged_in = false
50
52
  @use_continuation = opts[:use_continuation] || true
53
+ # Token cache, populated in #get_token and depopulated in #post. Type => Token
54
+ @tokens = {}
55
+ # The most recent kind of token acquired. Used in #post, set/reset in #get_token.
56
+ @prev_token_type = ''
57
+ # Set to prevent token cache handling from producing an infinite call loop. Defaults to true, set to false when
58
+ # token recache is being handled.
59
+ @first_token_try = true
51
60
 
52
61
  assertion = opts[:assertion]
53
62
  @assertion = assertion == :user || assertion == :bot ? assertion : nil
@@ -66,14 +75,24 @@ module MediaWiki
66
75
  }
67
76
  base_params[:assert] = @assertion.to_s if @assertion
68
77
  params = base_params.merge(params)
69
- header = {}
70
- if defined? @custom_agent
71
- header['User-Agent'] = @custom_agent
72
- else
73
- header['User-Agent'] = @logged_in ? "#{@name}/MediaWiki::Butt" : 'NotLoggedIn/MediaWiki::Butt'
78
+
79
+ unless @custom_agent
80
+ @session.headers['User-Agent'] = @logged_in ? "#{@name}/MediaWiki::Butt" : 'NotLoggedIn/MediaWiki::Butt'
74
81
  end
75
82
 
76
- response = JSON.parse(@client.post(@uri, params, header).body)
83
+ response = JSON.parse(@session.post(@url, params).body)
84
+
85
+ # If our tokens have expired, clear them, re-set the relevant token argument, and re-call this #post method
86
+ if response.dig('error', 'code') == 'badtoken' && @first_token_try
87
+ @tokens.clear
88
+ token_param = params.keys.select { |i| i.to_s.end_with?('token') }[0]
89
+ params[token_param] = get_token(@prev_token_type)
90
+ # Prevent token retry attempt in next #post call
91
+ @first_token_try = false
92
+ return post(params)
93
+ end
94
+ # Reset token retry value if no badtoken error has occurred.
95
+ @first_token_try = true
77
96
 
78
97
  if @assertion
79
98
  code = response.dig('error', 'code')
@@ -134,23 +153,19 @@ module MediaWiki
134
153
  # @since 0.3.0 as is_user_bot?
135
154
  # @since 0.4.1 as user_bot?
136
155
  def user_bot?
137
- begin
138
- post({ action: 'query', assert: 'bot' })
139
- true
140
- rescue MediaWiki::Butt::NotBotError
141
- false
142
- end
156
+ post({ action: 'query', assert: 'bot' })
157
+ true
158
+ rescue MediaWiki::Butt::NotBotError
159
+ false
143
160
  end
144
161
 
145
162
  # Checks whether this instance is logged in.
146
163
  # @return [Boolean] true if logged in, false if not.
147
164
  def logged_in?
148
- begin
149
- post({ action: 'query', assert: 'user' })
150
- true
151
- rescue MediaWiki::Butt::NotLoggedInError
152
- false
153
- end
165
+ post({ action: 'query', assert: 'user' })
166
+ true
167
+ rescue MediaWiki::Butt::NotLoggedInError
168
+ false
154
169
  end
155
170
 
156
171
  protected
@@ -166,5 +166,33 @@ module MediaWiki
166
166
  return true if response['delete']
167
167
  raise MediaWiki::Butt::EditError.new(response.dig('error', 'code') || 'Unknown error code')
168
168
  end
169
+
170
+ # Patrol an edit by its recentchanges or revision ID.
171
+ # @param opts [Hash<Symbol, String>] Options param.
172
+ # @option :rcid [String, Integer] Recentchanges ID to patrol.
173
+ # @option :revid [String, Integer] Revision ID to patrol.
174
+ # @option :tags [String, Array<String>] Change tags to apply to the entry in the patrol log, either as a string of
175
+ # tags separated by | or as an array of tag strings.
176
+ # @see https://www.mediawiki.org/wiki/API:Patrol Patrol API documentation
177
+ # @raise [PatrolError]
178
+ # @return [String] The title of the page that was patrolled, if it was patrolled.
179
+ def patrol(opts = {})
180
+ params = {
181
+ action: 'patrol',
182
+ token: get_token('patrol')
183
+ }
184
+
185
+ params[:rcid] = opts[:rcid] if opts[:rcid]
186
+ params[:revid] = opts[:revid] if opts[:revid]
187
+ params[:tags] = opts[:tags] if opts[:tags]
188
+
189
+ if opts[:tags]
190
+ params[:tags] = opts[:tags].is_a?(Array) ? opts[:tags].join('|') : opts[:tags]
191
+ end
192
+
193
+ response = post(params)
194
+ return response['patrol']['title'] if response['patrol']
195
+ raise MediaWiki::Butt::PatrolError.new(response.dig('error', 'code') || 'Unknown error code')
196
+ end
169
197
  end
170
198
  end
@@ -6,5 +6,6 @@ module MediaWiki
6
6
  class NotLoggedInError < StandardError; end
7
7
  class NotBotError < StandardError; end
8
8
  class UploadInvalidFileExtError < StandardError; end
9
+ class PatrolError < StandardError; end
9
10
  end
10
11
  end
@@ -21,7 +21,7 @@ module MediaWiki
21
21
 
22
22
  ret = []
23
23
  response['query']['logevents'].each do |log|
24
- ret << get_block(log)
24
+ ret << loghash_block(log)
25
25
  end
26
26
 
27
27
  ret
@@ -38,7 +38,7 @@ module MediaWiki
38
38
 
39
39
  ret = []
40
40
  response['query']['logevents'].each do |log|
41
- ret << get_blockreblock(log)
41
+ ret << loghash_block(log)
42
42
  end
43
43
 
44
44
  ret
@@ -55,7 +55,7 @@ module MediaWiki
55
55
 
56
56
  ret = []
57
57
  response['query']['logevents'].each do |log|
58
- ret << get_blockunblock(log)
58
+ ret << loghash_unblock(log)
59
59
  end
60
60
 
61
61
  ret
@@ -15,7 +15,7 @@ module MediaWiki
15
15
 
16
16
  ret = []
17
17
  response['query']['logevents'].each do |log|
18
- ret << get_general(log)
18
+ ret << loghash_general(log)
19
19
  end
20
20
 
21
21
  ret
@@ -31,7 +31,7 @@ module MediaWiki
31
31
 
32
32
  ret = []
33
33
  resp['query']['logevents'].each do |log|
34
- ret << get_general(log)
34
+ ret << loghash_general(log)
35
35
  end
36
36
 
37
37
  ret
@@ -14,7 +14,7 @@ module MediaWiki
14
14
 
15
15
  ret = []
16
16
  resp['query']['logevents'].each do |log|
17
- ret << get_importinterwiki(log)
17
+ ret << loghash_importinterwiki(log)
18
18
  end
19
19
 
20
20
  ret
@@ -30,7 +30,7 @@ module MediaWiki
30
30
 
31
31
  ret = []
32
32
  resp['query']['logevents'].each do |log|
33
- ret << get_importupload(log)
33
+ ret << loghash_importupload(log)
34
34
  end
35
35
 
36
36
  ret
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
  require_relative '../../../constants'
2
3
  require_relative 'block'
3
4
  require_relative 'delete'
@@ -53,65 +54,63 @@ module MediaWiki
53
54
  case log['type']
54
55
  when 'block'
55
56
  case log['action']
56
- when 'block'
57
- hash = get_blockblock(log)
57
+ when 'block', 'reblock'
58
+ hash = loghash_block(log)
58
59
  when 'unblock'
59
- hash = get_blockunblock(log)
60
- when 'reblock'
61
- hash = get_blockreblock(log)
60
+ hash = loghash_unblock(log)
62
61
  end
63
62
  when 'delete'
64
63
  case log['action']
65
64
  when 'delete', 'restore'
66
- hash = get_deletedelete(log)
65
+ hash = loghash_general(log)
67
66
  end
68
67
  when 'import'
69
68
  case log['action']
70
69
  when 'interwiki'
71
- hash = get_importinterwiki(log)
70
+ hash = loghash_importinterwiki(log)
72
71
  when 'upload'
73
- hash = get_importupload(log)
72
+ hash = loghash_importupload(log)
74
73
  end
75
74
  when 'merge'
76
75
  case log['action']
77
76
  when 'merge'
78
- hash = get_mergemerge(log)
77
+ hash = loghash_merge(log)
79
78
  end
80
79
  when 'move'
81
80
  case log['action']
82
81
  when 'move', 'move_redir'
83
- hash = get_move(log)
82
+ hash = loghash_move(log)
84
83
  end
85
84
  when 'newusers'
86
85
  case log['action']
87
86
  when 'autocreate', 'create', 'create2'
88
- hash = get_user(log)
87
+ hash = loghash_user(log)
89
88
  end
90
89
  when 'patrol'
91
90
  case log['action']
92
91
  when 'patrol'
93
- hash = get_patrol(log)
92
+ hash = loghash_patrol(log)
94
93
  end
95
94
  when 'protect'
96
95
  case log['action']
97
96
  when 'modify', 'protect'
98
- hash = get_protect(log)
97
+ hash = loghash_protect(log)
99
98
  when 'move_prot'
100
- hash = get_protectmoveprot(log)
99
+ hash = loghash_protectmoveprot(log)
101
100
  when 'unprotect'
102
- hash = get_protectunprotect(log)
101
+ hash = loghash_protectunprotect(log)
103
102
  end
104
103
  when 'rights'
105
104
  case log['action']
106
105
  when 'autopromote'
107
- hash = get_rightsautopromote(log)
106
+ hash = loghash_rightsautopromote(log)
108
107
  when 'rights'
109
- hash = get_rightsrights(log)
108
+ hash = loghash_rightsrights(log)
110
109
  end
111
110
  when 'upload'
112
111
  case log['action']
113
112
  when 'overwrite', 'upload'
114
- hash = get_upload(log)
113
+ hash = loghash_upload(log)
115
114
  end
116
115
  end
117
116
 
@@ -150,20 +149,22 @@ module MediaWiki
150
149
  post(params)
151
150
  end
152
151
 
153
- def get_block(log)
154
- {
152
+ def loghash_block(log)
153
+ hash = {
155
154
  id: log['logid'],
156
155
  blocked: log['title'],
157
- flags: log['block']['flags'],
158
- duration: log['block']['duration'],
159
- expiry: DateTime.xmlschema(log['block']['expiry']),
156
+ flags: log['params']['flags'],
157
+ duration: log['params']['duration'],
160
158
  blocker: log['user'],
161
159
  comment: log['comment'],
162
160
  timestamp: DateTime.xmlschema(log['timestamp'])
163
161
  }
162
+ hash[:expiry] = DateTime.xmlschema(log['params']['expiry']) if log['params'].key?('expiry')
163
+
164
+ hash
164
165
  end
165
166
 
166
- def get_unblock(log)
167
+ def loghash_unblock(log)
167
168
  {
168
169
  id: log['logid'],
169
170
  blocked: log['title'],
@@ -173,7 +174,7 @@ module MediaWiki
173
174
  }
174
175
  end
175
176
 
176
- def get_importinterwiki(log)
177
+ def loghash_importinterwiki(log)
177
178
  {
178
179
  id: log['logid'],
179
180
  title: log['title'],
@@ -185,7 +186,18 @@ module MediaWiki
185
186
  }
186
187
  end
187
188
 
188
- def get_general(log)
189
+ def loghash_importupload(log)
190
+ {
191
+ id: log['logid'],
192
+ title: log['title'],
193
+ user: log['user'],
194
+ comment: log['comment'],
195
+ timestamp: DateTime.xmlschema(log['timestamp']),
196
+ count: log['params']['count']
197
+ }
198
+ end
199
+
200
+ def loghash_general(log)
189
201
  {
190
202
  id: log['logid'],
191
203
  title: log['title'],
@@ -195,7 +207,7 @@ module MediaWiki
195
207
  }
196
208
  end
197
209
 
198
- def get_merge(log)
210
+ def loghash_merge(log)
199
211
  {
200
212
  id: log['logid'],
201
213
  title: log['title'],
@@ -207,7 +219,7 @@ module MediaWiki
207
219
  }
208
220
  end
209
221
 
210
- def get_move(log)
222
+ def loghash_move(log)
211
223
  hash = {
212
224
  id: log['logid'],
213
225
  timestamp: DateTime.xmlschema(log['timestamp'])
@@ -215,22 +227,22 @@ module MediaWiki
215
227
 
216
228
  if log.key?('actionhidden')
217
229
  hash[:hidden] = true
218
- hash[:title] = nil
230
+ hash[:old_title] = nil
219
231
  hash[:comment] = nil
220
232
  hash[:suppressedredirect] = log.key('suppressed')
221
233
  else
222
- hash[:title] = log['title']
223
- hash[:new_title] = log['move']['new_title']
234
+ hash[:old_title] = log['title']
235
+ hash[:new_title] = log['params']['target_title']
224
236
  hash[:user] = log['user']
225
237
  hash[:comment] = log['comment']
226
238
 
227
- hash[:suppressedredirect] = log['move'].key?('suppressedredirect')
239
+ hash[:suppressedredirect] = log['params'].key?('suppressedredirect')
228
240
  end
229
241
 
230
242
  hash
231
243
  end
232
244
 
233
- def get_user(log)
245
+ def loghash_user(log)
234
246
  {
235
247
  id: log['logid'],
236
248
  new_user: log['title'],
@@ -240,23 +252,19 @@ module MediaWiki
240
252
  }
241
253
  end
242
254
 
243
- def get_patrol(log)
244
- hash = {
255
+ def loghash_patrol(log)
256
+ {
245
257
  id: log['logid'],
246
258
  title: log['title'],
247
259
  user: log['user'],
248
260
  comment: log['comment'],
249
- current_revision: log['patrol']['cur'],
250
- previous_revision: log['patrol']['prev'],
261
+ current_revision: log['params']['curid'],
262
+ previous_revision: log['params']['previd'],
251
263
  timestamp: DateTime.xmlschema(log['timestamp'])
252
264
  }
253
- auto = log['patrol']['auto']
254
- hash[:automatic] = auto == 1
255
-
256
- hash
257
265
  end
258
266
 
259
- def get_protect(log)
267
+ def loghash_protect(log)
260
268
  hash = {
261
269
  id: log['logid'],
262
270
  title: log['title'],
@@ -268,22 +276,25 @@ module MediaWiki
268
276
 
269
277
  hash[:details] = []
270
278
 
271
- log['params']['detail'].each do |detail|
272
- details_hash = {
273
- type: detail['type'],
274
- level: detail['level']
275
- }
276
- expire = detail['expiry']
277
- if expire != 'infinite'
278
- details_hash[:expiry] = DateTime.xmlschema(expire)
279
+ # It appears that older protection logs did not have a details key.
280
+ if log['params'].key?('details')
281
+ log['params']['details'].each do |detail|
282
+ details_hash = {
283
+ type: detail['type'],
284
+ level: detail['level']
285
+ }
286
+ expire = detail['expiry']
287
+ if expire != 'infinite'
288
+ details_hash[:expiry] = DateTime.xmlschema(expire)
289
+ end
290
+ hash[:details] << details_hash
279
291
  end
280
- hash[:details] << details_hash
281
292
  end
282
293
 
283
294
  hash
284
295
  end
285
296
 
286
- def get_protectmoveprot(log)
297
+ def loghash_protectmoveprot(log)
287
298
  {
288
299
  id: log['logid'],
289
300
  title: log['title'],
@@ -294,7 +305,7 @@ module MediaWiki
294
305
  }
295
306
  end
296
307
 
297
- def get_protectunprotect(log)
308
+ def loghash_protectunprotect(log)
298
309
  {
299
310
  id: log['logid'],
300
311
  title: log['title'],
@@ -304,32 +315,30 @@ module MediaWiki
304
315
  }
305
316
  end
306
317
 
307
- def get_rightsautopromote(log)
318
+ def loghash_rightsautopromote(log)
308
319
  {
309
320
  id: log['logid'],
310
- title: log['title'],
311
321
  user: log['user'],
312
- new_rights: log['rights']['new'].split(', '),
313
- old_rights: log['rights']['old'].split(', '),
322
+ new_rights: log['params']['newgroups'],
323
+ old_rights: log['params']['oldgroups'],
314
324
  comment: log['comment'],
315
325
  timestamp: DateTime.xmlschema(log['timestamp'])
316
326
  }
317
327
  end
318
328
 
319
- def get_rightsrights(log)
329
+ def loghash_rightsrights(log)
320
330
  {
321
331
  id: log['logid'],
322
- title: log['title'],
323
332
  to: log['title'],
324
333
  from: log['user'],
325
- new_rights: log['rights']['new'].split(', '),
326
- old_rights: log['rights']['old'].split(', '),
334
+ new_rights: log['params']['newgroups'],
335
+ old_rights: log['params']['oldgroups'],
327
336
  comment: log['comment'],
328
337
  timestamp: DateTime.xmlschema(log['timestamp'])
329
338
  }
330
339
  end
331
340
 
332
- def get_upload(log)
341
+ def loghash_upload(log)
333
342
  {
334
343
  id: log['logid'],
335
344
  title: log['title'],
@@ -14,7 +14,7 @@ module MediaWiki
14
14
 
15
15
  ret = []
16
16
  response['query']['logevents'].each do |log|
17
- ret << get_mergemerge(log)
17
+ ret << loghash_merge(log)
18
18
  end
19
19
 
20
20
  ret
@@ -14,7 +14,7 @@ module MediaWiki
14
14
 
15
15
  ret = []
16
16
  response['query']['logevents'].each do |log|
17
- ret << get_move(log)
17
+ ret << loghash_move(log)
18
18
  end
19
19
 
20
20
  ret
@@ -31,7 +31,7 @@ module MediaWiki
31
31
 
32
32
  ret = []
33
33
  resp['query']['logevents'].each do |log|
34
- ret << get_move(log)
34
+ ret << loghash_move(log)
35
35
  end
36
36
 
37
37
  ret
@@ -14,7 +14,7 @@ module MediaWiki
14
14
 
15
15
  ret = []
16
16
  response['query']['logevents'].each do |log|
17
- ret << get_user(log)
17
+ ret << loghash_user(log)
18
18
  end
19
19
 
20
20
  ret
@@ -31,7 +31,7 @@ module MediaWiki
31
31
 
32
32
  ret = []
33
33
  resp['query']['logevents'].each do |log|
34
- ret << get_user(log)
34
+ ret << loghash_user(log)
35
35
  end
36
36
 
37
37
  ret
@@ -47,7 +47,7 @@ module MediaWiki
47
47
 
48
48
  ret = []
49
49
  resp['query']['logevents'].each do |log|
50
- ret << get_user(log)
50
+ ret << loghash_user(log)
51
51
  end
52
52
 
53
53
  ret
@@ -14,7 +14,7 @@ module MediaWiki
14
14
 
15
15
  ret = []
16
16
  response['query']['logevents'].each do |log|
17
- ret << get_patrol(log)
17
+ ret << loghash_patrol(log)
18
18
  end
19
19
 
20
20
  ret
@@ -15,7 +15,7 @@ module MediaWiki
15
15
 
16
16
  ret = []
17
17
  response['query']['logevents'].each do |log|
18
- ret << get_protect(log)
18
+ ret << loghash_protect(log)
19
19
  end
20
20
 
21
21
  ret
@@ -32,7 +32,7 @@ module MediaWiki
32
32
 
33
33
  ret = []
34
34
  resp['query']['logevents'].each do |log|
35
- ret << get_protectmoveprot(log)
35
+ ret << loghash_protectmoveprot(log)
36
36
  end
37
37
 
38
38
  ret
@@ -49,7 +49,7 @@ module MediaWiki
49
49
 
50
50
  ret = []
51
51
  response['query']['logevents'].each do |log|
52
- ret << get_protect(log)
52
+ ret << loghash_protect(log)
53
53
  end
54
54
 
55
55
  ret
@@ -65,7 +65,7 @@ module MediaWiki
65
65
 
66
66
  ret = []
67
67
  resp['query']['logevents'].each do |log|
68
- ret << get_protectunprotect(log)
68
+ ret << loghash_protectunprotect(log)
69
69
  end
70
70
 
71
71
  ret
@@ -16,7 +16,7 @@ module MediaWiki
16
16
 
17
17
  ret = []
18
18
  resp['query']['logevents'].each do |log|
19
- ret << get_rightsautopromote(log)
19
+ ret << loghash_rightsautopromote(log)
20
20
  end
21
21
 
22
22
  ret
@@ -33,7 +33,7 @@ module MediaWiki
33
33
 
34
34
  ret = []
35
35
  resp['query']['logevents'].each do |log|
36
- ret << get_rightsrights(log)
36
+ ret << loghash_rightsrights(log)
37
37
  end
38
38
 
39
39
  ret
@@ -15,7 +15,7 @@ module MediaWiki
15
15
 
16
16
  ret = []
17
17
  resp['query']['logevents'].each do |log|
18
- ret << get_upload(log)
18
+ ret << loghash_upload(log)
19
19
  end
20
20
 
21
21
  ret
@@ -32,7 +32,7 @@ module MediaWiki
32
32
 
33
33
  ret = []
34
34
  resp['query']['logevents'].each do |log|
35
- ret << get_upload(log)
35
+ ret << loghash_upload(log)
36
36
  end
37
37
 
38
38
  ret
@@ -32,7 +32,7 @@ module MediaWiki
32
32
  def get_tags(limit = @query_limit_default)
33
33
  params = {
34
34
  list: 'tags',
35
- limit: get_limited(limit)
35
+ tglimit: get_limited(limit)
36
36
  }
37
37
 
38
38
  query_ary(params, 'tags', 'name')
@@ -4,11 +4,11 @@ module MediaWiki
4
4
  module Search
5
5
  # Gets the amount of results for the search value.
6
6
  # @param search_value [String] The thing to search for.
7
- # @param namespace [Fixnum] The namespace to search in. Defaults to 0 (the main namespace).
7
+ # @param namespace [Integer] The namespace to search in. Defaults to 0 (the main namespace).
8
8
  # @see https://www.mediawiki.org/wiki/API:Search MediaWiki Search API Docs
9
9
  # @since 0.4.0
10
10
  # @return [Fixnum] The number of pages that matched the search.
11
- def get_search_result_amount(search_value, namespace = 0)
11
+ def get_search_result_amount(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN'])
12
12
  params = {
13
13
  action: 'query',
14
14
  list: 'search',
@@ -22,11 +22,11 @@ module MediaWiki
22
22
 
23
23
  # Gets an array containing page titles that matched the search.
24
24
  # @param search_value [String] The thing to search for.
25
- # @param namespace [Fixnum] The namespace to search in. Defaults to 0 (the main namespace).
25
+ # @param namespace [Integer] The namespace to search in. Defaults to 0 (the main namespace).
26
26
  # @see https://www.mediawiki.org/wiki/API:Search MediaWiki Search API Docs
27
27
  # @since 0.4.0
28
28
  # @return [Array<String>] The page titles that matched the search.
29
- def get_search_results(search_value, namespace = 0)
29
+ def get_search_results(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN'])
30
30
  params = {
31
31
  list: 'search',
32
32
  srsearch: search_value,
@@ -36,9 +36,26 @@ module MediaWiki
36
36
  query_ary(params, 'search', 'title')
37
37
  end
38
38
 
39
+ # Gets an array containing page titles that matched the search.
40
+ # @param search_value [String] The thing to search for.
41
+ # @param namespace [Integer] The namespace to search in. Defaults to 0 (the main namespace).
42
+ # @see https://www.mediawiki.org/wiki/API:Search MediaWiki Search API Docs
43
+ # @return [Array<String>] The page titles that matched the search.
44
+ def get_search_text_results(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN'], limit = @query_limit_default)
45
+ params = {
46
+ list: 'search',
47
+ srsearch: search_value,
48
+ srwhat: 'text',
49
+ srlimit: get_limited(limit),
50
+ srnamespace: validate_namespace(namespace)
51
+ }
52
+
53
+ query_ary(params, 'search', 'title')
54
+ end
55
+
39
56
  # Searches the wiki by a prefix.
40
57
  # @param prefix [String] The prefix.
41
- # @param limit [Fixnum] The maximum number of results to get, maximum of 100 for users and 200 for bots. This is
58
+ # @param limit [Integer] The maximum number of results to get, maximum of 100 for users and 200 for bots. This is
42
59
  # one of the methods that does *not* use the query_limit_default attribute.
43
60
  # @see https://www.mediawiki.org/wiki/API:Prefixsearch MediaWiki Prefixsearch API Docs
44
61
  # @since 0.10.0
@@ -14,26 +14,25 @@ module MediaWiki
14
14
 
15
15
  # Obtains a token for the current user (or lack thereof) for specific actions. This uses the functionality
16
16
  # introduced in MediaWiki 1.27
17
- # @param type [String, Array<String>] The type of token to get. See #TOKEN_TYPES to see the valid types. If it
18
- # is invalid, it will default to 'csrf'. If it is an array, it will join by a pipe for the API.
19
- # @return [String, Hash<String => String>] Either a token or a set of tokens organized by type. If multiple
20
- # valid types are provided in the parameter, it returns a hash identical to the API response (see API docs).
17
+ # @param type [String] The type of token to get. See #TOKEN_TYPES to see the valid types. If it is invalid, it
18
+ # will default to 'csrf'.
19
+ # @return [String] A token for the provided type.
21
20
  def get_token(type = 'csrf')
21
+ type = 'csrf' unless TOKEN_TYPES.include?(type)
22
+
23
+ return @tokens[type] if @tokens.key?(type)
24
+
22
25
  params = {
23
26
  action: 'query',
24
- meta: 'tokens'
27
+ meta: 'tokens',
28
+ type: type
25
29
  }
26
30
 
27
- if type.is_a?(Array)
28
- type = (type - TOKEN_TYPES).empty? ? type.join('|') : 'csrf'
29
- else
30
- type = TOKEN_TYPES.include?(type) ? type : 'csrf'
31
- end
32
- params[:type] = type
33
-
34
31
  resp = post(params)
35
32
  tokens = resp['query']['tokens']
36
- tokens.size > 1 ? tokens : tokens["#{type}token"]
33
+ token = tokens["#{type}token"]
34
+ @tokens[type] = token
35
+ token
37
36
  end
38
37
  end
39
38
  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: 3.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-18 00:00:00.000000000 Z
12
+ date: 2020-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: httpclient
15
+ name: patron
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.8'
20
+ version: '0.13'
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: '2.8'
27
+ version: '0.13'
28
28
  description: " MediaWiki::Butt provides a fully-featured interface to the MediaWiki
29
29
  API. It includes methods for changing wiki content, authentication, and
30
30
  queries.\n\n"
@@ -94,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.6.10
97
+ rubygems_version: 3.1.3
99
98
  signing_key:
100
99
  specification_version: 4
101
100
  summary: Interacting with the MediaWiki API