mediawiki-butt 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbd268a2d756469fbc632169feaeaa48b2eaabea
4
- data.tar.gz: dad624c4add5afefe4a0dd5bcbcd9b09dbc203d5
3
+ metadata.gz: 5f0cb702f0e050eec5aad59b978c319b3bdb4d88
4
+ data.tar.gz: c3d22dd52186fd7e1bfd837230a5984287835087
5
5
  SHA512:
6
- metadata.gz: dc460415bd8589e103c3956c5c24cb4754aef9c0a0395a6b9f5e534a878d68606395797e75f0cb0aa0460eb51fdd72e5fd950209708b316144d478fb2b9afd59
7
- data.tar.gz: b7cfec3633270b2374c7e219166e6ce917a8632b7605df9d1af34cb7a7233d00601c398a2e08719ce002e54753f07a43016e09808f0f0d501e5575b80367ab68
6
+ metadata.gz: 5331fe0d0bb49e849ef1d68a50a461215dbb6008563d66d80105340420f86b6ae62e2fe1eab09ab5c19fb10e7a080f99dcf3c185a9b94e0d6b09735ef2afceef
7
+ data.tar.gz: 62bbf5cae65347c3040dda3271ac711e5ff8e5aac2e56bee3b04df02b55edc1f1d036c04739b6a39639a25166f9fc74838e2b96a2f78ad7f7a83cdfd69d12ee0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
  ## Version 0
3
+ ### Version 0.4.1
4
+ * check_login and check_create now use case/when statements instead of elsifs.
5
+ * check_create no longer returns anything.
6
+ * Update minimum Ruby version to 2.1, for refinements.
7
+ * Fix $namespaces hash syntax.
8
+ * Generally improved if statement syntax.
9
+ * Generally shortened a lot of code by using better syntax.
10
+
3
11
  ### Version 0.4.0
4
12
  * New get_userrights method for getting an array of all user rights that user has.
5
13
  * New get_user_gender method for getting the gender of the provided user.
@@ -8,37 +8,40 @@ module MediaWiki
8
8
  # @param secondtry [Boolean] Whether this login is the first or second try. False for first, true for second.
9
9
  # @return [Boolean] true if successful, else false.
10
10
  def check_login(result, secondtry)
11
- if result == "Success"
11
+ case result
12
+ when "Success"
12
13
  @logged_in = true
13
14
  return true
14
- elsif result == "NeedToken" && secondtry == true
15
- raise MediaWiki::Butt::NeedTokenMoreThanOnceError
16
- return false
17
- elsif result == "NoName"
15
+ when "NeedToken"
16
+ if secondtry == true
17
+ raise MediaWiki::Butt::NeedTokenMoreThanOnceError
18
+ return false
19
+ end
20
+ when "NoName"
18
21
  raise MediaWiki::Butt::NoNameError
19
22
  return false
20
- elsif result == "Illegal"
23
+ when "Illegal"
21
24
  raise MediaWiki::Butt::IllegalUsernameError
22
25
  return false
23
- elsif result == "NotExists"
26
+ when "NotExists"
24
27
  raise MediaWiki::Butt::UsernameNotExistsError
25
28
  return false
26
- elsif result == "EmptyPass"
29
+ when "EmptyPass"
27
30
  raise MediaWiki::Butt::EmptyPassError
28
31
  return false
29
- elsif result == "WrongPass"
32
+ when "WrongPass"
30
33
  raise MediaWiki::Butt::WrongPassError
31
34
  return false
32
- elsif result == "WrongPluginPass"
35
+ when "WrongPluginPass"
33
36
  raise MediaWiki::Butt::WrongPluginPassError
34
37
  return false
35
- elsif result == "CreateBlocked"
38
+ when "CreateBlocked"
36
39
  raise MediaWiki::Butt::CreateBlockedError
37
40
  return false
38
- elsif result == "Throttled"
41
+ when "Throttled"
39
42
  raise MediaWiki::Butt::ThrottledError
40
43
  return false
