rbmediawiki 0.1 → 0.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.
data/lib/api.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #coding: utf-8
1
2
  require 'yaml'
2
3
  require 'net/http'
3
4
  require 'rubygems'
@@ -41,13 +42,14 @@ class Api
41
42
  #for using then when making requests. If the user is already logged iy
42
43
  #does nothing
43
44
 
44
- def login()
45
+ def login(password = nil)
45
46
  if @config['logged']
46
47
  return true
47
48
  end
48
-
49
- puts "Introduce password for #{@config['user']} at #{@config['base_url']}"
50
- password = gets.chomp
49
+ if (!password)
50
+ puts "Introduce password for #{@config['user']} at #{@config['base_url']}"
51
+ password = gets.chomp
52
+ end
51
53
 
52
54
  post_me = add_post('lgname',@config['user'])
53
55
  post_me = add_post('lgpassword',password, post_me)
@@ -890,7 +892,10 @@ class Api
890
892
  response = Net::HTTP.new(uri.host, uri.port).start { |http|
891
893
  http.request(request)
892
894
  }
893
- return_result = XmlSimple.xml_in(response.body, { 'ForceArray' => false })
895
+ resputf8 = '<?xml version="1.0" encoding="UTF-8" ?>'+response.body[21..-1]
896
+
897
+ return_result = XmlSimple.xml_in(resputf8, { 'ForceArray' => false })
898
+ return return_result
894
899
  end
895
900
 
896
901
  def add_post(key, value, post_me = nil)
data/lib/category.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'deep_merge'
2
-
3
1
  require 'api'
4
2
  require 'page'
5
3
 
@@ -1,5 +1,5 @@
1
+ #coding: utf-8
1
2
  require 'page'
2
- require 'generator'
3
3
 
4
4
  class Misc_generator
5
5
  def initialize(site)
@@ -17,40 +17,36 @@ class Misc_generator
17
17
  # * diffto: Revision ID to diff each revision to. Use "prev", "next" and "cur" for the previous, next and current revision respectively.
18
18
 
19
19
 
20
- def history( titles, rvlimit = 1, rvprop = "ids|timestamp|flags|comment|user|size|content", rvstartid = nil, rvendid = nil, rvdir = "older", rvuser = nil, diffto = "prev")
21
- g = Generator.new { |g|
22
- pages = Hash.new
23
- finish = false
24
- while !finish
25
- result = @site.query_prop_revisions(titles, rvprop, rvlimit, rvstartid, rvendid, nil, nil, rvdir, rvuser, nil, nil, nil, nil, nil, nil, diffto )
26
- result['query']['pages']['page']['revisions'].each {|rv|
27
- g.yield rv
28
- }
29
- if result.key?('query-continue')
30
- rvstartid = result['query-continue']['revisions']['rvstartid']
31
- else
32
- finish = true
33
- end
20
+ def history( titles, rvlimit = 50, rvprop = "ids|timestamp|flags|comment|user|size|content", rvstartid = nil, rvendid = nil, rvdir = "older", rvuser = nil, diffto = "prev")
21
+ pages = Hash.new
22
+ finish = false
23
+ while !finish
24
+ result = @site.query_prop_revisions(titles, rvprop, rvlimit, rvstartid, rvendid, nil, nil, rvdir, rvuser, nil, nil, nil, nil, nil, nil, diffto )
25
+ result['query']['pages']['page']['revisions']['rev'].each {|rv|
26
+ puts rv
27
+ yield rv
28
+ }
29
+ if result.key?('query-continue')
30
+ rvstartid = result['query-continue']['revisions']['rvstartid']
31
+ else
32
+ finish = true
34
33
  end
35
- }
34
+ end
36
35
  end
37
36
 
