Skip to content

Commit

Permalink
Finished all Meta methods. Close #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
elifoster committed Oct 9, 2015
1 parent 6ad1357 commit 3a17569
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog
## Version 0
### Version 0.6.0
* New get_variables method.
* New get_function_hooks method.
* New get_extension_tags method.
* New get_skins method.
* New get_restriction_levels method.
* New get_restriction_types method.
* New get_restrictions_data method for the above methods.
* New get_allowed_file_extensions method.
* New get_all_usergroups method.
* New get_magic_words method.
* New get_special_page_aliases method.
* New get_namespace_aliases method.
* New get_namespaces method.
* New get_filerepo_favicons method.
* New get_filerepo_thumburls method.
* New get_nonlocal_filerepos method.
Expand Down
140 changes: 139 additions & 1 deletion lib/mediawiki/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,151 @@ def get_extensions

# Gets all languages and their codes.
# @return [Hash] All languages. Hash key value pair formatted as
# code => name
# code => name.
def get_languages
response = get_siteinfo('languages')
ret = {}
response['query']['languages'].each { |l| ret[l['code']] = l['*'] }
ret
end

# Gets all namespaces on the wiki and their IDs. Different from the
# Namespaces module.
# @return [Hash] All namespaces, formatted as ID => Name.
def get_namespaces
response = get_siteinfo('namespaces')
ret = {}
response['query']['namespaces'].each do |id, hash|
idid = response['query']['namespaces'][id]['id']
name = response['query']['namespaces'][id]['*']
ret[idid] = name
end
ret
end

# Gets all namespace aliases and their IDs.
# @return [Hash] All aliases, formatted as ID => Alias.
def get_namespace_aliases
response = get_siteinfo('namespacealiases')
ret = {}
response['query']['namespacealiases'].each do |a|
ret[i['id']] = i['*']
end
ret
end

# Gets all special page aliases.
# @return [Hash] All aliases, formatted as RealName => Alias.
def get_special_page_aliases
response = get_siteinfo('specialpagealiases')
ret = {}
response['query']['specialpagealiases'].each do |a|
ret[i['realname']] = i['aliases']
end
ret
end

# Gets all magic words and their aliases.
# @return [Hash] All magic words, formatted as Name => Alias.
def get_magic_words
response = get_siteinfo('magicwords')
ret = {}
response['query']['magicwords'].each do |w|
ret[w['name']] = w['aliases']
end
ret
end

# Gets all user groups total.
# @return [Hash] All groups, formatted as Name => [Rights].
def get_all_usergroups
response = get_siteinfo('usergroups')
ret = {}
response['query']['usergroups'].each do |g|
ret[g['name']] = g['rights']
end
ret
end

# Gets all file extensions that are allowed to be uploaded.
# @return [Array] All file extensions.
def get_allowed_file_extensions
response = get_siteinfo('fileextensions')
ret = []
response['query']['fileextensions'].each do |e|
ret.push(e['ext'])
end
ret
end

# Gets the response for the restrictions siteinfo API. Not really for
# use by users, mostly for the other two restriction methods.
def get_restrictions_data
response = get_siteinfo('restrictions')
return response['query']['restrictions']
end

# Gets all restriction/protection types.
# @return [Array] All protection types.
def get_restriction_types
restrictions = get_restrictions_data
ret = []
restrictions['types'].each { |t| ret.push(t) }
ret
end

# Gets all restriction/protection levels.
# @return [Array] All protection levels.
def get_restriction_levels
restrictions = get_restrictions_data
ret = []
restrictions['levels'].each { |l| ret.push(l) }
ret
end

# Gets all skins and their codes.
# @return [Hash] All skins, formatted as Code => Name
def get_skins
response = get_siteinfo('skins')
ret = {}
response['query']['skins'].each do |s|
ret[s['code']] = s['*']
end
ret
end

# Gets all HTML tags added by installed extensions.
# @return [Array] All extension tags.
def get_extension_tags
response = get_siteinfo('extensiontags')
ret = []
response['query']['extensiontags'].each do |t|
ret.push(t)
end
ret
end

# Gets all function hooks.
# @return [Array] All function hooks.
def get_function_hooks
response = get_siteinfo('functionhooks')
ret = []
response['query']['functionhooks'].each do |h|
ret.push(h)
end
ret
end

# Gets all variables that are usable on the wiki, such as NUMBEROFPAGES.
# @return [Array] All variable string values.
def get_variables
response = get_siteinfo('variables')
ret = []
response['query']['variables'].each do |v|
ret.push(v)
end
ret
end
end

module FileRepoInfo
Expand Down

0 comments on commit 3a17569

Please sign in to comment.