mediawiki-gateway 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9348630e11f96f1c356898c7c788f0a92331da51
4
- data.tar.gz: 04cb698dc943616403ea27dbbfc9ab02a89b1cc8
3
+ metadata.gz: 3bf439067ecdc78862001617673b8f7eca06812b
4
+ data.tar.gz: 2bc0d1305900bbc69f8bd66ab3809d3fefa64849
5
5
  SHA512:
6
- metadata.gz: 3103c1160612dd0edd49e5fde0e5a1af1ed08e49910185d45f37b0b82fcae2829d93cc8ac0e956441e0d65dc27fe96cb64a3850fe284c44cbee28ad04cc3a813
7
- data.tar.gz: 77190501400ca7b3213cfcbe0de6a2683ac7324c0550007cf321538a7c1adeae55630e338d0ff965a9969fdea0db4a4ee282005733ad1748bc9f89bcf0159a18
6
+ metadata.gz: 1a357d4c39d1d86a2a493e1c0f954c8e5a3095eaa8d4afb6eeb583cbd8512744f0d011eae82914a4455f1fde499cd75dd18bd895bc1dd4d872b58b2e87a9205d
7
+ data.tar.gz: eaa97ac659108a0cf6fead74380619706c274309b8a7073aa64b22d7fa38a6492385895a0ee7a2312393aded3951c63ecc82c28b70c26b78f5694c9209a265de
data/ChangeLog CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  = Revision history for mediawiki-gateway
4
4
 
5
+ == 1.1.0 [2016-01-05]
6
+
7
+ * Allow empty params for semantic_query.
8
+ * Add a method to purge a page. Pull request #93 by MusikAnimal.
9
+ * Follow redirects if HTTP 301, 302 or 307 is returned. Pull request #86
10
+ by Brandon Liu.
11
+ * Change exception superclass to StandardError. Pull request #85 by
12
+ Brandon Liu.
13
+ * Fixed categorymembers to use new continue rules. Pull request #82
14
+ by Asaf Bartov.
15
+ * Fix search to return nil if namespace not found. Pull request #88 by
16
+ Alexander Adrianov.
17
+ * Fixed MediaWiki::Gateway::Users#contributions to not continue when enough
18
+ contributions have been received. Pull request #79 by Michaël Witrant.
19
+
5
20
  == 1.0.0 [2014-10-31]
6
21
 
