Module: MediaWiki::Query::Meta::SiteInfo

Included in:
Butt
Defined in:
lib/mediawiki/query/meta/siteinfo.rb

Overview

Instance Method Summary collapse

Instance Method Details

#get_all_usergroupsHash<String, Array<String>>

Gets all user groups total.

Returns:

  • (Hash<String, Array<String>>)

    All groups, formatted as Name => [Rights].

Since:

  • 0.6.0



110
111
112
113
114
115
116
117
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 110

def get_all_usergroups
  response = get_siteinfo('usergroups')
  ret = {}
  response['query']['usergroups'].each do |g|
    ret[g['name']] = g['rights']
  end
  ret
end

#get_allowed_file_extensionsArray<String>

Gets all file extensions that are allowed to be uploaded.

Returns:

  • (Array<String>)

    All file extensions.

Since:

  • 0.6.0



122
123
124
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 122

def get_allowed_file_extensions
  get_siteinfo('fileextensions')['query']['fileextensions'].collect { |e| e['ext'] }
end

#get_article_path(article_name) ⇒ String

Returns The full article path for the provided article. This is protocol-relative.

Parameters:

  • article_name (String)

    The name of the article.

Returns:

  • (String)

    The full article path for the provided article. This is protocol-relative.



195
196
197
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 195

def get_article_path(article_name)
  get_server + get_base_article_path.sub('$1', article_name)
end

#get_base_article_pathString

Returns The article path for the wiki. It includes “$1”, which should be replaced with the actual name of the article. Does not include the URL for the wiki. For example: /wiki/$1 for Wikpedia.

Returns:

  • (String)

    The article path for the wiki. It includes “$1”, which should be replaced with the actual name of the article. Does not include the URL for the wiki. For example: /wiki/$1 for Wikpedia.



189
190
191
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 189

def get_base_article_path
  get_general['articlepath']
end

#get_extension_tagsArray<String>

Gets all HTML tags added by installed extensions.

Returns:

  • (Array<String>)

    All extension tags.

Since:

  • 0.6.0



163
164
165
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 163

def get_extension_tags
  get_siteinfo('extensiontags')['query']['extensiontags']
end

#get_extensionsArray<String>

Gets all extensions installed on the wiki.

Returns:

  • (Array<String>)

    All extension names.

Since:

  • 0.6.0



43
44
45
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 43

def get_extensions
   get_siteinfo('extensions')['query']['extensions'].collect { |e| e['name'] }
end

#get_function_hooksArray<String>

Gets all function hooks.

Returns:

  • (Array<String>)

    All function hooks.

Since:

  • 0.6.0



170
171
172
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 170

def get_function_hooks
  get_siteinfo('functionhooks')['query']['functionhooks']
end

#get_generalHash<String, Any>

Gets the general information for the wiki.

Returns:

  • (Hash<String, Any>)

    The general info and their according values.

Since:

  • 0.6.0



33
34
35
36
37
38
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 33

def get_general
  response = get_siteinfo('general')
  ret = {}
  response['query']['general'].each { |k, v| ret[k] = v }
  ret
end

#get_languagesHash<String, String>

Gets all languages and their codes.

Returns:

  • (Hash<String, String>)

    All languages. Hash key value pair formatted as code => name.

Since:

  • 0.6.0



50
51
52
53
54
55
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 50

def get_languages
  response = get_siteinfo('languages')
  ret = {}
  response['query']['languages'].each { |l| ret[l['code']] = l['*'] }
  ret
end

#get_magic_wordsHash<String, Array<String>>

Gets all magic words and their aliases.

Returns:

  • (Hash<String, Array<String>>)

    All magic words, formatted as Name => Alias.

Since:

  • 0.6.0



98
99
100
101
102
103
104
105
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 98

def get_magic_words
  response = get_siteinfo('magicwords')
  ret = {}
  response['query']['magicwords'].each do |w|
    ret[w['name']] = w['aliases']
  end
  ret
end

#get_namespace_aliasesHash<Fixnum, String>

Gets all namespace aliases and their IDs.

Returns:

  • (Hash<Fixnum, String>)

    All aliases, formatted as ID => Alias.

