rbmediawiki 0.2.6.1 → 0.2.6.2

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.
@@ -13,25 +13,23 @@ class Category
13
13
  #returns false if there aren't any, and raises NoPage if page doesn't exist
14
14
  def get_members(cmlimit = 500)
15
15
  cmcontinue = nil
16
- cms = Hash.new
16
+ cms = Array.new
17
17
  loop {
18
18
  result = @site.query_list_categorymembers(@title, @title, nil, nil, cmcontinue, cmlimit)
19
+ if result.key?('error') || !result['query']['categorymembers'].has_key?('cm')
20
+ raise NoPage.new(), "Page [[#{@title}]] does not exist"
21
+ end
22
+ if result['query']['categorymembers']['cm'].is_a? Array
23
+ cms = cms + result['query']['categorymembers']['cm']
24
+ else
25
+ cms.push(result['query']['categorymembers']['cm'])
26
+ end
19
27
  if result.key?('query-continue')
20
28
  cmcontinue = result['query-continue']['categorymembers']['cmcontinue']
21
- cms.deep_merge!(result['query'])
22
29
  else
23
- cms.deep_merge!(result['query'])
24
30
  break
25
31
  end
26
32
  }
27
- if cms['pages']['page'].key?('missing')
28
- raise NoPage.new(), "Page [[#{title}]] does not exist"
29
- elsif cms.key?('categorymembers')
30
- members = Array.new
31
- cms['categorymembers']['cm'].each{|el| members.push(Page.new(el['title']))}
32
- return members
33
- else return false
34
- end
35
-
33
+ return cms
36
34
  end
37
35
  end
@@ -217,61 +217,131 @@ class Page
217
217
  end
218
218
 
219
219
 
220
- #not working in r1.9
221
- # #get interwiki links
222
- # #min is the minimum number of elements to return, lllimit is the number of
223
- # #elements to request from the API in each iteration. The method will
224
- # #request elements until it has at least min elements.
225
- # #returns false if there aren't any, and raises NoPage if page doesn't exist
226
- # def get_interwikis(min = nil, lllimit = 500)
227
- # llcontinue = nil
228
- # iws = Hash.new
229
- # count = 0
230
- # loop {
231
- # result = @site.query_prop_langlinks(@normtitle, lllimit, llcontinue)
232
- # iws.deep_merge!(result['query'])
233
- # if result.key?('query-continue') && min && count < min
234
- # count += lllimit
235
- # llcontinue = result['query-continue']['langlinks']['llcontinue']
236
- # else
237
- # break
238
- # end
239
- # }
240
- # if iws['pages']['page'].key?('missing')
241
- # raise NoPage.new(), "Page [[#{title}]] does not exist"
242
- # elsif iws['pages']['page'].key?('langlinks')
243
- # return iws['pages']['page']['langlinks']['ll']
244
- # else return false
245
- # end
246
- # end
220
+ #get interwiki links
221
+ #min is the minimum number of elements to return, lllimit is the number of
222
+ #elements to request from the API in each iteration. The method will
223
+ #request elements until it has at least min elements.
224
+ #returns false if there aren't any, and raises NoPage if page doesn't exist
225
+ def get_interwikis(min = nil, lllimit = 500)
226
+ llcontinue = nil
227
+ iws = Hash.new
228
+ count = 0
229
+ loop {
230
+ result = @site.query_prop_langlinks(@normtitle, lllimit, llcontinue)
231
+ if result['query']['pages']['page'].key?('missing')
232
+ raise NoPage.new(), "Page [[#{title}]] does not exist"
233
+ end
234
+ if !result['query'].key?('interwikis')
235
+ return nil
236
+ end
237
+ if result['query']['interwikis']['iw'].is_a? Array
238
+ iws = iws + result['query']['interwikis']['iw']
239
+ else
240
+ iws.push(result['query']['interwikis']['iw'])
241
+ end
242
+ if result.key?('query-continue') && min && count < min
243
+ count += lllimit
244
+ llcontinue = result['query-continue']['langlinks']['llcontinue']
245
+ else
246
+ break
247
+ end
248
+ }
249
+ return iws
250
+ end
251
+
247
252
  #
