mediawiki-gateway 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/README +4 -0
  2. data/Rakefile +4 -3
  3. data/VERSION +1 -1
  4. data/doc/classes/MediaWiki.html +8 -8
  5. data/doc/classes/MediaWiki/Config.html +71 -71
  6. data/doc/classes/MediaWiki/Gateway.html +474 -262
  7. data/doc/created.rid +1 -1
  8. data/doc/files/{README_txt.html → README.html} +8 -5
  9. data/doc/files/{script/delete_book_rb.html → lib/media_wiki/config_rb.html} +7 -6
  10. data/doc/files/{media_wiki → lib/media_wiki}/gateway_rb.html +3 -4
  11. data/doc/files/{media_wiki → lib/media_wiki}/utils_rb.html +2 -2
  12. data/doc/files/script/create_page_rb.html +2 -3
  13. data/doc/files/{media_wiki/config_rb.html → script/delete_batch_rb.html} +5 -5
  14. data/doc/files/script/export_xml_rb.html +2 -2
  15. data/doc/files/script/get_page_rb.html +2 -2
  16. data/doc/files/script/import_xml_rb.html +2 -2
  17. data/doc/files/script/run_fake_media_wiki_rb.html +117 -0
  18. data/doc/files/script/upload_commons_rb.html +2 -3
  19. data/doc/files/script/upload_file_rb.html +2 -3
  20. data/doc/fr_file_index.html +6 -6
  21. data/doc/fr_method_index.html +13 -11
  22. data/doc/index.html +1 -1
  23. data/lib/media_wiki/gateway.rb +128 -15
  24. data/mediawiki-gateway.gemspec +12 -10
  25. data/script/create_page.rb +1 -2
  26. data/script/{delete_book.rb → delete_batch.rb} +1 -1
  27. data/script/export_xml.rb +1 -1
  28. data/script/get_page.rb +1 -1
  29. data/script/import_xml.rb +1 -1
  30. data/script/upload_commons.rb +1 -2
  31. data/script/upload_file.rb +1 -2
  32. data/spec/gateway_spec.rb +1 -1
  33. metadata +26 -14
  34. data/doc/files/script/undelete_page_rb.html +0 -101
  35. data/script/undelete_page.rb +0 -15
data/doc/index.html CHANGED
@@ -19,6 +19,6 @@
19
19
  <frame src="fr_class_index.html" name="Classes" />
20
20
  <frame src="fr_method_index.html" name="Methods" />
21
21
  </frameset>
22
- <frame src="files/README_txt.html" name="docwin" />
22
+ <frame src="files/README.html" name="docwin" />
23
23
  </frameset>
24
24
  </html>
@@ -152,28 +152,141 @@ module MediaWiki
152
152
  titles += REXML::XPath.match(make_api_request(form_data), "//p").map { |x| x.attributes["title"] }
153
153
  end
154
154
 
155
- # Upload file to MediaWiki
155
+ # Upload a file, or get the status of pending uploads. Several
156
+ # methods are available:
157
+ #
158
+ # * Upload file contents directly.
159
+ # * Have the MediaWiki server fetch a file from a URL, using the
160
+ # "url" parameter
161
+ #
156
162
  # Requires Mediawiki 1.16+
157
163
  #
158
- # [path] Path to file to upload
159
- # [options] Hash of additional options
164
+ # Arguments:
165
+ # * [path] Path to file to upload. Set to nil if uploading from URL.
166
+ # * [options] Hash of additional options
167
+ #
168
+ # Note that queries using session keys must be done in the same login
169
+ # session as the query that originally returned the key (i.e. do not
170
+ # log out and then log back in).
160
171
  #
161
172
  # Options:
162
- # * [description] Description of this file
163
- # * [target] Target filename, defaults to local name if not given
164
- # * [summary] Edit summary for history
173
+ # * 'filename' - Target filename (defaults to local name if not given), options[:target] is alias for this.
174
+ # * 'comment' - Upload comment. Also used as the initial page text for new files if "text" is not specified.
175
+ # * 'text' - Initial page text for new files
176
+ # * 'watch' - Watch the page
177
+ # * 'ignorewarnings' - Ignore any warnings
178
+ # * 'url' - Url to fetch the file from. Set path to nil if you want to use this.
179
+ #
180
+ # Deprecated but still supported options:
181
+ # * :description - Description of this file. Used as 'text'.
182
+ # * :target - Target filename, same as 'filename'.
183
+ # * :summary - Edit summary for history. Used as 'comment'. Also used as 'text' if neither it or :description is specified.
184
+ #
185
+ # Examples:
186
+ # mw.upload('/path/to/local/file.jpg', 'filename' => "RemoteFile.jpg")
187
+ # mw.upload(nil, 'filename' => "RemoteFile2.jpg", 'url' => 'http://remote.com/server/file.jpg')
188
+ #
165
189
  def upload(path, options={})
