mediawiki-butt 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,216 +3,216 @@ module MediaWiki
3
3
  # Constants Namespace IDs. Taken from https://www.mediawiki.org/wiki/Extension_default_namespaces
4
4
  module Namespaces
5
5
  $namespaces = {
6
- "MAIN" => 0,
7
- "TALK" => 1,
8
- "USER" => 2,
9
- "USER_TALK" => 3,
10
- "PROJECT" => 4,
11
- "PROJECT_TALK" => 5,
12
- "FILE" => 6,
13
- "FILE_TALK" => 7,
14
- "MEDIAWIKI" => 8,
15
- "MEDIAWIKI_TALK" => 9,
16
- "TEMPLATE" => 10,
17
- "TEMPLATE_TALK" => 11,
18
- "HELP" => 12,
19
- "HELP_TALK" => 13,
20
- "CATEGORY" => 14,
21
- "CATEGORY_TALK" => 15,
22
- "SPECIAL" => -1,
23
- "MEDIA" => -2,
6
+ 'MAIN' => 0,
7
+ 'TALK' => 1,
8
+ 'USER' => 2,
9
+ 'USER_TALK' => 3,
10
+ 'PROJECT' => 4,
11
+ 'PROJECT_TALK' => 5,
12
+ 'FILE' => 6,
13
+ 'FILE_TALK' => 7,
14
+ 'MEDIAWIKI' => 8,
15
+ 'MEDIAWIKI_TALK' => 9,
16
+ 'TEMPLATE' => 10,
17
+ 'TEMPLATE_TALK' => 11,
18
+ 'HELP' => 12,
19
+ 'HELP_TALK' => 13,
20
+ 'CATEGORY' => 14,
21
+ 'CATEGORY_TALK' => 15,
22
+ 'SPECIAL' => -1,
23
+ 'MEDIA' => -2,
24
24
 
25
25
  # Extension:LiquidThreads
26
- "LQT_THREAD" => 90,
27
- "LQT_THREAD_TALK" => 91,
28
- "LQT_SUMMARY" => 92,
29
- "LQT_SUMMARY_TALK" => 93,
26
+ 'LQT_THREAD' => 90,
27
+ 'LQT_THREAD_TALK' => 91,
28
+ 'LQT_SUMMARY' => 92,
29
+ 'LQT_SUMMARY_TALK' => 93,
30
30
 
31
31
  # Extension:Semantic MediaWiki / Extension:Semantic Forms
32
- "SMW_RELATION" => 100,
33
- "SMW_RELATION_TALK" => 101,
34
- "SMW_PROPERTY" => 102,
35
- "SMW_PROPERTY_TALK" => 103,
36
- "SMW_TYPE" => 104,
37
- "SMW_TYPE_TALK" => 105,
38
- "SMW_FORM" => 106,
39
- "SMW_FORM_TALK" => 107,
40
- "SF_CONCEPT" => 108,
41
- "SF_CONCEPT_TALK" => 109,
32
+ 'SMW_RELATION' => 100,
33
+ 'SMW_RELATION_TALK' => 101,
34
+ 'SMW_PROPERTY' => 102,
35
+ 'SMW_PROPERTY_TALK' => 103,
36
+ 'SMW_TYPE' => 104,
37
+ 'SMW_TYPE_TALK' => 105,
38
+ 'SMW_FORM' => 106,
39
+ 'SMW_FORM_TALK' => 107,
40
+ 'SF_CONCEPT' => 108,
41
+ 'SF_CONCEPT_TALK' => 109,
42
42
 
43
43
  # Extension:DPLforum
44
- "DPLF_FORUM" => 110,
45
- "DPLF_FORUM_TAlK" => 111,
44
+ 'DPLF_FORUM' => 110,
45
+ 'DPLF_FORUM_TAlK' => 111,
46
46
 
47
47
  # Extension:RefHelper
48
- "RFH_CITE" => 120,
49
- "RFH_CITE_TALK" => 121,
48
+ 'RFH_CITE' => 120,
49
+ 'RFH_CITE_TALK' => 121,
50
50
 
51
51
  # Extension:SemanticAccessControl
52
- "ACL_USERGROUP" => 160,
53
- "ACL_ACL" => 162,
52
+ 'ACL_USERGROUP' => 160,
53
+ 'ACL_ACL' => 162,
54
54
 
55
55
  # Extension:Semantic Drilldown
56
- "SED_FILTER" => 170,
57
- "SED_FILTER_TALK" => 171,
56
+ 'SED_FILTER' => 170,
57
+ 'SED_FILTER_TALK' => 171,
58
58
 
59
59
  # Extension:SocialProfile
60
- "SCP_USERWIKI" => 200,
61
- "SCP_USERWIKI_TALK" => 201,
62
- "SCP_USERPROFILE" => 202,
63
- "SCP_USERPROFILE_TALK" => 203,
60
+ 'SCP_USERWIKI' => 200,
61
+ 'SCP_USERWIKI_TALK' => 201,
62
+ 'SCP_USERPROFILE' => 202,
63
+ 'SCP_USERPROFILE_TALK' => 203,
64
64
 
65
65
  # Extension:Proofread Page
66
- "PRP_PAGE" => 250,
67
- "PRP_PAGE_TALK" => 251,
68
- "PRP_INDEX" => 252,
69
- "PRP_INDEX_TALK" => 253,
66
+ 'PRP_PAGE' => 250,
67
+ 'PRP_PAGE_TALK' => 251,
68
+ 'PRP_INDEX' => 252,
69
+ 'PRP_INDEX_TALK' => 253,
70
70
 
71
71
  # Extension:TrustedMath
72
- "TRM_MATH" => 262,
73
- "TRM_MATH_TALK" => 263,
72
+ 'TRM_MATH' => 262,
73
+ 'TRM_MATH_TALK' => 263,
74
74
 
75
75
  # Extension:Widgets
76
- "WID_WIDGET" => 274,
77
- "WID_WIDGET_TALK" => 275,
76
+ 'WID_WIDGET' => 274,
77
+ 'WID_WIDGET_TALK' => 275,
78
78
 
79
79
  # Extension:EmbedScript
80
- "EMS_JSAPPLET" => 280,
81
- "EMS_JSAPPLET_TALK" => 281,
80
+ 'EMS_JSAPPLET' => 280,
81
+ 'EMS_JSAPPLET_TALK' => 281,
82
82
 
83
83
  # Extension:PollNY
84
- "PLN_POLL" => 300,
85
- "PLN_POLL_TALK" => 301,
84
+ 'PLN_POLL' => 300,
85
+ 'PLN_POLL_TALK' => 301,
86
86
 
87
87
  # Extension:Semantic Image Annotator
88
- "SIA_IMAGE_ANNOTATOR" => 380,
88
+ 'SIA_IMAGE_ANNOTATOR' => 380,
89
89
 
90
90
  # Extension:Wiki2LaTeX
91
- "WTL_WIKI2LATEX" => 400,
92
- "WTL_WIKI2LATEX_TALK" => 401,
91
+ 'WTL_WIKI2LATEX' => 400,
92
+ 'WTL_WIKI2LATEX_TALK' => 401,
93
93
 
94
94
  # Extension:Workflow
95
- "WRF_WORKFLOW" => 410,
96
- "WRF_WORKFLOW_TALK" => 411,
95
+ 'WRF_WORKFLOW' => 410,
96
+ 'WRF_WORKFLOW_TALK' => 411,
97
97
 
98
98
  # Extension:Maps
99
- "MAP_LAYER" => 420,
100
- "MAP_LAYER_TALK" => 421,
99
+ 'MAP_LAYER' => 420,
100
+ 'MAP_LAYER_TALK' => 421,
101
101
 
102
102
  # Extension:QuizTabulate
103
- "QTB_QUIZ" => 430,
104
- "QTB_QUIZ_TALK" => 431,
103
+ 'QTB_QUIZ' => 430,
104
+ 'QTB_QUIZ_TALK' => 431,
105
105
 
106
106
  # Extension:Education Program
107
- "EDP_EDUCATION_PROGRAM" => 446,
108
- "EDP_EDUCATION_PROGRAM_TALK" => 447,
107
+ 'EDP_EDUCATION_PROGRAM' => 446,
108
+ 'EDP_EDUCATION_PROGRAM_TALK' => 447,
109
109
 
110
110
  # Extension:BoilerRoom
111
- "BLR_BOILERPLATE" => 450,
112
- "BLR_BOILERPLATE_TALK" => 451,
111
+ 'BLR_BOILERPLATE' => 450,
112
+ 'BLR_BOILERPLATE_TALK' => 451,
113
113
 
114
114
  # Extension:UploadWizard
115
- "UPW_CAMPAIGN" => 460,
116
- "UPW_CAMPAIGN_TALK" => 461,
115
+ 'UPW_CAMPAIGN' => 460,
116
+ 'UPW_CAMPAIGN_TALK' => 461,
117
117
 
118
118
  # Extension:EventLogging
119
- "ELG_SCHEMA" => 470,
120
- "ELG_SCHEMA_TALK" => 471,
119
+ 'ELG_SCHEMA' => 470,
120
+ 'ELG_SCHEMA_TALK' => 471,
121
121
 
122
122
  # Extension:ZeroBanner
123
- "ZRB_ZERO" => 480,
124
- "ZRB_ZERO_TALK" => 481,
123
+ 'ZRB_ZERO' => 480,
124
+ 'ZRB_ZERO_TALK' => 481,
125
125
 
126
126
  # Extension:JsonConfig
127
- "JSC_CONFIG" => 482,
128
- "JSC_CONFIG_TALK" => 483,
129
- "JSC_DATA" => 486,
130
- "JSC_DATA_TALK" => 487,
127
+ 'JSC_CONFIG' => 482,
128
+ 'JSC_CONFIG_TALK' => 483,
129
+ 'JSC_DATA' => 486,
130
+ 'JSC_DATA_TALK' => 487,
131
131
 
132
132
  # Extension:Graph
133
- "GRP_GRAPH" => 484,
134
- "GRP_GRAPH_TALK" => 485,
133
+ 'GRP_GRAPH' => 484,
134
+ 'GRP_GRAPH_TALK' => 485,
135
135
 
136
136
  # Extension:OpenStackManager
137
- "OSM_NOVA_RESOURCE" => 488,
138
- "OSM_NOVA_RESOURCE_TALK" => 489,
137
+ 'OSM_NOVA_RESOURCE' => 488,
138
+ 'OSM_NOVA_RESOURCE_TALK' => 489,
139
139
 
140
140
  # Extension:GWToolset
141
- "GWT_GWTOOLSET" => 490,
142
- "GWT_GWTOOLSET_TALK" => 491,
141
+ 'GWT_GWTOOLSET' => 490,
142
+ 'GWT_GWTOOLSET_TALK' => 491,
143
143
 
144
144
  # Extension:BlogPage
145
- "BLP_BLOG" => 500,
146
- "BLP_BLOG_TALK" => 501,
145
+ 'BLP_BLOG' => 500,
146
+ 'BLP_BLOG_TALK' => 501,
147
147
 
148
148
  # Extension:XMLContentExtension
149
- "XCE_XML" => 580,
150
- "XCE_XML_TALK" => 581,
151
- "XCE_SCHEMA" => 582,
152
- "XCE_SCHEMA_TALK" => 583,
149
+ 'XCE_XML' => 580,
150
+ 'XCE_XML_TALK' => 581,
151
+ 'XCE_SCHEMA' => 582,
152
+ 'XCE_SCHEMA_TALK' => 583,
153
153
 
154
154
  # Extension:FanBoxes
155
- "FNB_USERBOX" => 600,
156
- "FNB_USERBOX_TALK" => 601,
155
+ 'FNB_USERBOX' => 600,
156
+ 'FNB_USERBOX_TALK' => 601,
157
157
 
158
158
  # Extension:LinkFilter
159
- "LFT_LINK" => 700,
160
- "LFT_LINK_TALK" => 701,
159
+ 'LFT_LINK' => 700,
160
+ 'LFT_LINK_TALK' => 701,
161
161
 
162
162
  # Extension:TimedMediaHandler
163
- "TMH_TIMEDTEXT" => 710,
164
- "TMH_TIMEDTEXT_TALK" => 711,
163
+ 'TMH_TIMEDTEXT' => 710,
164
+ 'TMH_TIMEDTEXT_TALK' => 711,
165
165
 
166
166
  # Extension:QPoll
167
- "QPL_INTERPRETATION" => 800,
168
- "QPL_INTERPRETATION_TALK" => 801,
167
+ 'QPL_INTERPRETATION' => 800,
168
+ 'QPL_INTERPRETATION_TALK' => 801,
169
169
 
170
170
  # Extension:SemanticMustacheFormat :3,
171
- "SMF_MUSTACHE" => 806,
172
- "SMF_MUSTACHE_TALK" => 807,
171
+ 'SMF_MUSTACHE' => 806,
172
+ 'SMF_MUSTACHE_TALK' => 807,
173
173
 
174
174
  # Extension:R
175
- "R_R" => 814,
176
- "R_R_TALK" => 815,
175
+ 'R_R' => 814,
176
+ 'R_R_TALK' => 815,
177
177
 
178
178
  # Extension:Scribunto
179
- "SCR_MODULE" => 828,
180
- "SCR_MODULE_TALK" => 829,
179
+ 'SCR_MODULE' => 828,
180
+ 'SCR_MODULE_TALK' => 829,
181
181
 
182
182
  # Extension:SecurePoll
183
- "SEP_SECUREPOLL" => 830,
184
- "SEP_SECUREPOLL_TALK" => 831,
183
+ 'SEP_SECUREPOLL' => 830,
184
+ 'SEP_SECUREPOLL_TALK' => 831,
185
185
 
186
186
  # Extension:CentralNotice
187
- "CNT_CNBANNER" => 866,
188
- "CNT_CNBANNER_TALK" => 867,
187
+ 'CNT_CNBANNER' => 866,
188
+ 'CNT_CNBANNER_TALK' => 867,
189
189
 
190
190
  # Extension:Translate
191
- "TRN_TRANSLATIONS" => 1198,
192
- "TRN_TRANSLATIOTALK" => 1199,
191
+ 'TRN_TRANSLATIONS' => 1198,
192
+ 'TRN_TRANSLATIOTALK' => 1199,
193
193
 
194
194
  # Extension:PackageForce
195
- "PKF_PACKAGEFORCE" => 1300,
196
- "PKF_PACKAGEFORCE_TALK" => 1301,
195
+ 'PKF_PACKAGEFORCE' => 1300,
196
+ 'PKF_PACKAGEFORCE_TALK' => 1301,
197
197
 
198
198
  # Extension:BlueSpice
199
- "BLS_BLOG" => 1502,
200
- "BLS_BLOG_TALK" => 1503,
201
- "BLS_BOOK" => 1504,
202
- "BLS_BOOK_TALK" => 1505,
199
+ 'BLS_BLOG' => 1502,
200
+ 'BLS_BLOG_TALK' => 1503,
201
+ 'BLS_BOOK' => 1504,
202
+ 'BLS_BOOK_TALK' => 1505,
203
203
 
204
204
  # Extension:Gadgets
205
- "GDG_GADGET" => 2300,
206
- "GDG_GADGET_TALK" => 2301,
207
- "GDG_GADGET_DEFININTION" => 2302,
208
- "GDG_GADGET_DEFININTION_TALK" => 2303,
205
+ 'GDG_GADGET' => 2300,
206
+ 'GDG_GADGET_TALK' => 2301,
207
+ 'GDG_GADGET_DEFININTION' => 2302,
208
+ 'GDG_GADGET_DEFININTION_TALK' => 2303,
209
209
 
210
210
  # Extension:VisualEditor
211
- "VSE_VISUALEDITOR" => 2500,
212
- "VSE_VISUALEDITOR_TALK" => 2501,
211
+ 'VSE_VISUALEDITOR' => 2500,
212
+ 'VSE_VISUALEDITOR_TALK' => 2501,
213
213
 
214
214
  # Extension:Flow
215
- "FLW_TOPIC" => 2600
215
+ 'FLW_TOPIC' => 2600
216
216
  }
