mediawiki-butt 1.3.0 → 2.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d0b018bfc1617afe7610706ea9347c71ad79a57
4
- data.tar.gz: 5c356aeacdbcd8697eed165665335c48afb38fdd
3
+ metadata.gz: fc7e6ec26beb5a87466af0dd75da94fecac69de3
4
+ data.tar.gz: 61a5969d08c863a80bf8d76f1a3d61c0a0da4d75
5
5
  SHA512:
6
- metadata.gz: abff053b2c91f898e7d97996c2c866b1269b1461e9d8bf50c7670aaeabd60994d8248fc79b494d6600b9da947722d31a50d0f282223cb468ab16a0a4dffd9dbf
7
- data.tar.gz: 3357c256bbfe5b77270e014011a36e45a3ae74bac3f432c5585a555c1e0a1f6ad6d267d202ba63161bcf986a946cacb2f372012e23bd9351bb103b81b7fed43b
6
+ metadata.gz: 8096b955d2b02aa44a4fe267cca4ad1a280ab3374a8c0074acee9d102e7b2eef766704c5b3c5463f6b461d2f661ee7166645607f90dcc47d55f721eb739b8d04
7
+ data.tar.gz: c28a5db8c069352687b896934aa072bfe13dd31d6795ddc21b38d3e24f596bfe7ac8c157d9629521e2afff415b521e9018778a02aa4f06ecd557de45e768939b
@@ -1,4 +1,23 @@
1
1
  # Changelog
