Module: MediaWiki::Administration

Included in:
Butt
Defined in:
lib/mediawiki/administration.rb

Instance Method Summary collapse

Instance Method Details

#block(user, expiry = '2 weeks', reason = nil, nocreate = true) ⇒ Fixnum

Blocks the user.

Parameters:

  • expiry (String) (defaults to: '2 weeks')

    The expiry timestamp using a relative expiry time.

  • nocreate (Boolean) (defaults to: true)

    Whether to allow them to create an account.

  • user (String)

    The user affected.

  • reason (String) (defaults to: nil)

    The reason to show in the block log.

Returns:

  • (Fixnum)

    The block ID.

Raises:

  • (BlockError)

See Also:

Since:

  • 0.5.0



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

def block(user, expiry = '2 weeks', reason = nil, nocreate = true)
  params = {
    action: 'block',
    user: user,
    expiry: expiry
  }

  token = get_token
  params[:reason] = reason if reason
  params[:nocreate] = '1' if nocreate
  params[:token] = token

  response = post(params)

  if response.key?('error')
    raise MediaWiki::Butt::BlockError.new(response.dig('error', 'code') || 'Unknown error code')
  end

  response['id'].to_i
end

#unblock(user, reason = nil) ⇒ Fixnum

Unblocks the user.

Parameters:

  • user (String)

    The user affected.

  • reason (String) (defaults to: nil)

    The reason to show in the block log.

Returns:

  • (Fixnum)

    The block ID.

Raises:

  • (BlockError)

See Also:

Since:

  • 0.5.0



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mediawiki/administration.rb', line 41

def unblock(user, reason = nil)
  params = {
    action: 'unblock',
    user: user
  }
  token = get_token
  params[:reason] = reason if reason
  params[:token] = token

  response = post(params)

  if response.key?('error')
    raise MediaWiki::Butt::BlockError.new(response.dig('error', 'code') || 'Unknown error code')
  end

  response['id'].to_i
end