mediawiki-butt 0.7.0 → 0.8.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 +4 -4
- data/lib/mediawiki/administration.rb +4 -2
- data/lib/mediawiki/butt.rb +8 -11
- data/lib/mediawiki/constants.rb +213 -215
- data/lib/mediawiki/edit.rb +7 -4
- data/lib/mediawiki/query/lists.rb +192 -101
- data/lib/mediawiki/query/meta/userinfo.rb +13 -9
- data/lib/mediawiki/query/properties/contributors.rb +70 -0
- data/lib/mediawiki/query/properties/files.rb +95 -0
- data/lib/mediawiki/query/properties/pages.rb +445 -0
- data/lib/mediawiki/query/properties/properties.rb +45 -0
- data/lib/mediawiki/query/query.rb +27 -1
- metadata +9 -20
- data/CHANGELOG.md +0 -119
- data/lib/mediawiki/query/properties.rb +0 -107
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'contributors'
|
2
|
+
require_relative 'pages'
|
3
|
+
require_relative 'files'
|
4
|
+
|
5
|
+
module MediaWiki
|
6
|
+
module Query
|
7
|
+
module Properties
|
8
|
+
include MediaWiki::Query::Properties::Contributors
|
9
|
+
include MediaWiki::Query::Properties::Pages
|
10
|
+
include MediaWiki::Query::Properties::Files
|
11
|
+
|
12
|
+
# Gets the token for the given type. This method should rarely be
|
13
|
+
# used by normal users.
|
14
|
+
# @param type [String] The type of token.
|
15
|
+
# @param title [String] The page title for the token. Optional.
|
16
|
+
# @return [String] The token. If the butt isn't logged in, it returns
|
17
|
+
# with '+\\'.
|
18
|
+
def get_token(type, title = nil)
|
19
|
+
if @logged_in == true
|
20
|
+
# There is some weird thing with MediaWiki where you must pass a valid
|
21
|
+
# inprop parameter in order to get any response at all. This is why
|
22
|
+
# there is a displaytitle inprop as well as gibberish in the titles
|
23
|
+
# parameter. And to avoid normalization, it's capitalized.
|
24
|
+
params = {
|
25
|
+
action: 'query',
|
26
|
+
prop: 'info',
|
27
|
+
inprop: 'displaytitle',
|
28
|
+
intoken: type
|
29
|
+
}
|
30
|
+
|
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
|
+
return response['query']['pages'][revid]["#{type}token"]
|
39
|
+
else
|
40
|
+
return '+\\'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,11 +1,37 @@
|
|
1
1
|
require_relative 'meta/meta'
|
2
2
|
require_relative 'lists'
|
3
|
-
require_relative 'properties'
|
3
|
+
require_relative 'properties/properties'
|
4
4
|
|
5
5
|
module MediaWiki
|
6
6
|
module Query
|
7
7
|
include MediaWiki::Query::Meta
|
8
8
|
include MediaWiki::Query::Lists
|
9
9
|
include MediaWiki::Query::Properties
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
# Gets the limited version of the integer, to ensure nobody provides an int
|
16
|
+
# that is too large.
|
17
|
+
# @param integer [Int] The number to limit.
|
18
|
+
# @param max_user [Int] The maximum limit for normal users.
|
19
|
+
# @param max_bot [Int] The maximum limit for bot users.
|
20
|
+
# @return [Int] The capped number.
|
21
|
+
def get_limited(integer, max_user = 500, max_bot = 5000)
|
22
|
+
if integer > 500
|
23
|
+
if user_bot? == true
|
24
|
+
if integer > 5000
|
25
|
+
return 5000
|
26
|
+
else
|
27
|
+
return integer
|
28
|
+
end
|
29
|
+
else
|
30
|
+
return 500
|
31
|
+
end
|
32
|
+
else
|
33
|
+
return integer
|
34
|
+
end
|
35
|
+
end
|
10
36
|
end
|
11
37
|
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: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
@@ -9,36 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: string-utility
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 2.0.0
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 2.0.0
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: httpclient
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
31
17
|
requirements:
|
32
18
|
- - ">="
|
33
19
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
20
|
+
version: 2.6.0.1
|
35
21
|
type: :runtime
|
36
22
|
prerelease: false
|
37
23
|
version_requirements: !ruby/object:Gem::Requirement
|
38
24
|
requirements:
|
39
25
|
- - ">="
|
40
26
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
27
|
+
version: 2.6.0.1
|
42
28
|
description: " MediaWiki::Butt is a Ruby Gem that provides a fully-featured MediaWiki
|
43
29
|
API interface. It includes methods for changing wiki content, authentication,
|
44
30
|
\ and queries.\n\n"
|
@@ -47,7 +33,6 @@ executables: []
|
|
47
33
|
extensions: []
|
48
34
|
extra_rdoc_files: []
|
49
35
|
files:
|
50
|
-
- CHANGELOG.md
|
51
36
|
- lib/mediawiki-butt.rb
|
52
37
|
- lib/mediawiki/administration.rb
|
53
38
|
- lib/mediawiki/auth.rb
|
@@ -60,7 +45,10 @@ files:
|
|
60
45
|
- lib/mediawiki/query/meta/meta.rb
|
61
46
|
- lib/mediawiki/query/meta/siteinfo.rb
|
62
47
|
- lib/mediawiki/query/meta/userinfo.rb
|
63
|
-
- lib/mediawiki/query/properties.rb
|
48
|
+
- lib/mediawiki/query/properties/contributors.rb
|
49
|
+
- lib/mediawiki/query/properties/files.rb
|
50
|
+
- lib/mediawiki/query/properties/pages.rb
|
51
|
+
- lib/mediawiki/query/properties/properties.rb
|
64
52
|
- lib/mediawiki/query/query.rb
|
65
53
|
homepage: https://github.com/ftb-gamepedia/mediawiki-butt-ruby
|
66
54
|
licenses:
|
@@ -88,3 +76,4 @@ signing_key:
|
|
88
76
|
specification_version: 4
|
89
77
|
summary: Interacting with the MediaWiki API
|
90
78
|
test_files: []
|
79
|
+
has_rdoc:
|
data/CHANGELOG.md
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
## Version 0
|
3
|
-
### Version 0.7.0
|
4
|
-
* upload's filename argument is no longer splat, because arrays.
|
5
|
-
* Fix incorrect regex $ when ^ should be used in upload.
|
6
|
-
* New get_all_categories method.
|
7
|
-
* New get_all_images method.
|
8
|
-
* Fix some user_bot? calls.
|
9
|
-
* user_bot? returns false when not logged in and username is not set.
|
10
|
-
* Refactor Query module to have its own folder, and subfolder for meta. This shouldn't change anything on the user's end.
|
11
|
-
* A couple methods no longer stupidly print stuff.
|
12
|
-
* New get_categories_in_page method.
|
13
|
-
|
14
|
-
### Version 0.6.0
|
15
|
-
* Slightly expanded Gem description.
|
16
|
-
* Finished all Meta modules and their methods, except for the allmessages meta query. [#6](https://github.com/ftb-gamepedia/mediawiki-butt-ruby/issues/6)
|
17
|
-
* New get_variables method.
|
18
|
-
* New get_function_hooks method.
|
19
|
-
* New get_extension_tags method.
|
20
|
-
* New get_skins method.
|
21
|
-
* New get_restriction_levels method.
|
22
|
-
* New get_restriction_types method.
|
23
|
-
* New get_restrictions_data method for the above methods.
|
24
|
-
* New get_allowed_file_extensions method, and refactored #upload to only allow files with those extensions.
|
25
|
-
* New get_all_usergroups method.
|
26
|
-
* New get_magic_words method.
|
27
|
-
* New get_special_page_aliases method.
|
28
|
-
* New get_namespace_aliases method.
|
29
|
-
* New get_namespaces method.
|
30
|
-
* New get_filerepo_favicons method.
|
31
|
-
* New get_filerepo_thumburls method.
|
32
|
-
* New get_nonlocal_filerepos method.
|
33
|
-
* New get_local_filerepos method.
|
34
|
-
* New get_filerepo_urls method.
|
35
|
-
* New get_filerepo_rooturls method.
|
36
|
-
* Refactor get_filerepo_names to use new get_filerepoinfo method.
|
37
|
-
* New get_filerepoinfo method, in a similar style to get_userlists.
|
38
|
-
* New get_current_user_options for getting a hash containing all of the currently logged in user's preferences.
|
39
|
-
* New get_email_address method for getting the currently logged in user's email address.
|
40
|
-
* New get_realname method for getting the currently logged in user's real name.
|
41
|
-
* New get_changeable_groups method for getting the currently logged in user's groups that they can change (add/remove people from)
|
42
|
-
* New current_user_hasmsg? method for checking if the user has any unread messages.
|
43
|
-
* check_login no longer returns false, ever, because any code after a fail is unreachable.
|
44
|
-
* prop parameter in get_current_user_meta is now optional, for get_current_user_name.
|
45
|
-
* New get_current_user_name method, for something fairly obvious.
|
46
|
-
* New get_siteinfo method, in a similar style to get_userlists.
|
47
|
-
* New get_statistics method, for getting a hash of the wiki's statistics.
|
48
|
-
* New get_general method, for getting hash of the 'general' wiki information.
|
49
|
-
* New get_extensions method, for getting an array of all extension names installed.
|
50
|
-
* New get_languages method, for getting a hash of all the languages, formatted as code => name.
|
51
|
-
* User-Agent header is now set for each post. It defaults to 'NotLoggedIn/MediaWiki::Butt', or "#{name}/MediaWiki::Butt" if logged in. This might cause some slight performance issues ([#5](https://github.com/FTB-Gamepedia/MediaWiki-Butt-Ruby/issues/5))
|
52
|
-
|
53
|
-
### Version 0.5.0
|
54
|
-
* New Administration module for administrative methods.
|
55
|
-
* New block and unblock methods, for (un)blocking users.
|
56
|
-
* Refactor token stuff. It still doesn't work exactly how I'd like yet, but it's better than it was before. Ideally I'd like to have it get the login-specific tokens on login and set them to some well-named instance variables. Then clear those on logout.
|
57
|
-
* Single-line each `do end` loops have been converted into `{...}` style loops.
|
58
|
-
* New delete method for deleting pages.
|
59
|
-
* New move method for moving pages.
|
60
|
-
|
61
|
-
### Version 0.4.1
|
62
|
-
* params[:format] is now automatically set to 'json', so it no longer needs to be defined in each method.
|
63
|
-
* Fixed a lot of styling issues thanks to Rubocop.
|
64
|
-
* check_login and check_create now use case/when statements instead of elsifs.
|
65
|
-
* check_create no longer returns anything.
|
66
|
-
* Update minimum Ruby version to 2.1, for refinements.
|
67
|
-
* Fix $namespaces hash syntax.
|
68
|
-
* Generally improved if statement syntax.
|
69
|
-
* Generally shortened a lot of code by using better syntax.
|
70
|
-
|
71
|
-
### Version 0.4.0
|
72
|
-
* New get_userrights method for getting an array of all user rights that user has.
|
73
|
-
* New get_user_gender method for getting the gender of the provided user.
|
74
|
-
* New get_current_user_meta for getting userlists about the currently logged in user. Essentially the equivalent of get_userlists for logged in users.
|
75
|
-
* Fix all userlist methods to work without supplying a username.
|
76
|
-
* New get_registration_time method to get when the user registered.
|
77
|
-
* Update to work with latest version of string-utility.
|
78
|
-
* Namespaces are now in a hash instead of just a bunch of variables.
|
79
|
-
* Namespace parameters are now actually limited to the valid namespaces constant. It will default to the main namespace (0) if the integer provided is not in the namespaces hash.
|
80
|
-
* get_random_pages no longer wrongly sets the rnlimit to the namespaces argument rather than the namespace argument.
|
81
|
-
|
82
|
-
### Version 0.3.1
|
83
|
-
* Fix edit and create_page NoMethodErrors.
|
84
|
-
* Remove dependency for JSON as the version we use is included in the Ruby standard library.
|
85
|
-
|
86
|
-
### Version 0.3.0
|
87
|
-
* New upload method to upload by URL.
|
88
|
-
* New create_page method.
|
89
|
-
* New get_userlists method.
|
90
|
-
* New get_usergroups method.
|
91
|
-
* New get_contrib_count method.
|
92
|
-
* Refactor get_usergroups and is_current_user_bot? to use new get_userinfo method.
|
93
|
-
* Minor refactors to make optional arguments more Ruby-like with splat arguments.
|
94
|
-
* #edit no longer prints the edit token, because that's stupid.
|
95
|
-
* #edit no longer sets the summary if it is nil.
|
96
|
-
|
97
|
-
### Version 0.2.1
|
98
|
-
* Fix gemspec. You should actually have the new stuff now.
|
99
|
-
|
100
|
-
### Version 0.2.0
|
101
|
-
* New get_id method to get the pageid from the title.
|
102
|
-
* New get_random_pages method to get an array of random articles.
|
103
|
-
* New Namespace module full of constants.
|
104
|
-
* is_current_user_bot is now called as is_current_user_bot?.
|
105
|
-
* New get_edit_token method for obtaining an edit token based on the page title.
|
106
|
-
* New edit method and module for editing pages.
|
107
|
-
* Fix logout parsing error
|
108
|
-
|
109
|
-
### Version 0.1.1
|
110
|
-
* Got rid of pointless array in is_current_user_bot
|
111
|
-
* Potentially fixed docs
|
112
|
-
* Raise errors on unsuccessful account creation
|
113
|
-
* #login properly returns true if the login is successful on the first try
|
114
|
-
* #logout returns true/false if it logs the user out. Basically returns true if @logged_in is true, and false if not, because the logout action has no errors.
|
115
|
-
* Account creation stuff actually returns true/false on success/fail. It also handles errors now.
|
116
|
-
* Better Category title regex in get_category_members
|
117
|
-
|
118
|
-
### Version 0.1.0
|
119
|
-
* Initial version.
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module MediaWiki
|
2
|
-
module Query
|
3
|
-
module Properties
|
4
|
-
# Gets the wiki text for the given page. Returns nil if it for some
|
5
|
-
# reason cannot get the text, for example, if the page does not exist.
|
6
|
-
# @param title [String] The page title
|
7
|
-
# @return [String/nil] String containing page contents, or nil
|
8
|
-
def get_text(title)
|
9
|
-
params = {
|
10
|
-
action: 'query',
|
11
|
-
prop: 'revisions',
|
12
|
-
rvprop: 'content',
|
13
|
-
titles: title
|
14
|
-
}
|
15
|
-
|
16
|
-
response = post(params)
|
17
|
-
revid = nil
|
18
|
-
response['query']['pages'].each { |r, _| revid = r }
|
19
|
-
|
20
|
-
if response['query']['pages'][revid]['missing'] == ''
|
21
|
-
return nil
|
22
|
-
else
|
23
|
-
return response['query']['pages'][revid]['revisions'][0]['*']
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Gets the revision ID for the given page.
|
28
|
-
# @param title [String] The page title
|
29
|
-
# @return [Int/nil] the ID or nil
|
30
|
-
def get_id(title)
|
31
|
-
params = {
|
32
|
-
action: 'query',
|
33
|
-
prop: 'revisions',
|
34
|
-
rvprop: 'content',
|
35
|
-
titles: title
|
36
|
-
}
|
37
|
-
|
38
|
-
response = post(params)
|
39
|
-
response['query']['pages'].each do |revid, _|
|
40
|
-
if revid != '-1'
|
41
|
-
return revid.to_i
|
42
|
-
else
|
43
|
-
return nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Gets the token for the given type. This method should rarely be
|
49
|
-
# used by normal users.
|
50
|
-
# @param type [String] The type of token.
|
51
|
-
# @param title [String] The page title for the token. Optional.
|
52
|
-
# @return [String] The token. If the butt isn't logged in, it returns
|
53
|
-
# with '+\\'.
|
54
|
-
def get_token(type, title = nil)
|
55
|
-
if @logged_in == true
|
56
|
-
# There is some weird thing with MediaWiki where you must pass a valid
|
57
|
-
# inprop parameter in order to get any response at all. This is why
|
58
|
-
# there is a displaytitle inprop as well as gibberish in the titles
|
59
|
-
# parameter. And to avoid normalization, it's capitalized.
|
60
|
-
params = {
|
61
|
-
action: 'query',
|
62
|
-
prop: 'info',
|
63
|
-
inprop: 'displaytitle',
|
64
|
-
intoken: type
|
65
|
-
}
|
66
|
-
|
67
|
-
title = 'Somegibberish' if title.nil?
|
68
|
-
params[:titles] = title
|
69
|
-
response = post(params)
|
70
|
-
revid = nil
|
71
|
-
response['query']['pages'].each { |r, _| revid = r }
|
72
|
-
|
73
|
-
# URL encoding is not needed for some reason.
|
74
|
-
return response['query']['pages'][revid]["#{type}token"]
|
75
|
-
else
|
76
|
-
return '+\\'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Gets all categories in the page.
|
81
|
-
# @param title [String] The page title.
|
82
|
-
# @return [Array/Nil] An array of all the categories, or nil if the title
|
83
|
-
# is not an actual page.
|
84
|
-
def get_categories_in_page(title)
|
85
|
-
params = {
|
86
|
-
action: 'query',
|
87
|
-
prop: 'categories',
|
88
|
-
titles: title
|
89
|
-
}
|
90
|
-
|
91
|
-
response = post(params)
|
92
|
-
pageid = nil
|
93
|
-
ret = []
|
94
|
-
response['query']['pages'].each { |r, _| pageid = r }
|
95
|
-
if response['query']['pages'][pageid]['missing'] == ''
|
96
|
-
return nil
|
97
|
-
else
|
98
|
-
response['query']['pages'][pageid]['categories'].each do |c|
|
99
|
-
ret.push(c['title'])
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
ret
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|