mediawiki-butt 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/mediawiki/edit.rb +40 -37
- data/lib/mediawiki/exceptions.rb +1 -0
- data/lib/mediawiki/query/lists/categories.rb +3 -3
- data/lib/mediawiki/query/lists/users.rb +1 -0
- data/lib/mediawiki/query/meta/siteinfo.rb +18 -0
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc7e6ec26beb5a87466af0dd75da94fecac69de3
|
4
|
+
data.tar.gz: 61a5969d08c863a80bf8d76f1a3d61c0a0da4d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8096b955d2b02aa44a4fe267cca4ad1a280ab3374a8c0074acee9d102e7b2eef766704c5b3c5463f6b461d2f661ee7166645607f90dcc47d55f721eb739b8d04
|
7
|
+
data.tar.gz: c28a5db8c069352687b896934aa072bfe13dd31d6795ddc21b38d3e24f596bfe7ac8c157d9629521e2afff415b521e9018778a02aa4f06ecd557de45e768939b
|
data/CHANGELOG.md
CHANGED
@@ -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!**
|
data/lib/mediawiki/edit.rb
CHANGED
@@ -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
|
9
|
-
# @
|
10
|
-
#
|
11
|
-
# @
|
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,
|
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
|
-
|
29
|
-
|
30
|
-
params[:
|
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
|
49
|
-
# @
|
50
|
-
#
|
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,
|
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
|
-
|
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]
|
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
|
-
|
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
|
119
|
-
# @
|
120
|
-
# @
|
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,
|
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
|
-
|
135
|
-
params[:
|
136
|
-
params[:
|
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
|
|
data/lib/mediawiki/exceptions.rb
CHANGED
@@ -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,
|
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,
|
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,
|
45
|
+
get_category_members(category, 'file', limit)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -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:
|
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:
|
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:
|
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.
|
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:
|