Module: MediaWiki::Query::Lists::Users
- Included in:
- QueryPage, RecentChanges
- Defined in:
- lib/mediawiki/query/lists/users.rb
Instance Method Summary collapse
-
#get_contrib_count(username = nil) ⇒ Boolean, Fixnum
Gets contribution count for the user.
-
#get_full_watchlist(user = nil, limit = @query_limit_default) ⇒ Array<String>
Gets the user’s full watchlist.
-
#get_registration_time(username = nil) ⇒ DateTime, Boolean
Gets when the user registered.
-
#get_user_contributions(user, limit = @query_limit_default) ⇒ Hash<Fixnum, Hash<Symbol, Any>>
Gets the latest contributions by the user until the limit.
-
#get_user_gender(username) ⇒ String
Gets the gender for the provded user.
-
#get_usergroups(username = nil) ⇒ Array<String>, Boolean
Gets an array of all the user’s groups.
-
#get_userlists(prop, username = nil) ⇒ String, Nil
Gets user information.
-
#get_userrights(username = nil) ⇒ Array<String>, Boolean
Gets the user rights for the user.
Instance Method Details
#get_contrib_count(username = nil) ⇒ Boolean, Fixnum
Gets contribution count for the user. logged in user.
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.
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.
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.
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.
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.
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.
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 = (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.
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 |