mediawiki-gateway 0.1.4 → 0.1.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 CHANGED
@@ -36,6 +36,8 @@ begin
36
36
  gemspec.authors = ["Jani Patokallio"]
37
37
  gemspec.add_dependency 'rest-client'
38
38
  gemspec.add_development_dependency 'sham_rack'
39
+ gemspec.add_development_dependency 'jeweler'
40
+ gemspec.add_development_dependency 'activesupport'
39
41
  end
40
42
  rescue LoadError
41
43
  puts "Jeweler not available. Install it with: gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -47,7 +47,7 @@ module MediaWiki
47
47
  if ! page or page.attributes["missing"]
48
48
  nil
49
49
  else
50
- page.elements["revisions/rev"].text
50
+ page.elements["revisions/rev"].text || ""
51
51
  end
52
52
  end
53
53
 
@@ -76,7 +76,7 @@ module MediaWiki
76
76
  # OPTIMIZE: unifiy the keys in +options+ like symbolize_keys! but w/o
77
77
  if options["linkbase"] or options[:linkbase]
78
78
  linkbase = options["linkbase"] || options[:linkbase]
79
- rendered = rendered.gsub(/\shref="\/wiki\/(.*)"/, ' href="' + linkbase + '/wiki/\1"')
79
+ rendered = rendered.gsub(/\shref="\/wiki\/([\w\(\)_\-\.%\d:,]*)"/, ' href="' + linkbase + '/wiki/\1"')
80
80
  end
81
81
  if options["noeditsections"] or options[:noeditsections]
82
82
  rendered = rendered.gsub(/<span class="editsection">\[.+\]<\/span>/, '')
@@ -424,12 +424,16 @@ module MediaWiki
424
424
  end
425
425
 
426
426
  # Get API XML response
427
- # If there are errors, print and bail out
427
+ # If there are errors, raise exception
428
428
  # Otherwise return XML root
429
429
  def get_response(res)
430
- doc = REXML::Document.new(res).root
430
+ begin
431
+ doc = REXML::Document.new(res).root
432
+ rescue REXML::ParseException => e
433
+ raise "Response is not XML. Are you sure you are pointing to api.php?"
434
+ end
431
435
  @log.debug("RES: #{doc}")
432
- raise "API error, response does not contain Mediawiki API XML: #{res}" unless [ "api", "mediawiki" ].include? doc.name
436
+ raise "Response does not contain Mediawiki API XML: #{res}" unless [ "api", "mediawiki" ].include? doc.name
433
437
  if doc.elements["error"]
434
438
  code = doc.elements["error"].attributes["code"]
435
439
  info = doc.elements["error"].attributes["info"]
@@ -1,77 +1,74 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mediawiki-gateway}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.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 = %q{2010-11-04}
12
+ s.date = %q{2010-11-26}
13
13
  s.description = %q{}
14
14
  s.email = %q{jpatokal@iki.fi}
