rbmediawiki 0.2.5 → 0.2.6
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/rbmediawiki/page.rb +143 -450
- data/lib/rbmediawiki/page_generator.rb +13 -7
- data/lib/rbmediawiki.rb +1 -1
- metadata +1 -1
data/lib/rbmediawiki/page.rb
CHANGED
@@ -1,465 +1,158 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#This class represents a page. It gives methods for dealing with single
|
5
|
-
#pages: obtainig the content, putting it, appending content, deleting, etc.
|
6
|
-
class Page
|
7
|
-
attr_reader :title
|
8
|
-
def initialize(title = nil, site = nil)
|
9
|
-
@site = site ? site : Api.new()
|
10
|
-
@title = title
|
11
|
-
@normtitle = title.gsub(" ","_")
|
12
|
-
end
|
13
|
-
|
14
|
-
#retrieves the content of the page
|
15
|
-
def get()
|
16
|
-
result = @site.query_prop_revisions(@normtitle, 'content')
|
17
|
-
if result.key?('error')
|
18
|
-
raise RbmediawikiError, "#{title}: "+result['error']['code']
|
19
|
-
else
|
20
|
-
return result['query']['pages']['page']['revisions']['rev']
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
#returns false if it is not a redirect, the redirected title if it is
|
25
|
-
def redirect?()
|
26
|
-
txt = this.get
|
27
|
-
if (txt =~ /#REDIRECT\s+\[\[(.*)\]\]/)
|
28
|
-
return $1
|
29
|
-
else
|
30
|
-
return false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
#puts the text of a page.
|
35
|
-
# * text: the new content of the page
|
36
|
-
# * summary: editting summary
|
37
|
-
# * minor: is a minor edit? default->true
|
38
|
-
# * bot: is a bot flagged edit?
|
39
|
-
def put(text, summary = nil, minor = true, bot = true, password = nil)
|
40
|
-
#require login
|
41
|
-
@site.login(password)
|
42
|
-
result = @site.query_prop_info(@normtitle, nil, 'edit')
|
43
|
-
token = result['query']['pages']['page']['edittoken']
|
44
|
-
result = @site.edit(@normtitle, nil, text, token, summary, minor, nil, bot)
|
45
|
-
if result.key?('error')
|
46
|
-
raise RbmediawikiError, "#{title}: "+result['error']['code']
|
47
|
-
else
|
48
|
-
return true
|
49
|
-
end
|
50
|
-
puts "content put"
|
51
|
-
end
|
52
|
-
|
53
|
-
#appends texto to a page
|
54
|
-
#same as #put, but the text is appended and the previous content preserved
|
55
|
-
def append(text, summary = nil, minor = true, bot = true)
|
56
|
-
#require login
|
57
|
-
@site.login
|
58
|
-
puts text
|
59
|
-
result = @site.query_prop_info(@normtitle, nil, 'edit')
|
60
|
-
token = result['query']['pages']['page']['edittoken']
|
61
|
-
result = @site.edit(@normtitle, nil, text, token, summary, minor, nil, bot, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, text)
|
62
|
-
if result.key?('error')
|
63
|
-
raise RbmediawikiError, "#{title}: "+result['error']['code']
|
64
|
-
else
|
65
|
-
return true
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
#prepends text to a page
|
70
|
-
#same as #put, but the text is prepended and the previous content preserved
|
71
|
-
def prepend(text, summary = nil, minor = true, bot = true)
|
72
|
-
#require login
|
73
|
-
@site.login
|
74
|
-
result = @site.query_prop_info(@normtitle, nil, 'edit')
|
75
|
-
token = result['query']['pages']['page']['edittoken']
|
76
|
-
result = @site.edit(@normtitle, nil, text, token, summary, minor, nil, bot, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, text)
|
77
|
-
if result.key?('error')
|
78
|
-
raise RbmediawikiError, "#{title}: "+result['error']['code']
|
79
|
-
else
|
80
|
-
return true
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
#adds a section to a page
|
85
|
-
#same as #append, but is a section what is appended.
|
86
|
-
#title is the title of the new section
|
87
|
-
def addsection(text, title, minor = false, bot = true)
|
88
|
-
#require login
|
89
|
-
@site.login
|
90
|
-
result = @site.query_prop_info(@normtitle, nil, 'edit')
|
91
|
-
token = result['query']['pages']['page']['edittoken']
|
92
|
-
result = @site.edit(@normtitle, section, text, token, title, minor, nil, bot)
|
93
|
-
if result.key?('error')
|
94
|
-
raise RbmediawikiError, "#{title}: "+result['error']['code']
|
95
|
-
else
|
96
|
-
return true
|
97
|
-
end
|
1
|
+
class Page_generator
|
2
|
+
def initialize(site)
|
3
|
+
@site = site
|
98
4
|
end
|
99
5
|
|
100
|
-
#
|
101
|
-
# *
|
102
|
-
# *
|
103
|
-
# *
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
6
|
+
#gets pages alphabetically from a certain start point
|
7
|
+
# * from: starting point (Default starts from the beginning)
|
8
|
+
# * limit: pages to get per query (default: 500)
|
9
|
+
# * prefix: Only list titles that start with this value
|
10
|
+
# * namespace: The namespace to enumerate. By default, the main namespace will be enumerated
|
11
|
+
# * How to filter redirects
|
12
|
+
# * all: List all pages regardless of their redirect flag (default)
|
13
|
+
# * redirects: Only list redirects
|
14
|
+
# * nonredirects: Don't list redirects
|
15
|
+
# * minsize: Only list pages that are at least this many bytes in size
|
16
|
+
# * maxsize: Only list pages that are at most this many bytes in size
|
17
|
+
# * prtype: Only list pages that have been protected from this type of action
|
18
|
+
# * edit: Only list edit-protected pages
|
19
|
+
# * move: Only list move-protected pages
|
20
|
+
# * prleve: Only list pages that have been protected at this level. Cannot be used without prtype
|
21
|
+
# * autoconfirmed: Only autoconfirmed users can edit/move/whatever
|
22
|
+
# * sysop: Only sysops can edit/move/whatever
|
23
|
+
# * Empty: Everyone can edit/move/whatever
|
24
|
+
# * prfiltercascade: Filter protections based on cascadingness (ignored when apprtype isn't set)
|
25
|
+
# * One value: cascading, noncascading, all
|
26
|
+
# * Default: all
|
27
|
+
# *filterlanglinks: Filter based on whether a page has langlinks
|
28
|
+
# * One value: withlanglinks, withoutlanglinks, all
|
29
|
+
# * Default: all
|
30
|
+
def all_pages(from = "!", limit = "500", prefix = nil, namespace = nil, filterredir = nil, minsize = nil, maxsize = nil, prtype = nil, prlevel = nil, prfiltercascade = nil, filterlanglinks = nil)
|
31
|
+
pages = Hash.new
|
32
|
+
count = 0
|
33
|
+
finish = false
|
34
|
+
while !finish
|
35
|
+
result = @site.query_list_allpages(nil, from, prefix, namespace, filterredir, minsize, maxsize, prtype, prlevel, prfiltercascade, limit, nil, filterlanglinks)
|
36
|
+
result['query']['allpages']['p'].each {|page|
|
37
|
+
yield Page.new(page['title'], @site)
|
38
|
+
}
|
39
|
+
if result.key?('query-continue')
|
40
|
+
from = result['query-continue']['allpages']['apfrom']
|
41
|
+
else
|
42
|
+
finish = true
|
43
|
+
end
|
114
44
|
end
|
115
45
|
end
|
116
|
-
|
117
|
-
#protects a page.
|
118
|
-
#reason is the reason for the protection
|
119
|
-
#expiry is a timescamp (default is infinite).
|
120
|
-
#protections is the action and group that can perform that action, separated
|
121
|
-
#by pipes. Exapmple "edit=sysop|move=autoconfirmed".Default is edit=sysop|move=sysop
|
122
|
-
def protect(reason = nil, expiry = 'infinite', protections = 'edit=sysop|move=sysop')
|
123
|
-
#require login
|
124
|
-
@site.login
|
125
|
-
result = @site.query_prop_info(@normtitle, nil, 'protect')
|
126
|
-
token = result['query']['pages']['page']['protecttoken']
|
127
|
-
result = @site.protect(@normtitle, token, protections, expiry, reason)
|
128
|
-
if result.key?('error')
|
129
|
-
raise RbmediawikiError, "#{title}: "+result['error']['code']
|
130
|
-
else
|
131
|
-
return true
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
#semipotects a page.
|
136
|
-
#is the same as protect, but default for protections is "edit=autoconfirmed|move=autoconfirmed"
|
137
|
-
def semiprotect(reason = nil, expiry = 'infinite')
|
138
|
-
protect(reason, expiry, 'edit=autoconfirmed|move=autoconfirmed')
|
139
|
-
#possible errors: user doesn't have privileges
|
140
|
-
end
|
141
46
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
47
|
+
def linksearch(euquery, eulimit = 500, eunamespace = 0)
|
48
|
+
pages = Hash.new
|
49
|
+
count = 0
|
50
|
+
finish = false
|
51
|
+
euoffset = nil
|
52
|
+
while !finish
|
53
|
+
result = @site.query_list_exturlusage(nil, nil, euoffset, nil, euquery, eunamespace, eulimit)
|
54
|
+
result['query']['exturlusage']['eu'].each {|page|
|
55
|
+
yield Page.new(page['title'], @site)
|
56
|
+
}
|
57
|
+
if result.key?('query-continue')
|
58
|
+
euoffset = result['query-continue']['exturlusage']['euoffset']
|
59
|
+
else
|
60
|
+
finish = true
|
61
|
+
end
|
154
62
|
end
|
155
63
|
end
|
156
64
|
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
65
|
+
#Returns pages where eititle is transcluded in.
|
66
|
+
#eilimit is the max results for query (default: 500)
|
67
|
+
#einamespace is the namespace to work in
|
68
|
+
def templateusage(eititle, eilimit = 500, einamespace = nil)
|
69
|
+
pages = Hash.new
|
70
|
+
finish = false
|
71
|
+
eioffset = nil
|
72
|
+
while !finish
|
73
|
+
result = @site.query_list_embeddedin(nil, eititle, eioffset, einamespace, nil, eilimit)
|
74
|
+
result['query']['embeddedin']['ei'].each {|page|
|
75
|
+
yield Page.new(page['title'], @site)
|
76
|
+
}
|
77
|
+
if result.key?('query-continue')
|
78
|
+
eioffset = result['query-continue']['embeddedin']['eicontinue']
|
79
|
+
else
|
80
|
+
finish = true
|
81
|
+
end
|
166
82
|
end
|
167
|
-
if !result.has_key?('deletedRevs')
|
168
|
-
return false
|
169
|
-
end
|
170
|
-
token = result['query']['deletedrevs']['page']['token']
|
171
|
-
result = @site.undelete(@normtitle, token, reason)
|
172
|
-
return true
|
173
83
|
end
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
#but the token is the same. We only want the token
|
190
|
-
if result['query']['pages']['page']['revisions']['rev'].is_a? Array
|
191
|
-
token = result['query']['pages']['page']['revisions']['rev'][0]['rollbacktoken']
|
192
|
-
else
|
193
|
-
token = result['query']['pages']['page']['revisions']['rev']['rollbacktoken']
|
194
|
-
end
|
195
|
-
result = @site.rollback(@normtitle, user, token, summary, markbot)
|
196
|
-
if result.key?('error')
|
197
|
-
raise RbmediawikiError, "#{@title}: "+result['error']['code']
|
198
|
-
else
|
199
|
-
return true
|
84
|
+
def alllinks(alprefix, allimit = 500, alnamespace = nil)
|
85
|
+
pages = Hash.new
|
86
|
+
finish = false
|
87
|
+
aloffset = nil
|
88
|
+
while !finish
|
89
|
+
result = @site.query_list_alllinks(nil, aloffset, nil, alprefix, nil, nil, nil, alnamespace, allimit, nil, nil, true)
|
90
|
+
puts result
|
91
|
+
result['query']['alllinks']['l'].each {|page|
|
92
|
+
yield Page.new(page['title'], @site)
|
93
|
+
}
|
94
|
+
if result.key?('query-continue')
|
95
|
+
euoffset = result['query-continue']['alllinks']['alcontinue']
|
96
|
+
else
|
97
|
+
finish = true
|
98
|
+
end
|
200
99
|
end
|
201
100
|
end
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
101
|
+
def backlinks(bltitle, bllimit = 500, blnamespace = nil, blfilterredir = nil)
|
102
|
+
pages = Hash.new
|
103
|
+
finish = false
|
104
|
+
bloffset = nil
|
105
|
+
while !finish
|
106
|
+
result = @site.query_list_backlinks(nil, bltitle, bloffset, blnamespace, blfilterredir, bllimit, true )
|
107
|
+
puts result
|
108
|
+
result['query']['backlinks']['bl'].each {|page|
|
109
|
+
#TODO:code for dealing with redirects
|
110
|
+
# if page.key?('redirlinks')
|
111
|
+
# #checking probable double redirect
|
112
|
+
# if page['redirlinks'].key?('bl')
|
113
|
+
# puts page
|
114
|
+
# page['redirlinks']['bl'].each {|page2|
|
115
|
+
# puts page2
|
116
|
+
# yield Page.new(page2['title'], @site)
|
117
|
+
# }
|
118
|
+
# end
|
119
|
+
# else
|
120
|
+
puts page
|
121
|
+
yield Page.new(page['title'], @site)
|
122
|
+
# end
|
123
|
+
}
|
124
|
+
if result.key?('query-continue')
|
125
|
+
bloffset = result['query-continue']['backlinks']['blcontinue']
|
126
|
+
else
|
127
|
+
finish = true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
217
131
|
end
|
218
132
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
244
|
-
# else return false
|
245
|
-
# end
|
246
|
-
# end
|
247
|
-
#
|
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
|
-
#
|
275
|
-
# #gets templates used in a page
|
276
|
-
# #min is the minimum number of elements to return, tllimit is the number of
|
277
|
-
# #elements to request from the API in each iteration. The method will
|
278
|
-
# #request elements until it has at least min elements.
|
279
|
-
# #returns false if there aren't any, and raises NoPage if page doesn't exist
|
280
|
-
# def get_templates(min = nil, tllimit = 500)
|
281
|
-
# tlcontinue = nil
|
282
|
-
# tls = Hash.new
|
283
|
-
# count = 0
|
284
|
-
# loop {
|
285
|
-
# result = @site.query_prop_templates(@normtitle, nil, tllimit, tlcontinue)
|
286
|
-
# tls.deep_merge!(result['query'])
|
287
|
-
# if result.key?('query-continue')&& min && count < min
|
288
|
-
# count += lllimit
|
289
|
-
# tlcontinue = result['query-continue']['templates']['tlcontinue']
|
290
|
-
# else
|
291
|
-
# break
|
292
|
-
# end
|
293
|
-
# }
|
294
|
-
# if tls['pages']['page'].key?('missing')
|
295
|
-
# raise NoPage.new(), "Page [[#{@title}]] does not exist"
|
296
|
-
# elsif tls['pages']['page'].key?('templates')
|
297
|
-
# return tls['pages']['page']['templates']['tl']
|
298
|
-
# else return false
|
299
|
-
# end
|
300
|
-
# end
|
301
|
-
#
|
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
|
334
|
-
#
|
335
|
-
# #gets external links used in a page
|
336
|
-
# #min is the minimum number of elements to return, ellimit is the number of
|
337
|
-
# #elements to request from the API in each iteration. The method will
|
338
|
-
# #request elements until it has at least min elements.
|
339
|
-
# #returns false if there aren't any, and raises NoPage if page doesn't exist
|
340
|
-
# def get_external_links(min = nil, ellimit = 500)
|
341
|
-
# eloffset = nil
|
342
|
-
# els = Hash.new
|
343
|
-
# count = 0
|
344
|
-
# loop {
|
345
|
-
# result = @site.query_prop_extlinks(@normtitle, ellimit, eloffset)
|
346
|
-
# els.deep_merge!(result['query'])
|
347
|
-
# if result.key?('query-continue')&& min && count < min
|
348
|
-
# count += lllimit
|
349
|
-
# eloffset = result['query-continue']['extlinks']['elcontinue']
|
350
|
-
# else
|
351
|
-
# break
|
352
|
-
# end
|
353
|
-
# }
|
354
|
-
# if els['pages']['page'].key?('missing')
|
355
|
-
# raise NoPage.new(), "Page [[#{@title}]] does not exist"
|
356
|
-
# elsif els['pages']['page'].key?('extlinks')
|
357
|
-
# return els['pages']['page']['extlinks']['el']
|
358
|
-
# else return false
|
359
|
-
# end
|
360
|
-
# end
|
361
|
-
#
|
362
|
-
# #gets backlinks (what links here) used in a page
|
363
|
-
# #min is the minimum number of elements to return, bllimit is the number of
|
364
|
-
# #elements to request from the API in each iteration. The method will
|
365
|
-
# #request elements until it has at least min elements.
|
366
|
-
# #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
|
-
# bls.deep_merge!(result['query'])
|
374
|
-
# if result.key?('query-continue')&& min && count < min
|
375
|
-
# count += lllimit
|
376
|
-
# blcontinue = result['query-continue']['backlinks']['blcontinue']
|
377
|
-
# else
|
378
|
-
# break
|
379
|
-
# end
|
380
|
-
# }
|
381
|
-
# if bls['pages']['page'].key?('missing')
|
382
|
-
# raise NoPage.new(), "Page [[#{@title}]] does not exist"
|
383
|
-
# elsif bls['backlinks'].key?('bl')
|
384
|
-
# return bls['backlinks']['bl']
|
385
|
-
# else return false
|
386
|
-
# end
|
387
|
-
# end
|
388
|
-
#
|
389
|
-
# #gets deleted revisions of a page
|
390
|
-
# #min is the minimum number of elements to return, drlimit is the number of
|
391
|
-
# #elements to request from the API in each iteration. The method will
|
392
|
-
# #request elements until it has at least min elements.
|
393
|
-
# #returns false if there aren't any
|
394
|
-
# def get_deletedrevs(min = nil, drlimit = 500)
|
395
|
-
# @site.login
|
396
|
-
# drcontinue = nil
|
397
|
-
# drs = Hash.new
|
398
|
-
# count = 0
|
399
|
-
# loop {
|
400
|
-
# result = @site.query_list_deletedrevs(@normtitle, nil, nil, nil, nil, nil, nil, drcontinue, nil, nil, nil, nil, drlimit)
|
401
|
-
# drs.deep_merge!(result['query'])
|
402
|
-
# if result.key?('query-continue')&& min && count < min
|
403
|
-
# count += lllimit
|
404
|
-
# drcontinue = result['query-continue']['deletedrevs']['drstart']
|
405
|
-
# else
|
406
|
-
# break
|
407
|
-
# end
|
408
|
-
# }
|
409
|
-
# if drs['deletedrevs'].key?('page')
|
410
|
-
# return drs['deletedrevs']['page']['revisions']['rev']
|
411
|
-
# else return false
|
412
|
-
# end
|
413
|
-
# end
|
414
|
-
#
|
415
|
-
# #gets pages in which this page is embedded (or transcluded). Returns a list
|
416
|
-
# #of Page elements
|
417
|
-
# #min is the minimum number of elements to return, eilimit is the number of
|
418
|
-
# #elements to request from the API in each iteration. The method will
|
419
|
-
# #request elements until it has at least min elements.
|
420
|
-
# #returns false if there aren't any, and raises NoPage if page doesn't exist
|
421
|
-
# def get_embeddedin(min = nil, eilimit = 500)
|
422
|
-
# eicontinue = nil
|
423
|
-
# eis = Hash.new
|
424
|
-
# count = 0
|
425
|
-
# loop {
|
426
|
-
# result = @site.query_list_embeddedin(@normtitle, @normtitle, eicontinue, nil, nil, eilimit)
|
427
|
-
# eis.deep_merge!(result['query'])
|
428
|
-
# if result.key?('query-continue')&& min && count < min
|
429
|
-
# count += lllimit
|
430
|
-
# eicontinue = result['query-continue']['embeddedin']['eicontinue']
|
431
|
-
# else
|
432
|
-
# break
|
433
|
-
# end
|
434
|
-
# }
|
435
|
-
# if eis['pages']['page'].key?('missing')
|
436
|
-
# raise NoPage.new(), "Page [[#{@title}]] does not exist"
|
437
|
-
# elsif eis['embeddedin'].key?('ei')
|
438
|
-
# members = Array.new
|
439
|
-
# eis['embeddedin']['ei'].each{|el| members.push(Page.new(el['title']))}
|
440
|
-
# return members
|
441
|
-
# else return false
|
442
|
-
# end
|
443
|
-
# end
|
444
|
-
#
|
445
|
-
# #returns the size of the page content in bytes
|
446
|
-
# #Raises NoPage if the page doesn't exist
|
447
|
-
# def get_size
|
448
|
-
# result = @site.query_prop_info(@normtitle)
|
449
|
-
# if result['query']['pages']['page'].key?('missing')
|
450
|
-
# raise NoPage.new(), "Page [[#{@normtitle}]] does not exist"
|
451
|
-
# else
|
452
|
-
# return result['query']['pages']['page']['length']
|
453
|
-
# end
|
454
|
-
# end
|
455
|
-
|
456
|
-
end
|
457
|
-
|
458
|
-
class NoPage < RuntimeError
|
459
|
-
end
|
460
|
-
|
461
|
-
class PageExists < RuntimeError
|
462
|
-
end
|
463
|
-
|
464
|
-
class RbmediawikiError < RuntimeError
|
133
|
+
#TODO
|
134
|
+
#opensearch
|
135
|
+
#prop links
|
136
|
+
#prop langlinks?
|
137
|
+
#prop images
|
138
|
+
#prop templates
|
139
|
+
#prop categories
|
140
|
+
#prop extlinks
|
141
|
+
#list allimages
|
142
|
+
#list allcategories
|
143
|
+
#list allusers
|
144
|
+
#list blocks
|
145
|
+
#list categorymembers
|
146
|
+
#list deletedrevs
|
147
|
+
#list imageusage
|
148
|
+
#list logevents
|
149
|
+
#list recentchanges
|
150
|
+
#list search
|
151
|
+
#list usercontribs
|
152
|
+
#list watchlist
|
153
|
+
#list exturlusage
|
154
|
+
#list users
|
155
|
+
#list random
|
156
|
+
#list protectedtitles
|
157
|
+
#list globalblocks
|
465
158
|
end
|
@@ -104,16 +104,22 @@ class Page_generator
|
|
104
104
|
while !finish
|
105
105
|
result = @site.query_list_backlinks(nil, bltitle, bloffset, blnamespace, blfilterredir, bllimit, true )
|
106
106
|
result['query']['backlinks']['bl'].each {|page|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
#TODO:code for dealing with redirects
|
108
|
+
# if page.key?('redirlinks')
|
109
|
+
# #checking probable double redirect
|
110
|
+
# if page['redirlinks'].key?('bl')
|
111
|
+
# puts page
|
112
|
+
# page['redirlinks']['bl'].each {|page2|
|
113
|
+
# puts page2
|
114
|
+
# yield Page.new(page2['title'], @site)
|
115
|
+
# }
|
116
|
+
# end
|
117
|
+
# else
|
112
118
|
yield Page.new(page['title'], @site)
|
113
|
-
|
119
|
+
# end
|
114
120
|
}
|
115
121
|
if result.key?('query-continue')
|
116
|
-
|
122
|
+
bloffset = result['query-continue']['backlinks']['blcontinue']
|
117
123
|
else
|
118
124
|
finish = true
|
119
125
|
end
|
data/lib/rbmediawiki.rb
CHANGED