38
- def history_diff( titles, rvlimit = 50, rvprop = "ids|timestamp|flags|comment|user|size|content", rvstartid = nil, rvendid = nil, rvdir = "older", rvuser= nil)
39
- g = Generator.new { |g|
40
- pages = Hash.new
41
- finish = false
42
- while !finish
43
- result = @site.query_prop_revisions(titles, rvprop, rvlimit, rvstartid, rvendid, nil, nil, rvdir, rvuser)
44
- puts result['query']['pages']['page']['revisions']
45
- result['query']['pages']['page']['revisions'].each {|rv|
46
- g.yield rv
47
- }
48
- if result.key?('query-continue')
49
- rvstartid = result['query-continue']['revisions']['rvstartid']
50
- else
51
- finish = true
52
- end
37
+ def history_diff( titles, rvlimit = 30, rvprop = "timestamp|comment|user|size", rvstartid = nil, rvendid = nil, rvdir = "older", rvuser= nil, diffto = "prev")
38
+ pages = Hash.new
39
+ finish = false
40
+ while !finish
41
+ result = @site.query_prop_revisions("japonés", rvprop, rvlimit, rvstartid, rvendid, nil, nil, rvdir, rvuser, nil, nil, nil, nil, nil, nil, "prev")
42
+ result['query']['pages']['page']['revisions'].each {|rv|
43
+ yield rv
44
+ }
45
+ if result.key?('query-continue')
46
+ rvstartid = result['query-continue']['revisions']['rvstartid']
47
+ else
48
+ finish = true
53
49
  end
54
- }
50
+ end
55
51
  end
56
52
  end
data/lib/page.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  #TODO: rollback
2
2
  #TODO: patrol
3
- require 'deep_merge'
4
3
 
5
4
  require 'api'
6
5
 
@@ -24,14 +23,24 @@ class Page
24
23
  end
25
24
  end
26
25
 