15
15
  s.extra_rdoc_files = [
16
16
  "README"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "README",
21
- "Rakefile",
22
- "VERSION",
23
- "config/hosts.yml",
24
- "doc/classes/MediaWiki.html",
25
- "doc/classes/MediaWiki/Config.html",
26
- "doc/classes/MediaWiki/Gateway.html",
27
- "doc/created.rid",
28
- "doc/files/README.html",
29
- "doc/files/lib/media_wiki/config_rb.html",
30
- "doc/files/lib/media_wiki/gateway_rb.html",
31
- "doc/files/lib/media_wiki/utils_rb.html",
32
- "doc/files/script/create_page_rb.html",
33
- "doc/files/script/delete_batch_rb.html",
34
- "doc/files/script/export_xml_rb.html",
35
- "doc/files/script/get_page_rb.html",
36
- "doc/files/script/import_xml_rb.html",
37
- "doc/files/script/run_fake_media_wiki_rb.html",
38
- "doc/files/script/upload_commons_rb.html",
39
- "doc/files/script/upload_file_rb.html",
40
- "doc/fr_class_index.html",
41
- "doc/fr_file_index.html",
42
- "doc/fr_method_index.html",
43
- "doc/index.html",
44
- "doc/rdoc-style.css",
45
- "lib/media_wiki.rb",
46
- "lib/media_wiki/config.rb",
47
- "lib/media_wiki/gateway.rb",
48
- "lib/media_wiki/utils.rb",
49
- "mediawiki-gateway.gemspec",
50
- "script/create_page.rb",
51
- "script/delete_batch.rb",
52
- "script/export_xml.rb",
53
- "script/get_page.rb",
54
- "script/import_xml.rb",
55
- "script/run_fake_media_wiki.rb",
56
- "script/upload_commons.rb",
57
- "script/upload_file.rb",
58
- "spec/fake_media_wiki/api_pages.rb",
59
- "spec/fake_media_wiki/app.rb",
60
- "spec/fake_media_wiki/query_handling.rb",
61
- "spec/gateway_spec.old",
62
- "spec/gateway_spec.rb",
63
- "spec/import-test-data.xml"
19
+ "README",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "config/hosts.yml",
23
+ "doc/classes/MediaWiki.html",
24
+ "doc/classes/MediaWiki/Config.html",
25
+ "doc/classes/MediaWiki/Gateway.html",
26
+ "doc/created.rid",
27
+ "doc/files/README.html",
28
+ "doc/files/lib/media_wiki/config_rb.html",
29
+ "doc/files/lib/media_wiki/gateway_rb.html",
30
+ "doc/files/lib/media_wiki/utils_rb.html",
31
+ "doc/files/script/create_page_rb.html",
32
+ "doc/files/script/delete_batch_rb.html",
33
+ "doc/files/script/export_xml_rb.html",
34
+ "doc/files/script/get_page_rb.html",
35
+ "doc/files/script/import_xml_rb.html",
36
+ "doc/files/script/run_fake_media_wiki_rb.html",
37
+ "doc/files/script/upload_commons_rb.html",
38
+ "doc/files/script/upload_file_rb.html",
39
+ "doc/fr_class_index.html",
40
+ "doc/fr_file_index.html",
41
+ "doc/fr_method_index.html",
42
+ "doc/index.html",
43
+ "doc/rdoc-style.css",
44
+ "lib/media_wiki.rb",
45
+ "lib/media_wiki/config.rb",
46
+ "lib/media_wiki/gateway.rb",
47
+ "lib/media_wiki/utils.rb",
48
+ "mediawiki-gateway.gemspec",
49
+ "script/create_page.rb",
50
+ "script/delete_batch.rb",
51
+ "script/export_xml.rb",
52
+ "script/get_page.rb",
53
+ "script/import_xml.rb",
54
+ "script/run_fake_media_wiki.rb",
55
+ "script/upload_commons.rb",
56
+ "script/upload_file.rb",
57
+ "spec/fake_media_wiki/api_pages.rb",
58
+ "spec/fake_media_wiki/app.rb",
59
+ "spec/fake_media_wiki/query_handling.rb",
60
+ "spec/gateway_spec.rb",
61
+ "spec/import-test-data.xml"
64
62
  ]