2
+ ## Version 2
3
+ ### Version 2.0.0
4
+ **Breaking changes!**
5
+ * Logical reversal of the redirect param for move (#58)
6
+ * Switch around type and limit params in `get_category_members` (#57)
7
+ * Remove post-install message
8
+ * Strip leading and trailing whitespace from username in get_userlists, affecting the following methods (#55):
9
+ * `get_userrights`
10
+ * `get_contrib_count`
11
+ * `get_registration_time`
12
+ * `get_user_gender`
13
+ * Change return values of `#upload` to be more useful (#54)
14
+ * `true`/`false` return value denote success/failure
15
+ * `UploadInvalidFileExtError` is raised when the file extension is not valid
16
+ * `EditError` is raised for any errors that occurred during the upload
17
+ * New siteinfo methods `get_server`, `get_base_article_path`, and `get_article_path` (#20).
18
+ * Modify the `edit`, `create_page`, and `move` methods to take options hashes instead of a bunch of unnamed arguments. (#53, #52)
19
+ * Documentation is now stored in master branch
20
+
2
21
  ## Version 1
3
22
  ### Version 1.3.0
4
23
  **Security update!**
@@ -5,10 +5,10 @@ module MediaWiki
5
5
  # Performs a standard non-creation edit.
6
6
  # @param title [String] The page title.
7
7
  # @param text [String] The new content.
8
- # @param minor [Boolean] Will mark the edit as minor if true.
9
- # @param bot [Boolean] Will mark the edit as bot edit if true. Defaults to true, for your convenience, bot
10
- # developers.
11
- # @param summary [String] The edit summary. Optional.
8
+ # @param opts [Hash<Symbol, Any>] The options hash for optional values in the request.
9
+ # @option opts [Boolean] :minor Will mark the edit as minor if true.
10
+ # @option opts [Boolean] :bot Will mark the edit as bot edit if true. Defaults to true.
11
+ # @option opts [String] :summary The edit summary. Optional.
12
12
  # @see https://www.mediawiki.org/wiki/API:Changing_wiki_content Changing wiki content on the MediaWiki API
13
13
  # documentation
14
14
  # @see https://www.mediawiki.org/wiki/API:Edit MediaWiki Edit API Docs
@@ -16,21 +16,20 @@ module MediaWiki
16
16
  # @raise [EditError] if the edit failed somehow
17
17
  # @return [String] The new revision ID
18
18
  # @return [Boolean] False if there was no change in the edit.
19
- def edit(title, text, minor = false, bot = true, summary = nil)
19
+ def edit(title, text, opts = {})
20
+ opts[:bot] = opts.key?(:bot) ? opts[:bot] : true
20
21
  params = {
21
22
  action: 'edit',
22
23
  title: title,
23
24
  text: text,
24
25
  nocreate: 1,
25
- format: 'json'
26
+ format: 'json',
27
+ token: get_token('edit', title)
26
28
  }
27
29
 
28
- token = get_token('edit', title)
29
-
30
- params[:summary] = summary unless summary.nil?
31
- params[:minor] = '1' if minor
32
- params[:bot] = '1' if bot
33
- params[:token] = token
30
+ params[:summary] ||= opts[:summary]
31
+ params[:minor] = '1' if opts[:minor]
32
+ params[:bot] = '1' if opts[:bot]
34
33
 
35
34
  response = post(params)
36
35
 
@@ -45,29 +44,29 @@ module MediaWiki
45
44
  # Creates a new page.
46
45
  # @param title [String] The new page's title.
47
46
  # @param text [String] The new page's content.
48
- # @param summary [String] The edit summary.
49
- # @param bot [Boolean] Will mark the edit as a bot edit if true. Defaults to true, for your convenience, bot
50
- # developers.
47
+ # @param opts [Hash<Symbol, Any>] The options hash for optional values in the request.
48
+ # @option opts [String] :summary The edit summary. Defaults to "New page".
49
+ # @option opts [Boolean] :bot Will mark the edit as a bot edit if true. Defaults to true.
51
50
  # @see https://www.mediawiki.org/wiki/API:Changing_wiki_content Changing wiki content on the MediaWiki API
52
51
  # documentation
53
52
  # @see https://www.mediawiki.org/wiki/API:Edit MediaWiki Edit API Docs
54
53
  # @since 0.3.0
55
54
  # @raise [EditError] If there was some error when creating the page.
56
55
  # @return [String] The new page ID
57
- def create_page(title, text, summary = 'New page', bot = true)
56
+ def create_page(title, text, opts = {})
57
+ opts[:bot] = opts.key?(:bot) ? opts[:bot] : true
58
+ opts[:summary] ||= 'New page'
58
59
  params = {
59
60
  action: 'edit',
60
61
  title: title,
61
- summary: summary,
62
62
  text: text,
63
+ summary: opts[:summary],
63
64
  createonly: 1,
64
- format: 'json'
65
+ format: 'json',
66
+ token: get_token('edit', title)
65
67
  }
66
68
 
67
- token = get_token('edit', title)
68
-
69
- params[:bot] = '1' if bot
70
- params[:token] = token
69
+ params[:bot] = '1' if opts[:bot]
71
70
 
72
71
  response = post(params)
73
72
 
@@ -79,13 +78,14 @@ module MediaWiki
79
78
  # @param url [String] The URL to the file.
80
79
  # @param filename [String] The preferred filename. This can include File: at the beginning, but it will be
81
80
  # removed through regex. Optional. If omitted, it will be everything after the last slash in the URL.
82
- # @return [Boolean] True if the upload was successful, false if the file extension is not valid.
81
+ # @return [Boolean] Whether the upload was successful. It is likely that if it returns false, it also raised a
82
+ # warning.
83
+ # @raise [UploadInvalidFileExtError] When the file extension provided is not valid for the wiki.
84
+ # @raise [EditError]
83
85
  # @see https://www.mediawiki.org/wiki/API:Changing_wiki_content Changing wiki content on the MediaWiki API
84
86
  # documentation
85
87
  # @see https://www.mediawiki.org/wiki/API:Upload MediaWiki Upload API Docs
86
88
  # @since 0.3.0
87
- # @return [Boolean] Whether the upload was successful. It is likely that if it returns false, it also raised a
88
- # warning.
89
89
  def upload(url, filename = nil)
90
90
  params = {
91
91
  action: 'upload',
@@ -97,7 +97,7 @@ module MediaWiki
97
97
 
98
98
  ext = filename.split('.')[-1]
99
99
  allowed_extensions = get_allowed_file_extensions
100
- return false unless allowed_extensions.include?(ext)
100
+ raise MediaWiki::Butt::UploadInvalidFileExtError.new unless allowed_extensions.include?(ext)
101
101
 
102
102
  token = get_token('edit', filename)
103
103
  params[:filename] = filename
@@ -109,33 +109,36 @@ module MediaWiki
109
109
  warn warning
110
110
  end
111
111
 
112
- response.dig('upload', 'result') == 'Success'
112
+ return true if response.dig('upload', 'result') == 'Success'
113
+ raise MediaWiki::Butt::EditError.new(response.dig('error', 'code') || 'Unknown error code')
113
114
  end
114
115
 
115
116
  # Performs a move on a page.
116
117
  # @param from [String] The page to be moved.
117
118
  # @param to [String] The destination of the move.
118
- # @param reason [String] The reason for the move, which shows up in the log. Optional.
119
- # @param talk [Boolean] Whether to move the associated talk page.
120
- # @param redirect [Boolean] Whether to create a redirect.
119
+ # @param opts [Hash<Symbol, Any>] The options hash for optional values in the request.
120
+ # @option opts [String] :reason The reason for the move, which shows up in the log.
121
+ # @option opts [Boolean] :talk Whether to move the associated talk page. Defaults to true.
122
+ # @option opts [Boolean] :suppress_redirect Set to a truthy value in order to prevent the API from making a redirect
123
+ # page.
121
124
  # @see https://www.mediawiki.org/wiki/API:Changing_wiki_content Changing wiki content on the MediaWiki API
122
125
  # documentation
123
126
  # @see https://www.mediawiki.org/wiki/API:Move MediaWiki Move API Docs
124
127
  # @since 0.5.0
125
128
  # @raise [EditError]
126
129
  # @return [Boolean] True if it was successful.
127
- def move(from, to, reason = nil, talk = true, redirect = false)
130
+ def move(from, to, opts = {})
131
+ opts[:talk] = opts.key?(:talk) ? opts[:talk] : true
128
132
  params = {
129
133
  action: 'move',
130
134
  from: from,
131
- to: to
135
+ to: to,
136
+ token: get_token('move', from)
132
137
  }
133
138
 
134
- token = get_token('move', from)
135
- params[:reason] = reason unless reason.nil?
136
- params[:movetalk] = '1' if talk
137
- params[:noredirect] = '1' if redirect
138
- params[:token] = token
139
+ params[:reason] ||= opts[:reason]
140
+ params[:movetalk] = '1' if opts[:talk]
141
+ params[:noredirect] = '1' if opts[:suppress_redirect]
139
142
 
140
143
  response = post(params)
141
144
 
@@ -5,5 +5,6 @@ module MediaWiki
5
5
  class BlockError < StandardError; end
6
6
  class NotLoggedInError < StandardError; end
7
7
  class NotBotError < StandardError; end
8
+ class UploadInvalidFileExtError < StandardError; end
8
9
  end
9
10
  end
@@ -11,7 +11,7 @@ module MediaWiki
11
11
  # @see https://www.mediawiki.org/wiki/API:Categorymembers MediaWiki Category Members API Docs
12
12
  # @since 0.1.0
13
13
  # @return [Array<String>] All category members until the limit
14
- def get_category_members(category, limit = @query_limit_default, type = 'page')
14
+ def get_category_members(category, type = 'page', limit = @query_limit_default)
15
15
  params = {
16
16
  list: 'categorymembers',
17
17
  cmprop: 'title',
@@ -33,7 +33,7 @@ module MediaWiki
33
33
  # @since 0.9.0
34
34
  # @return [Array<String>] All subcategories.
35
35
  def get_subcategories(category, limit = @query_limit_default)
36
- get_category_members(category, limit, 'subcat')
36
+ get_category_members(category, 'subcat', limit)
37
37
  end
38
38
 
39
39
  # Gets all of the files in a given category.
@@ -42,7 +42,7 @@ module MediaWiki
42
42
  # @since 0.9.0
43
43
  # @return [Array<String>] All files in the category.
44
44
  def get_files_in_category(category, limit = @query_limit_default)
45
- get_category_members(category, limit, 'file')
45
+ get_category_members(category, 'file', limit)
46
46
  end
47
47
  end
48
48
  end
@@ -16,6 +16,7 @@ module MediaWiki
16
16
  return unless @logged_in
17
17
  response = get_current_user_meta(prop)
18
18
  else
19
+ username.strip!
19
20
  params = {
20
21
  action: 'query',
21
22
  list: 'users',
@@ -177,6 +177,24 @@ module MediaWiki
177
177
  def get_variables
178
178
  get_siteinfo('variables')['query']['variables']
179
179
  end
180
+
181
+ # Gets the protocol-relative server URL for the wiki.
182
+ # @return [String] The server URL for the wiki. For example: //en.wikipedia.org for Wikipedia.
183
+ def get_server
184
+ get_general['server']
185
+ end
186
+
187
+ # @return [String] The article path for the wiki. It includes "$1", which should be replaced with the actual
188
+ # name of the article. Does not include the URL for the wiki. For example: /wiki/$1 for Wikpedia.
189
+ def get_base_article_path
190
+ get_general['articlepath']
191
+ end
192
+
193
+ # @param article_name [String] The name of the article.
194
+ # @return [String] The full article path for the provided article. This is protocol-relative.
195
+ def get_article_path(article_name)
196
+ get_server + get_base_article_path.sub('$1', article_name)
197
+ end
180
198
  end
181
199
  end
182
200
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki-butt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-18 00:00:00.000000000 Z
12
+ date: 2017-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
@@ -79,7 +79,7 @@ licenses:
79
79
  - MIT
80
80
  metadata:
81
81
  issue_tracker: https://github.com/ftb-gamepedia/mediawiki-butt-ruby/issues
82
- post_install_message: ONE OF US! ONE OF US!
82
+ post_install_message:
83
83
  rdoc_options: []
84
84
  require_paths:
85
85
  - lib
@@ -95,9 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.6.4
98
+ rubygems_version: 2.6.10
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Interacting with the MediaWiki API
102
102
  test_files: []
103
- has_rdoc: