mediawiki-butt 0.11.1 → 1.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 +28 -5
- data/lib/mediawiki/administration.rb +18 -17
- data/lib/mediawiki/auth.rb +52 -193
- data/lib/mediawiki/butt.rb +51 -32
- data/lib/mediawiki/constants.rb +127 -130
- data/lib/mediawiki/edit.rb +58 -71
- data/lib/mediawiki/exceptions.rb +2 -123
- data/lib/mediawiki/query/lists/all.rb +35 -45
- data/lib/mediawiki/query/lists/backlinks.rb +23 -34
- data/lib/mediawiki/query/lists/categories.rb +17 -28
- data/lib/mediawiki/query/lists/log/block.rb +17 -33
- data/lib/mediawiki/query/lists/log/delete.rb +8 -24
- data/lib/mediawiki/query/lists/log/import.rb +9 -24
- data/lib/mediawiki/query/lists/log/log.rb +36 -63
- data/lib/mediawiki/query/lists/log/merge.rb +5 -12
- data/lib/mediawiki/query/lists/log/move.rb +6 -20
- data/lib/mediawiki/query/lists/log/newusers.rb +13 -36
- data/lib/mediawiki/query/lists/log/patrol.rb +5 -13
- data/lib/mediawiki/query/lists/log/protect.rb +20 -50
- data/lib/mediawiki/query/lists/log/rights.rb +10 -24
- data/lib/mediawiki/query/lists/log/upload.rb +10 -24
- data/lib/mediawiki/query/lists/miscellaneous.rb +10 -19
- data/lib/mediawiki/query/lists/querypage.rb +60 -62
- data/lib/mediawiki/query/lists/recent_changes.rb +18 -30
- data/lib/mediawiki/query/lists/search.rb +14 -29
- data/lib/mediawiki/query/lists/users.rb +43 -61
- data/lib/mediawiki/query/meta/filerepoinfo.rb +18 -20
- data/lib/mediawiki/query/meta/siteinfo.rb +30 -33
- data/lib/mediawiki/query/meta/userinfo.rb +48 -66
- data/lib/mediawiki/query/properties/contributors.rb +18 -22
- data/lib/mediawiki/query/properties/files.rb +18 -20
- data/lib/mediawiki/query/properties/pages.rb +129 -211
- data/lib/mediawiki/query/properties/properties.rb +20 -25
- data/lib/mediawiki/query/query.rb +0 -25
- data/lib/mediawiki/utils.rb +9 -8
- data/lib/mediawiki/watch.rb +52 -0
- metadata +6 -4
@@ -9,38 +9,33 @@ module MediaWiki
|
|
9
9
|
include MediaWiki::Query::Properties::Pages
|
10
10
|
include MediaWiki::Query::Properties::Files
|
11
11
|
|
12
|
-
# Gets the token for the given type. This method should rarely be
|
13
|
-
# used by normal users.
|
12
|
+
# Gets the token for the given type. This method should rarely be used by normal users.
|
14
13
|
# @param type [String] The type of token.
|
15
14
|
# @param title [String] The page title for the token. Optional.
|
16
15
|
# @see https://www.mediawiki.org/wiki/API:Info MediaWiki Info API Docs
|
17
16
|
# @since 0.5.0
|
18
|
-
# @return [String] The token. If the butt isn't logged in, it returns
|
19
|
-
# with '+\\'.
|
17
|
+
# @return [String] The token. If the butt isn't logged in, it returns with '+\\'.
|
20
18
|
def get_token(type, title = nil)
|
21
|
-
|
22
|
-
# There is some weird thing with MediaWiki where you must pass a valid
|
23
|
-
# inprop parameter in order to get any response at all. This is why
|
24
|
-
# there is a displaytitle inprop as well as gibberish in the titles
|
25
|
-
# parameter. And to avoid normalization, it's capitalized.
|
26
|
-
params = {
|
27
|
-
action: 'query',
|
28
|
-
prop: 'info',
|
29
|
-
inprop: 'displaytitle',
|
30
|
-
intoken: type
|
31
|
-
}
|
19
|
+
return '+\\' unless @logged_in
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
# There is some weird thing with MediaWiki where you must pass a valid inprop parameter in order to get any
|
22
|
+
# response at all. This is why there is a displaytitle inprop as well as gibberish in the titles parameter.
|
23
|
+
# And to avoid normalization, it's capitalized.
|
24
|
+
params = {
|
25
|
+
action: 'query',
|
26
|
+
prop: 'info',
|
27
|
+
inprop: 'displaytitle',
|
28
|
+
intoken: type
|
29
|
+
}
|
38
30
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
31
|
+
title = 'Somegibberish' if title.nil?
|
32
|
+
params[:titles] = title
|
33
|
+
response = post(params)
|
34
|
+
revid = nil
|
35
|
+
response['query']['pages'].each { |r, _| revid = r }
|
36
|
+
|
37
|
+
# URL encoding is not needed for some reason.
|
38
|
+
response['query']['pages'][revid]["#{type}token"]
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end
|
@@ -7,30 +7,5 @@ module MediaWiki
|
|
7
7
|
include MediaWiki::Query::Meta
|
8
8
|
include MediaWiki::Query::Lists
|
9
9
|
include MediaWiki::Query::Properties
|
10
|
-
|
11
|
-
protected
|
12
|
-
|
13
|
-
# Gets the limited version of the integer, to ensure nobody provides an int
|
14
|
-
# that is too large.
|
15
|
-
# @param integer [Int] The number to limit.
|
16
|
-
# @param max_user [Int] The maximum limit for normal users.
|
17
|
-
# @param max_bot [Int] The maximum limit for bot users.
|
18
|
-
# @since 0.8.0
|
19
|
-
# @return [Int] The capped number.
|
20
|
-
def get_limited(integer, max_user = 500, max_bot = 5000)
|
21
|
-
if integer > max_user
|
22
|
-
if user_bot?
|
23
|
-
if integer > max_bot
|
24
|
-
return max_bot
|
25
|
-
else
|
26
|
-
return integer
|
27
|
-
end
|
28
|
-
else
|
29
|
-
return max_user
|
30
|
-
end
|
31
|
-
else
|
32
|
-
return integer
|
33
|
-
end
|
34
|
-
end
|
35
10
|
end
|
36
11
|
end
|
data/lib/mediawiki/utils.rb
CHANGED
@@ -3,17 +3,18 @@ module MediaWiki
|
|
3
3
|
# requiring 'mediawiki-butt' or 'mediawiki/butt'; you must require it explicitly.
|
4
4
|
class Utils
|
5
5
|
# Encodes the URL like mw.util.rawurlencode JS.
|
6
|
-
# @todo
|
6
|
+
# @todo Require StringUtility and use its safely_gsub method.
|
7
7
|
# @param str [String] The string to replace (typically a page title).
|
8
8
|
# @return [String] The encoded string.
|
9
9
|
def self.encode_url(str)
|
10
|
-
str.gsub!(/!/,'%21') || str
|
11
|
-
str.gsub!(/'/,'%27') || str
|
12
|
-
str.gsub!(/\(/,'%28') || str
|
13
|
-
str.gsub!(/\)/,'%29') || str
|
14
|
-
str.gsub!(/\*/,'%2A') || str
|
15
|
-
str.gsub!(/~/,'%7E') || str
|
16
|
-
|
10
|
+
str.gsub!(/!/, '%21') || str
|
11
|
+
str.gsub!(/'/, '%27') || str
|
12
|
+
str.gsub!(/\(/, '%28') || str
|
13
|
+
str.gsub!(/\)/, '%29') || str
|
14
|
+
str.gsub!(/\*/, '%2A') || str
|
15
|
+
str.gsub!(/~/, '%7E') || str
|
16
|
+
|
17
|
+
str
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module MediaWiki
|
2
|
+
module Watch
|
3
|
+
# Adds a page or an array of pages to the current user's watchlist.
|
4
|
+
# @param titles [Array<String>, String] An array of page titles, or a page title as a string.
|
5
|
+
# @return [Hash{String => Nil, Boolean}] Keys are page titles. Nil value means the page was missing, but it
|
6
|
+
# was watched anyway. True means the page was watched and it exists. False means the page was not watched.
|
7
|
+
# @see https://www.mediawiki.org/wiki/API:Watch MediaWiki Watch API
|
8
|
+
def watch(titles)
|
9
|
+
watch_request(titles)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Removes a page or an array of pages from the current user's watchlist.
|
13
|
+
# @param (see #watch)
|
14
|
+
# @return (see #watch)
|
15
|
+
# @see https://www.mediawiki.org/wiki/API:Watch MediaWiki Watch API
|
16
|
+
def unwatch(titles)
|
17
|
+
watch_request(titles, true)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Submits a watch action request.
|
23
|
+
# @param (see #watch)
|
24
|
+
# @param unwatch [Boolean] Whether the request should unwatch the pages or not.
|
25
|
+
# @return (see #watch)
|
26
|
+
def watch_request(titles, unwatch = false)
|
27
|
+
titles = titles.is_a?(Array) ? titles : [titles]
|
28
|
+
params = {
|
29
|
+
action: 'watch',
|
30
|
+
titles: titles.shift(get_limited(titles.length, 50, 500)).join('|'),
|
31
|
+
token: get_token('watch')
|
32
|
+
}
|
33
|
+
success_key = 'watched'
|
34
|
+
if unwatch
|
35
|
+
params[:unwatch] = 1
|
36
|
+
success_key = 'unwatched'
|
37
|
+
end
|
38
|
+
|
39
|
+
response = post(params)
|
40
|
+
ret = {}
|
41
|
+
response['watch'].each do |entry|
|
42
|
+
title = entry['title']
|
43
|
+
if entry.key?(success_key)
|
44
|
+
ret[title] = entry.key?('missing') ? nil : true
|
45
|
+
else
|
46
|
+
ret[title] = false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
ret
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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: 0.
|
4
|
+
version: 1.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-
|
12
|
+
date: 2016-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httpclient
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/mediawiki/query/properties/properties.rb
|
73
73
|
- lib/mediawiki/query/query.rb
|
74
74
|
- lib/mediawiki/utils.rb
|
75
|
+
- lib/mediawiki/watch.rb
|
75
76
|
homepage: https://github.com/ftb-gamepedia/mediawiki-butt-ruby
|
76
77
|
licenses:
|
77
78
|
- MIT
|
@@ -85,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
86
|
requirements:
|
86
87
|
- - ">="
|
87
88
|
- !ruby/object:Gem::Version
|
88
|
-
version: '2.
|
89
|
+
version: '2.3'
|
89
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
91
|
requirements:
|
91
92
|
- - ">="
|
@@ -93,8 +94,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
96
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.6.4
|
97
98
|
signing_key:
|
98
99
|
specification_version: 4
|
99
100
|
summary: Interacting with the MediaWiki API
|
100
101
|
test_files: []
|
102
|
+
has_rdoc:
|