module MediaWiki::Query::Lists::Users

Public Instance Methods

get_contrib_count(username = nil) click to toggle source

Gets contribution count for the user. @param username [String] The username to get the contribution count of. Optional. Defaults to the currently logged in user. @see get_userlists @since 0.3.0 @return [Boolean] False if username is nil and not logged in. @return [Fixnum] The number of contributions the user has made.

# 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) click to toggle source

Gets the user's full watchlist. If no user is provided, it will use the currently logged in user, according to the MediaWiki API. @param user [String] The username. @param limit [Fixnum] See #{get_all_images}. @see www.mediawiki.org/wiki/API:Watchlist MediaWiki Watchlist API Docs @since 0.8.0 @return [Array<String>] All the watchlist page titles.

# 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) click to toggle source

Gets when the user registered. @param username [String] The username to get the registration date and time of. Optional. Defaults to the currently logged in user. @see get_userlists @since 0.4.0 @return [DateTime] The registration date and time as a DateTime object. @return [Boolean] False when no username is provided and not logged in, or the user doesn't exist.

# 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) click to toggle source

Gets the latest contributions by the user until the limit. @param user [String] The username. @param limit [Fixnum] See #{get_all_images}. @see www.mediawiki.org/wiki/API:Usercontribs MediaWiki User Contributions API Docs @since 0.8.0 @return [Hash<Fixnum, Hash<Symbol, Any>>] Each contribution by its revid, containing the title, summary, total contribution size, and the size change relative to the previous edit.

# 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) click to toggle source

Gets the gender for the provded user. @param username [String] The user. @see get_userlists @since 0.4.0 @return [String] The gender. 'male', 'female', or 'unknown'.

# 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) click to toggle source

Gets an array of all the user's groups. @param username [String] The username to get groups of. Optional. Defaults to the currently logged in user. @see get_userlists @since 0.3.0 @return [Array<String>] All of the user's groups. @return [Boolean] False if username is nil and not logged in.

# 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) click to toggle source

Gets user information. This method should rarely be used by normal users, unless they want a huge amount of usnot g data at once. @param prop [String] The usprop parameter. @param username [String] The username to get info for. Optional. Defaults to the currently logged in user if omitted. @see www.mediawiki.org/wiki/API:Users MediaWiki User Lists API Docs @since 0.3.0 @return [String] Parsed full response if successful. @return [Nil] If the username is nil and the Butt is not logged in.

# 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) click to toggle source

Gets the user rights for the user. @param username [String] The user to get the rights for. Optional. Defaults to the currently logged in user. @see get_userlists @since 0.3.0 @return [Array<String>] All of the user's groups. @return [Boolean] False if username is nil and not logged in.

# 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