Module: MediaWiki::Gateway::Users
- Included in:
- MediaWiki::Gateway
- Defined in:
- lib/media_wiki/gateway/users.rb
Instance Method Summary collapse
-
#contributions(user, count = nil, options = {}) ⇒ Object
Get user contributions.
-
#create_account(options) ⇒ Object
Create a new account.
-
#email_user(user, subject, text, options = {}) ⇒ Object
Sends e-mail to a user.
-
#login(username, password, domain = 'local', options = {}) ⇒ Object
Login to MediaWiki.
-
#options(changes = {}, optionname = nil, optionvalue = nil, reset = false, options = {}) ⇒ Object
Sets options for currenlty logged in user.
-
#set_groups(user, groups_to_add = [], groups_to_remove = [], comment = '', options = {}) ⇒ Object
Set groups for a user.
-
#users(options = {}) ⇒ Object
Get a list of users.
Instance Method Details
#contributions(user, count = nil, options = {}) ⇒ Object
Get user contributions
- user
-
The user name
- count
-
Maximum number of contributions to retrieve, or nil for all
- options
-
Optional hash of options, eg. { ‘ucnamespace’ => 4 }. See www.mediawiki.org/wiki/API:Usercontribs
Returns array of hashes containing the “item” attributes defined here: www.mediawiki.org/wiki/API:Usercontribs
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/media_wiki/gateway/users.rb', line 45 def contributions(user, count = nil, = {}) result = [] iterate_query('usercontribs', '//item', nil, 'uccontinue', .merge( 'ucuser' => user, 'uclimit' => @options[:limit] )) { |element| result << hash = {} element.attributes.each { |key, value| hash[key] = value } break if count && result.size >= count } count ? result.take(count) : result end |
#create_account(options) ⇒ Object
Create a new account
- options
-
is
Hash
passed as query arguments. See www.mediawiki.org/wiki/API:Account_creation#Parameters for more information.
83 84 85 |
# File 'lib/media_wiki/gateway/users.rb', line 83 def create_account() send_request(.merge('action' => 'createaccount')) end |
#email_user(user, subject, text, options = {}) ⇒ Object
Sends e-mail to a user
- user
-
Username to send mail to (name only: eg. ‘Bob’, not ‘User:Bob’)
- subject
-
Subject of message
- content
-
Content of message
- options
-
Hash of additional options
Will raise a ‘noemail’ APIError if the target user does not have a confirmed email address, see www.mediawiki.org/wiki/API:E-mail for details.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/media_wiki/gateway/users.rb', line 68 def email_user(user, subject, text, = {}) res = send_request(.merge( 'action' => 'emailuser', 'target' => user, 'subject' => subject, 'text' => text, 'token' => get_token('email', "User:#{user}") )) res.elements['emailuser'].attributes['result'] == 'Success' end |
#login(username, password, domain = 'local', options = {}) ⇒ Object
Login to MediaWiki
- username
-
Username
- password
-
Password
- domain
-
Domain for authentication plugin logins (eg. LDAP), optional – defaults to ‘local’ if not given
- options
-
Hash of additional options
Throws MediaWiki::Unauthorized if login fails
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/media_wiki/gateway/users.rb', line 15 def login(username, password, domain = 'local', = {}) send_request(.merge( 'action' => 'login', 'lgname' => username, 'lgpassword' => password, 'lgdomain' => domain )) @password = password @username = username end |
#options(changes = {}, optionname = nil, optionvalue = nil, reset = false, options = {}) ⇒ Object
Sets options for currenlty logged in user
- changes
-
a
Hash
that will be transformed into an equal sign and pipe-separated key value parameter - optionname
-
a
String
indicating which option to change (optional) - optionvalue
-
the new value for optionname - allows pipe characters (optional)
- reset
-
a
Boolean
indicating if all preferences should be reset to site defaults (optional) - options
-
Hash of additional options
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/media_wiki/gateway/users.rb', line 94 def (changes = {}, optionname = nil, optionvalue = nil, reset = false, = {}) form_data = .merge( 'action' => 'options', 'token' => ) if changes && !changes.empty? form_data['change'] = changes.map { |key, value| "#{key}=#{value}" }.join('|') end if optionname && !optionname.empty? form_data[optionname] = optionvalue end if reset form_data['reset'] = true end send_request(form_data) end |
#set_groups(user, groups_to_add = [], groups_to_remove = [], comment = '', options = {}) ⇒ Object
Set groups for a user
- user
-
Username of user to modify
- groups_to_add
-
Groups to add user to, as an array or a string if a single group (optional)
- groups_to_remove
-
Groups to remove user from, as an array or a string if a single group (optional)
- options
-
Hash of additional options
121 122 123 124 |
# File 'lib/media_wiki/gateway/users.rb', line 121 def set_groups(user, groups_to_add = [], groups_to_remove = [], comment = '', = {}) token = get_userrights_token(user) userrights(user, token, groups_to_add, groups_to_remove, comment, ) end |
#users(options = {}) ⇒ Object
Get a list of users
- options
-
Optional hash of options, eg. { ‘augroup’ => ‘sysop’ }. See www.mediawiki.org/wiki/API:Allusers
Returns array of user names (empty if no matches)
32 33 34 35 36 |
# File 'lib/media_wiki/gateway/users.rb', line 32 def users( = {}) iterate_query('allusers', '//u', 'name', 'aufrom', .merge( 'aulimit' => @options[:limit] )) end |