65
63
  s.homepage = %q{http://github.com/jpatokal/media_wiki_gateway}
66
- s.rdoc_options = ["--charset=UTF-8"]
67
64
  s.require_paths = ["lib"]
68
65
  s.rubygems_version = %q{1.3.7}
69
66
  s.summary = %q{Connect to the mediawiki API}
70
67
  s.test_files = [
71
68
  "spec/fake_media_wiki/api_pages.rb",
72
- "spec/fake_media_wiki/app.rb",
73
- "spec/fake_media_wiki/query_handling.rb",
74
- "spec/gateway_spec.rb"
69
+ "spec/fake_media_wiki/app.rb",
70
+ "spec/fake_media_wiki/query_handling.rb",
71
+ "spec/gateway_spec.rb"
75
72
  ]
76
73
 
77
74
  if s.respond_to? :specification_version then
@@ -81,13 +78,19 @@ Gem::Specification.new do |s|
81
78
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
79
  s.add_runtime_dependency(%q<rest-client>, [">= 0"])
83
80
  s.add_development_dependency(%q<sham_rack>, [">= 0"])
81
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
82
+ s.add_development_dependency(%q<activesupport>, [">= 0"])
84
83
  else
85
84
  s.add_dependency(%q<rest-client>, [">= 0"])
86
85
  s.add_dependency(%q<sham_rack>, [">= 0"])
86
+ s.add_dependency(%q<jeweler>, [">= 0"])
87
+ s.add_dependency(%q<activesupport>, [">= 0"])
87
88
  end
88
89
  else
89
90
  s.add_dependency(%q<rest-client>, [">= 0"])
90
91
  s.add_dependency(%q<sham_rack>, [">= 0"])
92
+ s.add_dependency(%q<jeweler>, [">= 0"])
93
+ s.add_dependency(%q<activesupport>, [">= 0"])
91
94
  end
92
95
  end
93
96
 
@@ -1,3 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Sample script for uploading files to Mediawiki Commons (interactive)
4
+
1
5
  require 'lib/media_wiki'
2
6
 
3
7
  config = MediaWiki::Config.new(ARGV, "upload")
@@ -28,6 +28,7 @@ module FakeMediaWiki
28
28
  @pages = ApiPages.new
29
29
  @pages.add('Main Page', 'Content')
30
30
  @pages.add('Main 2', 'Content')
31
+ @pages.add('Empty', '')
31
32
  @pages.add('Level/Level/Index', '{{#include:Foo}} {{#include:Bar}}')
32
33
  @pages.add_namespace(100, "Book")
33
34
  @pages.add('Book:Italy', 'Introduction')
data/spec/gateway_spec.rb CHANGED
@@ -192,6 +192,14 @@ describe MediaWiki::Gateway do
192
192
 
193
193
  end
194
194
 
195
+ describe "for an existing empty wiki page" do
196
+
197
+ it "returns an empty string" do
198
+ @gateway.get("Empty").should == ""
199
+ end
200
+
201
+ end
202
+
195
203
  describe "for a missing wiki page" do
196
204
 
197
205
  it "returns nil" do
@@ -292,7 +300,7 @@ describe MediaWiki::Gateway do
292
300
  it "should create the page" do
293
301
  expected = <<-XML
294
302
  <api>
295
- <edit new='' result='Success' pageid='6' title='A New Page' oldrevid='0' newrevid='6'/>
303
+ <edit new='' result='Success' pageid='7' title='A New Page' oldrevid='0' newrevid='7'/>
296
304
  </api>
297
305
  XML
298
306
  Hash.from_xml(@page.to_s).should == Hash.from_xml(expected)
@@ -315,7 +323,7 @@ describe MediaWiki::Gateway do
315
323
  it "should overwrite the existing page" do
316
324
  expected = <<-XML
317
325
  <api>
318
- <edit result='Success' pageid='6' title='Main Page' oldrevid='1' newrevid='6'/>
326
+ <edit result='Success' pageid='7' title='Main Page' oldrevid='1' newrevid='7'/>
319
327
  </api>
320
328
  XML
321
329
  Hash.from_xml(@new_page.to_s).should == Hash.from_xml(expected)
@@ -481,7 +489,7 @@ describe MediaWiki::Gateway do
481
489
  end
482
490
 
483
491
  it "should list all pages" do
484
- @list.sort.should == [ "Book:Italy", "Foopage", "Level/Level/Index", "Main 2", "Main Page" ]
492
+ @list.sort.should == [ "Book:Italy", "Empty", "Foopage", "Level/Level/Index", "Main 2", "Main Page" ]
485
493
  end
486
494
 
487
495
  end
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.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: 2010-11-04 00:00:00 +11:00
18
+ date: 2010-11-26 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,6 +46,34 @@ dependencies:
46
46
  version: "0"
47
47
  type: :development
48
48
  version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: activesupport
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ version_requirements: *id004
49
77
  description: ""
50
78
  email: jpatokal@iki.fi
51
79
  executables: []
@@ -55,7 +83,6 @@ extensions: []
55
83
  extra_rdoc_files:
56
84
  - README
57
85
  files:
58
- - .gitignore
59
86
  - README
60
87
  - Rakefile
61
88
  - VERSION
@@ -97,7 +124,6 @@ files:
97
124
  - spec/fake_media_wiki/api_pages.rb
98
125
  - spec/fake_media_wiki/app.rb
99
126
  - spec/fake_media_wiki/query_handling.rb
100
- - spec/gateway_spec.old
101
127
  - spec/gateway_spec.rb
102
128
  - spec/import-test-data.xml
103
129
  has_rdoc: true
@@ -105,8 +131,8 @@ homepage: http://github.com/jpatokal/media_wiki_gateway
105
131
  licenses: []
106
132
 
107
133
  post_install_message:
108
- rdoc_options:
109
- - --charset=UTF-8
134
+ rdoc_options: []
135
+
110
136
  require_paths:
111
137
  - lib
112
138
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- coverage
2
- pkg
3
- nbproject
@@ -1,535 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe MediaWiki::Gateway do
4
-
5
- def media_wiki_url
6
- "#{LonelyPlanet::OnRails.environment.services[:atlas_mediawiki]}"
7
- end
8
-
9
- before do
10
- @gateway = MediaWiki::Gateway.new({:url => media_wiki_url, :username => 'atlasmw', :password => 'wombat'})
11
- $fake_media_wiki.reset
12
- end
13
-
14
- describe '.wiki_to_uri' do
15
-
16
- it "should underscore spaces" do
17
- MediaWiki.wiki_to_uri('getting there').should == 'getting_there'
18
- end
19
-
20
- it "should escape ampersands" do
21
- MediaWiki.wiki_to_uri('getting there & away').should == 'getting_there_%26_away'
22
- end
23
-
24
- it "should escape UTF-8" do
25
- MediaWiki.wiki_to_uri('Phở').should == 'Ph%E1%BB%9F'
26
- end
27
-
28
- it "should escape each path component but leave slashes untouched" do
29
- MediaWiki.wiki_to_uri('Phở/B&r/B z').should == 'Ph%E1%BB%9F/B%26r/B_z'
30
- end
31
-
32
- it "should pass through nil" do
33
- MediaWiki.wiki_to_uri(nil).should == nil
34
- end
35
-
36
- end
37
-
38
- describe '#login' do
39
-
40
- describe "with a valid username & password" do
41
-
42
- before do
43
- @gateway.login('atlasmw', 'wombat')
44
- end
45
-
46
- it "should login successfully" do
47
- $fake_media_wiki.logged_in('atlasmw').should == true
48
- end
49
-
50
- end
51
-
52
- describe "with an non-existent username" do
53
-
54
- it "should raise an error" do
55
- lambda do
56
- @gateway.login('bogususer', 'sekrit')
57
- end.should raise_error(StandardError)
58
- end
59
-
60
- end
61
-
62
- describe "with an incorrect password" do
63
-
64
- it "should raise an error" do
65
- lambda do
66
- @gateway.login('atlasmw', 'sekrit')
67
- end.should raise_error(StandardError)
68
- end
69
-
70
- end
71
-
72
- end
73
-
74
- describe "#get_token" do
75
-
76
- describe "when not logged in" do
77
-
78
- describe "requesting an edit token" do
79
-
80
- before do
81
- @token = @gateway.get_token('edit', 'Main Page')
82
- end
83
-
84
- it "should return a blank token" do
85
- @token.should_not == nil
86
- @token.should == "+\\"
87
- end
88
-
89
- end
90
-
91
- describe "requesting an import token" do
92
-
93
- it "should raise an error" do
94
- lambda do
95
- @gateway.get_token('import', 'Main Page')
96
- end.should raise_error(StandardError)
97
- end
98
-
99
- end
100
-
101
- end
102
-
103
- describe "when logged in as admin user" do
104
-
105
- before do
106
- @gateway.login('atlasmw', 'wombat')
107
- end
108
-
109
- describe "requesting an edit token for a single page" do
110
-
111
- before do
112
- @token = @gateway.get_token('edit', 'Main Page')
113
- end
114
-
115
- it "should return a token" do
116
- @token.should_not == nil
117
- @token.should_not == "+\\"
118
- end
119
-
120
- end
121
-
122
- describe "requesting an edit token for multiple pages" do
123
-
124
- before do
125
- @token = @gateway.get_token('edit', "Main Page|Another Page")
126
- end
127
-
128
- it "should return a token" do
129
- @token.should_not == nil
130
- @token.should_not == "+\\"
131
- end
132
-
133
- end
134
-
135
- describe "requesting an import token" do
136
-
137
- before do
138
- @token = @gateway.get_token('import', 'Main Page')
139
- end
140
-
141
- it "should return a token" do
142
- @token.should_not == nil
143
- @token.should_not == "+\\"
144
- end
145
-
146
- end
147
-
148
- end
149
-
150
- end
151
-
152
- describe "#get" do
153
-
154
- describe "for an existing wiki page" do
155
-
156
- before do
157
- $fake_media_wiki.add_page("page/title", "Wiki-text content")
158
- end
159
-
160
- it "returns raw page content" do
161
- @gateway.get("page/title").should == "Wiki-text content"
162
- end
163
-
164
- end
165
-
166
- describe "for a missing wiki page" do
167
-
168
- it "returns nil" do
169
- @gateway.get("page/missing").should be_nil
170
- end
171
-
172
- end
173
-
174
- describe "for root (/)" do
175
-
176
- it "returns nil" do
177
- @gateway.get("").should be_nil
178
- end
179
-
180
- end
181
-
182
- end
183
-
184
- describe "#render" do
185
-
186
- describe "for an existing wiki page" do
187
-
188
- before do
189
- @pages = @gateway.render('Main Page')
190
- end
191
-
192
- it "should return the page content" do
193
- expected = "Sample <B>HTML</B> content"
194
- @pages.to_s.should == expected
195
- end
196
- end
197
-
198
- describe "for a missing wiki page" do
199
-
200
- before do
201
- @pages = @gateway.render('Invalidpage')
202
- end
203
-
204
- it "should return nil" do
205
- @pages.should == nil
206
- end
207
-
208
- end
209
-
210
- end
211
-
212
- describe "#semantic_query" do
213
-
214
- before do
215
- @response = @gateway.semantic_query('[[place-id::123]]', ['mainlabel=Page'])
216
- end
217
-
218
- it "should return an HTML string" do
219
- @response.should == "Sample <B>HTML</B> content"
220
- end
221
-
222
- end
223
-
224
- describe "#create" do
225
-
226
- before do
227
- @gateway.login('atlasmw', 'wombat')
228
- end
229
-
230
- describe "when creating a new page" do
231
-
232
- before do
233
- @page = @gateway.create("A New Page", "Some content")
234
- end
235
-
236
- it "should create the page" do
237
- expected = <<-XML
238
- <api>
239
- <edit new='' result='Success' pageid='5' title='A New Page' oldrevid='0' newrevid='5'/>
240
- </api>
241
- XML
242
- Hash.from_xml(@page.to_s).should == Hash.from_xml(expected)
243
- end
244
-
245
- end
246
-
247
- describe "when creating a page that already exists" do
248
-
249
- before do
250
- @existing_page = $fake_media_wiki.add_page("The Page", "Some content")
251
- end
252
-
253
- describe "and the 'overwrite' option is set" do
254
-
255
- before do
256
- @new_page = @gateway.create("The Page", "Some new content", :summary => "The summary", :overwrite => true)
257
- end
258
-
259
- it "should overwrite the existing page" do
260
- expected = <<-XML
261
- <api>
262
- <edit result='Success' pageid='#{@existing_page[:pageid] + 1}' title='The Page' oldrevid='#{@existing_page[:pageid]}' newrevid='#{@existing_page[:pageid] + 1}'/>
263
- </api>
264
- XML
265
- Hash.from_xml(@new_page.to_s).should == Hash.from_xml(expected)
266
- end
267
-
268
- end
269
-
270
- describe "and the 'overwrite' option is not set" do
271
-
272
- it "should raise an error" do
273
- lambda do
274
- @gateway.create("The Page", "Some new content")
275
- end.should raise_error(StandardError)
276
- end
277
-
278
- end
279
-
280
- end
281
-
282
- end
283
-
284
- describe "#delete" do
285
-
286
- describe "when logged in as admin" do
287
-
288
- describe "and the page exists" do
289
- def delete_response
290
- <<-XML
291
- <api>
292
- <delete title='Deletable Page' reason='Default reason'/>
293
- </api>
294
- XML
295
- end
296
-
297
- before do
298
- @gateway.login("atlasmw", "wombat")
299
- @gateway.create("Deletable Page", "Some content")
300
- @page = @gateway.delete("Deletable Page")
301
- end
302
-
303
- it "should delete the page" do
304
- Hash.from_xml(@page.to_s) == Hash.from_xml(delete_response)
305
- end
306
- end
307
-
308
- describe "and the page does not exist" do
309
-
310
- before do
311
- @gateway.login("atlasmw", "wombat")
312
- end
313
-
314
- it "should raise an error" do
315
- lambda do
316
- @gateway.delete("Missing Page")
317
- end.should raise_error(StandardError)
318
- end
319
- end
320
- end
321
-
322
- describe "when not logged in" do
323
-
324
- before do
325
- @gateway.create("Deletable Page", "Some content")
326
- end
327
-
328
- it "should raise an error" do
329
- lambda do
330
- @gateway.delete("Deletable Page")
331
- end.should raise_error(StandardError)
332
- end
333
-
334
- end
335
-
336
- end
337
-
338
- describe "#import" do
339
-
340
- def import_file
341
- File.dirname(__FILE__) + "/import-test-data.xml"
342
- end
343
-
344
- describe "when not logged in" do
345
-
346
- it "should raise an error" do
347
- lambda do
348
- @gateway.import(import_file)
349
- end.should raise_error(StandardError)
350
- end
351
-
352
- end
353
-
354
- describe "when logged in as admin" do
355
-
356
- def import_response
357
- <<-XML
358
- <api>
359
- <import>
360
- <page title='Main Page' ns='0' revisions='0'/>
361
- <page title='Template:Header' ns='10' revisions='1'/>
362
- </import>
363
- </api>
364
- XML
365
- end
366
-
367
- before do
368
- @gateway.login("atlasmw", "wombat")
369
- @page = @gateway.import(import_file)
370
- end
371
-
372
- it "should import content" do
373
- Hash.from_xml(@page.to_s) == Hash.from_xml(import_response)
374
- end
375
-
376
- end
377
-
378
- end
379
-
380
- describe "#export" do
381
-
382
- def export_data
383
- page = $fake_media_wiki.page_by_title("Main Page")
384
- <<-XML
385
- <mediawiki>
386
- <page>
387
- <title>#{page[:title]}</title>
388
- <id>#{page[:pageid]}</id>
389
- <revision>
390
- <id>#{page[:pageid]}</id>
391
- <text>#{page[:content]}</text>
392
- </revision>
393
- </page>
394
- </mediawiki>
395
- XML
396
- end
397
-
398
- before do
399
- @page = @gateway.export("Main Page")
400
- end
401
-
402
- it "should return export data for the page" do
403
- Hash.from_xml(@page.to_s).should == Hash.from_xml(export_data)
404
- end
405
-
406
- end
407
-
408
- describe "#list" do
409
-
410
- before do
411
- $fake_media_wiki.reset
412
- end
413
-
414
- describe "with an empty key" do
415
-
416
- before do
417
- @list = @gateway.list("")
418
- end
419
-
420
- it "should list all pages" do
421
- @list.sort.should == [ "Book:Italy", "Level/Level/Index", "Main 2", "Main Page" ]
422
- end
423
-
424
- end
425
-
426
- describe "with a namespace as the key" do
427
-
428
- before do
429
- @list = @gateway.list("Book:")
430
- end
431
-
432
- it "should list all pages in the namespace" do
433
- @list.should == [ "Book:Italy" ]
434
- end
435
-
436
- end
437
-
438
- describe "with a partial title as the key" do
439
-
440
- before do
441
- @list = @gateway.list("Main")
442
- end
443
-
444
- it "should list all pages in the main namespace that start with key" do
445
- @list.sort.should == [ "Main 2", "Main Page" ]
446
- end
447
-
448
- end
449
-
450
- end
451
-
452
- describe "#search" do
453
-
454
- before do
455
- $fake_media_wiki.reset
456
- @gateway.create("Search Test", "Foo KEY Blah")
457
- @gateway.create("Search Test 2", "Zomp KEY Zorg")
458
- @gateway.create("Book:Search Test", "Bar KEY Baz")
459
- @gateway.create("Sandbox:Search Test", "Evil KEY Evil")
460
- end
461
-
462
- describe "with an empty key" do
463
-
464
- it "should raise an error" do
465
- lambda do
466
- @gateway.search("")
467
- end.should raise_error(StandardError)
468
- end
469
-
470
- end
471
-
472
- describe "with a valid key and no namespaces" do
473
-
474
- before do
475
- @search = @gateway.search("KEY")
476
- end
477
-
478
- it "should list all matching pages in the main namespace" do
479
- @search.should == [ "Search Test", "Search Test 2" ]
480
- end
481
-
482
- end
483
-
484
- describe "with a valid key and a namespace string" do
485
-
486
- before do
487
- @search = @gateway.search("KEY", "Book")
488
- end
489
-
490
- it "should list all matching pages in the specified namespaces" do
491
- @search.should == [ "Book:Search Test" ]
492
- end
493
-
494
- end
495
-
496
- describe "with a valid key and a namespace array" do
497
-
498
- before do
499
- @search = @gateway.search("KEY", ["Book", "Sandbox"])
500
- end
501
-
502
- it "should list all matching pages in the specified namespaces" do
503
- @search.should == [ "Sandbox:Search Test", "Book:Search Test" ]
504
- end
505
-
506
- end
507
-
508
- end
509
-
510
- describe "#namespaces_by_prefix" do
511
-
512
- before do
513
- $fake_media_wiki.reset
514
- @namespaces = @gateway.namespaces_by_prefix
515
- end
516
-
517
- it "should list all namespaces" do
518
- @namespaces.should == { "" => 0, "Book" => 100, "Sandbox" => 200}
519
- end
520
-
521
- end
522
-
523
- describe "#extensions" do
524
-
525
- before do
526
- $fake_media_wiki.reset
527
- @extensions = @gateway.extensions
528
- end
529
-
530
- it "should list all namespaces" do
531
- @extensions.should == { "FooExtension" => "r1", "BarExtension" => "r2" }
532
- end
533
-
534
- end
535
- end