mediawiki-gateway 0.4.4 → 0.4.5
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/Rakefile +8 -3
- data/lib/media_wiki.rb +1 -1
- data/lib/media_wiki/gateway.rb +66 -2
- data/mediawiki-gateway.gemspec +18 -3
- data/spec/gateway_spec.rb +132 -128
- metadata +76 -5
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'thread'
|
2
2
|
require 'rake'
|
3
|
-
require
|
4
|
-
require '
|
3
|
+
require "rubygems/package_task"
|
4
|
+
require 'rdoc/task'
|
5
5
|
require 'spec/rake/spectask'
|
6
6
|
require 'lib/media_wiki'
|
7
7
|
|
@@ -9,7 +9,7 @@ task :default => ['spec']
|
|
9
9
|
|
10
10
|
desc 'generate API documentation to doc/index.html'
|
11
11
|
|
12
|
-
|
12
|
+
RDoc::Task.new do |rd|
|
13
13
|
rd.rdoc_dir = 'doc'
|
14
14
|
rd.main = 'README'
|
15
15
|
rd.rdoc_files.include "README", "lib/media_wiki/**/*\.rb", "script/**/*\.rb"
|
@@ -42,6 +42,11 @@ begin
|
|
42
42
|
gemspec.add_development_dependency 'jeweler'
|
43
43
|
gemspec.add_development_dependency 'sham_rack'
|
44
44
|
gemspec.add_development_dependency 'rr'
|
45
|
+
gemspec.add_development_dependency 'rcov'
|
46
|
+
gemspec.add_development_dependency 'rspec', '~> 1.3'
|
47
|
+
gemspec.add_development_dependency 'ruby-debug'
|
48
|
+
gemspec.add_development_dependency 'sinatra'
|
49
|
+
gemspec.add_development_dependency 'activemodel'
|
45
50
|
end
|
46
51
|
rescue LoadError
|
47
52
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
data/lib/media_wiki.rb
CHANGED
data/lib/media_wiki/gateway.rb
CHANGED
@@ -16,6 +16,7 @@ module MediaWiki
|
|
16
16
|
# [options] Hash of options
|
17
17
|
#
|
18
18
|
# Options:
|
19
|
+
# [:bot] When set to true, executes API queries with the bot parameter (see http://www.mediawiki.org/wiki/API:Edit#Parameters). Defaults to false.
|
19
20
|
# [:ignorewarnings] Log API warnings and invalid page titles, instead throwing MediaWiki::APIError
|
20
21
|
# [:limit] Maximum number of results returned per search (see http://www.mediawiki.org/wiki/API:Query_-_Lists#Limits), defaults to the MediaWiki default of 500.
|
21
22
|
# [:loglevel] Log level to use, defaults to Logger::WARN. Set to Logger::DEBUG to dump every request and response to the log.
|
@@ -28,7 +29,8 @@ module MediaWiki
|
|
28
29
|
:loglevel => Logger::WARN,
|
29
30
|
:maxlag => 5,
|
30
31
|
:retry_count => 3,
|
31
|
-
:retry_delay => 10
|
32
|
+
:retry_delay => 10,
|
33
|
+
:bot => false
|
32
34
|
}
|
33
35
|
@options = default_options.merge(options)
|
34
36
|
@wiki_url = url
|
@@ -141,6 +143,67 @@ module MediaWiki
|
|
141
143
|
create(title, content, {:overwrite => true}.merge(options))
|
142
144
|
end
|
143
145
|
|
146
|
+
# Protect/unprotect a page
|
147
|
+
#
|
148
|
+
# Arguments:
|
149
|
+
# * [title] Page title to protect, string
|
150
|
+
# * [protections] Protections to apply, hash or array of hashes
|
151
|
+
#
|
152
|
+
# Protections:
|
153
|
+
# * [:action] (required) The action to protect, string
|
154
|
+
# * [:group] (required) The group allowed to perform the action, string
|
155
|
+
# * [:expiry] The protection expiry as a GNU timestamp, string
|
156
|
+
#
|
157
|
+
# * [options] Hash of additional options
|
158
|
+
#
|
159
|
+
# Options:
|
160
|
+
# * [:cascade] Protect pages included in this page, boolean
|
161
|
+
# * [:reason] Reason for protection, string
|
162
|
+
#
|
163
|
+
# Examples:
|
164
|
+
# 1. mw.protect('Main Page', {:action => 'edit', :group => 'all'}, {:cascade => true})
|
165
|
+
# 2. prt = [{:action => 'move', :group => 'sysop', :expiry => 'never'},
|
166
|
+
# {:action => 'edit', :group => 'autoconfirmed', :expiry => 'next Monday 16:04:57'}]
|
167
|
+
# mw.protect('Main Page', prt, {:reason => 'awesomeness'})
|
168
|
+
#
|
169
|
+
def protect(title, protections, options={})
|
170
|
+
# validate and format protections
|
171
|
+
protections = [protections] if protections.is_a?(Hash)
|
172
|
+
raise ArgumentError.new("Invalid type '#{protections.class}' for protections") unless protections.is_a?(Array)
|
173
|
+
valid_prt_options = %w(action group expiry)
|
174
|
+
required_prt_options = %w(action group)
|
175
|
+
p,e = [],[]
|
176
|
+
protections.each do |prt|
|
177
|
+
existing_prt_options = []
|
178
|
+
prt.keys.each do |opt|
|
179
|
+
if valid_prt_options.include?(opt.to_s)
|
180
|
+
existing_prt_options.push(opt.to_s)
|
181
|
+
else
|
182
|
+
raise ArgumentError.new("Unknown option '#{opt}' for protections")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
required_prt_options.each{|opt| raise ArgumentError.new("Missing required option '#{opt}' for protections") unless existing_prt_options.include?(opt)}
|
186
|
+
p.push("#{prt[:action]}=#{prt[:group]}")
|
187
|
+
if prt.has_key?(:expiry)
|
188
|
+
e.push(prt[:expiry].to_s)
|
189
|
+
else
|
190
|
+
e.push('never')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# validate options
|
195
|
+
valid_options = %w(cascade reason)
|
196
|
+
options.keys.each{|opt| raise ArgumentError.new("Unknown option '#{opt}'") unless valid_options.include?(opt.to_s)}
|
197
|
+
|
198
|
+
# make API request
|
199
|
+
form_data = {'action' => 'protect', 'title' => title, 'token' => get_token('protect', title)}
|
200
|
+
form_data['protections'] = p.join('|')
|
201
|
+
form_data['expiry'] = e.join('|')
|
202
|
+
form_data['cascade'] = '' if options[:cascade] === true
|
203
|
+
form_data['reason'] = options[:reason].to_s if options[:reason]
|
204
|
+
make_api_request(form_data)
|
205
|
+
end
|
206
|
+
|
144
207
|
# Move a page to a new title
|
145
208
|
#
|
146
209
|
# [from] Old page name
|
@@ -501,7 +564,7 @@ module MediaWiki
|
|
501
564
|
|
502
565
|
private
|
503
566
|
|
504
|
-
# Fetch token (type 'delete', 'edit', 'import', 'move')
|
567
|
+
# Fetch token (type 'delete', 'edit', 'import', 'move', 'protect')
|
505
568
|
def get_token(type, page_titles)
|
506
569
|
form_data = {'action' => 'query', 'prop' => 'info', 'intoken' => type, 'titles' => page_titles}
|
507
570
|
res, dummy = make_api_request(form_data)
|
@@ -569,6 +632,7 @@ module MediaWiki
|
|
569
632
|
if form_data.kind_of? Hash
|
570
633
|
form_data['format'] = 'xml'
|
571
634
|
form_data['maxlag'] = @options[:maxlag]
|
635
|
+
form_data['bot']="1" if @options[:bot]
|
572
636
|
end
|
573
637
|
log.debug("REQ: #{form_data.inspect}, #{@cookies.inspect}")
|
574
638
|
RestClient.post(@wiki_url, form_data, @headers.merge({:cookies => @cookies})) do |response, &block|
|
data/mediawiki-gateway.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mediawiki-gateway"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jani Patokallio"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-04-18"
|
13
13
|
s.description = ""
|
14
14
|
s.email = "jpatokal@iki.fi"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -46,7 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
]
|
47
47
|
s.homepage = "http://github.com/jpatokal/mediawiki-gateway"
|
48
48
|
s.require_paths = ["lib"]
|
49
|
-
s.rubygems_version = "1.8.
|
49
|
+
s.rubygems_version = "1.8.10"
|
50
50
|
s.summary = "Connect to the mediawiki API"
|
51
51
|
|
52
52
|
if s.respond_to? :specification_version then
|
@@ -58,12 +58,22 @@ Gem::Specification.new do |s|
|
|
58
58
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
59
59
|
s.add_development_dependency(%q<sham_rack>, [">= 0"])
|
60
60
|
s.add_development_dependency(%q<rr>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
63
|
+
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<sinatra>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<activemodel>, [">= 0"])
|
61
66
|
else
|
62
67
|
s.add_dependency(%q<rest-client>, [">= 1.3.0"])
|
63
68
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
64
69
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
65
70
|
s.add_dependency(%q<sham_rack>, [">= 0"])
|
66
71
|
s.add_dependency(%q<rr>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
74
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
75
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
76
|
+
s.add_dependency(%q<activemodel>, [">= 0"])
|
67
77
|
end
|
68
78
|
else
|
69
79
|
s.add_dependency(%q<rest-client>, [">= 1.3.0"])
|
@@ -71,6 +81,11 @@ Gem::Specification.new do |s|
|
|
71
81
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
72
82
|
s.add_dependency(%q<sham_rack>, [">= 0"])
|
73
83
|
s.add_dependency(%q<rr>, [">= 0"])
|
84
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
85
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
86
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
87
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
88
|
+
s.add_dependency(%q<activemodel>, [">= 0"])
|
74
89
|
end
|
75
90
|
end
|
76
91
|
|
data/spec/gateway_spec.rb
CHANGED
@@ -4,149 +4,153 @@ require 'spec_helper'
|
|
4
4
|
require 'sham_rack'
|
5
5
|
require 'spec/fake_media_wiki/app'
|
6
6
|
$fake_media_wiki = FakeMediaWiki::App.new
|
7
|
+
unless $fake_media_wiki.instance_of? FakeMediaWiki::App
|
8
|
+
# This is a horrible workaround for some bizarre conflict with later versions of ShamRack/Rack/Sinatra/Builder/...
|
9
|
+
$fake_media_wiki = $fake_media_wiki.instance_eval('@app').instance_eval('@app').app.app.app.app.app
|
10
|
+
end
|
7
11
|
ShamRack.mount($fake_media_wiki, 'dummy-wiki.example')
|
8
12
|
|
9
13
|
describe MediaWiki::Gateway do
|
10
|
-
|
14
|
+
|
11
15
|
before do
|
12
16
|
@gateway = MediaWiki::Gateway.new('http://dummy-wiki.example/w/api.php')
|
13
17
|
$fake_media_wiki.reset
|
14
18
|
end
|
15
19
|
|
16
20
|
describe '#login' do
|
17
|
-
|
21
|
+
|
18
22
|
describe "with a valid username & password" do
|
19
|
-
|
23
|
+
|
20
24
|
before do
|
21
25
|
@gateway.login('atlasmw', 'wombat')
|
22
26
|
end
|
23
|
-
|
27
|
+
|
24
28
|
it "should login successfully with the default domain" do
|
25
29
|
$fake_media_wiki.logged_in('atlasmw').should == true
|
26
30
|
end
|
27
|
-
|
31
|
+
|
28
32
|
end
|
29
33
|
|
30
34
|
describe "with a valid username, password and domain" do
|
31
|
-
|
35
|
+
|
32
36
|
before do
|
33
37
|
@gateway.login('ldapuser', 'ldappass', 'ldapdomain')
|
34
38
|
end
|
35
|
-
|
39
|
+
|
36
40
|
it "should login successfully" do
|
37
41
|
$fake_media_wiki.logged_in('ldapuser').should == true
|
38
42
|
end
|
39
|
-
|
43
|
+
|
40
44
|
end
|
41
|
-
|
45
|
+
|
42
46
|
describe "with an non-existent username" do
|
43
|
-
|
47
|
+
|
44
48
|
it "should raise an error" do
|
45
49
|
lambda do
|
46
50
|
@gateway.login('bogususer', 'sekrit')
|
47
51
|
end.should raise_error(MediaWiki::Unauthorized)
|
48
52
|
end
|
49
|
-
|
53
|
+
|
50
54
|
end
|
51
|
-
|
55
|
+
|
52
56
|
describe "with an incorrect password" do
|
53
|
-
|
57
|
+
|
54
58
|
it "should raise an error" do
|
55
59
|
lambda do
|
56
60
|
@gateway.login('atlasmw', 'sekrit')
|
57
61
|
end.should raise_error(MediaWiki::Unauthorized)
|
58
62
|
end
|
59
|
-
|
63
|
+
|
60
64
|
end
|
61
65
|
|
62
66
|
describe "with an incorrect domain" do
|
63
|
-
|
67
|
+
|
64
68
|
it "should raise an error" do
|
65
69
|
lambda do
|
66
70
|
@gateway.login('atlasmw', 'wombat', 'bogusdomain')
|
67
71
|
end.should raise_error(MediaWiki::Unauthorized)
|
68
72
|
end
|
69
|
-
|
73
|
+
|
70
74
|
end
|
71
|
-
|
75
|
+
|
72
76
|
end
|
73
77
|
|
74
78
|
describe "#get_token" do
|
75
|
-
|
79
|
+
|
76
80
|
describe "when not logged in" do
|
77
|
-
|
81
|
+
|
78
82
|
describe "requesting an edit token" do
|
79
|
-
|
83
|
+
|
80
84
|
before do
|
81
85
|
@token = @gateway.send(:get_token, 'edit', 'Main Page')
|
82
86
|
end
|
83
|
-
|
87
|
+
|
84
88
|
it "should return a blank token" do
|
85
89
|
@token.should_not == nil
|
86
90
|
@token.should == "+\\"
|
87
91
|
end
|
88
|
-
|
92
|
+
|
89
93
|
end
|
90
|
-
|
94
|
+
|
91
95
|
describe "requesting an import token" do
|
92
|
-
|
96
|
+
|
93
97
|
it "should raise an error" do
|
94
98
|
lambda do
|
95
99
|
@gateway.send(:get_token, 'import', 'Main Page')
|
96
100
|
end.should raise_error(MediaWiki::Unauthorized)
|
97
101
|
end
|
98
|
-
|
102
|
+
|
99
103
|
end
|
100
|
-
|
104
|
+
|
101
105
|
end
|
102
|
-
|
106
|
+
|
103
107
|
describe "when logged in as admin user" do
|
104
|
-
|
108
|
+
|
105
109
|
before do
|
106
110
|
@gateway.login('atlasmw', 'wombat')
|
107
111
|
end
|
108
|
-
|
112
|
+
|
109
113
|
describe "requesting an edit token for a single page" do
|
110
|
-
|
114
|
+
|
111
115
|
before do
|
112
116
|
@token = @gateway.send(:get_token, 'edit', 'Main Page')
|
113
117
|
end
|
114
|
-
|
118
|
+
|
115
119
|
it "should return a token" do
|
116
120
|
@token.should_not == nil
|
117
121
|
@token.should_not == "+\\"
|
118
122
|
end
|
119
|
-
|
123
|
+
|
120
124
|
end
|
121
|
-
|
125
|
+
|
122
126
|
describe "requesting an edit token for multiple pages" do
|
123
|
-
|
127
|
+
|
124
128
|
before do
|
125
129
|
@token = @gateway.send(:get_token, 'edit', "Main Page|Another Page")
|
126
130
|
end
|
127
|
-
|
131
|
+
|
128
132
|
it "should return a token" do
|
129
133
|
@token.should_not == nil
|
130
134
|
@token.should_not == "+\\"
|
131
135
|
end
|
132
|
-
|
136
|
+
|
133
137
|
end
|
134
|
-
|
138
|
+
|
135
139
|
describe "requesting an import token" do
|
136
|
-
|
140
|
+
|
137
141
|
before do
|
138
142
|
@token = @gateway.send(:get_token, 'import', 'Main Page')
|
139
143
|
end
|
140
|
-
|
144
|
+
|
141
145
|
it "should return a token" do
|
142
146
|
@token.should_not == nil
|
143
147
|
@token.should_not == "+\\"
|
144
148
|
end
|
145
|
-
|
149
|
+
|
146
150
|
end
|
147
151
|
|
148
152
|
end
|
149
|
-
|
153
|
+
|
150
154
|
end
|
151
155
|
|
152
156
|
describe "#get" do
|
@@ -233,14 +237,14 @@ describe MediaWiki::Gateway do
|
|
233
237
|
end
|
234
238
|
|
235
239
|
describe "#render" do
|
236
|
-
|
240
|
+
|
237
241
|
describe "for an existing wiki page" do
|
238
242
|
|
239
243
|
before do
|
240
244
|
@pages = @gateway.render('Main Page')
|
241
245
|
end
|
242
246
|
|
243
|
-
it "should return the page content" do
|
247
|
+
it "should return the page content" do
|
244
248
|
expected = 'Sample <B>HTML</B> content.'
|
245
249
|
@pages.to_s.should == expected
|
246
250
|
end
|
@@ -284,9 +288,9 @@ describe MediaWiki::Gateway do
|
|
284
288
|
end
|
285
289
|
|
286
290
|
end
|
287
|
-
|
291
|
+
|
288
292
|
describe "for a missing wiki page" do
|
289
|
-
|
293
|
+
|
290
294
|
before do
|
291
295
|
@pages = @gateway.render('Invalidpage')
|
292
296
|
end
|
@@ -294,23 +298,23 @@ describe MediaWiki::Gateway do
|
|
294
298
|
it "should return nil" do
|
295
299
|
@pages.should == nil
|
296
300
|
end
|
297
|
-
|
301
|
+
|
298
302
|
end
|
299
303
|
|
300
304
|
end
|
301
|
-
|
305
|
+
|
302
306
|
describe "#create" do
|
303
|
-
|
307
|
+
|
304
308
|
before do
|
305
309
|
@gateway.login('atlasmw', 'wombat')
|
306
310
|
end
|
307
311
|
|
308
312
|
describe "when creating a new page" do
|
309
|
-
|
313
|
+
|
310
314
|
before do
|
311
315
|
@page = @gateway.create("A New Page", "Some content")
|
312
316
|
end
|
313
|
-
|
317
|
+
|
314
318
|
it "should create the page" do
|
315
319
|
expected = <<-XML
|
316
320
|
<api>
|
@@ -319,21 +323,21 @@ describe MediaWiki::Gateway do
|
|
319
323
|
XML
|
320
324
|
Hash.from_xml(@page.to_s).should == Hash.from_xml(expected)
|
321
325
|
end
|
322
|
-
|
326
|
+
|
323
327
|
end
|
324
|
-
|
328
|
+
|
325
329
|
describe "when creating a page that already exists" do
|
326
|
-
|
330
|
+
|
327
331
|
before do
|
328
332
|
$fake_media_wiki.reset
|
329
333
|
end
|
330
|
-
|
334
|
+
|
331
335
|
describe "and the 'overwrite' option is set" do
|
332
|
-
|
336
|
+
|
333
337
|
before do
|
334
338
|
@new_page = @gateway.create("Main Page", "Some new content", :summary => "The summary", :overwrite => true)
|
335
339
|
end
|
336
|
-
|
340
|
+
|
337
341
|
it "should overwrite the existing page" do
|
338
342
|
expected = <<-XML
|
339
343
|
<api>
|
@@ -342,21 +346,21 @@ describe MediaWiki::Gateway do
|
|
342
346
|
XML
|
343
347
|
Hash.from_xml(@new_page.to_s).should == Hash.from_xml(expected)
|
344
348
|
end
|
345
|
-
|
349
|
+
|
346
350
|
end
|
347
|
-
|
351
|
+
|
348
352
|
describe "and the 'overwrite' option is not set" do
|
349
|
-
|
353
|
+
|
350
354
|
it "should raise an error" do
|
351
355
|
lambda do
|
352
356
|
@gateway.create("Main Page", "Some new content")
|
353
357
|
end.should raise_error(MediaWiki::APIError)
|
354
358
|
end
|
355
|
-
|
359
|
+
|
356
360
|
end
|
357
|
-
|
361
|
+
|
358
362
|
end
|
359
|
-
|
363
|
+
|
360
364
|
end
|
361
365
|
|
362
366
|
describe "#edit" do
|
@@ -364,7 +368,7 @@ describe MediaWiki::Gateway do
|
|
364
368
|
$fake_media_wiki.reset
|
365
369
|
@edit_page = @gateway.edit("Main Page", "Some new content")
|
366
370
|
end
|
367
|
-
|
371
|
+
|
368
372
|
it "should overwrite the existing page" do
|
369
373
|
expected = <<-XML
|
370
374
|
<api>
|
@@ -373,22 +377,22 @@ describe MediaWiki::Gateway do
|
|
373
377
|
XML
|
374
378
|
Hash.from_xml(@edit_page.to_s).should == Hash.from_xml(expected)
|
375
379
|
end
|
376
|
-
|
380
|
+
|
377
381
|
end
|
378
382
|
|
379
383
|
describe "#upload" do
|
380
|
-
|
384
|
+
|
381
385
|
before do
|
382
386
|
@gateway.login('atlasmw', 'wombat')
|
383
387
|
end
|
384
388
|
|
385
389
|
describe "when uploading a new file" do
|
386
|
-
|
390
|
+
|
387
391
|
before do
|
388
392
|
stub(File).new(anything) { "SAMPLEIMAGEDATA" }
|
389
393
|
@page = @gateway.upload("some/path/sample_image.jpg")
|
390
394
|
end
|
391
|
-
|
395
|
+
|
392
396
|
it "should open the file" do
|
393
397
|
File.should have_received.new("some/path/sample_image.jpg")
|
394
398
|
end
|
@@ -401,9 +405,9 @@ describe MediaWiki::Gateway do
|
|
401
405
|
XML
|
402
406
|
Hash.from_xml(@page.to_s).should == Hash.from_xml(expected)
|
403
407
|
end
|
404
|
-
|
408
|
+
|
405
409
|
end
|
406
|
-
|
410
|
+
|
407
411
|
end
|
408
412
|
|
409
413
|
describe "#delete" do
|
@@ -418,25 +422,25 @@ describe MediaWiki::Gateway do
|
|
418
422
|
</api>
|
419
423
|
XML
|
420
424
|
end
|
421
|
-
|
425
|
+
|
422
426
|
before do
|
423
427
|
@gateway.login("atlasmw", "wombat")
|
424
|
-
|
428
|
+
|
425
429
|
create("Deletable Page", "Some content")
|
426
430
|
@page = @gateway.delete("Deletable Page")
|
427
431
|
end
|
428
432
|
|
429
433
|
it "should delete the page" do
|
430
434
|
Hash.from_xml(@page.to_s) == Hash.from_xml(delete_response)
|
431
|
-
end
|
435
|
+
end
|
432
436
|
end
|
433
|
-
|
437
|
+
|
434
438
|
describe "and the page does not exist" do
|
435
|
-
|
439
|
+
|
436
440
|
before do
|
437
441
|
@gateway.login("atlasmw", "wombat")
|
438
442
|
end
|
439
|
-
|
443
|
+
|
440
444
|
it "should raise an error" do
|
441
445
|
lambda do
|
442
446
|
@gateway.delete("Missing Page")
|
@@ -450,7 +454,7 @@ describe MediaWiki::Gateway do
|
|
450
454
|
before do
|
451
455
|
create("Deletable Page", "Some content")
|
452
456
|
end
|
453
|
-
|
457
|
+
|
454
458
|
it "should raise an error" do
|
455
459
|
lambda do
|
456
460
|
@gateway.delete("Deletable Page")
|
@@ -458,7 +462,7 @@ describe MediaWiki::Gateway do
|
|
458
462
|
end
|
459
463
|
|
460
464
|
end
|
461
|
-
|
465
|
+
|
462
466
|
end
|
463
467
|
|
464
468
|
describe "#undelete" do
|
@@ -468,7 +472,7 @@ describe MediaWiki::Gateway do
|
|
468
472
|
$fake_media_wiki.reset
|
469
473
|
@gateway.login("atlasmw", "wombat")
|
470
474
|
end
|
471
|
-
|
475
|
+
|
472
476
|
describe "and the page no longer exists" do
|
473
477
|
before do
|
474
478
|
@revs = @gateway.undelete("Sandbox:Undeleted")
|
@@ -477,7 +481,7 @@ describe MediaWiki::Gateway do
|
|
477
481
|
it "should recreate the given page" do
|
478
482
|
@gateway.list("Sandbox:Undeleted").should == [ "Sandbox:Undeleted" ]
|
479
483
|
end
|
480
|
-
|
484
|
+
|
481
485
|
it "should report one undeleted revision" do
|
482
486
|
@revs.should == 1
|
483
487
|
end
|
@@ -503,17 +507,17 @@ describe MediaWiki::Gateway do
|
|
503
507
|
end
|
504
508
|
|
505
509
|
end
|
506
|
-
|
510
|
+
|
507
511
|
end
|
508
512
|
|
509
513
|
describe "#list" do
|
510
|
-
|
514
|
+
|
511
515
|
before do
|
512
516
|
$fake_media_wiki.reset
|
513
517
|
end
|
514
|
-
|
518
|
+
|
515
519
|
describe "with an empty key" do
|
516
|
-
|
520
|
+
|
517
521
|
before do
|
518
522
|
@list = @gateway.list("")
|
519
523
|
end
|
@@ -521,11 +525,11 @@ describe MediaWiki::Gateway do
|
|
521
525
|
it "should list all pages" do
|
522
526
|
@list.sort.should == [ "Book:Italy", "Empty", "Foopage", "Level/Level/Index", "Main 2", "Main Page", "Redirect" ]
|
523
527
|
end
|
524
|
-
|
528
|
+
|
525
529
|
end
|
526
530
|
|
527
531
|
describe "with a namespace as the key" do
|
528
|
-
|
532
|
+
|
529
533
|
before do
|
530
534
|
@list = @gateway.list("Book:")
|
531
535
|
end
|
@@ -533,11 +537,11 @@ describe MediaWiki::Gateway do
|
|
533
537
|
it "should list all pages in the namespace" do
|
534
538
|
@list.should == [ "Book:Italy" ]
|
535
539
|
end
|
536
|
-
|
540
|
+
|
537
541
|
end
|
538
542
|
|
539
543
|
describe "with a partial title as the key" do
|
540
|
-
|
544
|
+
|
541
545
|
before do
|
542
546
|
@list = @gateway.list("Main")
|
543
547
|
end
|
@@ -545,13 +549,13 @@ describe MediaWiki::Gateway do
|
|
545
549
|
it "should list all pages in the main namespace that start with key" do
|
546
550
|
@list.sort.should == [ "Main 2", "Main Page" ]
|
547
551
|
end
|
548
|
-
|
552
|
+
|
549
553
|
end
|
550
554
|
|
551
555
|
end
|
552
556
|
|
553
557
|
describe "#search" do
|
554
|
-
|
558
|
+
|
555
559
|
before do
|
556
560
|
$fake_media_wiki.reset
|
557
561
|
@gateway.create("Search Test", "Foo KEY Blah")
|
@@ -559,31 +563,31 @@ describe MediaWiki::Gateway do
|
|
559
563
|
@gateway.create("Book:Search Test", "Bar KEY Baz")
|
560
564
|
@gateway.create("Sandbox:Search Test", "Evil KEY Evil")
|
561
565
|
end
|
562
|
-
|
566
|
+
|
563
567
|
describe "with an empty key" do
|
564
|
-
|
568
|
+
|
565
569
|
it "should raise an error" do
|
566
570
|
lambda do
|
567
571
|
@gateway.search("")
|
568
572
|
end.should raise_error(MediaWiki::APIError)
|
569
573
|
end
|
570
|
-
|
574
|
+
|
571
575
|
end
|
572
576
|
|
573
577
|
describe "with a valid key and no namespaces" do
|
574
|
-
|
578
|
+
|
575
579
|
before do
|
576
580
|
@search = @gateway.search("KEY")
|
577
581
|
end
|
578
582
|
|
579
583
|
it "should list all matching pages in the main namespace" do
|
580
|
-
@search.should
|
584
|
+
@search.should =~ [ "Search Test", "Search Test 2" ]
|
581
585
|
end
|
582
|
-
|
586
|
+
|
583
587
|
end
|
584
588
|
|
585
589
|
describe "with a valid key and a namespace string" do
|
586
|
-
|
590
|
+
|
587
591
|
before do
|
588
592
|
@search = @gateway.search("KEY", "Book")
|
589
593
|
end
|
@@ -591,25 +595,25 @@ describe MediaWiki::Gateway do
|
|
591
595
|
it "should list all matching pages in the specified namespaces" do
|
592
596
|
@search.should == [ "Book:Search Test" ]
|
593
597
|
end
|
594
|
-
|
598
|
+
|
595
599
|
end
|
596
600
|
|
597
601
|
describe "with a valid key and a namespace array" do
|
598
|
-
|
602
|
+
|
599
603
|
before do
|
600
604
|
@search = @gateway.search("KEY", ["Book", "Sandbox"])
|
601
605
|
end
|
602
606
|
|
603
607
|
it "should list all matching pages in the specified namespaces" do
|
604
|
-
@search.should
|
608
|
+
@search.should =~ [ "Sandbox:Search Test", "Book:Search Test" ]
|
605
609
|
end
|
606
|
-
|
610
|
+
|
607
611
|
end
|
608
612
|
|
609
613
|
end
|
610
|
-
|
614
|
+
|
611
615
|
describe "#namespaces_by_prefix" do
|
612
|
-
|
616
|
+
|
613
617
|
before do
|
614
618
|
$fake_media_wiki.reset
|
615
619
|
@namespaces = @gateway.namespaces_by_prefix
|
@@ -622,7 +626,7 @@ describe MediaWiki::Gateway do
|
|
622
626
|
end
|
623
627
|
|
624
628
|
describe "#semantic_query" do
|
625
|
-
|
629
|
+
|
626
630
|
before do
|
627
631
|
@response = @gateway.semantic_query('[[place::123]]', ['mainlabel=Page'])
|
628
632
|
end
|
@@ -630,9 +634,9 @@ describe MediaWiki::Gateway do
|
|
630
634
|
it "should return an HTML string" do
|
631
635
|
@response.should == 'Sample <B>HTML</B> content.'
|
632
636
|
end
|
633
|
-
|
637
|
+
|
634
638
|
end
|
635
|
-
|
639
|
+
|
636
640
|
describe "#import" do
|
637
641
|
|
638
642
|
def import_file
|
@@ -640,7 +644,7 @@ describe MediaWiki::Gateway do
|
|
640
644
|
end
|
641
645
|
|
642
646
|
describe "when not logged in" do
|
643
|
-
|
647
|
+
|
644
648
|
it "should raise an error" do
|
645
649
|
lambda do
|
646
650
|
@gateway.import(import_file)
|
@@ -650,7 +654,7 @@ describe MediaWiki::Gateway do
|
|
650
654
|
end
|
651
655
|
|
652
656
|
describe "when logged in as admin" do
|
653
|
-
|
657
|
+
|
654
658
|
def import_response
|
655
659
|
<<-XML
|
656
660
|
<api>
|
@@ -661,22 +665,22 @@ describe MediaWiki::Gateway do
|
|
661
665
|
</api>
|
662
666
|
XML
|
663
667
|
end
|
664
|
-
|
668
|
+
|
665
669
|
before do
|
666
670
|
@gateway.login("atlasmw", "wombat")
|
667
671
|
@page = @gateway.import(import_file)
|
668
672
|
end
|
669
|
-
|
673
|
+
|
670
674
|
it "should import content" do
|
671
675
|
Hash.from_xml(@page.to_s) == Hash.from_xml(import_response)
|
672
676
|
end
|
673
|
-
|
677
|
+
|
674
678
|
end
|
675
|
-
|
679
|
+
|
676
680
|
end
|
677
|
-
|
681
|
+
|
678
682
|
describe "#export" do
|
679
|
-
|
683
|
+
|
680
684
|
def export_response
|
681
685
|
<<-XML
|
682
686
|
<mediawiki>
|
@@ -691,19 +695,19 @@ describe MediaWiki::Gateway do
|
|
691
695
|
</mediawiki>
|
692
696
|
XML
|
693
697
|
end
|
694
|
-
|
698
|
+
|
695
699
|
before do
|
696
700
|
@page = @gateway.export("Main Page")
|
697
701
|
end
|
698
|
-
|
702
|
+
|
699
703
|
it "should return export data for the page" do
|
700
704
|
Hash.from_xml(@page.to_s).should == Hash.from_xml(export_response)
|
701
705
|
end
|
702
|
-
|
706
|
+
|
703
707
|
end
|
704
708
|
|
705
709
|
describe "#namespaces_by_prefix" do
|
706
|
-
|
710
|
+
|
707
711
|
before do
|
708
712
|
$fake_media_wiki.reset
|
709
713
|
@namespaces = @gateway.send :namespaces_by_prefix
|
@@ -716,7 +720,7 @@ describe MediaWiki::Gateway do
|
|
716
720
|
end
|
717
721
|
|
718
722
|
describe "#extensions" do
|
719
|
-
|
723
|
+
|
720
724
|
before do
|
721
725
|
$fake_media_wiki.reset
|
722
726
|
@extensions = @gateway.extensions
|
@@ -733,14 +737,14 @@ describe MediaWiki::Gateway do
|
|
733
737
|
form_data['createonly'] = "" unless options[:overwrite]
|
734
738
|
@gateway.send(:make_api_request, form_data)
|
735
739
|
end
|
736
|
-
|
740
|
+
|
737
741
|
describe "#user_rights" do
|
738
|
-
|
742
|
+
|
739
743
|
describe "when logged in as admin" do
|
740
744
|
before do
|
741
745
|
@gateway.login("atlasmw", "wombat")
|
742
746
|
end
|
743
|
-
|
747
|
+
|
744
748
|
describe "requesting a userrights token for an existing user" do
|
745
749
|
|
746
750
|
before do
|
@@ -752,7 +756,7 @@ describe MediaWiki::Gateway do
|
|
752
756
|
@token.should_not == "+\\"
|
753
757
|
end
|
754
758
|
end
|
755
|
-
|
759
|
+
|
756
760
|
describe "requesting a userrights token for an nonexistant user" do
|
757
761
|
|
758
762
|
it "should raise an error" do
|
@@ -761,9 +765,9 @@ describe MediaWiki::Gateway do
|
|
761
765
|
end.should raise_error(MediaWiki::APIError)
|
762
766
|
end
|
763
767
|
end
|
764
|
-
|
768
|
+
|
765
769
|
describe "changing a user's groups with a valid token" do
|
766
|
-
|
770
|
+
|
767
771
|
def userrights_response
|
768
772
|
<<-XML
|
769
773
|
<api>
|
@@ -778,18 +782,18 @@ describe MediaWiki::Gateway do
|
|
778
782
|
</api>
|
779
783
|
XML
|
780
784
|
end
|
781
|
-
|
785
|
+
|
782
786
|
before do
|
783
787
|
@token = @gateway.send(:get_userrights_token, 'nonadmin')
|
784
788
|
@result = @gateway.send(:userrights, 'nonadmin', @token, 'newgroup', 'oldgroup', 'because I can')
|
785
789
|
end
|
786
|
-
|
790
|
+
|
787
791
|
it "should return a result matching the input" do
|
788
792
|
Hash.from_xml(@result.to_s).should == Hash.from_xml(userrights_response)
|
789
793
|
end
|
790
|
-
|
794
|
+
|
791
795
|
end
|
792
|
-
|
796
|
+
|
793
797
|
end
|
794
798
|
end
|
795
799
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediawiki-gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 5
|
10
|
+
version: 0.4.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jani Patokallio
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rest-client
|
@@ -89,6 +89,77 @@ dependencies:
|
|
89
89
|
version: "0"
|
90
90
|
type: :development
|
91
91
|
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: rcov
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
type: :development
|
105
|
+
version_requirements: *id006
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
name: rspec
|
108
|
+
prerelease: false
|
109
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ~>
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 9
|
115
|
+
segments:
|
116
|
+
- 1
|
117
|
+
- 3
|
118
|
+
version: "1.3"
|
119
|
+
type: :development
|
120
|
+
version_requirements: *id007
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: ruby-debug
|
123
|
+
prerelease: false
|
124
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
type: :development
|
134
|
+
version_requirements: *id008
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: sinatra
|
137
|
+
prerelease: false
|
138
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
type: :development
|
148
|
+
version_requirements: *id009
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: activemodel
|
151
|
+
prerelease: false
|
152
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
version: "0"
|
161
|
+
type: :development
|
162
|
+
version_requirements: *id010
|
92
163
|
description: ""
|
93
164
|
email: jpatokal@iki.fi
|
94
165
|
executables: []
|
@@ -154,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
225
|
requirements: []
|
155
226
|
|
156
227
|
rubyforge_project:
|
157
|
-
rubygems_version: 1.8.
|
228
|
+
rubygems_version: 1.8.10
|
158
229
|
signing_key:
|
159
230
|
specification_version: 3
|
160
231
|
summary: Connect to the mediawiki API
|