217
217
  end
218
218
  end
@@ -1,10 +1,13 @@
1
1
  module MediaWiki
2
2
  module Edit
3
- # Performs a standard edit. It cannot create pages. Please use create_page for that.
3
+ # Performs a standard edit.
4
+ # It cannot create pages. Please use create_page for that.
4
5
  # @param title [String] The page title.
5
6
  # @param text [String] The new content.
6
- # @param minor [Boolean] Will mark the edit as minor if true. Defaults to false.
7
- # @param bot [Boolean] Will mark the edit as bot edit if true. Defualts to true, for your convenience, bot developers.
7
+ # @param minor [Boolean] Will mark the edit as minor if true.
8
+ # Defaults to false.
9
+ # @param bot [Boolean] Will mark the edit as bot edit if true.
10
+ # Defualts to true, for your convenience, bot developers.
8
11
  # @param summary [String] The edit summary. Optional.
9
12
  # @return [String] The new revision ID, or if it failed, the error code.
10
13
  def edit(title, text, minor = false, bot = true, *summary)
@@ -16,7 +19,7 @@ module MediaWiki
16
19
  format: 'json'
17
20
  }
18
21
 
19
- token = get_edit_token(title)
22
+ token = get_token('edit', title)
20
23
 
21
24
  params[:summary] = summary if defined? summary
