Class: MediaWiktory::Wikipedia::Actions::Protect
- 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
-
#cascade ⇒ self
Enable cascading protection (i.e. protect transcluded templates and images used in this page).
-
#expiry(*values) ⇒ self
Expiry timestamps.
-
#pageid(value) ⇒ self
ID of the page to (un)protect.
-
#protections(*values) ⇒ self
List of protection levels, formatted action=level (e.g. edit=sysop).
-
#reason(value) ⇒ self
Reason for (un)protecting.
-
#tags(*values) ⇒ self
Change tags to apply to the entry in the protection log.
-
#title(value) ⇒ self
Title of the page to (un)protect.
-
#token(value) ⇒ self
A "csrf" token retrieved from action=query&meta=tokens.
-
#watch ⇒ self
If set, add the page being (un)protected to the current user's watchlist.
-
#watchlist(value) ⇒ self
Unconditionally add or remove the page from the current user's watchlist, use preferences or do not change watch.
Methods inherited from Post
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
#cascade ⇒ self
Enable cascading protection (i.e. protect transcluded templates and images used in this page). Ignored if none of the given protection levels support cascading.
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.
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.
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.
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.
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.
76 77 78 |
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 76 def (*values) values.inject(self) { |res, val| res.(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.
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
116 117 118 |
# File 'lib/mediawiktory/wikipedia/actions/protect.rb', line 116 def token(value) merge(token: value.to_s) end |
#watch ⇒ self
If set, add the page being (un)protected to the current user's watchlist.
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.
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 |