@@ -12,6 +12,7 @@ import ApiURLDirector from './util/builders/url/api.director.js'
12
12
import WikimediaDesktopURLDirector from './util/builders/url/desktop.director.js'
13
13
import WikimediaMobileURLDirector from './util/builders/url/mobile.director.js'
14
14
import VisualEditorURLDirector from './util/builders/url/visual-editor.director.js'
15
+ import MediawikiRestApiURLDirector from './util/builders/url/mediawiki-rest-api.director.js'
15
16
import { checkApiAvailability } from './util/mw-api.js'
16
17
import { BLACKLISTED_NS } from './util/const.js'
17
18
@@ -48,16 +49,19 @@ class MediaWiki {
48
49
#actionApiPath: string
49
50
#restApiPath: string
50
51
#modulePathOpt: string
52
+ #mediawikiRestApiPath: string
51
53
#username: string
52
54
#password: string
53
55
#domain: string
54
56
55
57
public wikimediaDesktopUrlDirector : WikimediaDesktopURLDirector
56
58
public wikimediaMobileUrlDirector : WikimediaMobileURLDirector
57
- public visualEditorURLDirector : VisualEditorURLDirector
59
+ public visualEditorUrlDirector : VisualEditorURLDirector
60
+ public mediawikiRestApiUrlDirector : MediawikiRestApiURLDirector
58
61
59
62
public visualEditorApiUrl : URL
60
63
public actionApiUrl : URL
64
+ public mediawikiRestApiUrl : URL
61
65
public webUrl : URL
62
66
public wikimediaDesktopApiUrl : URL
63
67
public wikimediaMobileApiUrl : URL
@@ -66,12 +70,10 @@ class MediaWiki {
66
70
public mobileModulePath : string
67
71
68
72
#apiUrlDirector: ApiURLDirector
69
- #wikimediaDesktopUrlDirector: WikimediaDesktopURLDirector
70
- #wikimediaMobileUrlDirector: WikimediaMobileURLDirector
71
- #visualEditorURLDirector: VisualEditorURLDirector
72
73
#hasWikimediaDesktopApi: boolean | null
73
74
#hasWikimediaMobileApi: boolean | null
74
75
#hasVisualEditorApi: boolean | null
76
+ #hasMediawikiRestApi: boolean | null
75
77
#hasCoordinates: boolean | null
76
78
77
79
set username ( value : string ) {
@@ -98,6 +100,13 @@ class MediaWiki {
98
100
}
99
101
}
100
102
103
+ set mediawikiRestApiPath ( value : string ) {
104
+ if ( value ) {
105
+ this . #mediawikiRestApiPath = value
106
+ this . setMediawikiRestApiURL ( )
107
+ }
108
+ }
109
+
101
110
set domain ( value : string ) {
102
111
this . #domain = value
103
112
}
@@ -117,6 +126,7 @@ class MediaWiki {
117
126
this . actionApiUrl = this . urlDirector . buildURL ( this . #actionApiPath)
118
127
this . setWikimediaDesktopApiUrl ( )
119
128
this . setWikimediaMobileApiUrl ( )
129
+ this . setMediawikiRestApiURL ( )
120
130
this . setVisualEditorURL ( )
121
131
this . setModuleURL ( )
122
132
this . setMobileModuleUrl ( )
@@ -143,6 +153,7 @@ class MediaWiki {
143
153
144
154
this . #actionApiPath = 'w/api.php'
145
155
this . #restApiPath = 'api/rest_v1'
156
+ this . #mediawikiRestApiPath = 'w/rest.php/v1/page/'
146
157
this . #wikiPath = 'wiki/'
147
158
this . #modulePathOpt = 'w/load.php'
148
159
@@ -163,6 +174,7 @@ class MediaWiki {
163
174
this . #hasWikimediaDesktopApi = null
164
175
this . #hasWikimediaMobileApi = null
165
176
this . #hasVisualEditorApi = null
177
+ this . #hasMediawikiRestApi = null
166
178
this . #hasCoordinates = null
167
179
}
168
180
@@ -172,31 +184,40 @@ class MediaWiki {
172
184
173
185
public async hasWikimediaDesktopApi ( ) : Promise < boolean > {
174
186
if ( this . #hasWikimediaDesktopApi === null ) {
175
- this . # wikimediaDesktopUrlDirector = new WikimediaDesktopURLDirector ( this . wikimediaDesktopApiUrl . href )
176
- this . #hasWikimediaDesktopApi = await checkApiAvailability ( this . # wikimediaDesktopUrlDirector. buildArticleURL ( this . apiCheckArticleId ) )
187
+ this . wikimediaDesktopUrlDirector = new WikimediaDesktopURLDirector ( this . wikimediaDesktopApiUrl . href )
188
+ this . #hasWikimediaDesktopApi = await checkApiAvailability ( this . wikimediaDesktopUrlDirector . buildArticleURL ( this . apiCheckArticleId ) )
177
189
return this . #hasWikimediaDesktopApi
178
190
}
179
191
return this . #hasWikimediaDesktopApi
180
192
}
181
193
182
194
public async hasWikimediaMobileApi ( ) : Promise < boolean > {
183
195
if ( this . #hasWikimediaMobileApi === null ) {
184
- this . # wikimediaMobileUrlDirector = new WikimediaMobileURLDirector ( this . wikimediaMobileApiUrl . href )
185
- this . #hasWikimediaMobileApi = await checkApiAvailability ( this . # wikimediaMobileUrlDirector. buildArticleURL ( this . apiCheckArticleId ) )
196
+ this . wikimediaMobileUrlDirector = new WikimediaMobileURLDirector ( this . wikimediaMobileApiUrl . href )
197
+ this . #hasWikimediaMobileApi = await checkApiAvailability ( this . wikimediaMobileUrlDirector . buildArticleURL ( this . apiCheckArticleId ) )
186
198
return this . #hasWikimediaMobileApi
187
199
}
188
200
return this . #hasWikimediaMobileApi
189
201
}
190
202
191
203
public async hasVisualEditorApi ( ) : Promise < boolean > {
192
204
if ( this . #hasVisualEditorApi === null ) {
193
- this . #visualEditorURLDirector = new VisualEditorURLDirector ( this . visualEditorApiUrl . href )
194
- this . #hasVisualEditorApi = await checkApiAvailability ( this . #visualEditorURLDirector . buildArticleURL ( this . apiCheckArticleId ) )
205
+ this . visualEditorUrlDirector = new VisualEditorURLDirector ( this . visualEditorApiUrl . href )
206
+ this . #hasVisualEditorApi = await checkApiAvailability ( this . visualEditorUrlDirector . buildArticleURL ( this . apiCheckArticleId ) )
195
207
return this . #hasVisualEditorApi
196
208
}
197
209
return this . #hasVisualEditorApi
198
210
}
199
211
212
+ public async hasMediawikiRestApi ( ) : Promise < boolean > {
213
+ if ( this . #hasMediawikiRestApi === null ) {
214
+ this . mediawikiRestApiUrlDirector = new MediawikiRestApiURLDirector ( this . mediawikiRestApiUrl . href )
215
+ this . #hasMediawikiRestApi = await checkApiAvailability ( this . mediawikiRestApiUrlDirector . buildArticleURL ( this . apiCheckArticleId ) )
216
+ return this . #hasMediawikiRestApi
217
+ }
218
+ return this . #hasMediawikiRestApi
219
+ }
220
+
200
221
public async hasCoordinates ( downloader : Downloader ) : Promise < boolean > {
201
222
if ( this . #hasCoordinates === null ) {
202
223
const validNamespaceIds = this . namespacesToMirror . map ( ( ns ) => this . namespaces [ ns ] . num )
@@ -224,6 +245,10 @@ class MediaWiki {
224
245
this . wikimediaMobileApiUrl = this . urlDirector . buildWikimediaMobileApiUrl ( this . #restApiPath)
225
246
}
226
247
248
+ private setMediawikiRestApiURL ( ) {
249
+ this . mediawikiRestApiUrl = this . urlDirector . buildMediawikiRestApiUrl ( this . #mediawikiRestApiPath)
250
+ }
251
+
227
252
private setVisualEditorURL ( ) {
228
253
this . #apiUrlDirector = new ApiURLDirector ( this . actionApiUrl . href )
229
254
this . visualEditorApiUrl = this . #apiUrlDirector. buildVisualEditorURL ( )
@@ -459,13 +484,15 @@ class MediaWiki {
459
484
const mwMetaData : MWMetaData = {
460
485
webUrl : this . webUrl . href ,
461
486
actionApiUrl : this . actionApiUrl . href ,
487
+ mediawikiRestApiUrl : this . mediawikiRestApiUrl . href ,
462
488
modulePathOpt : this . #modulePathOpt,
463
489
modulePath : this . modulePath ,
464
490
mobileModulePath : this . mobileModulePath ,
465
491
webUrlPath : this . webUrl . pathname ,
466
492
wikiPath : this . #wikiPath,
467
493
baseUrl : this . baseUrl . href ,
468
494
actionApiPath : this . #actionApiPath,
495
+ mediawikiRestApiPath : this . #mediawikiRestApiPath,
469
496
restApiPath : this . #restApiPath,
470
497
domain : this . #domain,
471
498
0 commit comments