22
25
  params[:minor] = '1' if minor
@@ -25,20 +28,21 @@ module MediaWiki
25
28
 
26
29
  response = post(params)
27
30
 
28
- if response["edit"]["result"] == "Success"
29
- return response["edit"]["newrevid"]
31
+ if response['edit']['result'] == 'Success'
32
+ return response['edit']['newrevid']
30
33
  else
31
- return response["error"]["code"]
34
+ return response['error']['code']
32
35
  end
33
36
  end
34
37
 
35
38
  # Creates a new page.
36
39
  # @param title [String] The new page's title.
37
40
  # @param text [String] The new page's content.
38
- # @param summary [String] The edit summary. Defaults to "New page".
39
- # @param bot [Boolean] Will mark the edit as a bot edit if true. Defaults to true, for your convenience, bot developers.
41
+ # @param summary [String] The edit summary. Defaults to 'New page'.
42
+ # @param bot [Boolean] Will mark the edit as a bot edit if true.
43
+ # Defaults to true, for your convenience, bot developers.
40
44
  # @return [String] The new page ID, or if it failed, the error code.
41
- def create_page(title, text, summary = "New page", bot = true)
45
+ def create_page(title, text, summary = 'New page', bot = true)
42
46
  params = {
43
47
  action: 'edit',
44
48
  title: title,
@@ -48,24 +52,28 @@ module MediaWiki
48
52
  format: 'json'
49
53
  }