41
- elsif result == "Blocked"
44
+ when "Blocked"
42
45
  raise MediaWiki::Butt::BlockedError
43
46
  return false
44
47
  end
@@ -46,47 +49,34 @@ module MediaWiki
46
49
 
47
50
  # Checks the account creation result's error and raises the corresponding error.
48
51
  # @param error [String] The parsed error "code" string
49
- # @return [Boolean] Always false
50
52
  def check_create(error)
51
- if error == "noname"
53
+ case error
54
+ when "noname"
52
55
  raise MediaWiki::Butt::NoNameError
53
- return false
54
- elsif error == "userexists"
56
+ when "userexists"
55
57
  raise MediaWiki::Butt::UserExistsError
56
- return false
57
- elsif error == "password-name-match"
58
+ when "password-name-match"
58
59
  raise MediaWiki::Butt::UserPassMatchError
59
- return false
60
- elsif error == "password-login-forbidden"
60
+ when "password-login-forbidden"
61
61
  raise MediaWiki::Butt::PasswordLoginForbiddenError
62
- return false
63
- elsif error == "noemailtitle"
62
+ when "noemailtitle"
64
63
  raise MediaWiki::Butt::NoEmailTitleError
65
- return false
66
- elsif error == "invalidemailaddress"
64
+ when "invalidemailaddress"
67
65
  raise MediaWiki::Butt::InvalidEmailAddressError
68
- return false
69
- elsif error == "passwordtooshort"
66
+ when "passwordtooshort"
70
67
  raise MediaWiki::Butt::PasswordTooShortError
71
- return false
72
- elsif error == "noemail"
68
+ when "noemail"
73
69
  raise MediaWiki::Butt::NoEmailError
74
- return false
75
- elsif error == "acct_creation_throttle_hit"
70
+ when "acct_creation_throttle_hit"
76
71
  raise MediaWiki::Butt::ThrottledError
77
- return false
78
- elsif error == "aborted"
72
+ when "aborted"
79
73
  raise MediaWiki::Butt::AbortedError
80
- return false
81
- elsif error == "blocked"
74
+ when "blocked"
82
75
  raise MediaWiki::Butt::BlockedError
83
- return false
84
- elsif error == "permdenied-createaccount"
76
+ when "permdenied-createaccount"
85
77
  raise MediaWiki::Butt::PermDeniedError
86
- return false
87
- elsif error == "createaccount-hook-aborted"
78
+ when "createaccount-hook-aborted"
88
79
  raise MediaWiki::Butt::HookAbortedError
89
- return false
90
80
  end
91
81
  end
92
82
 
@@ -103,10 +93,10 @@ module MediaWiki
103
93
  }
104
94
 
105
95
  result = post(params)
106
- if check_login(result["login"]["result"], false) == true
96
+ if check_login(result["login"]["result"], false)
107
97
  @logged_in = true
108
98
  @tokens.clear
109
- return true
99
+ true
110
100
  elsif result["login"]["result"] == "NeedToken" && result["login"]["token"] != nil
111
101
  token = result["login"]["token"]