Since:

  • 0.6.0



74
75
76
77
78
79
80
81
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 74

def get_namespace_aliases
  response = get_siteinfo('namespacealiases')
  ret = {}
  response['query']['namespacealiases'].each do |i|
    ret[i['id']] = i['*']
  end
  ret
end

#get_namespacesHash<Fixnum, String>

Gets all namespaces on the wiki and their IDs. Different from the Namespaces module.

Returns:

  • (Hash<Fixnum, String>)

    All namespaces, formatted as ID => Name.

Since:

  • 0.6.0



60
61
62
63
64
65
66
67
68
69
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 60

def get_namespaces
  response = get_siteinfo('namespaces')
  ret = {}
  response['query']['namespaces'].each do |id, _|
    idid = response['query']['namespaces'][id]['id']
    name = response['query']['namespaces'][id]['*']
    ret[idid] = name
  end
  ret
end

#get_restriction_levelsArray<String>

Gets all restriction/protection levels.

Returns:

  • (Array<String>)

    All protection levels.

Since:

  • 0.6.0



144
145
146
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 144

def get_restriction_levels
  get_restrictions_data['levels']
end

#get_restriction_typesArray<String>

Gets all restriction/protection types.

Returns:

  • (Array<String>)

    All protection types.

Since:

  • 0.6.0



137
138
139
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 137

def get_restriction_types
  get_restrictions_data['types']
end

#get_restrictions_dataHash<String, Array<String>>

Gets the response for the restrictions siteinfo API. Not really for use by users, mostly for the other two restriction methods.

Returns:

  • (Hash<String, Array<String>>)

    All restriction data. See the other restriction methods.

Since:

  • 0.6.0



130
131
132
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 130

def get_restrictions_data
  get_siteinfo('restrictions')['query']['restrictions']
end

#get_serverString

Gets the protocol-relative server URL for the wiki.

Returns:

  • (String)

    The server URL for the wiki. For example: //en.wikipedia.org for Wikipedia.



183
184
185
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 183

def get_server
  get_general['server']
end

#get_siteinfo(prop) ⇒ Hash

Gets wiki information. This method should rarely be used by normal users.

Parameters:

  • prop (String)

    The siprop parameter.

Returns:

  • (Hash)

    Parsed full response.

Since:

  • 0.6.0



10
11
12
13
14
15
16
17
18
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 10

def get_siteinfo(prop)
  params = {
    action: 'query',
    meta: 'siteinfo',
    siprop: prop
  }

  post(params)
end

#get_skinsHash<String, String>

Gets all skins and their codes.

Returns:

  • (Hash<String, String>)

    All skins, formatted as Code => Name

Since:

  • 0.6.0



151
152
153
154
155
156
157
158
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 151

def get_skins
  response = get_siteinfo('skins')
  ret = {}
  response['query']['skins'].each do |s|
    ret[s['code']] = s['*']
  end
  ret
end

#get_special_page_aliasesHash<String, Array<String>>

Gets all special page aliases.

Returns:

  • (Hash<String, Array<String>>)

    All aliases, formatted as RealName => Alias.

Since:

  • 0.6.0



86
87
88
89
90
91
92
93
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 86

def get_special_page_aliases
  response = get_siteinfo('specialpagealiases')
  ret = {}
  response['query']['specialpagealiases'].each do |i|
    ret[i['realname']] = i['aliases']
  end
  ret
end

#get_statisticsHash<String, Fixnum>

Gets the statistics for the wiki.

Returns:

  • (Hash<String, Fixnum>)

    The statistics and their according values.

Since:

  • 0.6.0



23
24
25
26
27
28
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 23

def get_statistics
  response = get_siteinfo('statistics')
  ret = {}
  response['query']['statistics'].each { |k, v| ret[k] = v }
  ret
end

#get_variablesArray<String>

Gets all variables that are usable on the wiki, such as NUMBEROFPAGES.

Returns:

  • (Array<String>)

    All variable string values.

Since:

  • 0.6.0



177
178
179
# File 'lib/mediawiki/query/meta/siteinfo.rb', line 177

def get_variables
  get_siteinfo('variables')['query']['variables']
end