50
54
 
51
- token = get_edit_token(title)
55
+ token = get_token('edit', title)
52
56
 
53
57
  params[:bot] = '1' if bot
54
58
  params[:token] = token
55
59
 
56
60
  response = post(params)
57
61
 
58
- if response["edit"]["result"] == "Success"
59
- return response["edit"]["pageid"]
62
+ if response['edit']['result'] == 'Success'
63
+ return response['edit']['pageid']
60
64
  else
61
- return response["error"]["code"]
65
+ return response['error']['code']
62
66
  end
63
67
  end
64
68
 
65
69
  # Uploads a file from a URL.
66
70
  # @param url [String] The URL to the file.
67
- # @param filename [String] The preferred filename. This can include File: at the beginning, but it will be removed through regex. Optional. If ommitted, it will be everything after the last slash in the URL.
68
- # @return [Boolean/String] true if the upload was successful, else the warning key.
71
+ # @param filename [String] The preferred filename.
72
+ # This can include File: at the beginning, but it will be removed
73
+ # through regex. Optional. If ommitted, it will be everything after
74
+ # the last slash in the URL.
75
+ # @return [Boolean/String] true if the upload was successful, else the
76
+ # warning's key.
69
77
  def upload(url, *filename)
70
78
  params = {
71
79
  action: 'upload',
@@ -73,19 +81,73 @@ module MediaWiki
73
81
  format: 'json'
74
82
  }