26
+ #returns false if it is not a redirect, the redirected title if it is
27
+ def redirect?()
28
+ txt = this.get
29
+ if (txt =~ /#REDIRECT\s+\[\[(.*)\]\]/)
30
+ return $1
31
+ else
32
+ return false
33
+ end
34
+ end
35
+
27
36
  #puts the text of a page.
28
37
  # * text: the new content of the page
29
38
  # * summary: editting summary
30
39
  # * minor: is a minor edit? default->true
31
40
  # * bot: is a bot flagged edit?
32
- def put(text, summary = nil, minor = true, bot = true)
41
+ def put(text, summary = nil, minor = true, bot = true, password = nil)
33
42
  #require login
34
- @site.login
43
+ @site.login(password)
35
44
  result = @site.query_prop_info(@normtitle, nil, 'edit')
36
45
  token = result['query']['pages']['page']['edittoken']
37
46
  result = @site.edit(@normtitle, nil, text, token, summary, minor, nil, bot)
@@ -40,6 +49,7 @@ class Page
40
49
  else
41
50
  return true
42
51
  end
52
+ puts "content put"
43
53
  end
44
54
 
45
55
  #appends texto to a page
@@ -209,240 +219,241 @@ class Page
209
219
  end
210
220
 
211
221
 
212
- #get interwiki links
213
- #min is the minimum number of elements to return, lllimit is the number of
214
- #elements to request from the API in each iteration. The method will
215
- #request elements until it has at least min elements.
216
- #returns false if there aren't any, and raises NoPage if page doesn't exist
217
- def get_interwikis(min = nil, lllimit = 500)
218
- llcontinue = nil
219
- iws = Hash.new
220
- count = 0
221
- loop {
222
- result = @site.query_prop_langlinks(@normtitle, lllimit, llcontinue)
223
- iws.deep_merge!(result['query'])
224
- if result.key?('query-continue') && min && count < min
225
- count += lllimit
226
- llcontinue = result['query-continue']['langlinks']['llcontinue']
227
- else
228
- break
229
- end
230
- }
231
- if iws['pages']['page'].key?('missing')
232
- raise NoPage.new(), "Page [[#{title}]] does not exist"
233
- elsif iws['pages']['page'].key?('langlinks')
234
- return iws['pages']['page']['langlinks']['ll']
235
- else return false
236
- end
237
- end
238
-
239
- #gets image links of a page
240
- #min is the minimum number of elements to return, imlimit is the number of
241
- #elements to request from the API in each iteration. The method will
242
- #request elements until it has at least min elements.
243
- #returns false if there aren't any, and raises NoPage if page doesn't exist
244
- def get_images(min = nil, imlimit = 500)
245
- imcontinue = nil
246
- ims = Hash.new
247
- count = 0
248
- loop {
249
- result = @site.query_prop_images(@normtitle, imlimit, imcontinue)
250
- ims.deep_merge!(result['query'])
251
- if result.key?('query-continue') && min && count < min
252
- count += lllimit
253
- imcontinue = result['query-continue']['images']['imcontinue']
254
- else
255
- break
256
- end
257
- }
258
- if ims['pages']['page'].key?('missing')
259
- raise NoPage.new(), "Page [[#{@title}]] does not exist"
260
- elsif ims['pages']['page'].key?('images')
261
- return ims['pages']['page']['images']['im']
262
- else return false
263
- end
264
- end
265
-
266
- #gets templates used in a page
267
- #min is the minimum number of elements to return, tllimit is the number of
268
- #elements to request from the API in each iteration. The method will
269
- #request elements until it has at least min elements.
270
- #returns false if there aren't any, and raises NoPage if page doesn't exist
271
- def get_templates(min = nil, tllimit = 500)
272
- tlcontinue = nil
273
- tls = Hash.new
274
- count = 0
275
- loop {
276
- result = @site.query_prop_templates(@normtitle, nil, tllimit, tlcontinue)
277
- tls.deep_merge!(result['query'])
278
- if result.key?('query-continue')&& min && count < min
279
- count += lllimit
280
- tlcontinue = result['query-continue']['templates']['tlcontinue']
281
- else
282
- break
283
- end
284
- }
285
- if tls['pages']['page'].key?('missing')
286
- raise NoPage.new(), "Page [[#{@title}]] does not exist"
287
- elsif tls['pages']['page'].key?('templates')
288
- return tls['pages']['page']['templates']['tl']
289
- else return false
290
- end
291
- end
292
-
293
- #gets templates used in a page
294
- #min is the minimum number of elements to return, cllimit is the number of
295
- #elements to request from the API in each iteration. The method will
296
- #request elements until it has at least min elements.
297
- #clshow can be "hidden" or "!hidden". Default shows both
298
- #if sortkey is true will return the sortkey. Default is true
299
- def get_categories(min = nil, cllimit = 500, clshow = nil, sortkey = true)
300
- clcontinue = nil
301
- cls = Hash.new
302
- count = 0
303
-
304
- if sortkey
305
- clprop = "sortkey"
306
- end
307
-
308
- loop {
309
- result = @site.query_prop_categories(@normtitle, clprop, clshow, cllimit, clcontinue)
310
- cls.deep_merge!(result['query'])
311
- if result.key?('query-continue')&& min && count < min
312
- count += lllimit
313
- clcontinue = result['query-continue']['categories']['clcontinue']
314
- else
315
- break
316
- end
317
- }
318
- if cls['pages']['page'].key?('missing')
319
- raise NoPage.new(), "Page [[#{@title}]] does not exist"
320
- elsif cls['pages']['page'].key?('categories')
321
- return cls['pages']['page']['categories']['cl']
322
- else return false
323
- end
324
- end
325
-
326
- #gets external links used in a page
327
- #min is the minimum number of elements to return, ellimit is the number of
328
- #elements to request from the API in each iteration. The method will
329
- #request elements until it has at least min elements.
330
- #returns false if there aren't any, and raises NoPage if page doesn't exist
331
- def get_external_links(min = nil, ellimit = 500)
332
- eloffset = nil
333
- els = Hash.new
334
- count = 0
335
- loop {
336
- result = @site.query_prop_extlinks(@normtitle, ellimit, eloffset)
337
- els.deep_merge!(result['query'])
338
- if result.key?('query-continue')&& min && count < min
339
- count += lllimit
340
- eloffset = result['query-continue']['extlinks']['elcontinue']
341
- else
342
- break
343
- end
344
- }
345
- if els['pages']['page'].key?('missing')
346
- raise NoPage.new(), "Page [[#{@title}]] does not exist"
347
- elsif els['pages']['page'].key?('extlinks')
348
- return els['pages']['page']['extlinks']['el']
349
- else return false
350
- end
351
- end
352
-
353
- #gets backlinks (what links here) used in a page
354
- #min is the minimum number of elements to return, bllimit is the number of
355
- #elements to request from the API in each iteration. The method will
356
- #request elements until it has at least min elements.
357
- #returns false if there aren't any, and raises NoPage if page doesn't exist
358
- def get_backlinks(min = nil, bllimit = 500, blnamespace = nil, blredirect = true)
359
- blcontinue = nil
360
- bls = Hash.new
361
- count = 0
362
- loop {
363
- result = @site.query_list_backlinks(@normtitle, @normtitle, blcontinue, blnamespace, nil, bllimit, blredirect)
364
- bls.deep_merge!(result['query'])
365
- if result.key?('query-continue')&& min && count < min
366
- count += lllimit
367
- blcontinue = result['query-continue']['backlinks']['blcontinue']
368
- else
369
- break
370
- end
371
- }
372
- if bls['pages']['page'].key?('missing')
373
- raise NoPage.new(), "Page [[#{@title}]] does not exist"
374
- elsif bls['backlinks'].key?('bl')
375
- return bls['backlinks']['bl']
376
- else return false
377
- end
378
- end
379
-
380
- #gets deleted revisions of a page
381
- #min is the minimum number of elements to return, drlimit is the number of
382
- #elements to request from the API in each iteration. The method will
383
- #request elements until it has at least min elements.
384
- #returns false if there aren't any
385
- def get_deletedrevs(min = nil, drlimit = 500)
386
- @site.login
387
- drcontinue = nil
388
- drs = Hash.new
389
- count = 0
390
- loop {
391
- result = @site.query_list_deletedrevs(@normtitle, nil, nil, nil, nil, nil, nil, drcontinue, nil, nil, nil, nil, drlimit)
392
- drs.deep_merge!(result['query'])
393
- if result.key?('query-continue')&& min && count < min
394
- count += lllimit
395
- drcontinue = result['query-continue']['deletedrevs']['drstart']
396
- else
397
- break
398
- end
399
- }
400
- if drs['deletedrevs'].key?('page')
401
- return drs['deletedrevs']['page']['revisions']['rev']
402
- else return false
403
- end
404
- end
405
-
406
- #gets pages in which this page is embedded (or transcluded). Returns a list
407
- #of Page elements
408
- #min is the minimum number of elements to return, eilimit is the number of
409
- #elements to request from the API in each iteration. The method will
410
- #request elements until it has at least min elements.
411
- #returns false if there aren't any, and raises NoPage if page doesn't exist
412
- def get_embeddedin(min = nil, eilimit = 500)
413
- eicontinue = nil
414
- eis = Hash.new
415
- count = 0
416
- loop {
417
- result = @site.query_list_embeddedin(@normtitle, @normtitle, eicontinue, nil, nil, eilimit)
418
- eis.deep_merge!(result['query'])
419
- if result.key?('query-continue')&& min && count < min
420
- count += lllimit
421
- eicontinue = result['query-continue']['embeddedin']['eicontinue']
422
- else
423
- break
424
- end
425
- }
426
- if eis['pages']['page'].key?('missing')
427
- raise NoPage.new(), "Page [[#{@title}]] does not exist"
428
- elsif eis['embeddedin'].key?('ei')
429
- members = Array.new
430
- eis['embeddedin']['ei'].each{|el| members.push(Page.new(el['title']))}
431
- return members
432
- else return false
433
- end
434
- end
435
-
436
- #returns the size of the page content in bytes
437
- #Raises NoPage if the page doesn't exist
438
- def get_size
439
- result = @site.query_prop_info(@normtitle)
440
- if result['query']['pages']['page'].key?('missing')
441
- raise NoPage.new(), "Page [[#{@normtitle}]] does not exist"
442
- else
443
- return result['query']['pages']['page']['length']
444
- end
445
- end
222
+ #not working in r1.9
223
+ # #get interwiki links
224
+ # #min is the minimum number of elements to return, lllimit is the number of
225
+ # #elements to request from the API in each iteration. The method will
226
+ # #request elements until it has at least min elements.
227
+ # #returns false if there aren't any, and raises NoPage if page doesn't exist
228
+ # def get_interwikis(min = nil, lllimit = 500)
229
+ # llcontinue = nil
230
+ # iws = Hash.new
231
+ # count = 0
232
+ # loop {
233
+ # result = @site.query_prop_langlinks(@normtitle, lllimit, llcontinue)
234
+ # iws.deep_merge!(result['query'])
235
+ # if result.key?('query-continue') && min && count < min
236
+ # count += lllimit
237
+ # llcontinue = result['query-continue']['langlinks']['llcontinue']
238
+ # else
239
+ # break
240
+ # end
241
+ # }
242
+ # if iws['pages']['page'].key?('missing')
243
+ # raise NoPage.new(), "Page [[#{title}]] does not exist"
244
+ # elsif iws['pages']['page'].key?('langlinks')
245
+ # return iws['pages']['page']['langlinks']['ll']
246
+ # else return false
247
+ # end
248
+ # end
249
+ #
250
+ # #gets image links of a page
251
+ # #min is the minimum number of elements to return, imlimit is the number of
252
+ # #elements to request from the API in each iteration. The method will
253
+ # #request elements until it has at least min elements.
254
+ # #returns false if there aren't any, and raises NoPage if page doesn't exist
255
+ # def get_images(min = nil, imlimit = 500)
256
+ # imcontinue = nil
257
+ # ims = Hash.new
258
+ # count = 0
259
+ # loop {
260
+ # result = @site.query_prop_images(@normtitle, imlimit, imcontinue)
261
+ # ims.deep_merge!(result['query'])
262
+ # if result.key?('query-continue') && min && count < min
263
+ # count += lllimit
264
+ # imcontinue = result['query-continue']['images']['imcontinue']
265
+ # else
266
+ # break
267
+ # end
268
+ # }
269
+ # if ims['pages']['page'].key?('missing')
270
+ # raise NoPage.new(), "Page [[#{@title}]] does not exist"
271
+ # elsif ims['pages']['page'].key?('images')
272
+ # return ims['pages']['page']['images']['im']
273
+ # else return false
274
+ # end
275
+ # end
276
+ #
277
+ # #gets templates used in a page
278
+ # #min is the minimum number of elements to return, tllimit is the number of
279
+ # #elements to request from the API in each iteration. The method will
280
+ # #request elements until it has at least min elements.
281
+ # #returns false if there aren't any, and raises NoPage if page doesn't exist
282
+ # def get_templates(min = nil, tllimit = 500)
283
+ # tlcontinue = nil
284
+ # tls = Hash.new
285
+ # count = 0
286
+ # loop {
287
+ # result = @site.query_prop_templates(@normtitle, nil, tllimit, tlcontinue)
288
+ # tls.deep_merge!(result['query'])
289
+ # if result.key?('query-continue')&& min && count < min
290
+ # count += lllimit
291
+ # tlcontinue = result['query-continue']['templates']['tlcontinue']
292
+ # else
293
+ # break
294
+ # end
295
+ # }
296
+ # if tls['pages']['page'].key?('missing')
297
+ # raise NoPage.new(), "Page [[#{@title}]] does not exist"
298
+ # elsif tls['pages']['page'].key?('templates')
299
+ # return tls['pages']['page']['templates']['tl']
300
+ # else return false
301
+ # end
302
+ # end
303
+ #
304
+ # #gets templates used in a page
305
+ # #min is the minimum number of elements to return, cllimit is the number of
306
+ # #elements to request from the API in each iteration. The method will
307
+ # #request elements until it has at least min elements.
308
+ # #clshow can be "hidden" or "!hidden". Default shows both
309
+ # #if sortkey is true will return the sortkey. Default is true
310
+ # def get_categories(min = nil, cllimit = 500, clshow = nil, sortkey = true)
311
+ # clcontinue = nil
312
+ # cls = Hash.new
313
+ # count = 0
314
+ #
315
+ # if sortkey
316
+ # clprop = "sortkey"
317
+ # end
318
+ #
319
+ # loop {
320
+ # result = @site.query_prop_categories(@normtitle, clprop, clshow, cllimit, clcontinue)
321
+ # cls.deep_merge!(result['query'])
322
+ # if result.key?('query-continue')&& min && count < min
323
+ # count += lllimit
324
+ # clcontinue = result['query-continue']['categories']['clcontinue']
325
+ # else
326
+ # break
327
+ # end
328
+ # }
329
+ # if cls['pages']['page'].key?('missing')
330
+ # raise NoPage.new(), "Page [[#{@title}]] does not exist"
331
+ # elsif cls['pages']['page'].key?('categories')
332
+ # return cls['pages']['page']['categories']['cl']
333
+ # else return false
334
+ # end
335
+ # end
336
+ #
337
+ # #gets external links used in a page
338
+ # #min is the minimum number of elements to return, ellimit is the number of
339
+ # #elements to request from the API in each iteration. The method will
340
+ # #request elements until it has at least min elements.
341
+ # #returns false if there aren't any, and raises NoPage if page doesn't exist
342
+ # def get_external_links(min = nil, ellimit = 500)
343
+ # eloffset = nil
344
+ # els = Hash.new
345
+ # count = 0
346
+ # loop {
347
+ # result = @site.query_prop_extlinks(@normtitle, ellimit, eloffset)
348
+ # els.deep_merge!(result['query'])
349
+ # if result.key?('query-continue')&& min && count < min
350
+ # count += lllimit
351
+ # eloffset = result['query-continue']['extlinks']['elcontinue']
352
+ # else
353
+ # break
354
+ # end
355
+ # }
356
+ # if els['pages']['page'].key?('missing')
357
+ # raise NoPage.new(), "Page [[#{@title}]] does not exist"
358
+ # elsif els['pages']['page'].key?('extlinks')
359
+ # return els['pages']['page']['extlinks']['el']
360
+ # else return false
361
+ # end
362
+ # end
363
+ #
364
+ # #gets backlinks (what links here) used in a page
365
+ # #min is the minimum number of elements to return, bllimit is the number of
366
+ # #elements to request from the API in each iteration. The method will
367
+ # #request elements until it has at least min elements.
368
+ # #returns false if there aren't any, and raises NoPage if page doesn't exist
369
+ # def get_backlinks(min = nil, bllimit = 500, blnamespace = nil, blredirect = true)
370
+ # blcontinue = nil
371
+ # bls = Hash.new
372
+ # count = 0
373
+ # loop {
374
+ # result = @site.query_list_backlinks(@normtitle, @normtitle, blcontinue, blnamespace, nil, bllimit, blredirect)
375
+ # bls.deep_merge!(result['query'])
376
+ # if result.key?('query-continue')&& min && count < min
377
+ # count += lllimit
378
+ # blcontinue = result['query-continue']['backlinks']['blcontinue']
379
+ # else
380
+ # break
381
+ # end
382
+ # }
383
+ # if bls['pages']['page'].key?('missing')
384
+ # raise NoPage.new(), "Page [[#{@title}]] does not exist"
385
+ # elsif bls['backlinks'].key?('bl')
386
+ # return bls['backlinks']['bl']
387
+ # else return false
388
+ # end
389
+ # end
390
+ #
391
+ # #gets deleted revisions of a page
392
+ # #min is the minimum number of elements to return, drlimit is the number of
393
+ # #elements to request from the API in each iteration. The method will
394
+ # #request elements until it has at least min elements.
395
+ # #returns false if there aren't any
396
+ # def get_deletedrevs(min = nil, drlimit = 500)
397
+ # @site.login
398
+ # drcontinue = nil
399
+ # drs = Hash.new
400
+ # count = 0
401
+ # loop {
402
+ # result = @site.query_list_deletedrevs(@normtitle, nil, nil, nil, nil, nil, nil, drcontinue, nil, nil, nil, nil, drlimit)
403
+ # drs.deep_merge!(result['query'])
404
+ # if result.key?('query-continue')&& min && count < min
405
+ # count += lllimit
406
+ # drcontinue = result['query-continue']['deletedrevs']['drstart']
407
+ # else
408
+ # break
409
+ # end
410
+ # }
411
+ # if drs['deletedrevs'].key?('page')
412
+ # return drs['deletedrevs']['page']['revisions']['rev']
413
+ # else return false
414
+ # end
415
+ # end
416
+ #
417
+ # #gets pages in which this page is embedded (or transcluded). Returns a list
418
+ # #of Page elements
419
+ # #min is the minimum number of elements to return, eilimit is the number of
420
+ # #elements to request from the API in each iteration. The method will
421
+ # #request elements until it has at least min elements.
422
+ # #returns false if there aren't any, and raises NoPage if page doesn't exist
423
+ # def get_embeddedin(min = nil, eilimit = 500)
424
+ # eicontinue = nil
425
+ # eis = Hash.new
426
+ # count = 0
427
+ # loop {
428
+ # result = @site.query_list_embeddedin(@normtitle, @normtitle, eicontinue, nil, nil, eilimit)
429
+ # eis.deep_merge!(result['query'])
430
+ # if result.key?('query-continue')&& min && count < min
431
+ # count += lllimit
432
+ # eicontinue = result['query-continue']['embeddedin']['eicontinue']
433
+ # else
434
+ # break
435
+ # end
436
+ # }
437
+ # if eis['pages']['page'].key?('missing')
438
+ # raise NoPage.new(), "Page [[#{@title}]] does not exist"
439
+ # elsif eis['embeddedin'].key?('ei')
440
+ # members = Array.new
441
+ # eis['embeddedin']['ei'].each{|el| members.push(Page.new(el['title']))}
442
+ # return members
443
+ # else return false
444
+ # end
445
+ # end
446
+ #
447
+ # #returns the size of the page content in bytes
448
+ # #Raises NoPage if the page doesn't exist
449
+ # def get_size
450
+ # result = @site.query_prop_info(@normtitle)
451
+ # if result['query']['pages']['page'].key?('missing')
452
+ # raise NoPage.new(), "Page [[#{@normtitle}]] does not exist"
453
+ # else
454
+ # return result['query']['pages']['page']['length']
455
+ # end
456
+ # end
446
457
 
447
458
  end
448
459
 
@@ -1,5 +1,4 @@
1
1
  require 'page'
2
- require 'generator'
3
2
 
4
3
  class Page_generator
5
4
  def initialize(site)
@@ -31,102 +30,93 @@ class Page_generator
31
30
  # * One value: withlanglinks, withoutlanglinks, all
32
31
  # * Default: all
33
32
  def all_pages(from = "!", limit = "500", prefix = nil, namespace = nil, filterredir = nil, minsize = nil, maxsize = nil, prtype = nil, prlevel = nil, prfiltercascade = nil, filterlanglinks = nil)
34
- g = Generator.new { |g|
35
- pages = Hash.new
36
- count = 0
37
- finish = false
38
- while !finish
39
- result = @site.query_list_allpages(nil, from, prefix, namespace, filterredir, minsize, maxsize, prtype, prlevel, prfiltercascade, limit, nil, filterlanglinks)
40
- result['query']['allpages']['p'].each {|page|
41
- g.yield Page.new(page['title'], @site)
42
- }
43
- if result.key?('query-continue')
44
- from = result['query-continue']['allpages']['apfrom']
45
- else
46
- finish = true
47
- end
33
+ pages = Hash.new
34
+ count = 0
35
+ finish = false
36
+ while !finish
37
+ result = @site.query_list_allpages(nil, from, prefix, namespace, filterredir, minsize, maxsize, prtype, prlevel, prfiltercascade, limit, nil, filterlanglinks)
38
+ result['query']['allpages']['p'].each {|page|
39
+ yield Page.new(page['title'], @site)
40
+ }
41
+ if result.key?('query-continue')
42
+ from = result['query-continue']['allpages']['apfrom']
43
+ else
44
+ finish = true
48
45
  end
49
- }
46
+ end
50
47
  end
51
48
 
52
49
  def linksearch(euquery, eulimit = 500, eunamespace = 0)
53
- g = Generator.new { |g|
54
- pages = Hash.new
55
- count = 0
56
- finish = false
57
- euoffset = nil
58
- while !finish
59
- result = @site.query_list_exturlusage(nil, nil, euoffset, nil, euquery, eunamespace, eulimit)
60
- result['query']['exturlusage']['eu'].each {|page|
61
- g.yield Page.new(page['title'], @site)
62
- }
63
- if result.key?('query-continue')
64
- euoffset = result['query-continue']['exturlusage']['euoffset']
65
- else
66
- finish = true
67
- end
50
+ pages = Hash.new
51
+ count = 0
52
+ finish = false
53
+ euoffset = nil
54
+ while !finish
55
+ result = @site.query_list_exturlusage(nil, nil, euoffset, nil, euquery, eunamespace, eulimit)
56
+ result['query']['exturlusage']['eu'].each {|page|
57
+ yield Page.new(page['title'], @site)
58
+ }
59
+ if result.key?('query-continue')
60
+ euoffset = result['query-continue']['exturlusage']['euoffset']
61
+ else
62
+ finish = true
68
63
  end
69
- }
64
+ end
70
65
  end
71
66
  def templateusage(eititle, eilimit = 500, einamespace = nil)
72
- g = Generator.new { |g|
73
- pages = Hash.new
74
- finish = false
75
- eioffset = nil
76
- while !finish
77
- result = @site.query_list_embeddedin(nil, eititle, eioffset, einamespace, nil, eilimit)
78
- result['query']['embeddedin']['ei'].each {|page|
79
- g.yield Page.new(page['title'], @site)
80
- }
81
- if result.key?('query-continue')
82
- euoffset = result['query-continue']['embeddedin']['eioffset']
83
- else
84
- finish = true
85
- end
67
+ pages = Hash.new
68
+ finish = false
69
+ eioffset = nil
70
+ while !finish
71
+ result = @site.query_list_embeddedin(nil, eititle, eioffset, einamespace, nil, eilimit)
72
+ result['query']['embeddedin']['ei'].each {|page|
73
+ g.yield Page.new(page['title'], @site)
74
+ }
75
+ if result.key?('query-continue')
76
+ eioffset = result['query-continue']['embeddedin']['eicontinue']
77
+ else
78
+ finish = true
86
79
  end
87
- }
80
+ end
88
81
  end
89
82
  def alllinks(alprefix, allimit = 500, alnamespace = nil)
90
- g = Generator.new { |g|
91
- pages = Hash.new
92
- finish = false
93
- aloffset = nil
94
- while !finish
95
- result = @site.query_list_alllinks(nil, aloffset, nil, alprefix, nil, nil, nil, alnamespace, allimit, nil, nil, true)
96
- result['query']['alllinks']['l'].each {|page|
97
- g.yield Page.new(page['title'], @site)
98
- }
99
- if result.key?('query-continue')
100
- euoffset = result['query-continue']['alllinks']['alcontinue']
101
- else
102
- finish = true
103
- end
83
+ pages = Hash.new
84
+ finish = false
85
+ aloffset = nil
86
+ while !finish
87
+ result = @site.query_list_alllinks(nil, aloffset, nil, alprefix, nil, nil, nil, alnamespace, allimit, nil, nil, true)
88
+ result['query']['alllinks']['l'].each {|page|
89
+ yield Page.new(page['title'], @site)
90
+ }
91
+ if result.key?('query-continue')
92
+ euoffset = result['query-continue']['alllinks']['alcontinue']
93
+ else
94
+ finish = true
104
95
  end
105
- }
96
+ end
106
97
  end
107
98
  def backlinks(bltitle, bllimit = 500, blnamespace = nil, blfilterredir = nil)
108
- g = Generator.new { |g|
109
- pages = Hash.new
110
- finish = false
111
- bloffset = nil
112
- while !finish
113
- result = @site.query_list_backlinks(nil, bltitle, bloffset, blnamespace, blfilterredir, bllimit, true )
114
- result['query']['backlinks']['bl'].each {|page|
115
- if page.key?('redirect')
116
- page['redirlinks']['bl'].each {|page2|
117
- g.yield Page.new(page2['title'], @site)
118
- }
119
- else
120
- g.yield Page.new(page['title'], @site)
121
- end
122
- }
123
- if result.key?('query-continue')
124
- euoffset = result['query-continue']['backlinks']['blcontinue']
99
+ pages = Hash.new
100
+ finish = false
101
+ bloffset = nil
102
+ while !finish
103
+ result = @site.query_list_backlinks(nil, bltitle, bloffset, blnamespace, blfilterredir, bllimit, true )
104
+ result['query']['backlinks']['bl'].each {|page|
105
+ if page.key?('redirect')
106
+ page['redirlinks']['bl'].each {|page2|
107
+ yield Page.new(page2['title'], @site)
108
+ }
125
109
  else
126
- finish = true
110
+ yield Page.new(page['title'], @site)
127
111
  end
112
+ }
113
+ if result.key?('query-continue')
114
+ euoffset = result['query-continue']['backlinks']['blcontinue']
115
+ else
116
+ finish = true
128
117
  end
129
- }
118
+ end
119
+
130
120
  end
131
121
 
132
122
  #TODO
data/lib/rbmediawiki.rb CHANGED
@@ -4,3 +4,4 @@ require 'category'
4
4
  require 'user'
5
5
  require 'page_generator'
6
6
  require 'misc_generator'
7
+ require 'fiber'
data/lib/user.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'deep_merge'
2
-
1
+ #coding: utf-8
3
2
  require 'api'
4
3
  require 'page'
5
4
 
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.1"
4
+ version: "0.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - chabacano
@@ -43,6 +43,8 @@ files:
43
43
  - util/querydesc
44
44
  has_rdoc: true
45
45
  homepage: http://en.wikipedia.org/User:chabacano/rbmediawiki
46
+ licenses: []
47
+
46
48
  post_install_message:
47
49
  rdoc_options: []
48
50
 
@@ -62,10 +64,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
64
  version:
63
65
  requirements: []
64
66
 
65
- rubyforge_project:
66
- rubygems_version: 1.1.1
67
+ rubyforge_project: rbmediawiki
68
+ rubygems_version: 1.3.3
67
69
  signing_key:
68
- specification_version: 2
70
+ specification_version: 3
69
71
  summary: Rbmediawiki is a framework for building bots for Mediawiki using its api.
70
72
  test_files: []
71
73