166
- comment = (options[:summary] || "Uploaded by MediaWiki::Gateway")
167
- file = File.new(path)
168
- filename = (options[:target] || File.basename(path))
169
- form_data = { 'action' => 'upload',
170
- 'filename' => filename,
171
- 'file' => file,
172
- 'token' => get_token('edit', filename),
173
- 'text' => (options[:description] || options[:summary]),
174
- 'comment' => comment}
190
+ if options[:description]
191
+ options['text'] = options[:description]
192
+ options.delete(:description)
193
+ end
194
+
195
+ if options[:target]
196
+ options['filename'] = options[:target]
197
+ options.delete(:target)
198
+ end
199
+
200
+ if options[:summary]
201
+ options['text'] ||= options[:summary]
202
+ options['comment'] = options[:summary]
203
+ options.delete(:summary)
204
+ end
205
+
206
+ options['comment'] ||= "Uploaded by MediaWiki::Gateway"
207
+ options['file'] = File.new(path) if path
208
+ full_name = path || options['url']
209
+ options['filename'] ||= File.basename(full_name) if full_name
210
+
211
+ raise ArgumentError.new(
212
+ "One of the 'file', 'url' or 'sessionkey' options must be specified!"
213
+ ) unless options['file'] || options['url'] || options['sessionkey']
214
+
215
+ form_data = options.merge(
216
+ 'action' => 'upload',
217
+ 'token' => get_token('edit', options['filename'])
218
+ )
219
+
175
220
  make_api_request(form_data)
176
221
  end
222
+
223
+ # Requests image info from MediaWiki. Follows redirects.
224
+ #
225
+ # _file_name_or_page_id_ should be either:
226
+ # * a file name (String) you want info about without File: prefix.
227
+ # * or a Fixnum page id you of the file.
228
+ #
229
+ # _options_ is +Hash+ passed as query arguments. See
230
+ # http://www.mediawiki.org/wiki/API:Query_-_Properties#imageinfo_.2F_ii
231
+ # for more information.
232
+ #
233
+ # options['iiprop'] should be either a string of properties joined by
234
+ # '|' or an +Array+ (or more precisely something that responds to #join).
235
+ #
236
+ # +Hash+ like object is returned where keys are image properties.
237
+ #
238
+ # Example:
239
+ # mw.image_info(
240
+ # "Trooper.jpg", 'iiprop' => ['timestamp', 'user']
241
+ # ).each do |key, value|
242
+ # puts "#{key.inspect} => #{value.inspect}"
243
+ # end
244
+ #
245
+ # Output:
246
+ # "timestamp" => "2009-10-31T12:59:11Z"
247
+ # "user" => "Valdas"
248
+ #
249
+ def image_info(file_name_or_page_id, options={})
250
+ options['iiprop'] = options['iiprop'].join('|') \
251
+ if options['iiprop'].respond_to?(:join)
252
+ form_data = options.merge(
253
+ 'action' => 'query',
254
+ 'prop' => 'imageinfo',
255
+ 'redirects' => true
256
+ )
257
+
258
+ case file_name_or_page_id
259
+ when Fixnum
260
+ form_data['pageids'] = file_name_or_page_id
261
+ else
262
+ form_data['titles'] = "File:#{file_name_or_page_id}"
263
+ end
264
+
265
+ xml = make_api_request(form_data)
266
+ page = xml.elements["query/pages/page"]
267
+ if ! page or page.attributes["missing"]
268
+ nil
269
+ elsif xml.elements["query/redirects/r"]
270
+ # We're dealing with redirect here.
271
+ image_info(page.attributes["pageid"].to_i, options)
272
+ else
273
+ page.elements["imageinfo/ii"].attributes
274
+ end
275
+ end
276
+
277
+ # Download _file_name_. Returns file contents. All options are passed to
278
+ # #image_info however options['iiprop'] is forced to url. You can still
279
+ # set other options to control what file you want to download.
280
+ def download(file_name, options={})
281
+ options['iiprop'] = 'url'
282
+
283
+ attributes = image_info(file_name, options)
284
+ if attributes
285
+ RestClient.get attributes['url']
286
+ else
287
+ nil
288
+ end
289
+ end
177
290
 