248
- # #gets image links of a page
249
- # #min is the minimum number of elements to return, imlimit is the number of
250
- # #elements to request from the API in each iteration. The method will
251
- # #request elements until it has at least min elements.
252
- # #returns false if there aren't any, and raises NoPage if page doesn't exist
253
- # def get_images(min = nil, imlimit = 500)
254
- # imcontinue = nil
255
- # ims = Hash.new
256
- # count = 0
257
- # loop {
258
- # result = @site.query_prop_images(@normtitle, imlimit, imcontinue)
259
- # ims.deep_merge!(result['query'])
260
- # if result.key?('query-continue') && min && count < min
261
- # count += lllimit
262
- # imcontinue = result['query-continue']['images']['imcontinue']
263
- # else
264
- # break
265
- # end
266
- # }
267
- # if ims['pages']['page'].key?('missing')
268
- # raise NoPage.new(), "Page [[#{@title}]] does not exist"
269
- # elsif ims['pages']['page'].key?('images')
270
- # return ims['pages']['page']['images']['im']
271
- # else return false
272
- # end
273
- # end
274
- #
253
+ #gets image links of a page
254
+ #min is the minimum number of elements to return, imlimit is the number of
255
+ #elements to request from the API in each iteration. The method will
256
+ #request elements until it has at least min elements.
257
+ #returns false if there aren't any, and raises NoPage if page doesn't exist
258
+ def get_images(min = nil, imlimit = 500)
259
+ imcontinue = nil
260
+ ims = Array.new
261
+ count = 0
262
+ loop {
263
+ result = @site.query_prop_images(@normtitle, imlimit, imcontinue)
264
+ proc_res = result['query']['pages']['page']
265
+ if proc_res.key?('missing')
266
+ raise NoPage.new(), "Page [[#{@title}]] does not exist"
267
+ end
268
+ if !proc_res.key?('images')
269
+ return nil
270
+ end
271
+ if proc_res['images']['im'].is_a? Array
272
+ ims = ims + proc_res['images']['im']
273
+ else
274
+ ims.push(proc_res['images']['im'])
275
+ end
276
+ if result.key?('query-continue') && min && count < min
277
+ count += lllimit
278
+ imcontinue = result['query-continue']['images']['imcontinue']
279
+ else
280
+ break
281
+ end
282
+ }
283
+ return ims
284
+ end
285
+ #gets categories used in a page
286
+ #min is the minimum number of elements to return, cllimit is the number of
287
+ #elements to request from the API in each iteration. The method will
288
+ #request elements until it has at least min elements.
289
+ #clshow can be "hidden" or "!hidden". Default shows both
290
+ #if sortkey is true will return the sortkey. Default is true
291
+ def get_categories(min = nil, cllimit = 500, clshow = nil, sortkey = true)
292
+ clcontinue = nil
293
+ cls = Array.new
294
+ count = 0
295
+
296
+ if sortkey
297
+ clprop = "sortkey"
298
+ end
299
+
300
+ loop {
301
+ result = @site.query_prop_categories(@normtitle, clprop, clshow, cllimit, clcontinue)
302
+ if result['query']['pages']['page'].key?('missing')
303
+ raise NoPage.new(), "Page [[#{@title}]] does not exist"
304
+ end
305
+ page = result['query']['pages']['page']
306
+ if page['categories']['cl'].is_a? Array
307
+ cls = cls + page['categories']['cl']
308
+ else
309
+ cls.push(page['categories']['cl'])
310
+ end
311
+
312
+ if result.key?('query-continue')&& min && count < min
313
+ count += lllimit
314
+ clcontinue = result['query-continue']['categories']['clcontinue']
315
+ else
316
+ break
317
+ end
318
+ }
319
+ return cls
320
+ end
321
+
322
+ def get_backlinks(bllimit = 500, blnamespace = nil, blredirect = true)
323
+ blcontinue = nil
324
+ bls = Array.new
325
+ loop {
326
+ result = @site.query_list_backlinks(@normtitle, @normtitle, blcontinue, blnamespace, nil, bllimit, blredirect)
327
+ if result['query']['pages']['page'].key?('missing')
328
+ raise NoPage.new(), "Page [[#{@title}]] does not exist"
329
+ end
330
+ if result['query']['backlinks']['bl'].is_a? Array
331
+ bls = bls + result['query']['backlinks']['bl']
332
+ else
333
+ bls.push(result['query']['backlinks']['bl'])
334
+ end
335
+ if result.key?('query-continue')
336
+ blcontinue = result['query-continue']['backlinks']['blcontinue']
337
+ else
338
+ break
339
+ end
340
+ }
341
+ return bls
342
+ end
343
+
344
+ #not working in r1.9
275
345
  # #gets templates used in a page
276
346
  # #min is the minimum number of elements to return, tllimit is the number of
277
347
  # #elements to request from the API in each iteration. The method will
@@ -299,38 +369,7 @@ class Page
299
369
  # end
300
370
  # end
301
371
  #
