Skip to content

Commit

Permalink
🐛 Fix #16 in a non-xbony manner.
Browse files Browse the repository at this point in the history
  • Loading branch information
elifoster committed Dec 7, 2015
1 parent dac4b9a commit 2e8845b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
5 changes: 3 additions & 2 deletions lib/mediawiki/butt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
module MediaWiki
class Butt
include MediaWiki::Auth
include MediaWiki::Query
include MediaWiki::Query::Meta::SiteInfo
include MediaWiki::Query::Meta::FileRepoInfo
include MediaWiki::Query::Meta::UserInfo
Expand Down Expand Up @@ -75,10 +76,10 @@ def post(params, autoparse = true, header = nil)
# the currently logged in user if nil.
# @return [Boolean] true if logged in as a bot, false if not logged in or
# logged in as a non-bot
def user_bot?(*username)
def user_bot?(username = nil)
groups = false

if defined? username
if !username.nil?

This comment has been minimized.

Copy link
@elifoster

elifoster Dec 7, 2015

Author Member

I also fixed the splat argument causing this method to always return false

groups = get_usergroups(username)
else
groups = get_usergroups if @logged_in
Expand Down
25 changes: 13 additions & 12 deletions lib/mediawiki/query/lists.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative '../constants'
require_relative 'query'

module MediaWiki
module Query
Expand All @@ -14,7 +15,7 @@ def what_links_here(title, limit = 500)
action: 'query',
list: 'backlinks',
bltitle: title,
bllimit: MediaWiki::Query.get_limited(limit)
bllimit: get_limited(limit)
}

ret = []
Expand All @@ -37,7 +38,7 @@ def get_category_members(category, limit = 500)
action: 'query',
list: 'categorymembers',
cmprop: 'title',
cmlimit: MediaWiki::Query.get_limited(limit)
cmlimit: get_limited(limit)
}

if category =~ /[Cc]ategory\:/
Expand All @@ -63,7 +64,7 @@ def get_random_pages(number_of_pages = 1, namespace = 0)
params = {
action: 'query',
list: 'random',
rnlimit: MediaWiki::Query.get_limited(number_of_pages, 10, 20)
rnlimit: get_limited(number_of_pages, 10, 20)
}

if @namespaces.value?(namespace)
Expand Down Expand Up @@ -275,7 +276,7 @@ def get_all_categories(limit = 500)
params = {
action: 'query',
list: 'allcategories',
aclimit: MediaWiki::Query.get_limited(limit)
aclimit: get_limited(limit)
}

response = post(params)
Expand All @@ -294,7 +295,7 @@ def get_all_images(limit = 500)
params = {
action: 'query',
list: 'allimages',
ailimit: MediaWiki::Query.get_limited(limit)
ailimit: get_limited(limit)
}

response = post(params)
Expand All @@ -314,7 +315,7 @@ def get_all_pages_in_namespace(namespace, limit = 500)
action: 'query',
list: 'allpages',
apnamespace: namespace,
aplimit: MediaWiki::Query.get_limited(limit)
aplimit: get_limited(limit)
}

response = post(params)
Expand All @@ -333,7 +334,7 @@ def get_all_users(group = nil, limit = 500)
params = {
action: 'query',
list: 'allusers',
aulimit: MediaWiki::Query.get_limited(limit)
aulimit: get_limited(limit)
}
params[:augroup] = group unless group.nil?

Expand All @@ -353,7 +354,7 @@ def get_all_blocks(limit = 500)
params = {
action: 'query',
list: 'blocks',
bklimit: MediaWiki::Query.get_limited(limit),
bklimit: get_limited(limit),
bkprop: 'id'
}

Expand All @@ -374,7 +375,7 @@ def get_all_transcluders(page, limit = 500)
action: 'query',
list: 'embeddedin',
eititle: page,
eilimit: MediaWiki::Query.get_limited(limit)
eilimit: get_limited(limit)
}

response = post(params)
Expand All @@ -393,7 +394,7 @@ def get_all_deleted_files(limit = 500)
params = {
action: 'query',
list: 'filearchive',
falimit: MediaWiki::Query.get_limited(limit)
falimit: get_limited(limit)
}

response = post(params)
Expand All @@ -412,7 +413,7 @@ def get_all_protected_titles(protection_level = nil, limit = 500)
params = {
action: 'query',
list: 'protectedtitles',
ptlimit: MediaWiki::Query.get_limited(limit)
ptlimit: get_limited(limit)
}
params[:ptlevel] = protection_level unless protection_level.nil?

