Class: MediaWiktory::Wikipedia::Actions::Protect

Inherits:
Post
  • Object
show all
Defined in:
lib/mediawiktory/wikipedia/actions/protect.rb

Overview

Change the protection level of a page.

Usage:

api.protect.title(value).perform # returns string with raw output
# or
api.protect.title(value).response # returns output parsed and wrapped into Response object

See Base for generic explanation of working with MediaWiki actions and Response for working with action responses.

All action's parameters are documented as its public methods, see below.

Instance Method Summary collapse

Methods inherited from Post

#perform

Methods inherited from Base

#inspect, #merge, #name, #perform, #response, #to_h, #to_param, #to_url

Methods included from GlobalParams

#assert, #assertuser, #centralauthtoken, #curtimestamp, #errorformat, #errorlang, #errorsuselocal, #format, #maxage, #maxlag, #origin, #requestid, #responselanginfo, #servedby, #smaxage, #uselang

Instance Method Details

#cascadeself

Enable cascading protection (i.e. protect transcluded templates and images used in this page). Ignored if none of the given protection levels support cascading.

Returns:

  • (self)


88
89
90
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 88

def cascade()
  merge(cascade: 'true')
end

#expiry(*values) ⇒ self

Expiry timestamps. If only one timestamp is set, it'll be used for all protections. Use infinite, indefinite, infinity, or never, for a never-expiring protection.

Parameters:

  • values (Array<String>)

Returns:

  • (self)


55
56
57
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 55

def expiry(*values)
  values.inject(self) { |res, val| res._expiry(val) }
end

#pageid(value) ⇒ self

ID of the page to (un)protect. Cannot be used together with title.

Parameters:

  • value (Integer)

Returns:

  • (self)


34
35
36
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 34

def pageid(value)
  merge(pageid: value.to_s)
end

#protections(*values) ⇒ self

List of protection levels, formatted action=level (e.g. edit=sysop). A level of all means everyone is allowed to take the action, i.e. no restriction.

Parameters:

  • values (Array<String>)

Returns:

  • (self)


42
43
44
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 42

def protections(*values)
  values.inject(self) { |res, val| res._protections(val) }
end

#reason(value) ⇒ self

Reason for (un)protecting.

Parameters:

  • value (String)

Returns:

  • (self)


68
69
70
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 68

def reason(value)
  merge(reason: value.to_s)
end

#tags(*values) ⇒ self

Change tags to apply to the entry in the protection log.

Parameters:

  • values (Array<String>)

    Allowed values: "ProveIt edit", "WPCleaner", "huggle", "large plot addition".

Returns:

  • (self)


76
77
78
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 76

def tags(*values)
  values.inject(self) { |res, val| res._tags(val) or fail ArgumentError, "Unknown value for tags: #{val}" }
end

#title(value) ⇒ self

Title of the page to (un)protect. Cannot be used together with pageid.

Parameters:

  • value (String)

Returns:

  • (self)


26
27
28
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 26

def title(value)
  merge(title: value.to_s)
end

#token(value) ⇒ self

A "csrf" token retrieved from action=query&meta=tokens

Parameters:

  • value (String)

Returns:

  • (self)


116
117
118
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 116

def token(value)
  merge(token: value.to_s)
end

#watchself

If set, add the page being (un)protected to the current user's watchlist.

Returns:

  • (self)


95
96
97
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 95

def watch()
  merge(watch: 'true')
end

#watchlist(value) ⇒ self

Unconditionally add or remove the page from the current user's watchlist, use preferences or do not change watch.

Parameters:

  • value (String)

    One of "watch", "unwatch", "preferences", "nochange".

Returns:

  • (self)


103
104
105
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 103

def watchlist(value)
  _watchlist(value) or fail ArgumentError, "Unknown value for watchlist: #{value}"
end