diff --git a/CHANGELOG.md b/CHANGELOG.md index b2b18ed..96b2042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/mediawiki/query.rb b/lib/mediawiki/query.rb index 37a899d..76c3762 100644 --- a/lib/mediawiki/query.rb +++ b/lib/mediawiki/query.rb @@ -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. @@ -26,7 +25,6 @@ def get_statistics response = get_siteinfo('statistics') ret = {} response['query']['statistics'].each { |k, v| ret[k] = v } - ret end @@ -36,7 +34,6 @@ def get_general response = get_siteinfo('general') ret = {} response['query']['general'].each { |k, v| ret[k] = v } - ret end @@ -46,7 +43,6 @@ def get_extensions response = get_siteinfo('extensions') ret = [] response['query']['extensions'].each { |e| ret.push(e['name']) } - ret end @@ -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