Module: MediaWiki::Query::Meta

Includes:
FileRepoInfo, UserInfo
Included in:
MediaWiki::Query
Defined in:
lib/mediawiki/query/meta/meta.rb,
lib/mediawiki/query/meta/siteinfo.rb,
lib/mediawiki/query/meta/userinfo.rb,
lib/mediawiki/query/meta/filerepoinfo.rb

Defined Under Namespace

Modules: FileRepoInfo, SiteInfo, UserInfo

Constant Summary collapse

TOKEN_TYPES =

All valid types of tokens. Taken from API:Tokens on MediaWiki.

%w(csrf watch patrol rollback userrights login createaccount)

Instance Method Summary collapse

Methods included from FileRepoInfo

#get_filerepo_favicons, #get_filerepo_names, #get_filerepo_rooturls, #get_filerepo_thumburls, #get_filerepo_urls, #get_filerepoinfo, #get_local_filerepos, #get_nonlocal_filerepos

Methods included from UserInfo

#current_user_hasmsg?, #get_changeable_groups, #get_current_user_meta, #get_current_user_name, #get_current_user_options, #get_email_address, #get_realname

Instance Method Details

#get_token(type = 'csrf') ⇒ String

Obtains a token for the current user (or lack thereof) for specific actions. This uses the functionality introduced in MediaWiki 1.27

Parameters:

  • type (String) (defaults to: 'csrf')

    The type of token to get. See #TOKEN_TYPES to see the valid types. If it is invalid, it will default to ‘csrf’.

Returns:

  • (String)

    A token for the provided type.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mediawiki/query/meta/meta.rb', line 20

def get_token(type = 'csrf')
  type = 'csrf' unless TOKEN_TYPES.include?(type)

  return @tokens[type] if @tokens.key?(type)

  params = {
    action: 'query',
    meta: 'tokens',
    type: type
  }

  resp = post(params)
  tokens = resp['query']['tokens']
  token = tokens["#{type}token"]
  @tokens[type] = token
  token
end