Class: MediaWiktory::Wikipedia::Actions::Edit

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

Overview

Create and edit pages.

Usage:

api.edit.title(value).perform # returns string with raw output
# or
api.edit.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

#appendtext(value) ⇒ self

Add this text to the end of the page. Overrides text.

Parameters:

  • value (String)

Returns:

  • (self)


188
189
190
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 188

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

#basetimestamp(value) ⇒ self

Timestamp of the base revision, used to detect edit conflicts. May be obtained through action=query&prop=revisions&rvprop=timestamp.

Parameters:

  • value (Time)

Returns:

  • (self)


108
109
110
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 108

def basetimestamp(value)
  merge(basetimestamp: value.iso8601)
end

#botself

Mark this edit as a bot edit.

Returns:

  • (self)


100
101
102
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 100

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

#captchaid(value) ⇒ self

CAPTCHA ID from previous request

Parameters:

  • value (String)

Returns:

  • (self)


261
262
263
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 261

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

#captchaword(value) ⇒ self

Answer to the CAPTCHA

Parameters:

  • value (String)

Returns:

  • (self)


253
254
255
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 253

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

#contentformat(value) ⇒ self

Content serialization format used for the input text.

Parameters:

  • value (String)

    One of "application/json", "text/x-wiki", "text/javascript", "text/css", "text/plain".

Returns:

  • (self)


219
220
221
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 219

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

#contentmodel(value) ⇒ self

Content model of the new content.

Parameters:

  • value (String)

    One of "GadgetDefinition", "SecurePoll", "MassMessageListContent", "JsonSchema", "wikitext", "javascript", "json", "css", "text", "Scribunto".

Returns:

  • (self)


232
233
234
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 232

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

#createonlyself

Don't edit the page if it exists already.

Returns:

  • (self)


130
131
132
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 130

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

#md5(value) ⇒ self

The MD5 hash of the text parameter, or the prependtext and appendtext parameters concatenated. If set, the edit won't be done unless the hash is correct.

Parameters:

  • value (String)

Returns:

  • (self)


172
173
174
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 172

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

#minorself

Minor edit.

Returns:

  • (self)


86
87
88
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 86

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

#nocreateself

Throw an error if the page doesn't exist.

Returns:

  • (self)


137
138
139
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 137

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

#notminorself

Non-minor edit.

Returns:

  • (self)


93
94
95
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 93

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

#pageid(value) ⇒ self

Page ID of the page to edit. Cannot be used together with title.

Parameters:

  • value (Integer)

Returns:

  • (self)


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

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

#prependtext(value) ⇒ self

Add this text to the beginning of the page. Overrides text.

Parameters:

  • value (String)

Returns:

  • (self)


180
181
182
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 180

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

#recreateself

Override any errors about the page having been deleted in the meantime.

Returns:

  • (self)


123
124
125
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 123

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

#redirectself

Automatically resolve redirects.

Returns:

  • (self)


211
212
213
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 211

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

#section(value) ⇒ self

Section number. 0 for the top section, new for a new section.

Parameters:

  • value (String)

Returns:

  • (self)


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

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

#sectiontitle(value) ⇒ self

The title for a new section.

Parameters:

  • value (String)

Returns:

  • (self)


50
51
52
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 50

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

#starttimestamp(value) ⇒ self

Timestamp when the editing process began, used to detect edit conflicts. An appropriate value may be obtained using curtimestamp when beginning the edit process (e.g. when loading the page content to edit).

Parameters:

  • value (Time)

Returns:

  • (self)


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

def starttimestamp(value)
  merge(starttimestamp: value.iso8601)
end

#summary(value) ⇒ self

Edit summary. Also section title when section=new and sectiontitle is not set.

Parameters:

  • value (String)

Returns:

  • (self)


66
67
68
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 66

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

#tags(*values) ⇒ self

Change tags to apply to the revision.

Parameters:

  • values (Array<String>)

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

Returns:

  • (self)


74
75
76
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 74

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

#text(value) ⇒ self

Page content.

Parameters:

  • value (String)

Returns:

  • (self)


58
59
60
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 58

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

#title(value) ⇒ self

Title of the page to edit. Cannot be used together with pageid.

Parameters:

  • value (String)

Returns:

  • (self)


26
27
28
# File 'lib/mediawiktory/wikipedia/actions/edit.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)


245
246
247
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 245

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

#undo(value) ⇒ self

Undo this revision. Overrides text, prependtext and appendtext.

Parameters:

  • value (Integer)

Returns:

  • (self)


196
197
198
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 196

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

#undoafter(value) ⇒ self

Undo all revisions from undo to this one. If not set, just undo one revision.

Parameters:

  • value (Integer)

Returns:

  • (self)


204
205
206
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 204

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

#unwatchself

Remove the page from the current user's watchlist.

Returns:

  • (self)


151
152
153
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 151

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

#watchself

Add the page to the current user's watchlist.

Returns:

  • (self)


144
145
146
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 144

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)


159
160
161
# File 'lib/mediawiktory/wikipedia/actions/edit.rb', line 159

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