rbmediawiki 0.2 → 0.2.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.
@@ -1,147 +0,0 @@
1
- require 'page'
2
-
3
- class Page_generator
4
- def initialize(site)
5
- @site = site
6
- end
7
-
8
- #gets pages alphabetically from a certain start point
9
- # * from: starting point (Default starts from the beginning)
10
- # * limit: pages to get per query (default: 500)
11
- # * prefix: Only list titles that start with this value
12
- # * namespace: The namespace to enumerate. By default, the main namespace will be enumerated
13
- # * How to filter redirects
14
- # * all: List all pages regardless of their redirect flag (default)
15
- # * redirects: Only list redirects
16
- # * nonredirects: Don't list redirects
17
- # * minsize: Only list pages that are at least this many bytes in size
18
- # * maxsize: Only list pages that are at most this many bytes in size
19
- # * prtype: Only list pages that have been protected from this type of action
20
- # * edit: Only list edit-protected pages
21
- # * move: Only list move-protected pages
22
- # * prleve: Only list pages that have been protected at this level. Cannot be used without prtype
23
- # * autoconfirmed: Only autoconfirmed users can edit/move/whatever
24
- # * sysop: Only sysops can edit/move/whatever
25
- # * Empty: Everyone can edit/move/whatever
26
- # * prfiltercascade: Filter protections based on cascadingness (ignored when apprtype isn't set)
27
- # * One value: cascading, noncascading, all
28
- # * Default: all
29
- # *filterlanglinks: Filter based on whether a page has langlinks
30
- # * One value: withlanglinks, withoutlanglinks, all
31
- # * Default: all
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)
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
45
- end
46
- end
47
- end
48
-
49
- def linksearch(euquery, eulimit = 500, eunamespace = 0)
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
63
- end
64
- end
65
- end
66
- def templateusage(eititle, eilimit = 500, einamespace = nil)
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
79
- end
80
- end
81
- end
82
- def alllinks(alprefix, allimit = 500, alnamespace = nil)
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
95
- end
96
- end
97
- end
98
- def backlinks(bltitle, bllimit = 500, blnamespace = nil, blfilterredir = nil)
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
- }
109
- else
110
- yield Page.new(page['title'], @site)
111
- end
112
- }
113
- if result.key?('query-continue')
114
- euoffset = result['query-continue']['backlinks']['blcontinue']
115
- else
116
- finish = true
117
- end
118
- end
119
-
120
- end
121
-
122
- #TODO
123
- #opensearch
124
- #prop links
125
- #prop langlinks?
126
- #prop images
127
- #prop templates
128
- #prop categories
129
- #prop extlinks
130
- #list allimages
131
- #list allcategories
132
- #list allusers
133
- #list blocks
134
- #list categorymembers
135
- #list deletedrevs
136
- #list imageusage
137
- #list logevents
138
- #list recentchanges
139
- #list search
140
- #list usercontribs
141
- #list watchlist
142
- #list exturlusage
143
- #list users
144
- #list random
145
- #list protectedtitles
146
- #list globalblocks
147
- end
data/lib/user.rb DELETED
@@ -1,113 +0,0 @@
1
- #coding: utf-8
2
- require 'api'
3
- require 'page'
4
-
5
- class User
6
- attr_reader :name
7
- def initialize(name = nil, site = nil)
8
- @username = name.gsub(" ","_")
9
- @site = site
10
- end
11
-
12
- #blocks the user with the given reason
13
- #the params are the usual block options
14
- def block(expiry, reason, anononly = true, nocreate = true, autoblock = true, noemail = false, allowusertalk = true, reblock = false)
15
- #require login
16
- @site.login
17
- result = @site.query_prop_info(@username, nil, 'block')
18
- token = result['query']['pages']['page']['blocktoken']
19
- result = @site.block(@username, token, nil, expiry, reason, anononly, nocreate, autoblock, noemail, nil, allowusertalk, reblock)
20
- if result.key?('error')
21
- raise RbykimediaError, "#{@username}: "+result['error']['code']
22
- else
23
- return true
24
- end
25
- end
26
-
27
- #unblocks the user
28
- def unblock(reason)
29
- #require login
30
- @site.login
31
- result = @site.query_prop_info(@username, nil, 'unblock')
32
- token = result['query']['pages']['page']['unblocktoken']
33
- result = @site.unblock(nil, @username, token, nil, reason)
34
- if result.key?('error')
35
- raise RbykimediaError, "#{@username}: "+result['error']['code']
36
- else
37
- return true
38
- end
39
- end
40
-
41
- #write a message in the user's talk page
42
- def write_msg(msg, summary = nil)
43
- page = Page.new("User talk:"+@username, @site)
44
- return page.append(msg, summary, false)
45
- end
46
-
47
- #write an email to the user
48
- def write_email(subject, text, ccme = nil)
49
- #require login
50
- @site.login
51
- result = @site.query_prop_info(@username, nil, 'email')
52
- puts result
53
- token = result['query']['pages']['page']['emailtoken']
54
- result = @site.emailuser(@username, subject, text, token, ccme)
55
- if result.key?('error')
56
- raise RbykimediaError, "#{@username}: "+result['error']['code']
57
- else
58
- return true
59
- end
60
- end
61
-
62
- #info about the user
63
- def info
64
- result = @site.query_list_users(nil, "blockinfo|groups|editcount|registration|emailable", @username)
65
- if result.key?('error')
66
- raise RbykimediaError, "#{@username}: "+result['error']['code']
67
- else
68
- return result
69
- end
70
- end
71
-
72
- #get user contributions
73
- #returns false if there aren't any
74
- def get_usercontribs(uclimit = 500, ucstart = nil, ucnamespace = nil)
75
- uccontinue = nil
76
- ucs = Hash.new
77
- puts ucstart
78
- loop {
79
- result = @site.query_list_usercontribs(nil, uclimit, ucstart, nil, uccontinue, @username, nil, "newer", ucnamespace)
80
- ucs.deep_merge!(result['query'])
81
- if result.key?('query-continue')
82
- ucstart = result['query-continue']['usercontribs']['ucstart']
83
- else
84
- break
85
- end
86
- }
87
- if ucs['usercontribs'].key?('item')
88
- return ucs['usercontribs']['item']
89
- else
90
- return false
91
- end
92
- end
93
-
94
- #rollbacks (reverts) all edits by the user since a given time.
95
- #"since" is a timestamp. Default will rollback everything.
96
- #"namespace", if set, restricts the rollback to the given namespace
97
- def rollback(since = nil, namespace = nil)
98
- contribs = get_usercontribs(nil, since, nil)
99
- array_c = Array.new
100
- puts array_c
101
- contribs.each{|c| array_c.push(c['title'])}
102
- array_c.uniq!
103
- puts array_c
104
- array_c.each{|p|
105
- page = Page.new(p, @site)
106
- begin
107
- page.rollback(@username, "desde aquí", false)
108
- rescue RbykimediaError => error
109
- puts error
110
- end
111
- }
112
- end
113
- end
data/util/desc DELETED
@@ -1,308 +0,0 @@
1
- * action=expandtemplates *
2
- This module expand all templates in wikitext
3
-
4
- This module requires read rights.
5
- Parameters:
6
- title - Title of page
7
- Default: API
8
- text - Wikitext to convert
9
- generatexml - Generate XML parse tree
10
- Example:
11
- api.php?action=expandtemplates&text={{Project:Sandbox}}
12
-
13
- * action=parse *
14
- This module parses wikitext and returns parser output
15
-
16
- This module requires read rights.
17
- Parameters:
18
- title - Title of page the text belongs to
19
- Default: API
20
- text - Wikitext to parse
21
- page - Parse the content of this page. Cannot be used together with text and title
22
- redirects - If the page parameter is set to a redirect, resolve it
23
- oldid - Parse the content of this revision. Overrides page
24
- prop - Which pieces of information to get.
25
- NOTE: Section tree is only generated if there are more than 4 sections, or if the __TOC__ keyword is present
26
- Values (separate with '|'): text, langlinks, categories, links, templates, images, externallinks, sections, revid, displaytitle
27
- Default: text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle
28
- pst - Do a pre-save transform on the input before parsing it.
29
- Ignored if page or oldid is used.
30
- onlypst - Do a PST on the input, but don't parse it.
31
- Returns PSTed wikitext. Ignored if page or oldid is used.
32
- Example:
33
- api.php?action=parse&text={{Project:Sandbox}}
34
-
35
- * action=feedwatchlist *
36
- This module returns a watchlist feed
37
-
38
- This module requires read rights.
39
- Parameters:
40
- feedformat - The format of the feed
41
- One value: rss, atom
42
- Default: rss
43
- hours - List pages modified within this many hours from now
44
- The value must be between 1 and 72
45
- Default: 24
46
- allrev - Include multiple revisions of the same page within given timeframe.
47
- Example:
48
- api.php?action=feedwatchlist
49
-
50
- * action=help *
51
- Display this help screen.
52
-
53
- * action=paraminfo *
54
- Obtain information about certain API parameters
55
- Parameters:
56
- modules - List of module names (value of the action= parameter)
57
- querymodules - List of query module names (value of prop=, meta= or list= parameter)
58
- mainmodule - Get information about the main (top-level) module as well
59
- pagesetmodule - Get information about the pageset module (providing titles= and friends) as well
60
- Example:
61
- api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo
62
-
63
- * action=purge *
64
- Purge the cache for the given titles.
65
-
66
- This module requires read rights.
67
- This module requires write rights.
68
- Parameters:
69
- titles - A list of titles
70
- Example:
71
- api.php?action=purge&titles=Main_Page|API
72
-
73
- * action=rollback *
74
- Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,
75
- they will all be rolled back.
76
-
77
- This module requires read rights.
78
- This module requires write rights.
79
- This module only accepts POST requests.
80
- Parameters:
81
- title - Title of the page you want to rollback.
82
- user - Name of the user whose edits are to be rolled back. If set incorrectly, you'll get a badtoken error.
83
- token - A rollback token previously retrieved through prop=revisions
84
- summary - Custom edit summary. If not set, default summary will be used.
85
- markbot - Mark the reverted edits and the revert as bot edits
86
- Examples:
87
- api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC
88
- api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1
89
-
90
- * action=delete *
91
- Delete a page.
92
-
93
- This module requires read rights.
94
- This module requires write rights.
95
- This module only accepts POST requests.
96
- Parameters:
97
- title - Title of the page you want to delete. Cannot be used together with pageid
98
- pageid - Page ID of the page you want to delete. Cannot be used together with title
99
- token - A delete token previously retrieved through prop=info
100
- reason - Reason for the deletion. If not set, an automatically generated reason will be used.
101
- watch - Add the page to your watchlist
102
- unwatch - Remove the page from your watchlist
103
- oldimage - The name of the old image to delete as provided by iiprop=archivename
104
- Examples:
105
- api.php?action=delete&title=Main%20Page&token=123ABC
106
- api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move
107
-
108
- * action=undelete *
109
- Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be
110
- retrieved through list=deletedrevs
111
-
112
- This module requires read rights.
113
- This module requires write rights.
114
- This module only accepts POST requests.
115
- Parameters:
116
- title - Title of the page you want to restore.
117
- token - An undelete token previously retrieved through list=deletedrevs
118
- reason - Reason for restoring (optional)
119
- Default:
120
- timestamps - Timestamps of the revisions to restore. If not set, all revisions will be restored.
121
- Examples:
122
- api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page
123
- api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856
124
-
125
- * action=protect *
126
- Change the protection level of a page.
127
-
128
- This module requires read rights.
129
- This module requires write rights.
130
- This module only accepts POST requests.
131
- Parameters:
132
- title - Title of the page you want to (un)protect.
133
- token - A protect token previously retrieved through prop=info
134
- protections - Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)
135
- expiry - Expiry timestamps. If only one timestamp is set, it'll be used for all protections.
136
- Use 'infinite', 'indefinite' or 'never', for a neverexpiring protection.
137
- Default: infinite
138
- reason - Reason for (un)protecting (optional)
139
- Default:
140
- cascade - Enable cascading protection (i.e. protect pages included in this page)
141
- Ignored if not all protection levels are 'sysop' or 'protect'
142
- watch - If set, add the page being (un)protected to your watchlist
143
- Examples:
144
- api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000|never
145
- api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions
146
-
147
- * action=block *
148
- Block a user.
149
-
150
- This module requires read rights.
151
- This module requires write rights.
152
- This module only accepts POST requests.
153
- Parameters:
154
- user - Username, IP address or IP range you want to block
155
- token - A block token previously obtained through the gettoken parameter or prop=info
156
- gettoken - If set, a block token will be returned, and no other action will be taken
157
- expiry - Relative expiry time, e.g. '5 months' or '2 weeks'. If set to 'infinite', 'indefinite' or 'never', the block will never expire.
158
- Default: never
159
- reason - Reason for block (optional)
160
- anononly - Block anonymous users only (i.e. disable anonymous edits for this IP)
161
- nocreate - Prevent account creation
162
- autoblock - Automatically block the last used IP address, and any subsequent IP addresses they try to login from
163
- noemail - Prevent user from sending e-mail through the wiki. (Requires the "blockemail" right.)
164
- hidename - Hide the username from the block log. (Requires the "hideuser" right.)
165
- allowusertalk - Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)
166
- reblock - If the user is already blocked, overwrite the existing block
167
- Examples:
168
- api.php?action=block&user=123.5.5.12&expiry=3%20days&reason=First%20strike
169
- api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate&autoblock&noemail
170
-
171
- * action=unblock *
172
- Unblock a user.
173
-
174
- This module requires read rights.
175
- This module requires write rights.
176
- This module only accepts POST requests.
177
- Parameters:
178
- id - ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user
179
- user - Username, IP address or IP range you want to unblock. Cannot be used together with id
180
- token - An unblock token previously obtained through the gettoken parameter or prop=info
181
- gettoken - If set, an unblock token will be returned, and no other action will be taken
182
- reason - Reason for unblock (optional)
183
- Examples:
184
- api.php?action=unblock&id=105
185
- api.php?action=unblock&user=Bob&reason=Sorry%20Bob
186
-
187
- * action=move *
188
- Move a page.
189
-
190
- This module requires read rights.
191
- This module requires write rights.
192
- This module only accepts POST requests.
193
- Parameters:
194
- from - Title of the page you want to move. Cannot be used together with fromid.
195
- fromid - Page ID of the page you want to move. Cannot be used together with from.
196
- to - Title you want to rename the page to.
197
- token - A move token previously retrieved through prop=info
198
- reason - Reason for the move (optional).
199
- movetalk - Move the talk page, if it exists.
200
- movesubpages - Move subpages, if applicable
201
- noredirect - Don't create a redirect
202
- watch - Add the page and the redirect to your watchlist
203
- unwatch - Remove the page and the redirect from your watchlist
204
- Example:
205
- api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect
206
-
207
- * action=edit *
208
- Create and edit pages.
209
-
210
- This module requires read rights.
211
- This module requires write rights.
212
- This module only accepts POST requests.
213
- Parameters:
214
- title - Page title
215
- section - Section number. 0 for the top section, 'new' for a new section
216
- text - Page content
217
- token - Edit token. You can get one of these through prop=info
218
- summary - Edit summary. Also section title when section=new
219
- minor - Minor edit
220
- notminor - Non-minor edit
221
- bot - Mark this edit as bot
222
- basetimestamp - Timestamp of the base revision (gotten through prop=revisions&rvprop=timestamp).
223
- Used to detect edit conflicts; leave unset to ignore conflicts.
224
- starttimestamp - Timestamp when you obtained the edit token.
225
- Used to detect edit conflicts; leave unset to ignore conflicts.
226
- recreate - Override any errors about the article having been deleted in the meantime
227
- createonly - Don't edit the page if it exists already
228
- nocreate - Throw an error if the page doesn't exist
229
- captchaword - Answer to the CAPTCHA
230
- captchaid - CAPTCHA ID from previous request
231
- watch - Add the page to your watchlist
232
- unwatch - Remove the page from your watchlist
233
- md5 - The MD5 hash of the text parameter, or the prependtext and appendtext parameters concatenated.
234
- If set, the edit won't be done unless the hash is correct
235
- prependtext - Add this text to the beginning of the page. Overrides text.
236
- Don't use together with section: that won't do what you expect.
237
- appendtext - Add this text to the end of the page. Overrides text
238
- undo - Undo this revision. Overrides text, prependtext and appendtext
239
- undoafter - Undo all revisions from undo to this one. If not set, just undo one revision
240
- Examples:
241
- Edit a page (anonymous user):
242
- api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\
243
- Prepend __NOTOC__ to a page (anonymous user):
244
- api.php?action=edit&title=Test&summary=NOTOC&minor&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\
245
- Undo r13579 through r13585 with autosummary(anonymous user):
246
- api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\
247
-
248
- * action=emailuser *
249
- Email a user.
250
-
251
- This module requires read rights.
252
- This module requires write rights.
253
- This module only accepts POST requests.
254
- Parameters:
255
- target - User to send email to
256
- subject - Subject header
257
- text - Mail body
258
- token - A token previously acquired via prop=info
259
- ccme - Send a copy of this mail to me
260
- Example:
261
- api.php?action=emailuser&target=WikiSysop&text=Content
262
-
263
- * action=watch *
264
- Add or remove a page from/to the current user's watchlist
265
-
266
- This module requires read rights.
267
- This module requires write rights.
268
- Parameters:
269
- title - The page to (un)watch
270
- unwatch - If set the page will be unwatched rather than watched
271
- Examples:
272
- api.php?action=watch&title=Main_Page
273
- api.php?action=watch&title=Main_Page&unwatch
274
-
275
- * action=patrol *
276
- Patrol a page or revision.
277
-
278
- This module requires read rights.
279
- This module requires write rights.
280
- Parameters:
281
- token - Patrol token obtained from list=recentchanges
282
- rcid - Recentchanges ID to patrol
283
- Example:
284
- api.php?action=patrol&token=123abc&rcid=230672766
285
-
286
- * action=import *
287
- Import a page from another wiki, or an XML file
288
-
289
- This module requires read rights.
290
- This module requires write rights.
291
- This module only accepts POST requests.
292
- Parameters:
293
- token - Import token obtained through prop=info
294
- summary - Import summary
295
- xml - Uploaded XML file
296
- interwikisource - For interwiki imports: wiki to import from
297
- One value:
298
- interwikipage - For interwiki imports: page to import
299
- fullhistory - For interwiki imports: import the full history, not just the current version
300
- templates - For interwiki imports: import all included templates as well
301
- namespace - For interwiki imports: import to this namespace
302
- One value: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101
303
- Examples:
304
- Import [[meta:Help:Parserfunctions]] to namespace 100 with full history:
305
- api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&namespace=100&fullhistory&token=123ABC
306
-
307
-
308
-
data/util/genall.sh DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/sh
2
-
3
- ruby genqueryymlfromdesc.rb > queries.yml
4
- ruby genotherymlfromdesc.rb > other.yml
5
- ruby genquerycodefromyml.rb > queries.rb
6
- ruby genothercodefromyml.rb > other.rb
@@ -1,27 +0,0 @@
1
- #This script generates code from a yml description of the api (requests *other* than action=query, that ahs its own generator). The yml description can be obtained from the mediawikidocumentation using genotherymlfromdesc
2
- require 'yaml'
3
-
4
- Apiconf = YAML::load(File.open("other.yml"))
5
-
6
- str =""
7
- Apiconf.each {|root|
8
- root.each {|method|
9
- if Apiconf[method]
10
- str += "def #{method}("
11
- Apiconf[method].each {|param|
12
- str += "#{param} = nil, "
13
- }
14
- str = str+ "post_me = nil)\n\n"
15
- Apiconf[method].each {|param|
16
- str += " post_me = add_post('#{param}', #{param}, post_me)\n"
17
- }
18
- str += " post_me = add_post('action', '#{method}', post_me)\n"
19
- str += " post_me = format(post_me, 'xml')\n"
20
- str += " result = make_request(post_me)\n"
21
- str += " return result\n"
22
- str += "end\n\n"
23
- end
24
- }
25
- }
26
-
27
- puts str
@@ -1,23 +0,0 @@
1
- #this script generates an yml from the description of request to the api other than action=query. the description can be obtained at http://es.wikipedia.org/w/api.php
2
-
3
- file = File.new("desc", "r")
4
-
5
- str = ""
6
- parameters = false
7
- file.each {|line|
8
- case line
9
- when /^\* (.*)=(.*) \*/
10
- str += "#{$2}:\n"
11
- when /^Parameters.*/
12
- parameters = true
13
- when /^Example.*/
14
- parameters = false
15
- when /^ (\w*)\s*- (.*)/
16
- if parameters
17
- str += " - #{$1}\n"
18
- end
19
- end
20
- }
21
- puts str
22
- file.close
23
-
@@ -1,29 +0,0 @@
1
- #This script generates code from a yml description of the api (requests to the method action=query, other actions have another generator). The yml description can be obtained from the mediawikidocumentation using genqueryymlfromdesc
2
- require 'yaml'
3
-
4
- Apiconf = YAML::load(File.open("queries.yml"))
5
-
6
- str =""
7
- Apiconf.each {|root|
8
- root.each {|method|
9
- if Apiconf[method]
10
- method =~ /(.*)=(.*)/
11
- str += "def query_#{$1}_#{$2}(titles = nil, "
12
- Apiconf[method].each {|param|
13
- str += "#{param} = nil, "
14
- }
15
- str = str+ "pageids = nil, revids = nil, redirects = nil, indexpageids = nil, export = nil, exportnowrap = nil, post_me = nil)\n\n"
16
- Apiconf[method].each {|param|
17
- str += " post_me = add_post('#{param}', #{param}, post_me)\n"
18
- }
19
- str += " post_me = add_post('#{$1}', '#{$2}', post_me)\n"
20
- str += " post_me = query(post_me, titles, pageids, revids, redirects, indexpageids, export, exportnowrap)\n"
21
- str += " post_me = format(post_me, 'xml')\n"
22
- str += " result = make_request(post_me)\n"
23
- str += " return result\n"
24
- str += "end\n\n"
25
- end
26
- }
27
- }
28
-
29
- puts str
@@ -1,22 +0,0 @@
1
- #this script generates an yml from the description of request to the api for action=query. the description can be obtained at http://es.wikipedia.org/w/api.php
2
- file = File.new("querydesc", "r")
3
-
4
- str = ""
5
- parameters = false
6
- file.each {|line|
7
- case line
8
- when /^\* (.*)=(.*) \(.*\) \*/
9
- str += "#{$1}=#{$2}:\n"
10
- when /^Parameters.*/
11
- parameters = true
12
- when /^Example.*/
13
- parameters = false
14
- when /^ (\w*)\s*- (.*)/
15
- if parameters
16
- str += " - #{$1}\n"
17
- end
18
- end
19
- }
20
- puts str
21
- file.close
22
-