75
83
 
76
- filename = defined? filename ? filename.sub(/$File:/, "") : url.split('/')[-1]
77
-
78
- token = get_edit_token(filename)
84
+ if defined? filename
85
+ filename = filename.sub(/$File:/, '')
86
+ else
87
+ filename = url.split('/')[-1]
88
+ end
79
89
 
90
+ token = get_token('edit', filename)
80
91
  params[:filename] = filename
81
92
  params[:token] = token
82
93
 
83
94
  response = post(params)
84
- if response["upload"]["result"] == "Success"
95
+ if response['upload']['result'] == 'Success'
96
+ return true
97
+ elsif response['upload']['result'] == 'Warning'
98
+ return response['upload']['warnings'].keys[0]
99
+ end
100
+ end
101
+
102
+ # Performs a move on a page.
103
+ # @param from [String] The page to be moved.
104
+ # @param to [String] The destination of the move.
105
+ # @param reason [String] The reason for the move, which shows up in the log.
106
+ # Optionl.
107
+ # @param talk [Boolean] Whether to move the associated talk page.
108
+ # Defaults to true.
109
+ # @param redirect [Boolean] Whether to create a redirect. Defaults to false.
110
+ # @return [Boolean/String] true if successful, the error code if not.
111
+ def move(from, to, reason = nil, talk = true, redirect = false)
112
+ params = {
113
+ action: 'move',
114
+ from: from,
115
+ to: to
116
+ }
117
+
118
+ token = get_token('move', from)
119
+ params[:reason] = reason unless reason.nil?
120
+ params[:movetalk] = '1' if talk == true
121
+ params[:noredirect] = '1' if redirect == false
122
+ params[:token] = token
123
+
124
+ response = post(params)
125
+ if !response['move'].nil?
85
126
  return true
86
- elsif response["upload"]["result"] == "Warning"
87
- warnings = response["upload"]["warnings"]
88
- return warnings.keys[0]
127
+ else
128
+ return response['error']['code']
129
+ end
130
+ end
131
+
132
+ # Deletes a page.
133
+ # @param title [String] The page to delete.
134
+ # @param reason [String] The reason to be displayed in logs. Optional.
135
+ # @return [Boolean/String] true if successful, the error code if not.
136
+ def delete(title, reason = nil)
137
+ params = {
138
+ action: 'delete',
139
+ title: title
140
+ }
141
+
142
+ token = get_token('delete', title)
143
+ params[:reason] = reason unless reason.nil?
144
+ params[:token] = token
145
+
146
+ response = post(params)
147
+ if !response['delete'].nil?
148
+ return true
149
+ else
150
+ return response['error']['code']
89
151
  end
90
152
  end
91
153
  end