Module: MediaWiki::Query::Meta::UserInfo

Included in:
Butt, MediaWiki::Query::Meta
Defined in:
lib/mediawiki/query/meta/userinfo.rb

Overview

Instance Method Summary collapse

Instance Method Details

#current_user_hasmsg?Boolean

Returns whether or not the currently logged in user has any unread messages on their talk page.

Returns:

  • (Boolean)

    True if they have unreads, else false.

Since:

  • 0.7.0



38
39
40
41
42
43
# File 'lib/mediawiki/query/meta/userinfo.rb', line 38

def current_user_hasmsg?
  response = get_current_user_meta('hasmsg')
  return false unless response

  response['query']['userinfo']['messages'] == ''
end

#get_changeable_groupsBoolean, Hash<String, Array<String>>

Gets a hash-of-arrays containing all the groups the user can add and remove people from.

Returns:

  • (Boolean)

    False if get_current_user_meta is false

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

    All the groups that the user can :add, :remove, :addself, and :remove-self.

Since:

  • 0.7.0



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mediawiki/query/meta/userinfo.rb', line 50

def get_changeable_groups
  response = get_current_user_meta('changeablegroups')
  return false unless response

  changeablegroups = response['query']['userinfo']['changeablegroups']
  {
    :add => changeablegroups['add'],
    :remove => changeablegroups['remove'],
    :addself => changeablegroups['add-self'],
    :removeself => changeablegroups['add-self']
  }
end

#get_current_user_meta(prop = nil) ⇒ Hash, Boolean

Gets meta information for the currently logged in user.

Parameters:

  • prop (String) (defaults to: nil)

    The uiprop to get. Optional.

Returns:

  • (Hash)

    Full, parsed response.

  • (Boolean)

    False if not logged in.

Since:

  • 0.4.0



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mediawiki/query/meta/userinfo.rb', line 11

def get_current_user_meta(prop = nil)
  return false unless @logged_in

  params = {
    action: 'query',
    meta: 'userinfo',
    uiprop: prop
  }

  post(params)
end

#get_current_user_nameString, Boolean

Gets the current user’s username.

Returns:

  • (String)

    Returns the username.

  • (Boolean)

    False if not currently logged in.

Since:

  • 0.7.0



27
28
29
30
31
32
33
# File 'lib/mediawiki/query/meta/userinfo.rb', line 27

def get_current_user_name
  return @name if @name
  name = get_current_user_meta
  name = name['query']['userinfo']['name'] if name

  name
end

#get_current_user_optionsHash<String, Any>

Gets the user’s options.

Returns:

  • (Hash<String, Any>)

    The user’s options.

Since:

  • 0.7.0



90
91
92
93
94
# File 'lib/mediawiki/query/meta/userinfo.rb', line 90

def get_current_user_options
  response = get_current_user_meta('options')
  ret = {}
  response['query']['userinfo']['options'].each { |k, v| ret[k] = v }
end

#get_email_addressString, Nil

Gets the currently logged in user’s email address.

Returns:

  • (String)

    The user’s email address.

  • (Nil)

    If their email address is not set.

Since:

  • 0.7.0



79
80
81
82
83
84
85
# File 'lib/mediawiki/query/meta/userinfo.rb', line 79

def get_email_address
  response = get_current_user_meta('email')
  email = response['query']['userinfo']['email']
  return if email == ''

  email
end

#get_realnameString, Nil

Gets the currently logged in user’s real name.

Returns:

  • (String)

    The user’s real name.

  • (Nil)

    If they don’t have a real name set.

Since:

  • 0.7.0



67
68
69
70
71
72
73
# File 'lib/mediawiki/query/meta/userinfo.rb', line 67

def get_realname
  response = get_current_user_meta('realname')
  realname = response['query']['userinfo']['realname']
  return if realname == ''

  realname
end