112
102
  token_params = {
@@ -120,14 +110,14 @@ module MediaWiki
120
110
  #Consider refactor the @cookie initialization.
121
111
  @cookie = "#{result["login"]["cookieprefix"]}Session=#{result["login"]["sessionid"]}"
122
112
  result = post(token_params, true, { 'Set-Cookie' => @cookie })
123
- return check_login(result["login"]["result"], true)
113
+ check_login(result["login"]["result"], true)
124
114
  end
125
115
  end
126
116
 
127
117
  # Logs the current user out.
128
118
  # @return [Boolean] True if it was able to log anyone out, false if not (basically, if someone was logged in, it returns true).
129
119
  def logout
130
- if @logged_in == true
120
+ if @logged_in
131
121
  params = {
132
122
  action: 'logout',
133
123
  format: 'json'
@@ -20,11 +20,7 @@ module MediaWiki
20
20
  # @param use_ssl [Boolean] Whether or not to use SSL. Will default to true.
21
21
  # @return [MediaWiki::Butt] new instance of MediaWiki::Butt
22
22
  def initialize(url, use_ssl = true)
23
- if url =~ /api.php$/
24
- @url = url
25
- else
26
- @url = "#{url}/api.php"
27
- end
23
+ @url = url =~ /api.php$/ ? url : "#{url}/api.php"
28
24
 
29
25
  @client = HTTPClient.new
30
26
  @uri = URI.parse(@url)
@@ -44,16 +40,12 @@ module MediaWiki
44
40
  # We must use header.nil? rather than a splat argument and defined? header due to this error.
45
41
  # For those interested, the error is: undefined method `downcase' for {"Set-Cookie"=>"cookie"}:Hash (NoMethodError)
46
42
  # This is obvisouly an error in HTTPClient, but we must work around it until there is a fix in the gem.
47
- if header.nil?
48
- response = @client.post(@uri, params)
49
- else
50
- response = @client.post(@uri, params, header)
51
- end
43
+ res = header.nil? ? @client.post(@uri, params) : @client.post(@uri, params, header)
52
44
 
53
- if autoparse == true
54
- return JSON.parse(response.body)
45
+ if autoparse
46
+ return JSON.parse(res.body)
55
47
  else
56
- return response
48
+ return res
57
49
  end
58
50
  end
59
51
 
@@ -61,18 +53,10 @@ module MediaWiki
61
53
  # @param username [String] The username to check. Optional. Defaults to the currently logged in user if nil.
62
54
  # @return [Boolean] true if logged in as a bot, false if not logged in or logged in as a non-bot
63
55
  def is_user_bot?(*username)
64
- if defined? username
65
- groups = get_usergroups(username)
66
- else
67
- groups = get_usergroups
68
- end
56
+ groups = defined? username ? get_usergroups(username) : get_usergroups
69
57
 
70
58
  if groups != false
71
- if groups.include? "bot"
72
- return true
73
- else
74
- return false
75
- end
59
+ return groups.include?("bot")
76
60
  else
77
61
  return false
78
62
  end
@@ -3,216 +3,216 @@ module MediaWiki
3
3
  # Constants Namespace IDs. Taken from https://www.mediawiki.org/wiki/Extension_default_namespaces
4
4
  module Namespaces
5
5
  $namespaces = {
6
- "MAIN": 0,
7
- "TALK": 1,
8
- "USER": 2,
9
- "USER_TALK": 3,
10
- "PROJECT": 4,
11
- "PROJECT_TALK": 5,
12
- "FILE": 6,
13
- "FILE_TALK": 7,
14
- "MEDIAWIKI": 8,
15
- "MEDIAWIKI_TALK": 9,
16
- "TEMPLATE": 10,
17
- "TEMPLATE_TALK": 11,
18
- "HELP": 12,
19
- "HELP_TALK": 13,
20
- "CATEGORY": 14,
21
- "CATEGORY_TALK": 15,
22
- "SPECIAL": -1,
23
- "MEDIA": -2,
6
+ "MAIN" => 0,
7
+ "TALK" => 1,
8
+ "USER" => 2,
9
+ "USER_TALK" => 3,
10
+ "PROJECT" => 4,
11
+ "PROJECT_TALK" => 5,
12
+ "FILE" => 6,
13
+ "FILE_TALK" => 7,
14
+ "MEDIAWIKI" => 8,
15
+ "MEDIAWIKI_TALK" => 9,
16
+ "TEMPLATE" => 10,
17
+ "TEMPLATE_TALK" => 11,
18
+ "HELP" => 12,
19
+ "HELP_TALK" => 13,
20
+ "CATEGORY" => 14,
21
+ "CATEGORY_TALK" => 15,
22
+ "SPECIAL" => -1,
23
+ "MEDIA" => -2,
24
24
 
25
25
  # Extension:LiquidThreads
26
- "LQT_THREAD": 90,
27
- "LQT_THREAD_TALK": 91,
28
- "LQT_SUMMARY": 92,
29
- "LQT_SUMMARY_TALK": 93,
26
+ "LQT_THREAD" => 90,
27
+ "LQT_THREAD_TALK" => 91,
28
+ "LQT_SUMMARY" => 92,
29
+ "LQT_SUMMARY_TALK" => 93,
30
30
 
31
31
  # Extension:Semantic MediaWiki / Extension:Semantic Forms
32
- "SMW_RELATION": 100,
33
- "SMW_RELATION_TALK": 101,
34
- "SMW_PROPERTY": 102,
35
- "SMW_PROPERTY_TALK": 103,
36
- "SMW_TYPE": 104,
37
- "SMW_TYPE_TALK": 105,
38
- "SMW_FORM": 106,
39
- "SMW_FORM_TALK": 107,
40
- "SF_CONCEPT": 108,
41
- "SF_CONCEPT_TALK": 109,
32
+ "SMW_RELATION" => 100,
33
+ "SMW_RELATION_TALK" => 101,
34
+ "SMW_PROPERTY" => 102,
35
+ "SMW_PROPERTY_TALK" => 103,
36
+ "SMW_TYPE" => 104,
37
+ "SMW_TYPE_TALK" => 105,
38
+ "SMW_FORM" => 106,
39
+ "SMW_FORM_TALK" => 107,
40
+ "SF_CONCEPT" => 108,
41
+ "SF_CONCEPT_TALK" => 109,
42
42
 
43
43
  # Extension:DPLforum
44
- "DPLF_FORUM": 110,
45
- "DPLF_FORUM_TAlK": 111,
44
+ "DPLF_FORUM" => 110,
45
+ "DPLF_FORUM_TAlK" => 111,
46
46
 
47
47
  # Extension:RefHelper
48
- "RFH_CITE": 120,
49
- "RFH_CITE_TALK": 121,
48
+ "RFH_CITE" => 120,
49
+ "RFH_CITE_TALK" => 121,
50
50
 
51
51
  # Extension:SemanticAccessControl
52
- "ACL_USERGROUP": 160,
53
- "ACL_ACL": 162,
52
+ "ACL_USERGROUP" => 160,
53
+ "ACL_ACL" => 162,
54
54
 
55
55
  # Extension:Semantic Drilldown
56
- "SED_FILTER": 170,
57
- "SED_FILTER_TALK": 171,
56
+ "SED_FILTER" => 170,
57
+ "SED_FILTER_TALK" => 171,
58
58
 
59
59
  # Extension:SocialProfile
60
- "SCP_USERWIKI": 200,
61
- "SCP_USERWIKI_TALK": 201,
62
- "SCP_USERPROFILE": 202,
63
- "SCP_USERPROFILE_TALK": 203,
60
+ "SCP_USERWIKI" => 200,
61
+ "SCP_USERWIKI_TALK" => 201,
62
+ "SCP_USERPROFILE" => 202,
63
+ "SCP_USERPROFILE_TALK" => 203,
64
64
 
65
65
  # Extension:Proofread Page
66
- "PRP_PAGE": 250,
67
- "PRP_PAGE_TALK": 251,
68
- "PRP_INDEX": 252,
69
- "PRP_INDEX_TALK": 253,
66
+ "PRP_PAGE" => 250,
67
+ "PRP_PAGE_TALK" => 251,
68
+ "PRP_INDEX" => 252,
69
+ "PRP_INDEX_TALK" => 253,
70
70
 
71
71
  # Extension:TrustedMath
72
- "TRM_MATH": 262,
73
- "TRM_MATH_TALK": 263,
72
+ "TRM_MATH" => 262,
73
+ "TRM_MATH_TALK" => 263,
74
74
 
75
75
  # Extension:Widgets
76
- "WID_WIDGET": 274,
77
- "WID_WIDGET_TALK": 275,
76
+ "WID_WIDGET" => 274,
77
+ "WID_WIDGET_TALK" => 275,
78
78
 
79
79
  # Extension:EmbedScript
80
- "EMS_JSAPPLET": 280,
81
- "EMS_JSAPPLET_TALK": 281,
80
+ "EMS_JSAPPLET" => 280,
81
+ "EMS_JSAPPLET_TALK" => 281,
82
82
 
83
83
  # Extension:PollNY
84
- "PLN_POLL": 300,
85
- "PLN_POLL_TALK": 301,
84
+ "PLN_POLL" => 300,
85
+ "PLN_POLL_TALK" => 301,
86
86
 
87
87
  # Extension:Semantic Image Annotator
88
- "SIA_IMAGE_ANNOTATOR": 380,
88
+ "SIA_IMAGE_ANNOTATOR" => 380,
89
89
 
90
90
  # Extension:Wiki2LaTeX
91
- "WTL_WIKI2LATEX": 400,
92
- "WTL_WIKI2LATEX_TALK": 401,
91
+ "WTL_WIKI2LATEX" => 400,
92
+ "WTL_WIKI2LATEX_TALK" => 401,
93
93
 
94
94
  # Extension:Workflow
95
- "WRF_WORKFLOW": 410,
96
- "WRF_WORKFLOW_TALK": 411,
95
+ "WRF_WORKFLOW" => 410,
96
+ "WRF_WORKFLOW_TALK" => 411,
97
97
 
98
98
  # Extension:Maps
99
- "MAP_LAYER": 420,
100
- "MAP_LAYER_TALK": 421,
99
+ "MAP_LAYER" => 420,
100
+ "MAP_LAYER_TALK" => 421,
101
101
 
102
102
  # Extension:QuizTabulate
103
- "QTB_QUIZ": 430,
104
- "QTB_QUIZ_TALK": 431,
103
+ "QTB_QUIZ" => 430,
104
+ "QTB_QUIZ_TALK" => 431,
105
105
 
106
106
  # Extension:Education Program
107
- "EDP_EDUCATION_PROGRAM": 446,
108
- "EDP_EDUCATION_PROGRAM_TALK": 447,
107
+ "EDP_EDUCATION_PROGRAM" => 446,
108
+ "EDP_EDUCATION_PROGRAM_TALK" => 447,
109
109
 
110
110
  # Extension:BoilerRoom
111
- "BLR_BOILERPLATE": 450,
112
- "BLR_BOILERPLATE_TALK": 451,
111
+ "BLR_BOILERPLATE" => 450,
112
+ "BLR_BOILERPLATE_TALK" => 451,
113
113
 
114
114
  # Extension:UploadWizard
115
- "UPW_CAMPAIGN": 460,
116
- "UPW_CAMPAIGN_TALK": 461,
115
+ "UPW_CAMPAIGN" => 460,
116
+ "UPW_CAMPAIGN_TALK" => 461,
117
117
 
118
118
  # Extension:EventLogging
119
- "ELG_SCHEMA": 470,
120
- "ELG_SCHEMA_TALK": 471,
119
+ "ELG_SCHEMA" => 470,
120
+ "ELG_SCHEMA_TALK" => 471,
121
121
 
122
122
  # Extension:ZeroBanner
123
- "ZRB_ZERO": 480,
124
- "ZRB_ZERO_TALK": 481,
123
+ "ZRB_ZERO" => 480,
124
+ "ZRB_ZERO_TALK" => 481,
125
125
 
126
126
  # Extension:JsonConfig
127
- "JSC_CONFIG": 482,
128
- "JSC_CONFIG_TALK": 483,
129
- "JSC_DATA": 486,
130
- "JSC_DATA_TALK": 487,
127
+ "JSC_CONFIG" => 482,
128
+ "JSC_CONFIG_TALK" => 483,
129
+ "JSC_DATA" => 486,
130
+ "JSC_DATA_TALK" => 487,
131
131
 
132
132
  # Extension:Graph
133
- "GRP_GRAPH": 484,
134
- "GRP_GRAPH_TALK": 485,
133
+ "GRP_GRAPH" => 484,
134
+ "GRP_GRAPH_TALK" => 485,
135
135
 
136
136
  # Extension:OpenStackManager
137
- "OSM_NOVA_RESOURCE": 488,
138
- "OSM_NOVA_RESOURCE_TALK": 489,
137
+ "OSM_NOVA_RESOURCE" => 488,
138
+ "OSM_NOVA_RESOURCE_TALK" => 489,
139
139
 
140
140
  # Extension:GWToolset
141
- "GWT_GWTOOLSET": 490,
142
- "GWT_GWTOOLSET_TALK": 491,
141
+ "GWT_GWTOOLSET" => 490,
142
+ "GWT_GWTOOLSET_TALK" => 491,
143
143
 
144
144
  # Extension:BlogPage
145
- "BLP_BLOG": 500,
146
- "BLP_BLOG_TALK": 501,
145
+ "BLP_BLOG" => 500,
146
+ "BLP_BLOG_TALK" => 501,
147
147
 
148
148
  # Extension:XMLContentExtension
149
- "XCE_XML": 580,
150
- "XCE_XML_TALK": 581,
151
- "XCE_SCHEMA": 582,
152
- "XCE_SCHEMA_TALK": 583,
149
+ "XCE_XML" => 580,
150
+ "XCE_XML_TALK" => 581,
151
+ "XCE_SCHEMA" => 582,
152
+ "XCE_SCHEMA_TALK" => 583,
153
153
 
154
154
  # Extension:FanBoxes
155
- "FNB_USERBOX": 600,
156
- "FNB_USERBOX_TALK": 601,
155
+ "FNB_USERBOX" => 600,
156
+ "FNB_USERBOX_TALK" => 601,
157
157
 
158
158
  # Extension:LinkFilter
159
- "LFT_LINK": 700,
160
- "LFT_LINK_TALK": 701,
159
+ "LFT_LINK" => 700,
160
+ "LFT_LINK_TALK" => 701,
161
161
 
162
162
  # Extension:TimedMediaHandler
163
- "TMH_TIMEDTEXT": 710,
164
- "TMH_TIMEDTEXT_TALK": 711,
163
+ "TMH_TIMEDTEXT" => 710,
164
+ "TMH_TIMEDTEXT_TALK" => 711,
165
165
 
166
166
  # Extension:QPoll
167
- "QPL_INTERPRETATION": 800,
168
- "QPL_INTERPRETATION_TALK": 801,
167
+ "QPL_INTERPRETATION" => 800,
168
+ "QPL_INTERPRETATION_TALK" => 801,
169
169
 
170
170
  # Extension:SemanticMustacheFormat :3,
171
- "SMF_MUSTACHE": 806,
172
- "SMF_MUSTACHE_TALK": 807,
171
+ "SMF_MUSTACHE" => 806,
172
+ "SMF_MUSTACHE_TALK" => 807,
173
173
 
174
174
  # Extension:R
175
- "R_R": 814,
176
- "R_R_TALK": 815,
175
+ "R_R" => 814,
176
+ "R_R_TALK" => 815,
177
177
 
178
178
  # Extension:Scribunto
179
- "SCR_MODULE": 828,
180
- "SCR_MODULE_TALK": 829,
179
+ "SCR_MODULE" => 828,
180
+ "SCR_MODULE_TALK" => 829,
181
181
 
182
182
  # Extension:SecurePoll
183
- "SEP_SECUREPOLL": 830,
184
- "SEP_SECUREPOLL_TALK": 831,
183
+ "SEP_SECUREPOLL" => 830,
184
+ "SEP_SECUREPOLL_TALK" => 831,
185
185
 
186
186
  # Extension:CentralNotice
187
- "CNT_CNBANNER": 866,
188
- "CNT_CNBANNER_TALK": 867,
187
+ "CNT_CNBANNER" => 866,
188
+ "CNT_CNBANNER_TALK" => 867,
189
189
 
190
190
  # Extension:Translate
191
- "TRN_TRANSLATIONS": 1198,
192
- "TRN_TRANSLATIOTALK": 1199,
191
+ "TRN_TRANSLATIONS" => 1198,
192
+ "TRN_TRANSLATIOTALK" => 1199,
193
193
 
194
194
  # Extension:PackageForce
195
- "PKF_PACKAGEFORCE": 1300,
196
- "PKF_PACKAGEFORCE_TALK": 1301,
195
+ "PKF_PACKAGEFORCE" => 1300,
196
+ "PKF_PACKAGEFORCE_TALK" => 1301,
197
197
 
198
198
  # Extension:BlueSpice
199
- "BLS_BLOG": 1502,
200
- "BLS_BLOG_TALK": 1503,
201
- "BLS_BOOK": 1504,
202
- "BLS_BOOK_TALK": 1505,
199
+ "BLS_BLOG" => 1502,
200
+ "BLS_BLOG_TALK" => 1503,
201
+ "BLS_BOOK" => 1504,
202
+ "BLS_BOOK_TALK" => 1505,
203
203
 
204
204
  # Extension:Gadgets
205
- "GDG_GADGET": 2300,
206
- "GDG_GADGET_TALK": 2301,
207
- "GDG_GADGET_DEFININTION": 2302,
208
- "GDG_GADGET_DEFININTION_TALK": 2303,
205
+ "GDG_GADGET" => 2300,
206
+ "GDG_GADGET_TALK" => 2301,
207
+ "GDG_GADGET_DEFININTION" => 2302,
208
+ "GDG_GADGET_DEFININTION_TALK" => 2303,
209
209
 
210
210
  # Extension:VisualEditor
211
- "VSE_VISUALEDITOR": 2500,
212
- "VSE_VISUALEDITOR_TALK": 2501,
211
+ "VSE_VISUALEDITOR" => 2500,
212
+ "VSE_VISUALEDITOR_TALK" => 2501,
213
213
 
214
214
  # Extension:Flow
215
- "FLW_TOPIC": 2600
215
+ "FLW_TOPIC" => 2600
216
216
  }
217
217
  end
218
218
  end
@@ -19,8 +19,8 @@ module MediaWiki
19
19
  token = get_edit_token(title)
20
20
 
21
21
  params[:summary] = summary if defined? summary
22
- params[:minor] = '1' if minor == true
23
- params[:bot] = '1' if bot == true
22
+ params[:minor] = '1' if minor
23
+ params[:bot] = '1' if bot
24
24
  params[:token] = token
25
25
 
26
26
  response = post(params)
@@ -50,7 +50,7 @@ module MediaWiki
50
50
 
51
51
  token = get_edit_token(title)
52
52
 
53
- params[:bot] = '1' if bot == true
53
+ params[:bot] = '1' if bot
54
54
  params[:token] = token
55
55
 
56
56
  response = post(params)
@@ -73,11 +73,7 @@ module MediaWiki
73
73
  format: 'json'
74
74
  }
75
75
 
76
- if defined? filename
77
- filename = filename.sub(/$File:/, "")
78
- else
79
- filename = url.split('/')[-1]
80
- end
76
+ filename = defined? filename ? filename.sub(/$File:/, "") : url.split('/')[-1]
81
77
 
82
78
  token = get_edit_token(filename)
83
79
 
@@ -30,7 +30,7 @@ module MediaWiki
30
30
  # @param prop [String] The uiprop to get.
31
31
  # @return [Response/Boolean] Either a full, parsed response, or false if not logged in.
32
32
  def get_current_user_meta(prop)
33
- if @logged_in == true
33
+ if @logged_in
34
34
  params = {
35
35
  action: 'query',
36
36
  meta: 'userinfo',
@@ -38,8 +38,7 @@ module MediaWiki
38
38
  format: 'json'
39
39
  }
40
40
 
41
- response = post(params)
42
- return response
41
+ return response = post(params)
43
42
  else
44
43
  return false
45
44
  end
@@ -175,7 +174,7 @@ module MediaWiki
175
174
  end
176
175
 
177
176
  if limit > 500
178
- if is_user_bot? == true
177
+ if is_user_bot?
179
178
  if limit > 5000
180
179
  params[:cmlimit] = 5000
181
180
  else
@@ -193,7 +192,7 @@ module MediaWiki
193
192
  response["query"]["categorymembers"].each do |cm|
194
193
  ret.push(cm["title"])
195
194
  end
196
- return ret
195
+ ret
197
196
  end
198
197
 
199
198
  # Returns an array of random pages titles.
@@ -214,7 +213,7 @@ module MediaWiki
214
213
  end
215
214
 
216
215
  if number_of_pages > 10
217
- if is_user_bot? == true
216
+ if is_user_bot?
218
217
  if limit > 20
219
218
  params[:rnlimit] = 20
220
219
  else
@@ -241,7 +240,7 @@ module MediaWiki
241
240
  # @return [String/Nil] Parsed full response if successful, nil if the username is nil and the Butt is not logged in.
242
241
  def get_userlists(prop, username = nil)
243
242
  if username.nil?
244
- if @logged_in == true
243
+ if @logged_in
245
244
  response = get_current_user_meta(prop)
246
245
  else
247
246
  return false
@@ -267,7 +266,7 @@ module MediaWiki
267
266
  def get_usergroups(username = nil)
268
267
  ret = Array.new
269
268
  if username.nil?
270
- if @logged_in == true
269
+ if @logged_in
271
270
  info = get_userlists('groups')
272
271
  info["query"]["userinfo"]["groups"].each do |i|
273
272
  ret.push(i)
@@ -293,7 +292,7 @@ module MediaWiki
293
292
  def get_userrights(username = nil)
294
293
  ret = Array.new
295
294
  if username.nil?
296
- if @logged_in == true
295
+ if @logged_in
297
296
  info = get_userlists('rights')
298
297
  info["query"]["userinfo"]["rights"].each do |i|
299
298
  ret.push(i)
@@ -320,7 +319,7 @@ module MediaWiki
320
319
  def get_contrib_count(username = nil, autoparse = true)
321
320
  count = nil
322
321
  if username.nil?
323
- if @logged_in == true
322
+ if @logged_in
324
323
  info = get_userlists('editcount')
325
324
  count = info["query"]["userinfo"]["editcount"]
326
325
  else
@@ -333,7 +332,7 @@ module MediaWiki
333
332
  end
334
333
  end
335
334
 
336
- if autoparse == true
335
+ if autoparse
337
336
  countstring = count.to_s.separate
338
337
  return countstring
339
338
  end
@@ -347,7 +346,7 @@ module MediaWiki
347
346
  time = nil
348
347
  # Do note that in Userinfo, registration is called registrationdate.
349
348
  if username.nil?
350
- if @logged_in == true
349
+ if @logged_in
351
350
  info = get_userlists('registrationdate')
352
351
  time = info["query"]["userinfo"]["registrationdate"]
353
352
  else
@@ -363,7 +362,6 @@ module MediaWiki
363
362
  # %Y: Year including century, %m: Month num, %d day of month, %T Time as H:M:S
364
363
  timeformat = "%Y-%m-%dT%T"
365
364
  time = DateTime.strptime(time, timeformat)
366
- return time
367
365
  end
368
366
 
369
367
  # Gets the gender for the provded user.
@@ -426,6 +424,7 @@ module MediaWiki
426
424
  response["query"]["search"].each do |search|
427
425
  ret.push(search["title"])
428
426
  end
427
+
429
428
  return ret
430
429
  end
431
430
  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.0
4
+ version: 0.4.1
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: 2015-10-03 00:00:00.000000000 Z
12
+ date: 2015-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: string-utility
@@ -39,8 +39,8 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
- description: |2
43
- MediaWiki::Butt is a Ruby Gem that provides a fully-featured MediaWiki API interface.
42
+ description: " MediaWiki::Butt is a Ruby Gem that provides a fully-featured MediaWiki
43
+ API interface.\n"
44
44
  email: elifosterwy@gmail.com
45
45
  executables: []
46
46
  extensions: []
@@ -67,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: '2.0'
70
+ version: '2.1'
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="