mediawiki-gateway 0.6.2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +22 -0
  3. data/ChangeLog +16 -0
  4. data/README.md +80 -21
  5. data/Rakefile +28 -34
  6. data/bin/mediawiki-gateway +203 -0
  7. data/lib/media_wiki.rb +4 -9
  8. data/lib/media_wiki/exception.rb +11 -8
  9. data/lib/media_wiki/fake_wiki.rb +636 -0
  10. data/lib/media_wiki/gateway.rb +105 -940
  11. data/lib/media_wiki/gateway/files.rb +173 -0
  12. data/lib/media_wiki/gateway/pages.rb +400 -0
  13. data/lib/media_wiki/gateway/query.rb +98 -0
  14. data/lib/media_wiki/gateway/site.rb +101 -0
  15. data/lib/media_wiki/gateway/users.rb +182 -0
  16. data/lib/media_wiki/utils.rb +47 -13
  17. data/lib/media_wiki/version.rb +27 -0
  18. data/lib/mediawiki-gateway.rb +1 -0
  19. data/spec/{import-test-data.xml → data/import.xml} +0 -0
  20. data/spec/media_wiki/gateway/files_spec.rb +34 -0
  21. data/spec/media_wiki/gateway/pages_spec.rb +390 -0
  22. data/spec/media_wiki/gateway/query_spec.rb +84 -0
  23. data/spec/media_wiki/gateway/site_spec.rb +122 -0
  24. data/spec/media_wiki/gateway/users_spec.rb +171 -0
  25. data/spec/media_wiki/gateway_spec.rb +129 -0
  26. data/spec/{live_gateway_spec.rb → media_wiki/live_gateway_spec.rb} +31 -35
  27. data/spec/{utils_spec.rb → media_wiki/utils_spec.rb} +41 -39
  28. data/spec/spec_helper.rb +17 -16
  29. metadata +77 -135
  30. data/.ruby-version +0 -1
  31. data/.rvmrc +0 -34
  32. data/Gemfile +0 -19
  33. data/Gemfile.lock +0 -77
  34. data/LICENSE +0 -21
  35. data/config/hosts.yml +0 -17
  36. data/lib/media_wiki/config.rb +0 -69
  37. data/mediawiki-gateway.gemspec +0 -113
  38. data/samples/README +0 -18
  39. data/samples/create_page.rb +0 -13
  40. data/samples/delete_batch.rb +0 -14
  41. data/samples/download_batch.rb +0 -15
  42. data/samples/email_user.rb +0 -14
  43. data/samples/export_xml.rb +0 -14
  44. data/samples/get_page.rb +0 -11
  45. data/samples/import_xml.rb +0 -14
  46. data/samples/run_fake_media_wiki.rb +0 -8
  47. data/samples/search_content.rb +0 -12
  48. data/samples/semantic_query.rb +0 -17
  49. data/samples/upload_commons.rb +0 -45
  50. data/samples/upload_file.rb +0 -13
  51. data/spec/fake_media_wiki/api_pages.rb +0 -135
  52. data/spec/fake_media_wiki/app.rb +0 -360
  53. data/spec/fake_media_wiki/query_handling.rb +0 -136
  54. data/spec/gateway_spec.rb +0 -888