7
22
  * <b>Required Ruby version is now 1.9.3 or higher.</b>
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A Ruby framework for [MediaWiki API](http://www.mediawiki.org/wiki/API:Main_page) manipulation.
4
4
 
5
+ **Note**: This library is not actively maintained and uses deprecated API methods.
6
+ If you are starting a new project, please use the official Wikimedia Ruby client at
7
+ https://github.com/wikimedia/mediawiki-ruby-api instead.
8
+
5
9
  ## Features
6
10
 
7
11
  * Simple, elegant syntax for common operations
@@ -9,7 +13,8 @@ A Ruby framework for [MediaWiki API](http://www.mediawiki.org/wiki/API:Main_page
9
13
  * List, search operations work around API limits to fetch all results
10
14
  * Support for maxlag detection and automated retries on 503
11
15
  * Integrated logging
12
- * Tested up to MediaWiki 1.23
16
+ * Tested up to MediaWiki 1.24
17
+ * For 1.25+, you must skip deprecation warnings with `:ignorewarnings => true` in `MediaWiki::Gateway.new`. See [issue #69](https://github.com/jpatokal/mediawiki-gateway/issues/69).
13
18
  * Should work with Ruby 1.9.3 and higher
14
19
 
15
20
  ## Links
@@ -1,7 +1,7 @@
1
1
  module MediaWiki
2
2
 
3
3
  # General exception occurred within MediaWiki::Gateway, and parent class for MediaWiki::APIError, MediaWiki::Unauthorized.
4
- class Exception < ::Exception
4
+ class Exception < ::StandardError
5
5
  end
6
6
 
7
7
  # Wrapper for errors returned by MediaWiki API. Possible codes are defined in http://www.mediawiki.org/wiki/API:Errors_and_warnings.
@@ -127,7 +127,7 @@ module MediaWiki
127
127
  def make_api_request(form_data, continue_xpath = nil, retry_count = 1)
128
128
  form_data.update('format' => 'xml', 'maxlag' => @options[:maxlag])
129
129
 
130
- http_send(@wiki_url, form_data, @headers.merge(cookies: @cookies)) { |response, &block|
130
+ http_send(@wiki_url, form_data, @headers.merge(cookies: @cookies)) do |response|
131
131
  if response.code == 503 && retry_count < @options[:retry_count]
132
132
  log.warn("503 Service Unavailable: #{response.body}. Retry in #{@options[:retry_delay]} seconds.")
133
133
  sleep(@options[:retry_delay])
@@ -168,10 +168,11 @@ module MediaWiki
168
168
 
169
169
  return [doc, (continue_xpath && doc.elements['query-continue']) ?
170
170
  REXML::XPath.first(doc, continue_xpath) : nil]
171
- }
171
+ end
172
172
  end
173
173
 
174
- # Execute the HTTP request using either GET or POST as appropriate
174
+ # Execute the HTTP request using either GET or POST as appropriate.
175
+ # @yieldparam response
175
176
  def http_send url, form_data, headers, &block
176
177
  opts = @http_options.merge(url: url, headers: headers)
177
178
  opts[:method] = form_data['action'] == 'query' ? :get : :post
@@ -179,7 +180,20 @@ module MediaWiki
179
180
 
180
181
  log.debug("#{opts[:method].upcase}: #{form_data.inspect}, #{@cookies.inspect}")
181
182
 
182
- RestClient::Request.execute(opts, &block)
183
+ RestClient::Request.execute(opts) do |response, request, result|
184
+ # When a block is passed to RestClient::Request.execute, we must
185
+ # manually handle response codes ourselves. If no block is passed,
186
+ # then redirects are automatically handled, but HTTP errors also
187
+ # result in exceptions being raised. For now, we manually check for
188
+ # HTTP 503 errors (see: #make_api_request), but we must also manually
189
+ # handle HTTP redirects.
190
+ if [301, 302, 307].include?(response.code) && request.method == :get
191
+ response = response.follow_redirection(request, result)
192
+ end
193
+
194
+ block.call(response)
195
+ end
196
+
183
197
  end
184
198
 
185
199
  # Get API XML response
@@ -274,6 +274,7 @@ module MediaWiki
274
274
  def category_members(category, options = {})
275
275
  iterate_query('categorymembers', '//cm', 'title', 'cmcontinue', options.merge(
276
276
  'cmtitle' => category,
277
+ 'continue' => '', # new format, per https://www.mediawiki.org/wiki/API:Query#Continuing_queries
277
278
  'cmlimit' => @options[:limit]
278
279
  ))
279
280
  end
@@ -341,6 +342,19 @@ module MediaWiki
341
342
  end
342
343
  end
343
344
 
345
+ # Purge MediaWiki page. Does not follow redirects.
346
+ #
347
+ # [page_titles] Page titles to purge
348
+ # [options] Hash of additional options
349
+ #
350
+ # Returns purge object
351
+ def purge(page_titles, options = {})
352
+ page = send_request(options.merge(
353
+ 'action' => 'purge',
354
+ 'titles' => page_titles
355
+ ))
356
+ end
357
+
344
358
  # Convenience wrapper for _langlinks_ returning the title in language _lang_ (ISO code) for a given article of pageid, if it exists, via the interlanguage link
345
359
  #
346
360
  # Example:
@@ -25,7 +25,7 @@ module MediaWiki
25
25
  if namespaces
26
26
  form_data['srnamespace'] = Array(namespaces).map! { |ns|
27
27
  namespaces_by_prefix[ns]
28
- }.join('|')
28
+ }.compact.join('|')
29
29
  end
30
30
 
31
31
  begin
@@ -55,13 +55,13 @@ module MediaWiki
55
55
  if smw_version.to_f >= 1.7
56
56
  send_request(options.merge(
57
57
  'action' => 'ask',
58
- 'query' => "#{query}|#{params.join('|')}"
58
+ 'query' => [query, *params].join('|')
59
59
  ))
60
60
  else
61
61
  send_request(options.merge(
62
62
  'action' => 'parse',
63
63
  'prop' => 'text',
64
- 'text' => "{{#ask:#{query}|#{params.push('format=list').join('|')}}}"
64
+ 'text' => "{{#ask:#{[query, 'format=list', *params].join('|')}}}"
65
65
  )).elements['parse/text'].text
66
66
  end
67
67
  end
@@ -37,8 +37,8 @@ module MediaWiki
37
37
 
38
38
  # Get user contributions
39
39
  #
40
- # user: The user name
41
- # count: Maximum number of contributions to retreive, or nil for all
40
+ # [user] The user name
41
+ # [count] Maximum number of contributions to retrieve, or nil for all
42
42
  # [options] Optional hash of options, eg. { 'ucnamespace' => 4 }. See http://www.mediawiki.org/wiki/API:Usercontribs
43
43
  #
44
44
  # Returns array of hashes containing the "item" attributes defined here: http://www.mediawiki.org/wiki/API:Usercontribs
@@ -51,6 +51,7 @@ module MediaWiki
51
51
  )) { |element|
52
52
  result << hash = {}
53
53
  element.attributes.each { |key, value| hash[key] = value }
54
+ break if count && result.size >= count
54
55
  }
55
56
 
56
57
  count ? result.take(count) : result
@@ -3,7 +3,7 @@ module MediaWiki
3
3
  module Version
4
4
 
5
5
  MAJOR = 1
6
- MINOR = 0
6
+ MINOR = 1
7
7
  PATCH = 0
8
8
 
9
9
  class << self
@@ -753,7 +753,7 @@ end
753
753
  unless (pool_size = Integer(ENV['LIVE_POOL_SIZE'] || 2)) > 1
754
754
  warn 'Docker pool size must be greater than 1.'
755
755
  else
