Skip to content

Commit

Permalink
Styling, comments. A ton of new FileRepoInfo methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
elifoster committed Oct 8, 2015
1 parent 2330958 commit 6e075bb
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog
## Version 0
### Version 0.6.0
* New get_filerepo_favicons method.
* New get_filerepo_thumburls method.
* New get_nonlocal_filerepos method.
* New get_local_filerepos method.
* New get_filerepo_urls method.
* New get_filerepo_rooturls method.
* Refactor get_filerepo_names to use new get_filerepoinfo method.
* New get_filerepoinfo method, in a similar style to get_userlists.
* New get_current_user_options for getting a hash containing all of the currently logged in user's preferences.
* New get_email_address method for getting the currently logged in user's email address.
* New get_realname method for getting the currently logged in user's real name.
Expand Down
84 changes: 73 additions & 11 deletions lib/mediawiki/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module MediaWiki
module Query
module Meta
# TODO: namespaces and namespacealiases.
module SiteInfo
# Gets wiki information. This method should rarely be used by
# normal users.
Expand All @@ -26,7 +25,6 @@ def get_statistics
response = get_siteinfo('statistics')
ret = {}
response['query']['statistics'].each { |k, v| ret[k] = v }

ret
end

Expand All @@ -36,7 +34,6 @@ def get_general
response = get_siteinfo('general')
ret = {}
response['query']['general'].each { |k, v| ret[k] = v }

ret
end

Expand All @@ -46,7 +43,6 @@ def get_extensions
response = get_siteinfo('extensions')
ret = []
response['query']['extensions'].each { |e| ret.push(e['name']) }

ret
end

Expand All @@ -57,25 +53,91 @@ def get_languages
response = get_siteinfo('languages')
ret = {}
response['query']['languages'].each { |l| ret[l['code']] = l['*'] }

ret
end
end

module FileRepoInfo
# Returns an array of all the wiki's file repository names.
# @return [Array] All wiki's file repository names.
def get_filerepo_names
# Gets FileRepoInfo for the property.
# @param prop [String] The friprop to get.
# @return [Response] The full parsed response.
def get_filerepoinfo(prop)
params = {
action: 'query',
meta: 'filerepoinfo',
friprop: 'name'
friprop: prop
}

result = post(params)
post(params)
end

# Returns an array of all the wiki's file repository names.
# @return [Array] All wiki's file repository names.
def get_filerepo_names
response = get_filerepoinfo('name|displayname')
ret = {}
response['query']['repos'].each { |n, dn| ret[n] = dn }
ret
end

# Gets the root URLs for the file repositories.
# @return [Hash] A hash containing keys of the names, and values of the
# root URLs.
def get_filerepo_rooturls
response = get_filerepoinfo('name|rootUrl')
ret = {}
response['query']['repos'].each { |n, r| ret[n] = r }
ret
end

# Gets an array containing all local repositories.
# @return [Array] All repositories that are marked as local.
def get_local_filerepos
response = get_filerepoinfo('name|local')
ret = []
response['query']['repos'].each do |n, l|
ret.push(n) if l == 'true'
end

ret
end

# Gets an array containing all repositories that aren't local.
# @return [Array] All repositories that are not marked as local.
def get_nonlocal_filerepos
response = get_filerepoinfo('name|local')
ret = []
result['query']['repos'].each { |repo| ret.push(repo['name']) }
response['query']['repos'].each do |n, l|
ret.push(n) if l == 'false'
end

ret
end

# Gets the repository names and their according URLs.
# @return [Hash] Names as the keys, with their URLs as the values.
def get_filerepo_urls
response = get_filerepoinfo('name|url')
ret = {}
response['query']['repos'].each { |n, u| ret[n] = u }
ret
end

# Gets the repository names and their accoring thumbnail URLs.
# @return [Hash] Names as the keys, with their URLs as the values.
def get_filerepo_thumburls
response = get_filerepoinfo('name|thumbUrl')
ret = {}
response['query']['repos'].each { |n, u| ret[n] = u }
ret
end

# Gets the repository names and their according favicon URLs.
# @return [Hash] Names as the keys, with their favicons as the values.
def get_filerepo_favicons
response = get_filerepoinfo('name|favicon')
ret = {}
response['query']['repos'].each { |n, f| ret[n] = f }
ret
end
end
Expand Down

0 comments on commit 6e075bb

Please sign in to comment.