Module: MediaWiki::Query::Lists::Users

Included in:
QueryPage, RecentChanges
Defined in:
lib/mediawiki/query/lists/users.rb

Instance Method Summary collapse

Instance Method Details

#get_contrib_count(username = nil) ⇒ Boolean, Fixnum

Gets contribution count for the user. logged in user.

Parameters:

  • username (String) (defaults to: nil)

    The username to get the contribution count of. Optional. Defaults to the currently

Returns:

  • (Boolean)

    False if username is nil and not logged in.

  • (Fixnum)

    The number of contributions the user has made.

See Also:

Since:

  • 0.3.0



73
74
75
76
77
78
79
80
81
82
# File 'lib/mediawiki/query/lists/users.rb', line 73

def get_contrib_count(username = nil)
  if username.nil?
    return false unless @logged_in
    info = get_userlists('editcount')
    info['query']['userinfo']['editcount']
  else
    info = get_userlists('editcount', username)
    info['query']['users'].find { |hash| hash['name'] == username }['editcount']
  end
end

#get_full_watchlist(user = nil, limit = @query_limit_default) ⇒ Array<String>

Gets the user’s full watchlist. If no user is provided, it will use the currently logged in user, according to the MediaWiki API.

Parameters:

  • user (String) (defaults to: nil)

    The username.

  • limit (Fixnum) (defaults to: @query_limit_default)

Returns:

  • (Array<String>)

    All the watchlist page titles.

See Also:

Since:

  • 0.8.0



153
154
155
156
157
158
159
160
161
162
# File 'lib/mediawiki/query/lists/users.rb', line 153

def get_full_watchlist(user = nil, limit = @query_limit_default)
  params = {
    list: 'watchlist',
    wlprop: 'title',
    wllimit: get_limited(limit)
  }
  params[:wluser] = user if user

  query_ary(params, 'watchlist', 'title')
end

#get_registration_time(username = nil) ⇒ DateTime, Boolean

Gets when the user registered. currently logged in user.

Parameters:

  • username (String) (defaults to: nil)

    The username to get the registration date and time of. Optional. Defaults to the

Returns:

  • (DateTime)

    The registration date and time as a DateTime object.

  • (Boolean)

    False when no username is provided and not logged in, or the user doesn’t exist.

See Also:

Since:

  • 0.4.0



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/mediawiki/query/lists/users.rb', line 91

def get_registration_time(username = nil)
  # Do note that in Userinfo, registration is called registrationdate.
  if username.nil?
    return false unless @logged_in
    info = get_userlists('registrationdate')
    time = info['query']['userinfo']['registrationdate']
  else
    info = get_userlists('registration', username)
    time = info['query']['users'].find { |hash| hash['name'] == username }['registration']
  end

  return false if time.nil?

  DateTime.strptime(time, '%Y-%m-%dT%T')
end

#get_user_contributions(user, limit = @query_limit_default) ⇒ Hash<Fixnum, Hash<Symbol, Any>>

Gets the latest contributions by the user until the limit. total contribution size, and the size change relative to the previous edit.

Parameters:

  • user (String)

    The username.

  • limit (Fixnum) (defaults to: @query_limit_default)

Returns:

  • (Hash<Fixnum, Hash<Symbol, Any>>)

    Each contribution by its revid, containing the title, summary,

See Also:

Since:

  • 0.8.0



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/mediawiki/query/lists/users.rb', line 126

def get_user_contributions(user, limit = @query_limit_default)
  params = {
    list: 'usercontribs',
    ucuser: user,
    uclimit: get_limited(limit),
    ucprop: 'ids|title|comment|size|sizediff|flags|patrolled'
  }

  query(params, {}) do |return_val, query|
    query['usercontribs'].each do |item|
      return_val[item['revid']] = {
        title: item['title'],
        summary: item['comment'],
        total_size: item['size'],
        diff_size: item['sizediff']
      }
    end
  end
end

#get_user_gender(username) ⇒ String

Gets the gender for the provded user.

Parameters:

  • username (String)

    The user.

Returns:

  • (String)

    The gender. ‘male’, ‘female’, or ‘unknown’.

See Also:

Since:

  • 0.4.0



112
113
114
115
# File 'lib/mediawiki/query/lists/users.rb', line 112

def get_user_gender(username)
  info = get_userlists('gender', username)
  info['query']['users'].find { |hash| hash['name'] == username }['gender']
end

#get_usergroups(username = nil) ⇒ Array<String>, Boolean

Gets an array of all the user’s groups.

Parameters:

  • username (String) (defaults to: nil)

    The username to get groups of. Optional. Defaults to the currently logged in user.

Returns:

  • (Array<String>)

    All of the user’s groups.

  • (Boolean)

    False if username is nil and not logged in.

See Also:

Since:

  • 0.3.0



39
40
41
42
43
44
45
46
47
# File 'lib/mediawiki/query/lists/users.rb', line 39

def get_usergroups(username = nil)
  if username.nil?
    return false unless @logged_in
    get_userlists('groups')['query']['userinfo']['groups']
  else
    info = get_userlists('groups', username)
    info['query']['users'].collect { |i| i['groups'] }.flatten
  end
end

#get_userlists(prop, username = nil) ⇒ String, Nil

Gets user information. This method should rarely be used by normal users, unless they want a huge amount of usnot g data at once. if omitted.

Parameters:

  • prop (String)

    The usprop parameter.

  • username (String) (defaults to: nil)

    The username to get info for. Optional. Defaults to the currently logged in user

Returns:

  • (String)

    Parsed full response if successful.

  • (Nil)

    If the username is nil and the Butt is not logged in.

See Also:

Since:

  • 0.3.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mediawiki/query/lists/users.rb', line 14

def get_userlists(prop, username = nil)
  if username.nil?
    return unless @logged_in
    response = get_current_user_meta(prop)
  else
    username.strip!
    params = {
      action: 'query',
      list: 'users',
      usprop: prop,
      ususers: username
    }

    response = post(params)
  end

  response
end

#get_userrights(username = nil) ⇒ Array<String>, Boolean

Gets the user rights for the user.

Parameters:

  • username (String) (defaults to: nil)

    The user to get the rights for. Optional. Defaults to the currently logged in user.

Returns:

  • (Array<String>)

    All of the user’s groups.

  • (Boolean)

    False if username is nil and not logged in.

See Also:

Since:

  • 0.3.0



55
56
57
58
59
60
61
62
63
64
# File 'lib/mediawiki/query/lists/users.rb', line 55

def get_userrights(username = nil)
  if username.nil?
    return false unless @logged_in
    info = get_userlists('rights')
    info['query']['userinfo']['rights']
  else
    info = get_userlists('rights', username)
    info['query']['users'].find { |hash| hash['name'] == username }['rights']
  end
end