178
291
  # Imports a MediaWiki XML dump
179
292
  #
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mediawiki-gateway}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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-10-01}
12
+ s.date = %q{2010-10-15}
13
13
  s.description = %q{}
14
14
  s.email = %q{jpatokal@iki.fi}
15
15
  s.extra_rdoc_files = [
@@ -25,16 +25,16 @@ Gem::Specification.new do |s|
25
25
  "doc/classes/MediaWiki/Config.html",
26
26
  "doc/classes/MediaWiki/Gateway.html",
27
27
  "doc/created.rid",
28
- "doc/files/README_txt.html",
29
- "doc/files/media_wiki/config_rb.html",
30
- "doc/files/media_wiki/gateway_rb.html",
31
- "doc/files/media_wiki/utils_rb.html",
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
32
  "doc/files/script/create_page_rb.html",
33
- "doc/files/script/delete_book_rb.html",
33
+ "doc/files/script/delete_batch_rb.html",
34
34
  "doc/files/script/export_xml_rb.html",
35
35
  "doc/files/script/get_page_rb.html",
36
36
  "doc/files/script/import_xml_rb.html",
37
- "doc/files/script/undelete_page_rb.html",
37
+ "doc/files/script/run_fake_media_wiki_rb.html",
38
38
  "doc/files/script/upload_commons_rb.html",
39
39
  "doc/files/script/upload_file_rb.html",
40
40
  "doc/fr_class_index.html",
@@ -48,12 +48,11 @@ Gem::Specification.new do |s|
48
48
  "lib/media_wiki/utils.rb",
49
49
  "mediawiki-gateway.gemspec",
50
50
  "script/create_page.rb",
51
- "script/delete_book.rb",
51
+ "script/delete_batch.rb",
52
52
  "script/export_xml.rb",
53
53
  "script/get_page.rb",
54
54
  "script/import_xml.rb",
55
55
  "script/run_fake_media_wiki.rb",
56
- "script/undelete_page.rb",
57
56
  "script/upload_commons.rb",
58
57
  "script/upload_file.rb",
59
58
  "spec/fake_media_wiki/api_pages.rb",
@@ -80,9 +79,12 @@ Gem::Specification.new do |s|
80
79
  s.specification_version = 3
81
80
 
82
81
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
+ s.add_runtime_dependency(%q<rest_client>, [">= 0"])
83
83
  else
84
+ s.add_dependency(%q<rest_client>, [">= 0"])
84
85
  end
85
86
  else
87
+ s.add_dependency(%q<rest_client>, [">= 0"])
86
88
  end
87
89
  end
88
90
 
@@ -2,8 +2,7 @@
2
2
  #
3
3
  # Sample script for fetching a page's current contents in Wiki markup
4
4
  #
5
- require 'media_wiki/gateway'
6
- require 'media_wiki/config'
5
+ require 'lib/media_wiki'
7
6
 
8
7
  config = MediaWiki::Config.new ARGV
9
8
  config.abort("Name of article is mandatory.") unless config.article
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require 'media_wiki/gateway'
2
+ require 'lib/media_wiki'
3
3
 
4
4
  if ARGV.length <1
5
5
  raise "Syntax: delete_batch.rb <wiki-api-url> <startswith_pattern>"
data/script/export_xml.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Export MediaWiki pages as XML
4
4
  #
5
- require 'media_wiki/gateway'
5
+ require 'lib/media_wiki'
6
6
 
7
7
  if ARGV.length < 3
8
8
  raise "Syntax: export_xml.rb <host> <user> <password> [page page page...]"
data/script/get_page.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Sample script for fetching a page's current contents in Wiki markup
4
4
  #
5
- require 'media_wiki/gateway'
5
+ require 'lib/media_wiki'
6
6
 
7
7
  if ARGV.length < 2
8
8
  raise "Syntax: get_page.rb <host> <name>"
data/script/import_xml.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Import a MediaWiki XML dump
4
4
  #
5
- require 'media_wiki/gateway'
5
+ require 'lib/media_wiki'
6
6
 
7
7
  if ARGV.length < 3
8
8
  raise "Syntax: import_xml.rb <host> <username> <password> <file>"
@@ -1,5 +1,4 @@
1
- require 'lib/media_wiki/gateway'
2
- require 'lib/media_wiki/config'
1
+ require 'lib/media_wiki'
3
2
 
4
3
  config = MediaWiki::Config.new(ARGV, "upload")
5
4
  file = ARGV[0]
@@ -2,8 +2,7 @@
2
2
  #
3
3
  # Sample script for fetching a page's current contents in Wiki markup
4
4
  #
5
- require 'media_wiki/gateway'
6
- require 'media_wiki/config'
5
+ require 'lib/media_wiki'
7
6
 
8
7
  config = MediaWiki::Config.new(ARGV, "upload")
9
8
  config.abort("Name of file to upload is mandatory.") unless ARGV[0]
data/spec/gateway_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'active_support'
2
2
  require 'rr'
3
3
  require 'sham_rack'
4
4
 
5
- require 'media_wiki/gateway'
5
+ require 'media_wiki'
6
6
  require 'spec/fake_media_wiki/app'
7
7
 
8
8
  $fake_media_wiki = FakeMediaWiki::App.new
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jani Patokallio
@@ -15,10 +15,23 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-01 00:00:00 +10:00
18
+ date: 2010-10-15 00:00:00 +11:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rest_client
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
22
35
  description: ""
23
36
  email: jpatokal@iki.fi
24
37
  executables: []
@@ -37,16 +50,16 @@ files:
37
50
  - doc/classes/MediaWiki/Config.html
38
51
  - doc/classes/MediaWiki/Gateway.html
39
52
  - doc/created.rid
40
- - doc/files/README_txt.html
41
- - doc/files/media_wiki/config_rb.html
42
- - doc/files/media_wiki/gateway_rb.html
43
- - doc/files/media_wiki/utils_rb.html
53
+ - doc/files/README.html
54
+ - doc/files/lib/media_wiki/config_rb.html
55
+ - doc/files/lib/media_wiki/gateway_rb.html
56
+ - doc/files/lib/media_wiki/utils_rb.html
44
57
  - doc/files/script/create_page_rb.html
45
- - doc/files/script/delete_book_rb.html
58
+ - doc/files/script/delete_batch_rb.html
46
59
  - doc/files/script/export_xml_rb.html
47
60
  - doc/files/script/get_page_rb.html
48
61
  - doc/files/script/import_xml_rb.html
49
- - doc/files/script/undelete_page_rb.html
62
+ - doc/files/script/run_fake_media_wiki_rb.html
50
63
  - doc/files/script/upload_commons_rb.html
51
64
  - doc/files/script/upload_file_rb.html
52
65
  - doc/fr_class_index.html
@@ -60,12 +73,11 @@ files:
60
73
  - lib/media_wiki/utils.rb
61
74
  - mediawiki-gateway.gemspec
62
75
  - script/create_page.rb
63
- - script/delete_book.rb
76
+ - script/delete_batch.rb
64
77
  - script/export_xml.rb
65
78
  - script/get_page.rb
66
79
  - script/import_xml.rb
67
80
  - script/run_fake_media_wiki.rb
68
- - script/undelete_page.rb
69
81
  - script/upload_commons.rb
70
82
  - script/upload_file.rb
71
83
  - spec/fake_media_wiki/api_pages.rb
@@ -1,101 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>File: undelete_page.rb</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="fileHeader">
50
- <h1>undelete_page.rb</h1>
51
- <table class="header-table">
52
- <tr class="top-aligned-row">
53
- <td><strong>Path:</strong></td>
54
- <td>script/undelete_page.rb
55
- </td>
56
- </tr>
57
- <tr class="top-aligned-row">
58
- <td><strong>Last Update:</strong></td>
59
- <td>Thu Aug 05 17:26:12 +1000 2010</td>
60
- </tr>
61
- </table>
62
- </div>
63
- <!-- banner header -->
64
-
65
- <div id="bodyContent">
66
-
67
-
68
-
69
- <div id="contextContent">
70
-
71
-
72
-
73
- </div>
74
-
75
-
76
- </div>
77
-
78
-
79
- <!-- if includes -->
80
-
81
- <div id="section">
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
- <!-- if method_list -->
91
-
92
-
93
- </div>
94
-
95
-
96
- <div id="validator-badges">
97
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
98
- </div>
99
-
100
- </body>
101
- </html>