mediawiki-butt 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/mediawiki/administration.rb +54 -0
- data/lib/mediawiki/auth.rb +95 -87
- data/lib/mediawiki/butt.rb +39 -18
- data/lib/mediawiki/constants.rb +124 -124
- data/lib/mediawiki/edit.rb +85 -23
- data/lib/mediawiki/exceptions.rb +22 -20
- data/lib/mediawiki/query.rb +133 -124
- metadata +4 -3
data/lib/mediawiki/constants.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
45
|
-
|
44
|
+
'DPLF_FORUM' => 110,
|
45
|
+
'DPLF_FORUM_TAlK' => 111,
|
46
46
|
|
47
47
|
# Extension:RefHelper
|
48
|
-
|
49
|
-
|
48
|
+
'RFH_CITE' => 120,
|
49
|
+
'RFH_CITE_TALK' => 121,
|
50
50
|
|
51
51
|
# Extension:SemanticAccessControl
|
52
|
-
|
53
|
-
|
52
|
+
'ACL_USERGROUP' => 160,
|
53
|
+
'ACL_ACL' => 162,
|
54
54
|
|
55
55
|
# Extension:Semantic Drilldown
|
56
|
-
|
57
|
-
|
56
|
+
'SED_FILTER' => 170,
|
57
|
+
'SED_FILTER_TALK' => 171,
|
58
58
|
|
59
59
|
# Extension:SocialProfile
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
73
|
-
|
72
|
+
'TRM_MATH' => 262,
|
73
|
+
'TRM_MATH_TALK' => 263,
|
74
74
|
|
75
75
|
# Extension:Widgets
|
76
|
-
|
77
|
-
|
76
|
+
'WID_WIDGET' => 274,
|
77
|
+
'WID_WIDGET_TALK' => 275,
|
78
78
|
|
79
79
|
# Extension:EmbedScript
|
80
|
-
|
81
|
-
|
80
|
+
'EMS_JSAPPLET' => 280,
|
81
|
+
'EMS_JSAPPLET_TALK' => 281,
|
82
82
|
|
83
83
|
# Extension:PollNY
|
84
|
-
|
85
|
-
|
84
|
+
'PLN_POLL' => 300,
|
85
|
+
'PLN_POLL_TALK' => 301,
|
86
86
|
|
87
87
|
# Extension:Semantic Image Annotator
|
88
|
-
|
88
|
+
'SIA_IMAGE_ANNOTATOR' => 380,
|
89
89
|
|
90
90
|
# Extension:Wiki2LaTeX
|
91
|
-
|
92
|
-
|
91
|
+
'WTL_WIKI2LATEX' => 400,
|
92
|
+
'WTL_WIKI2LATEX_TALK' => 401,
|
93
93
|
|
94
94
|
# Extension:Workflow
|
95
|
-
|
96
|
-
|
95
|
+
'WRF_WORKFLOW' => 410,
|
96
|
+
'WRF_WORKFLOW_TALK' => 411,
|
97
97
|
|
98
98
|
# Extension:Maps
|
99
|
-
|
100
|
-
|
99
|
+
'MAP_LAYER' => 420,
|
100
|
+
'MAP_LAYER_TALK' => 421,
|
101
101
|
|
102
102
|
# Extension:QuizTabulate
|
103
|
-
|
104
|
-
|
103
|
+
'QTB_QUIZ' => 430,
|
104
|
+
'QTB_QUIZ_TALK' => 431,
|
105
105
|
|
106
106
|
# Extension:Education Program
|
107
|
-
|
108
|
-
|
107
|
+
'EDP_EDUCATION_PROGRAM' => 446,
|
108
|
+
'EDP_EDUCATION_PROGRAM_TALK' => 447,
|
109
109
|
|
110
110
|
# Extension:BoilerRoom
|
111
|
-
|
112
|
-
|
111
|
+
'BLR_BOILERPLATE' => 450,
|
112
|
+
'BLR_BOILERPLATE_TALK' => 451,
|
113
113
|
|
114
114
|
# Extension:UploadWizard
|
115
|
-
|
116
|
-
|
115
|
+
'UPW_CAMPAIGN' => 460,
|
116
|
+
'UPW_CAMPAIGN_TALK' => 461,
|
117
117
|
|
118
118
|
# Extension:EventLogging
|
119
|
-
|
120
|
-
|
119
|
+
'ELG_SCHEMA' => 470,
|
120
|
+
'ELG_SCHEMA_TALK' => 471,
|
121
121
|
|
122
122
|
# Extension:ZeroBanner
|
123
|
-
|
124
|
-
|
123
|
+
'ZRB_ZERO' => 480,
|
124
|
+
'ZRB_ZERO_TALK' => 481,
|
125
125
|
|
126
126
|
# Extension:JsonConfig
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
134
|
-
|
133
|
+
'GRP_GRAPH' => 484,
|
134
|
+
'GRP_GRAPH_TALK' => 485,
|
135
135
|
|
136
136
|
# Extension:OpenStackManager
|
137
|
-
|
138
|
-
|
137
|
+
'OSM_NOVA_RESOURCE' => 488,
|
138
|
+
'OSM_NOVA_RESOURCE_TALK' => 489,
|
139
139
|
|
140
140
|
# Extension:GWToolset
|
141
|
-
|
142
|
-
|
141
|
+
'GWT_GWTOOLSET' => 490,
|
142
|
+
'GWT_GWTOOLSET_TALK' => 491,
|
143
143
|
|
144
144
|
# Extension:BlogPage
|
145
|
-
|
146
|
-
|
145
|
+
'BLP_BLOG' => 500,
|
146
|
+
'BLP_BLOG_TALK' => 501,
|
147
147
|
|
148
148
|
# Extension:XMLContentExtension
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
156
|
-
|
155
|
+
'FNB_USERBOX' => 600,
|
156
|
+
'FNB_USERBOX_TALK' => 601,
|
157
157
|
|
158
158
|
# Extension:LinkFilter
|
159
|
-
|
160
|
-
|
159
|
+
'LFT_LINK' => 700,
|
160
|
+
'LFT_LINK_TALK' => 701,
|
161
161
|
|
162
162
|
# Extension:TimedMediaHandler
|
163
|
-
|
164
|
-
|
163
|
+
'TMH_TIMEDTEXT' => 710,
|
164
|
+
'TMH_TIMEDTEXT_TALK' => 711,
|
165
165
|
|
166
166
|
# Extension:QPoll
|
167
|
-
|
168
|
-
|
167
|
+
'QPL_INTERPRETATION' => 800,
|
168
|
+
'QPL_INTERPRETATION_TALK' => 801,
|
169
169
|
|
170
170
|
# Extension:SemanticMustacheFormat :3,
|
171
|
-
|
172
|
-
|
171
|
+
'SMF_MUSTACHE' => 806,
|
172
|
+
'SMF_MUSTACHE_TALK' => 807,
|
173
173
|
|
174
174
|
# Extension:R
|
175
|
-
|
176
|
-
|
175
|
+
'R_R' => 814,
|
176
|
+
'R_R_TALK' => 815,
|
177
177
|
|
178
178
|
# Extension:Scribunto
|
179
|
-
|
180
|
-
|
179
|
+
'SCR_MODULE' => 828,
|
180
|
+
'SCR_MODULE_TALK' => 829,
|
181
181
|
|
182
182
|
# Extension:SecurePoll
|
183
|
-
|
184
|
-
|
183
|
+
'SEP_SECUREPOLL' => 830,
|
184
|
+
'SEP_SECUREPOLL_TALK' => 831,
|
185
185
|
|
186
186
|
# Extension:CentralNotice
|
187
|
-
|
188
|
-
|
187
|
+
'CNT_CNBANNER' => 866,
|
188
|
+
'CNT_CNBANNER_TALK' => 867,
|
189
189
|
|
190
190
|
# Extension:Translate
|
191
|
-
|
192
|
-
|
191
|
+
'TRN_TRANSLATIONS' => 1198,
|
192
|
+
'TRN_TRANSLATIOTALK' => 1199,
|
193
193
|
|
194
194
|
# Extension:PackageForce
|
195
|
-
|
196
|
-
|
195
|
+
'PKF_PACKAGEFORCE' => 1300,
|
196
|
+
'PKF_PACKAGEFORCE_TALK' => 1301,
|
197
197
|
|
198
198
|
# Extension:BlueSpice
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
212
|
-
|
211
|
+
'VSE_VISUALEDITOR' => 2500,
|
212
|
+
'VSE_VISUALEDITOR_TALK' => 2501,
|
213
213
|
|
214
214
|
# Extension:Flow
|
215
|
-
|
215
|
+
'FLW_TOPIC' => 2600
|
216
216
|
}
|
217
217
|
end
|
218
218
|
end
|
data/lib/mediawiki/edit.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module MediaWiki
|
2
2
|
module Edit
|
3
|
-
# Performs a standard edit.
|
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.
|
7
|
-
#
|
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 =
|
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[
|
29
|
-
return response[
|
31
|
+
if response['edit']['result'] == 'Success'
|
32
|
+
return response['edit']['newrevid']
|
30
33
|
else
|
31
|
-
return response[
|
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
|
39
|
-
# @param bot [Boolean] Will mark the edit as a bot edit if true.
|
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 =
|
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 =
|
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[
|
59
|
-
return response[
|
62
|
+
if response['edit']['result'] == 'Success'
|
63
|
+
return response['edit']['pageid']
|
60
64
|
else
|
61
|
-
return response[
|
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.
|
68
|
-
#
|
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
|
-
|
77
|
-
|
78
|
-
|
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[
|
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
|
-
|
87
|
-
|
88
|
-
|
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
|