@@ -1 +0,0 @@
1
- 1.9.3-p448
data/.rvmrc DELETED
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p194@mediawiki-gateway"
10
-
11
- # Uncomment the following lines if you want to verify rvm version per project
12
- # rvmrc_rvm_version="1.14.5 (stable)" # 1.10.1 seams as a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
-
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficient compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
- then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
- [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
- \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
- else
29
- # If the environment file has not yet been created, use the RVM CLI to select.
30
- rvm --create "$environment_id" || {
31
- echo "Failed to create RVM environment '${environment_id}'."
32
- return 1
33
- }
34
- fi
data/Gemfile DELETED
@@ -1,19 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'rest-client', '>= 1.3.0'
4
- gem 'activesupport'
5
-
6
- group :development do
7
- gem 'atomic'
8
- gem 'jeweler'
9
- gem 'sham_rack'
10
- gem 'rr'
11
- gem 'simplecov'
12
- gem 'rspec', '~> 1.3'
13
- gem 'rspec-core'
14
- gem 'rspec-expectations'
15
- gem 'rspec-mocks'
16
- gem 'debugger'
17
- gem 'sinatra'
18
- gem 'activemodel'
19
- end
@@ -1,77 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- activemodel (3.2.8)
5
- activesupport (= 3.2.8)
6
- builder (~> 3.0.0)
7
- activesupport (3.2.8)
8
- i18n (~> 0.6)
9
- multi_json (~> 1.0)
10
- atomic (1.1.16)
11
- builder (3.0.0)
12
- columnize (0.3.6)
13
- debugger (1.6.1)
14
- columnize (>= 0.3.1)
15
- debugger-linecache (~> 1.2.0)
16
- debugger-ruby_core_source (~> 1.2.3)
17
- debugger-linecache (1.2.0)
18
- debugger-ruby_core_source (1.2.3)
19
- diff-lcs (1.2.5)
20
- git (1.2.5)
21
- i18n (0.6.0)
22
- jeweler (1.8.4)
23
- bundler (~> 1.0)
24
- git (>= 1.2.5)
25
- rake
26
- rdoc
27
- json (1.7.5)
28
- mime-types (1.19)
29
- multi_json (1.3.6)
30
- rack (1.4.1)
31
- rack-protection (1.2.0)
32
- rack
33
- rake (0.9.2.2)
34
- rdoc (3.12)
35
- json (~> 1.4)
36
- rest-client (1.6.7)
37
- mime-types (>= 1.16)
38
- rr (1.0.4)
39
- rspec (1.3.2)
40
- rspec-core (3.0.3)
41
- rspec-support (~> 3.0.0)
42
- rspec-expectations (3.0.3)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.0.0)
45
- rspec-mocks (3.0.3)
46
- rspec-support (~> 3.0.0)
47
- rspec-support (3.0.3)
48
- sham_rack (1.3.4)
49
- rack
50
- simplecov (0.6.4)
51
- multi_json (~> 1.0)
52
- simplecov-html (~> 0.5.3)
53
- simplecov-html (0.5.3)
54
- sinatra (1.3.3)
55
- rack (~> 1.3, >= 1.3.6)
56
- rack-protection (~> 1.2)
57
- tilt (~> 1.3, >= 1.3.3)
58
- tilt (1.3.3)
59
-
60
- PLATFORMS
61
- ruby
62
-
63
- DEPENDENCIES
64
- activemodel
65
- activesupport
66
- atomic
67
- debugger
68
- jeweler
69
- rest-client (>= 1.3.0)
70
- rr
71
- rspec (~> 1.3)
72
- rspec-core
73
- rspec-expectations
74
- rspec-mocks
75
- sham_rack
76
- simplecov
77
- sinatra
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- Copyright (c) Jani Patokallio and Lonely Planet 2010-2013
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
@@ -1,17 +0,0 @@
1
- ---
2
- en-wp:
3
- url: http://en.wikipedia.org/w/api.php
4
- pw: password
5
- user: username
6
- commons:
7
- url: http://commons.wikimedia.org/w/api.php
8
- pw: password
9
- user: username
10
- en-wv:
11
- url: http://en.wikivoyage.org/w/api.php
12
- pw: password
13
- user: username
14
- local:
15
- url: http://localhost/w/api.php
16
- pw: password
17
- user: username
@@ -1,69 +0,0 @@
1
- require 'optparse'
2
- require 'yaml'
3
-
4
- module MediaWiki
5
-
6
- class Config
7
-
8
- attr_reader :article, :desc, :file, :pw, :summary, :target, :url, :user
9
-
10
- def initialize(args, type = "read")
11
- @summary = "Automated edit via MediaWiki::Gateway"
12
- @opts = OptionParser.new do |opts|
13
- opts.banner = "Usage: [options]"
14
-
15
- opts.on("-h", "--host HOST", "Use preconfigured HOST in config/hosts.yml") do |host_id|
16
- yaml = YAML.load_file('config/hosts.yml')
17
- if yaml.include? host_id
18
- host = yaml[host_id]
19
- @url = host['url']
20
- @pw = host['pw']
21
- @user = host['user']
22
- else
23
- raise "Host #{host_id} not found in config/hosts.yml"
24
- end
25
- end
26
-
27
- if type == "upload"
28
- opts.on("-d", "--description DESCRIPTION", "Description of file to upload") do |desc|
29
- @desc = desc
30
- end
31
- opts.on("-t", "--target-file TARGET-FILE", "Target file name to upload to") do |target|
32
- @target = target
33
- end
34
- else
35
- opts.on("-a", "--article ARTICLE", "Name of article in Wiki") do |article|
36
- @article = article
37
- end
38
- end
39
-
40
- opts.on("-n", "--username USERNAME", "Username for login") do |user|
41
- @user = user
42
- end
43
-
44
- opts.on("-p", "--password PASSWORD", "Password for login") do |pw|
45
- @pw = pw
46
- end
47
-
48
- if type != "read"
49
- opts.on("-s", "--summary SUMMARY", "Edit summary for this change") do |summary|
50
- @summary = summary
51
- end
52
- end
53
-
54
- opts.on("-u", "--url URL", "MediaWiki API URL") do |url|
55
- @url = url
56
- end
57
- end
58
- @opts.parse!
59
- abort("URL (-u) or valid host (-h) is mandatory.") unless @url
60
- end
61
-
62
- def abort(error)
63
- puts "Error: #{error}\n\n#{@opts.to_s}"
64
- exit
65
- end
66
-
67
- end
68
- end
69
-
@@ -1,113 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: mediawiki-gateway 0.6.2 ruby lib
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "mediawiki-gateway"
9
- s.version = "0.6.2"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Jani Patokallio"]
14
- s.date = "2014-09-29"
15
- s.description = ""
16
- s.email = "jpatokal@iki.fi"
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".ruby-version",
23
- ".rvmrc",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE",
27
- "README.md",
28
- "Rakefile",
29
- "config/hosts.yml",
30
- "lib/media_wiki.rb",
31
- "lib/media_wiki/config.rb",
32
- "lib/media_wiki/exception.rb",
33
- "lib/media_wiki/gateway.rb",
34
- "lib/media_wiki/utils.rb",
35
- "mediawiki-gateway.gemspec",
36
- "samples/README",
37
- "samples/create_page.rb",
38
- "samples/delete_batch.rb",
39
- "samples/download_batch.rb",
40
- "samples/email_user.rb",
41
- "samples/export_xml.rb",
42
- "samples/get_page.rb",
43
- "samples/import_xml.rb",
44
- "samples/run_fake_media_wiki.rb",
45
- "samples/search_content.rb",
46
- "samples/semantic_query.rb",
47
- "samples/upload_commons.rb",
48
- "samples/upload_file.rb",
49
- "spec/fake_media_wiki/api_pages.rb",
50
- "spec/fake_media_wiki/app.rb",
51
- "spec/fake_media_wiki/query_handling.rb",
52
- "spec/gateway_spec.rb",
53
- "spec/import-test-data.xml",
54
- "spec/live_gateway_spec.rb",
55
- "spec/spec_helper.rb",
56
- "spec/utils_spec.rb"
57
- ]
58
- s.homepage = "http://github.com/jpatokal/mediawiki-gateway"
59
- s.rubygems_version = "2.4.1"
60
- s.summary = "Connect to the mediawiki API"
61
-
62
- if s.respond_to? :specification_version then
63
- s.specification_version = 4
64
-
65
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
- s.add_runtime_dependency(%q<rest-client>, [">= 1.3.0"])
67
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
68
- s.add_development_dependency(%q<atomic>, [">= 0"])
69
- s.add_development_dependency(%q<jeweler>, [">= 0"])
70
- s.add_development_dependency(%q<sham_rack>, [">= 0"])
71
- s.add_development_dependency(%q<rr>, [">= 0"])
72
- s.add_development_dependency(%q<simplecov>, [">= 0"])
73
- s.add_development_dependency(%q<rspec>, ["~> 1.3"])
74
- s.add_development_dependency(%q<rspec-core>, [">= 0"])
75
- s.add_development_dependency(%q<rspec-expectations>, [">= 0"])
76
- s.add_development_dependency(%q<rspec-mocks>, [">= 0"])
77
- s.add_development_dependency(%q<debugger>, [">= 0"])
78
- s.add_development_dependency(%q<sinatra>, [">= 0"])
79
- s.add_development_dependency(%q<activemodel>, [">= 0"])
80
- else
81
- s.add_dependency(%q<rest-client>, [">= 1.3.0"])
82
- s.add_dependency(%q<activesupport>, [">= 0"])
83
- s.add_dependency(%q<atomic>, [">= 0"])
84
- s.add_dependency(%q<jeweler>, [">= 0"])
85
- s.add_dependency(%q<sham_rack>, [">= 0"])
86
- s.add_dependency(%q<rr>, [">= 0"])
87
- s.add_dependency(%q<simplecov>, [">= 0"])
88
- s.add_dependency(%q<rspec>, ["~> 1.3"])
89
- s.add_dependency(%q<rspec-core>, [">= 0"])
90
- s.add_dependency(%q<rspec-expectations>, [">= 0"])
91
- s.add_dependency(%q<rspec-mocks>, [">= 0"])
92
- s.add_dependency(%q<debugger>, [">= 0"])
93
- s.add_dependency(%q<sinatra>, [">= 0"])
94
- s.add_dependency(%q<activemodel>, [">= 0"])
95
- end
96
- else
97
- s.add_dependency(%q<rest-client>, [">= 1.3.0"])
98
- s.add_dependency(%q<activesupport>, [">= 0"])
99
- s.add_dependency(%q<atomic>, [">= 0"])
100
- s.add_dependency(%q<jeweler>, [">= 0"])
101
- s.add_dependency(%q<sham_rack>, [">= 0"])
102
- s.add_dependency(%q<rr>, [">= 0"])
103
- s.add_dependency(%q<simplecov>, [">= 0"])
104
- s.add_dependency(%q<rspec>, ["~> 1.3"])
105
- s.add_dependency(%q<rspec-core>, [">= 0"])
106
- s.add_dependency(%q<rspec-expectations>, [">= 0"])
107
- s.add_dependency(%q<rspec-mocks>, [">= 0"])
108
- s.add_dependency(%q<debugger>, [">= 0"])
109
- s.add_dependency(%q<sinatra>, [">= 0"])
110
- s.add_dependency(%q<activemodel>, [">= 0"])
111
- end
112
- end
113
-
@@ -1,18 +0,0 @@
1
- Samples for using MediaWiki::Gateway. These expect to be run from the MediaWiki::Gateway root directory with ./config/hosts.yml accessible and configured with real usernames, passwords etc. Remove Logger::DEBUG from samples for less verbose output.
2
-
3
- All the samples use the local instance of MediaWiki::Gateway in ./lib. To use an installed gem, use this require line instead:
4
-
5
- require 'media_wiki'
6
-
7
- Examples:
8
-
9
- Check syntax for create page sample script
10
-
11
- ruby samples/create_page.rb
12
-
13
- Pipe the content of "content.txt" into the page 'Sandbox:MediaWikiGatewayTest' on the English Wikipedia
14
-
15
- ruby samples/create_page.rb -h en-wp -a Sandbox:MediaWikiGatewayTest <content.txt
16
- *or*
17
- ruby samples/create_page.rb --host en-wp --article Sandbox:MediaWikiGatewayTest <content.txt
18
-
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Sample script for updating a MediaWiki article's content
4
- #
5
- require './lib/media_wiki'
6
-
7
- config = MediaWiki::Config.new ARGV
8
- config.abort("Name of article is mandatory.") unless config.article
9
-
10
- mw = MediaWiki::Gateway.new(config.url, { :loglevel => Logger::DEBUG } )
11
- mw.login(config.user, config.pw)
12
- content = ARGF.read.to_s
13
- puts mw.create(config.article, content, {:overwrite => true, :summary => config.summary})
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require './lib/media_wiki'
3
-
4
- if ARGV.length <1
5
- raise "Syntax: delete_batch.rb <wiki-api-url> <startswith_pattern>"
6
- end
7
-
8
- rw = MediaWiki::Gateway.new(ARGV[0])
9
- rw.list(ARGV[1]).each do |title|
10
- print "Deleting #{title}..."
11
- rw.delete(title)
12
- end
13
- print "Done."
14
-
@@ -1,15 +0,0 @@
1
- require './lib/media_wiki'
2
-
3
- config = MediaWiki::Config.new ARGV
4
-
5
- mw = MediaWiki::Gateway.new(config.url, { :loglevel => Logger::DEBUG } )
6
- mw.login(config.user, config.pw)
7
- ARGF.readlines.each do |image|
8
- image.strip!
9
- unless File.exist? image
10
- File.open(image, 'w') do |file|
11
- file.write(mw.download(image))
12
- end
13
- end
14
- end
15
-
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Sample script for sending e-mail to a registered user
4
- #
5
- require './lib/media_wiki'
6
-
7
- config = MediaWiki::Config.new ARGV
8
- user, subject = ARGV
9
- config.abort("Syntax: email_user.rb [username] [subject] <content") unless user and subject
10
-
11
- mw = MediaWiki::Gateway.new(config.url, { :loglevel => Logger::DEBUG } )
12
- mw.login(config.user, config.pw)
13
- content = STDIN.read
14
- mw.email_user(user, subject, content)
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Export MediaWiki pages as XML
4
- #
5
- require './lib/media_wiki'
6
-
7
- if ARGV.length < 3
8
- raise "Syntax: export_xml.rb <host> <user> <password> [page page page...]"
9
- end
10
-
11
- mw = MediaWiki::Gateway.new(ARGV[0])
12
- mw.login(ARGV[1], ARGV[2])
13
- print mw.export(ARGV[3..-1])
14
-