756
- ENV.fetch('LIVE_VERSION', '1.23.4').split(/[\s:,]/).each { |version|
756
+ ENV.fetch('LIVE_VERSION', '1.23.7').split(/[\s:,]/).each { |version|
757
757
  describe_live(MediaWiki::Gateway, version: version, pool_size: pool_size) {
758
758
  include_examples 'live gateway'
759
759
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki-gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jani Patokallio
@@ -9,124 +9,124 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-31 00:00:00.000000000 Z
12
+ date: 2016-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.7'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.7'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: equivalent-xml
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: nokogiri
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: sham_rack
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: sinatra
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: hen
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ~>
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0.8'
91
- - - ">="
91
+ - - '>='
92
92
  - !ruby/object:Gem::Version
93
- version: 0.8.0
93
+ version: 0.8.3
94
94
  type: :development
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - "~>"
98
+ - - ~>
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0.8'
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.8.0
103
+ version: 0.8.3
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rake
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: rspec
120
120
  requirement: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  type: :development
126
126
  prerelease: false
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  description: A Ruby framework for MediaWiki API manipulation.
@@ -141,11 +141,6 @@ extra_rdoc_files:
141
141
  - ChangeLog
142
142
  - README.md
143
143
  files:
144
- - COPYING
145
- - ChangeLog
146
- - README.md
147
- - Rakefile
148
- - bin/mediawiki-gateway
149
144
  - lib/media_wiki.rb
150
145
  - lib/media_wiki/exception.rb
151
146
  - lib/media_wiki/fake_wiki.rb
@@ -158,6 +153,11 @@ files:
158
153
  - lib/media_wiki/utils.rb
159
154
  - lib/media_wiki/version.rb
160
155
  - lib/mediawiki-gateway.rb
156
+ - bin/mediawiki-gateway
157
+ - COPYING
158
+ - ChangeLog
159
+ - README.md
160
+ - Rakefile
161
161
  - spec/data/import.xml
162
162
  - spec/media_wiki/gateway/files_spec.rb
163
163
  - spec/media_wiki/gateway/pages_spec.rb
@@ -174,47 +174,45 @@ licenses:
174
174
  metadata: {}
175
175
  post_install_message: |2+
176
176
 
177
- mediawiki-gateway-1.0.0 [2014-10-31]:
177
+ mediawiki-gateway-1.1.0 [2016-01-05]:
178
178
 
179
- * <b>Required Ruby version is now 1.9.3 or higher.</b>
180
- * For better Unicode support, install the +unicode+ or +activesupport+ gem.
181
- * API methods are grouped into submodules of MediaWiki::Gateway.
182
- * MediaWiki::Utils has been added as a proper module.
183
- * MediaWiki::FakeWiki has been added as a first-class citizen.
184
- * MediaWiki::Config has been removed.
185
- * MediaWiki::Gateway#send_request allows generic API requests.
186
- * MediaWiki::Gateway::Query#custom_query has been made public.
187
- * MediaWiki::Gateway::new learned +user_agent+ option.
188
- * MediaWiki::Gateway#headers attribute has been exposed.
189
- * MediaWiki::Gateway#wiki_url attribute has been exposed.
190
- * Added +mediawiki-gateway+ command-line client.
191
- * Changed or removed some of the dependencies.
192
- * Housekeeping and internal refactoring.
179
+ * Allow empty params for semantic_query.
180
+ * Add a method to purge a page. Pull request #93 by MusikAnimal.
181
+ * Follow redirects if HTTP 301, 302 or 307 is returned. Pull request #86
182
+ by Brandon Liu.
183
+ * Change exception superclass to StandardError. Pull request #85 by
184
+ Brandon Liu.
185
+ * Fixed categorymembers to use new continue rules. Pull request #82
186
+ by Asaf Bartov.
187
+ * Fix search to return nil if namespace not found. Pull request #88 by
188
+ Alexander Adrianov.
189
+ * Fixed MediaWiki::Gateway::Users#contributions to not continue when enough
190
+ contributions have been received. Pull request #79 by Michaël Witrant.
193
191
 
194
192
  rdoc_options:
195
- - "--title"
196
- - mediawiki-gateway Application documentation (v1.0.0)
197
- - "--charset"
193
+ - --title
194
+ - mediawiki-gateway Application documentation (v1.1.0)
195
+ - --charset
198
196
  - UTF-8
199
- - "--line-numbers"
200
- - "--all"
201
- - "--main"
197
+ - --line-numbers
198
+ - --all
199
+ - --main
202
200
  - README.md
203
201
  require_paths:
204
202
  - lib
205
203
  required_ruby_version: !ruby/object:Gem::Requirement
206
204
  requirements:
207
- - - ">="
205
+ - - '>='
208
206
  - !ruby/object:Gem::Version
209
207
  version: 1.9.3
210
208
  required_rubygems_version: !ruby/object:Gem::Requirement
211
209
  requirements:
212
- - - ">="
210
+ - - '>='
213
211
  - !ruby/object:Gem::Version
214
212
  version: '0'
215
213
  requirements: []
216
214
  rubyforge_project:
217
- rubygems_version: 2.4.2
215
+ rubygems_version: 2.0.14
218
216
  signing_key:
219
217
  specification_version: 4
220
218
  summary: Connect to the MediaWiki API.