302
- # #gets templates used in a page
303
- # #min is the minimum number of elements to return, cllimit is the number of
304
- # #elements to request from the API in each iteration. The method will
305
- # #request elements until it has at least min elements.
306
- # #clshow can be "hidden" or "!hidden". Default shows both
307
- # #if sortkey is true will return the sortkey. Default is true
308
- # def get_categories(min = nil, cllimit = 500, clshow = nil, sortkey = true)
309
- # clcontinue = nil
310
- # cls = Hash.new
311
- # count = 0
312
- #
313
- # if sortkey
314
- # clprop = "sortkey"
315
- # end
316
- #
317
- # loop {
318
- # result = @site.query_prop_categories(@normtitle, clprop, clshow, cllimit, clcontinue)
319
- # cls.deep_merge!(result['query'])
320
- # if result.key?('query-continue')&& min && count < min
321
- # count += lllimit
322
- # clcontinue = result['query-continue']['categories']['clcontinue']
323
- # else
324
- # break
325
- # end
326
- # }
327
- # if cls['pages']['page'].key?('missing')
328
- # raise NoPage.new(), "Page [[#{@title}]] does not exist"
329
- # elsif cls['pages']['page'].key?('categories')
330
- # return cls['pages']['page']['categories']['cl']
331
- # else return false
332
- # end
333
- # end
372
+
334
373
  #
335
374
  # #gets external links used in a page
336
375
  # #min is the minimum number of elements to return, ellimit is the number of
@@ -364,25 +403,7 @@ class Page
364
403
  #elements to request from the API in each iteration. The method will
365
404
  #request elements until it has at least min elements.
366
405
  #returns false if there aren't any, and raises NoPage if page doesn't exist
367
- def get_backlinks(min = nil, bllimit = 500, blnamespace = nil, blredirect = true)
368
- blcontinue = nil
369
- bls = Hash.new
370
- count = 0
371
- loop {
372
- result = @site.query_list_backlinks(@normtitle, @normtitle, blcontinue, blnamespace, nil, bllimit, blredirect)
373
- if result['query']['pages']['page'].key?('missing')
374
- raise NoPage.new(), "Page [[#{@title}]] does not exist"
375
- end
376
- bls.merge!(result['query']['backlinks'])
377
- if result.key?('query-continue')&& min && count < min
378
- count += lllimit
379
- blcontinue = result['query-continue']['backlinks']['blcontinue']
380
- else
381
- break
382
- end
383
- }
384
- return bls['bl']
385
- end
406
+
386
407
 
387
408
  # #gets deleted revisions of a page
388
409
  # #min is the minimum number of elements to return, drlimit is the number of
@@ -69,24 +69,27 @@ class User
69
69
 
70
70
  #get user contributions
71
71
  #returns false if there aren't any
72
- def get_usercontribs(uclimit = 500, ucstart = nil, ucnamespace = nil)
72
+ def get_usercontribs(uclimit = 500, ucstart = nil, ucnamespace = nil, ucdir="newer")
73
73
  uccontinue = nil
74
- ucs = Hash.new
75
- puts ucstart
74
+ ucs = Array.new
76
75
  loop {
77
- result = @site.query_list_usercontribs(nil, uclimit, ucstart, nil, uccontinue, @username, nil, "newer", ucnamespace)
78
- ucs.deep_merge!(result['query'])
76
+ result = @site.query_list_usercontribs(nil, uclimit, ucstart, nil, uccontinue, @username, nil, ucdir, ucnamespace)
77
+ if !result['query']['usercontribs'].has_key?('item')
78
+ raise NoUser
79
+ end
80
+ items = result['query']['usercontribs']['item']
81
+ if items.is_a? Array
82
+ ucs = ucs + items
83
+ else
84
+ ucs.push(items)
85
+ end
79
86
  if result.key?('query-continue')
80
87
  ucstart = result['query-continue']['usercontribs']['ucstart']
81
88
  else
82
89
  break
83
90
  end
84
91
  }
85
- if ucs['usercontribs'].key?('item')
86
- return ucs['usercontribs']['item']
87
- else
88
- return false
89
- end
92
+ return ucs
90
93
  end
91
94
 
92
95
  #rollbacks (reverts) all edits by the user since a given time.
@@ -109,3 +112,7 @@ class User
109
112
  }
110
113
  end
111
114
  end
115
+
116
+
117
+ class NoUser < RuntimeError
118
+ end
data/lib/rbmediawiki.rb CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'xmlsimple'
5
5
 
6
6
  class Rbmediawiki
7
- VERSION = '0.2.6.1'
7
+ VERSION = '0.2.6.2'
8
8
  Dir["#{File.dirname(__FILE__)}/rbmediawiki/*.rb"].sort.each { |lib| require lib }
9
9
  end
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbmediawiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.1
4
+ version: 0.2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chabacano
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-24 00:00:00 +02:00
12
+ date: 2009-06-11 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency