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 +10 -5
- data/lib/category.rb +0 -2
- data/lib/misc_generator.rb +28 -32
- data/lib/page.rb +248 -237
- data/lib/page_generator.rb +71 -81
- data/lib/rbmediawiki.rb +1 -0
- data/lib/user.rb +1 -2
- metadata +6 -4
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
|
-
|
50
|
-
|
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
|
-
|
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
data/lib/misc_generator.rb
CHANGED
@@ -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 =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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 =
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
213
|
-
#
|
214
|
-
#
|
215
|
-
#request
|
216
|
-
#
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#request
|
243
|
-
#
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
#
|
268
|
-
#
|
269
|
-
#request
|
270
|
-
#
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
#
|
295
|
-
#
|
296
|
-
#request
|
297
|
-
#
|
298
|
-
#
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
#
|
328
|
-
#
|
329
|
-
#request
|
330
|
-
#
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
#
|
355
|
-
#
|
356
|
-
#request
|
357
|
-
#
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
#
|
382
|
-
#
|
383
|
-
#request
|
384
|
-
#
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
#
|
408
|
-
#
|
409
|
-
#
|
410
|
-
#request
|
411
|
-
#
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
#
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
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
|
|
data/lib/page_generator.rb
CHANGED
@@ -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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
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
data/lib/user.rb
CHANGED
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.
|
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.
|
67
|
+
rubyforge_project: rbmediawiki
|
68
|
+
rubygems_version: 1.3.3
|
67
69
|
signing_key:
|
68
|
-
specification_version:
|
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
|
|