mediawiki-butt 0.1.1 → 0.2.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/CHANGELOG.md +9 -0
- data/lib/mediawiki/auth.rb +3 -2
- data/lib/mediawiki/butt.rb +16 -23
- data/lib/mediawiki/query.rb +111 -7
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e649c5d1963a0f3e300d04d7953735b9207c66c
|
4
|
+
data.tar.gz: 6284a9046b3f8575b6c28e84695e454beb70263a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b021df89173e0d44ed1217dc8ca0cbf4e5b08a55b9e45844c54013dcada4f7b7187588cb9a79c0f4329021879b3218e2dffab8b3c8fafae72c95b3c3f0dafa
|
7
|
+
data.tar.gz: c80b130f381f088cd43215d592a622f1c1617b868fe03d7e9f9af093045c716a4baeab574be519a6aab886a677022fb981a6a252ac0a8766c3fb073c87a5bae1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
## Version 0
|
3
|
+
### Version 0.2.0
|
4
|
+
* New get_id method to get the pageid from the title.
|
5
|
+
* New get_random_pages method to get an array of random articles.
|
6
|
+
* New Namespace module full of constants.
|
7
|
+
* is_current_user_bot is now called as is_current_user_bot?.
|
8
|
+
* New get_edit_token method for obtaining an edit token based on the page title.
|
9
|
+
* New edit method and module for editing pages.
|
10
|
+
* Fix logout parsing error
|
11
|
+
|
3
12
|
### Version 0.1.1
|
4
13
|
* Got rid of pointless array in is_current_user_bot
|
5
14
|
* Potentially fixed docs
|
data/lib/mediawiki/auth.rb
CHANGED
@@ -119,7 +119,7 @@ module MediaWiki
|
|
119
119
|
|
120
120
|
#Consider refactor the @cookie initialization.
|
121
121
|
@cookie = "#{result["login"]["cookieprefix"]}Session=#{result["login"]["sessionid"]}"
|
122
|
-
result = post(token_params, true,
|
122
|
+
result = post(token_params, true, { 'Set-Cookie' => @cookie })
|
123
123
|
return check_login(result["login"]["result"], true)
|
124
124
|
end
|
125
125
|
end
|
@@ -129,7 +129,8 @@ module MediaWiki
|
|
129
129
|
def logout
|
130
130
|
if @logged_in == true
|
131
131
|
params = {
|
132
|
-
action: 'logout'
|
132
|
+
action: 'logout',
|
133
|
+
format: 'json'
|
133
134
|
}
|
134
135
|
|
135
136
|
post(params)
|
data/lib/mediawiki/butt.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require_relative 'auth'
|
2
2
|
require_relative 'query'
|
3
|
+
require_relative 'constants'
|
4
|
+
require_relative 'edit'
|
3
5
|
require 'httpclient'
|
4
6
|
require 'json'
|
5
7
|
|
@@ -9,6 +11,8 @@ module MediaWiki
|
|
9
11
|
include MediaWiki::Query::Meta
|
10
12
|
include MediaWiki::Query::Properties
|
11
13
|
include MediaWiki::Query::Lists
|
14
|
+
include MediaWiki::Constants::Namespaces
|
15
|
+
include MediaWiki::Edit
|
12
16
|
|
13
17
|
# Creates a new instance of MediaWiki::Butt. To work with any MediaWiki::Butt methods, you must first create an instance of it.
|
14
18
|
#
|
@@ -33,14 +37,13 @@ module MediaWiki
|
|
33
37
|
#
|
34
38
|
# @param params [Hash] A basic hash containing MediaWiki API parameters. Please see the MediaWiki API for more information.
|
35
39
|
# @param autoparse [Boolean] Whether or not to provide a parsed version of the response's JSON. Will default to true.
|
36
|
-
# @param
|
37
|
-
# @return [JSON/
|
38
|
-
def post(params, autoparse = true,
|
39
|
-
if
|
40
|
-
header = { 'Set-Cookie' => @cookie }
|
41
|
-
response = @client.post(@uri, params, header)
|
42
|
-
else
|
40
|
+
# @param header [Hash] The header hash. Optional.
|
41
|
+
# @return [JSON/HTTPMessage] Parsed JSON if autoparse is true, or raw response if not.
|
42
|
+
def post(params, autoparse = true, header = nil)
|
43
|
+
if header == nil
|
43
44
|
response = @client.post(@uri, params)
|
45
|
+
else
|
46
|
+
response = @client.post(@uri, params, header)
|
44
47
|
end
|
45
48
|
|
46
49
|
if autoparse == true
|
@@ -52,24 +55,14 @@ module MediaWiki
|
|
52
55
|
|
53
56
|
# Returns true if the currently logged in user is in the "bot" group. This can be helpful to some developers, but it is mostly for use internally in MediaWiki::Butt.
|
54
57
|
# @return [Boolean] true if logged in as a bot, false if not logged in or logged in as a non-bot
|
55
|
-
def is_current_user_bot
|
58
|
+
def is_current_user_bot?
|
56
59
|
if @logged_in == true
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
}
|
63
|
-
|
64
|
-
response = post(params)
|
65
|
-
response["query"]["userinfo"]["groups"].each do |g|
|
66
|
-
if g == "bot"
|
67
|
-
return true
|
68
|
-
else
|
69
|
-
next
|
70
|
-
end
|
60
|
+
groups = get_usergroups
|
61
|
+
if groups.include? "bot"
|
62
|
+
return true
|
63
|
+
else
|
64
|
+
return false
|
71
65
|
end
|
72
|
-
return false
|
73
66
|
else
|
74
67
|
return false
|
75
68
|
end
|
data/lib/mediawiki/query.rb
CHANGED
@@ -6,7 +6,7 @@ module MediaWiki
|
|
6
6
|
|
7
7
|
# Returns an array of all the wiki's file repository names.
|
8
8
|
# @return [Array] All wiki's file repository names.
|
9
|
-
def get_filerepo_names
|
9
|
+
def get_filerepo_names
|
10
10
|
params = {
|
11
11
|
action: 'query',
|
12
12
|
meta: 'filerepoinfo',
|
@@ -15,11 +15,33 @@ module MediaWiki
|
|
15
15
|
}
|
16
16
|
|
17
17
|
result = post(params)
|
18
|
-
|
18
|
+
ret = Array.new
|
19
19
|
result["query"]["repos"].each do |repo|
|
20
|
-
|
20
|
+
ret.push(repo["name"])
|
21
|
+
end
|
22
|
+
return ret
|
23
|
+
end
|
24
|
+
|
25
|
+
# Gets an array of all the currently logged in user's groups.
|
26
|
+
# @return [Array/Boolean] All of the user's groups, or false if not logged in.
|
27
|
+
def get_usergroups
|
28
|
+
if @logged_in == true
|
29
|
+
params = {
|
30
|
+
action: 'query',
|
31
|
+
meta: 'userinfo',
|
32
|
+
uiprop: 'groups',
|
33
|
+
format: 'json'
|
34
|
+
}
|
35
|
+
|
36
|
+
result = post(params)
|
37
|
+
ret = Array.new
|
38
|
+
result["query"]["userinfo"]["groups"].each do |g|
|
39
|
+
ret.push(g)
|
40
|
+
end
|
41
|
+
return ret
|
42
|
+
else
|
43
|
+
return false
|
21
44
|
end
|
22
|
-
return array
|
23
45
|
end
|
24
46
|
end
|
25
47
|
|
@@ -48,6 +70,53 @@ module MediaWiki
|
|
48
70
|
return response["query"]["pages"][$revid]["revisions"][0]["*"]
|
49
71
|
end
|
50
72
|
end
|
73
|
+
|
74
|
+
# Gets the revision ID for the given page.
|
75
|
+
# @param title [String] The page title
|
76
|
+
# @return [Int/nil] the ID or nil
|
77
|
+
def get_id(title)
|
78
|
+
params = {
|
79
|
+
action: 'query',
|
80
|
+
prop: 'revisions',
|
81
|
+
rvprop: 'content',
|
82
|
+
format: 'json',
|
83
|
+
titles: title
|
84
|
+
}
|
85
|
+
|
86
|
+
response = post(params)
|
87
|
+
response["query"]["pages"].each do |revid, data|
|
88
|
+
if revid != "-1"
|
89
|
+
return revid.to_i
|
90
|
+
else
|
91
|
+
return nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Gets the edit token for the given page. This method should rarely be used by normal users.
|
97
|
+
# @param page_name [String] The page title that you are going to be editing.
|
98
|
+
# @return [String] The edit token. If the butt isn't logged in, it returns with '+\\'.
|
99
|
+
def get_edit_token(page_name)
|
100
|
+
if @logged_in == true
|
101
|
+
params = {
|
102
|
+
action: 'query',
|
103
|
+
prop: 'info',
|
104
|
+
intoken: 'edit',
|
105
|
+
format: 'json',
|
106
|
+
titles: page_name
|
107
|
+
}
|
108
|
+
|
109
|
+
response = post(params)
|
110
|
+
response["query"]["pages"].each do |revid, data|
|
111
|
+
$revid = revid
|
112
|
+
end
|
113
|
+
|
114
|
+
# URL encoding is not needed for some reason.
|
115
|
+
return response["query"]["pages"][$revid]["edittoken"]
|
116
|
+
else
|
117
|
+
return "+\\"
|
118
|
+
end
|
119
|
+
end
|
51
120
|
end
|
52
121
|
|
53
122
|
module Lists
|
@@ -64,7 +133,7 @@ module MediaWiki
|
|
64
133
|
}
|
65
134
|
|
66
135
|
if limit > 500
|
67
|
-
if is_current_user_bot
|
136
|
+
if is_current_user_bot? == true
|
68
137
|
if limit > 5000
|
69
138
|
params[:bllimit] = 5000
|
70
139
|
else
|
@@ -85,7 +154,7 @@ module MediaWiki
|
|
85
154
|
return ret
|
86
155
|
end
|
87
156
|
|
88
|
-
# Returns an array of all
|
157
|
+
# Returns an array of all page titles that belong to a given category.
|
89
158
|
# @param category [String] The category title. It can include "Category:", or not, it doesn't really matter because we will add it if it is missing.
|
90
159
|
# @param limit [Int] The maximum number of members to get. Defaults to 500, and cannot be greater than that unless the user is a bot. If the user is a bot, the limit cannot be greater than 5000.
|
91
160
|
# @return [Array] All category members until the limit
|
@@ -104,7 +173,7 @@ module MediaWiki
|
|
104
173
|
end
|
105
174
|
|
106
175
|
if limit > 500
|
107
|
-
if is_current_user_bot
|
176
|
+
if is_current_user_bot? == true
|
108
177
|
if limit > 5000
|
109
178
|
params[:cmlimit] = 5000
|
110
179
|
else
|
@@ -124,6 +193,41 @@ module MediaWiki
|
|
124
193
|
end
|
125
194
|
return ret
|
126
195
|
end
|
196
|
+
|
197
|
+
# Returns an array of random pages titles.
|
198
|
+
# @param number_of_pages [Int] The number of articles to get. Defaults to 1. Cannot be greater than 10 for normal users, or 20 for bots.
|
199
|
+
# @param namespace [Int] The namespace ID. Defaults to '0' (the main namespace). Set to nil for all namespaces.
|
200
|
+
# @return [Array] All members
|
201
|
+
def get_random_pages(number_of_pages = 1, namespace = 0)
|
202
|
+
params = {
|
203
|
+
action: 'query',
|
204
|
+
list: 'random',
|
205
|
+
format: 'json'
|
206
|
+
}
|
207
|
+
|
208
|
+
params[:rnnamespace] = namespace if namespace != nil
|
209
|
+
|
210
|
+
if namespace > 10
|
211
|
+
if is_current_user_bot? == true
|
212
|
+
if limit > 20
|
213
|
+
params[:rnlimit] = 20
|
214
|
+
else
|
215
|
+
params[:rnlimit] = limit
|
216
|
+
end
|
217
|
+
else
|
218
|
+
params[:rnlimit] = 10
|
219
|
+
end
|
220
|
+
else
|
221
|
+
params[:rnlimit] = namespace
|
222
|
+
end
|
223
|
+
|
224
|
+
ret = Array.new
|
225
|
+
responce = post(params)
|
226
|
+
responce["query"]["random"].each do |a|
|
227
|
+
ret.push(a["title"])
|
228
|
+
end
|
229
|
+
return ret
|
230
|
+
end
|
127
231
|
end
|
128
232
|
end
|
129
233
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediawiki-butt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
8
|
+
- Eric Schneider (xbony2)
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
12
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: httpclient
|
@@ -72,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
75
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.4.5
|
76
|
+
rubygems_version: 2.4.5.1
|
76
77
|
signing_key:
|
77
78
|
specification_version: 4
|
78
79
|
summary: Interacting with the MediaWiki API
|