Expand All @@ -435,7 +436,7 @@ def get_user_contributions(user, limit = 500)
action: 'query',
list: 'usercontribs',
ucuser: user,
uclimit: MediaWiki::Query.get_limited(limit),
uclimit: get_limited(limit),
ucprop: 'ids|title|comment|size|sizediff|flags|patrolled'
}

Expand Down
4 changes: 3 additions & 1 deletion lib/mediawiki/query/properties/contributors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../query'

module MediaWiki
module Query
module Properties
Expand Down Expand Up @@ -46,7 +48,7 @@ def get_contributors_response(title, limit = 500)
action: 'query',
prop: 'contributors',
titles: title,
pclimit: MediaWiki::Query.get_limited(limit)
pclimit: get_limited(limit)
}

post(params)
Expand Down
6 changes: 4 additions & 2 deletions lib/mediawiki/query/properties/files.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../query'

module MediaWiki
module Query
module Properties
Expand All @@ -12,7 +14,7 @@ def get_duplicated_files_of(title, limit = 500)
action: 'query',
prop: 'duplicatefiles',
titles: title,
dflimit: MediaWiki::Query.get_limited(limit)
dflimit: get_limited(limit)
}

response = post(params)
Expand All @@ -34,7 +36,7 @@ def get_all_duplicated_files(limit = 500)
action: 'query',
generator: 'allimages',
prop: 'duplicatefiles',
dflimit: MediaWiki::Query.get_limited(limit)
dflimit: get_limited(limit)
}

response = post(params)
Expand Down
14 changes: 8 additions & 6 deletions lib/mediawiki/query/properties/pages.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../query'

module MediaWiki
module Query
module Properties
Expand Down Expand Up @@ -85,7 +87,7 @@ def get_external_links(page, limit = 500)
action: 'query',
titles: page,
prop: 'extlinks',
ellimit: MediaWiki::Query.get_limited(limit)
ellimit: get_limited(limit)
}

response = post(params)
Expand Down Expand Up @@ -302,7 +304,7 @@ def get_images_in_page(page, limit = 500)
action: 'query',
prop: 'images',
titles: page,
imlimit: MediaWiki::Query.get_limited(limit)
imlimit: get_limited(limit)
}

response = post(params)
Expand Down Expand Up @@ -330,7 +332,7 @@ def get_templates_in_page(page, limit = 500)
action: 'query',
prop: 'templates',
titles: page,
tllimit: MediaWiki::Query.get_limited(limit)
tllimit: get_limited(limit)
}

response = post(params)
Expand Down Expand Up @@ -358,7 +360,7 @@ def get_interwiki_links_in_page(page, limit = 500)
action: 'query',
prop: 'iwlinks',
titles: page,
tllimit: MediaWiki::Query.get_limited(limit)
tllimit: get_limited(limit)
}

response = post(params)
Expand Down Expand Up @@ -388,7 +390,7 @@ def get_other_langs_of_page(page, limit = 500)
action: 'query',
prop: 'langlinks',
titles: page,
lllimit: MediaWiki::Query.get_limited(limit),
lllimit: get_limited(limit),
llprop: 'url|langname|autonym'
}

Expand Down Expand Up @@ -422,7 +424,7 @@ def get_all_links_in_page(page, limit = 500)
action: 'query',
prop: 'links',
titles: page,
pllimit: MediaWiki::Query.get_limited(limit)
pllimit: get_limited(limit)
}

response = post(params)
Expand Down
15 changes: 6 additions & 9 deletions lib/mediawiki/query/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ module Query

protected

module_function

# Gets the limited version of the integer, to ensure nobody provides an int
# that is too large.
# @param integer [Int] The number to limit.
# @param max_user [Int] The maximum limit for normal users.
# @param max_bot [Int] The maximum limit for bot users.
# @param is_user_bot [Boolean] Set to true if the user is a bot.
# @return [Int] The capped number.
def get_limited(integer, max_user = 500, max_bot = 5000, is_user_bot = false)
if integer > 500
if is_user_bot
if integer > 5000
return 5000
def get_limited(integer, max_user = 500, max_bot = 5000)
if integer > max_user
if user_bot?
if integer > max_bot
return max_bot
else
return integer
end
else
return 500
return max_user
end
else
return integer
Expand Down

0 comments on commit 2e8845b

Please sign in to comment.