@@ -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 MediawikiRestApiDirector 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
@@ -47,6 +48,7 @@ class MediaWiki {
47
48
#actionApiPath: string
48
49
#restApiPath: string
49
50
#modulePathOpt: string
51
+ #mediawikiRestApiPath: string
50
52
#username: string
51
53
#password: string
52
54
#domain: string
@@ -55,6 +57,7 @@ class MediaWiki {
55
57
private wikimediaDesktopUrlDirector : WikimediaDesktopURLDirector
56
58
private wikimediaMobileUrlDirector : WikimediaMobileURLDirector
57
59
private visualEditorURLDirector : VisualEditorURLDirector
60
+ private mediawikiRestApiDirector : MediawikiRestApiDirector
58
61
59
62
public visualEditorApiUrl : URL
60
63
public actionApiUrl : URL
@@ -63,10 +66,12 @@ class MediaWiki {
63
66
public webUrl : URL
64
67
public WikimediaDesktopApiUrl : URL
65
68
public WikimediaMobileApiUrl : URL
69
+ public mediawikiRestApiUrl : URL
66
70
67
71
#hasWikimediaDesktopApi: boolean | null
68
72
#hasWikimediaMobileApi: boolean | null
69
73
#hasVisualEditorApi: boolean | null
74
+ #hasMediawikiRestApi: boolean | null
70
75
#hasCoordinates: boolean | null
71
76
72
77
set username ( value : string ) {
@@ -134,6 +139,8 @@ class MediaWiki {
134
139
135
140
this . #actionApiPath = 'w/api.php'
136
141
this . #restApiPath = 'api/rest_v1'
142
+ // TODO: there is no CLI param for this api yet
143
+ this . #mediawikiRestApiPath = 'w/rest.php/v1/page/'
137
144
this . #wikiPath = 'wiki/'
138
145
this . #modulePathOpt = 'w/load.php'
139
146
@@ -154,6 +161,7 @@ class MediaWiki {
154
161
this . #hasWikimediaDesktopApi = null
155
162
this . #hasWikimediaMobileApi = null
156
163
this . #hasVisualEditorApi = null
164
+ this . #hasMediawikiRestApi = null
157
165
this . #hasCoordinates = null
158
166
}
159
167
@@ -185,6 +193,14 @@ class MediaWiki {
185
193
return this . #hasVisualEditorApi
186
194
}
187
195
196
+ public async hasMediawikiRestApi ( ) : Promise < boolean > {
197
+ if ( this . #hasMediawikiRestApi === null ) {
198
+ this . #hasMediawikiRestApi = await checkApiAvailability ( this . mediawikiRestApiDirector . buildArticleURL ( this . apiCheckArticleId ) )
199
+ return this . #hasMediawikiRestApi
200
+ }
201
+ return this . #hasMediawikiRestApi
202
+ }
203
+
188
204
public async hasCoordinates ( downloader : Downloader ) : Promise < boolean > {
189
205
if ( this . #hasCoordinates === null ) {
190
206
const validNamespaceIds = this . namespacesToMirror . map ( ( ns ) => this . namespaces [ ns ] . num )
@@ -215,9 +231,12 @@ class MediaWiki {
215
231
private initApiURLDirector ( ) {
216
232
this . webUrl = this . baseUrlDirector . buildURL ( this . #wikiPath)
217
233
this . actionApiUrl = this . baseUrlDirector . buildURL ( this . #actionApiPath)
234
+ // TODO: refactor this workaround once PR#1929 is merged
235
+ this . mediawikiRestApiUrl = this . baseUrlDirector . buildURL ( this . #mediawikiRestApiPath)
218
236
this . apiUrlDirector = new ApiURLDirector ( this . actionApiUrl . href )
219
237
this . visualEditorApiUrl = this . apiUrlDirector . buildVisualEditorURL ( )
220
238
this . visualEditorURLDirector = new VisualEditorURLDirector ( this . visualEditorApiUrl . href )
239
+ this . mediawikiRestApiDirector = new MediawikiRestApiDirector ( this . baseUrl . href )
221
240
}
222
241
223
242
public async login ( downloader : Downloader ) {
@@ -442,6 +461,7 @@ class MediaWiki {
442
461
const mwMetaData : MWMetaData = {
443
462
webUrl : this . webUrl . href ,
444
463
actionApiUrl : this . actionApiUrl . href ,
464
+ mediawikiRestApiPath : this . mediawikiRestApiUrl . href ,
445
465
modulePathOpt : this . #modulePathOpt,
446
466
modulePath : this . modulePath ,
447
467
mobileModulePath : this . mobileModulePath ,
0 commit comments