-
Notifications
You must be signed in to change notification settings - Fork 8
/
MediaWiki.d.ts
398 lines (360 loc) · 10.2 KB
/
MediaWiki.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/// <reference path="MwEcho.d.ts" />
interface MwApiActionQuery {
action: string
formatversion?: number
origin?: string
prop?: string
continue?: string
uselang?: string
// When sourced from wikitext
titles?: string[]
// local descriptions
ppprop?: string
// PageImages
pilimit?: number
piprop?: string
pithumbsize?: number
// When using TextExtracts
exsentences?: string
exintro?: string
explaintext?: string
// Cirrus Search
generator?: string
maxage?: number
smaxage?: number
gsrqiprofile?: string
gsrlimit?: number
gsrnamespace?: string
gsrsearch?: string
}
interface MwApiQueryResponse {
query: {
pages: MwApiPageObject[]
}
}
interface MwApiPagePropsObject {
description: string
}
interface MwApiThumbnailObject {
width: number
height: number
source: string
}
interface MwApiPageObject {
title: string
description?: string
extract?: string
thumbnail?: MwApiThumbnailObject
pageprops?: MwApiPagePropsObject
}
interface MwTemplateRenderer {
render( data: Object, partials: Object ): JQuery;
}
interface MwTemplateCompiler {
compile( templateStr: string ): MwTemplateRenderer;
}
interface MwTemplate {
getCompiler( compilerName: string ): MwTemplateCompiler;
}
interface MwApi {
saveOption( name: string, value: unknown ): JQuery.Promise<any>;
saveOptions( options: Object ): JQuery.Promise<any>;
get( parameters: Object, ajaxOptions?: Object ): JQuery.Promise<MwApiQueryResponse|any>;
postWithToken( tokenType: string, params: Object, ajaxOptions?: Object ): JQuery.Promise<any>;
}
interface MwTitle {
getPrefixedText(): string
getTalkPage(): MwTitle|null
getUrl( params?: Object ): string
}
type MwTitleConstructor = new( title: string, namespace?: number ) => MwTitle;
type MwApiConstructor = new( options?: Object ) => MwApi;
interface MwCookieOptions {
expires?: Date|number|null;
prefix?: string;
domain?: string;
path?: string;
secure?: boolean;
sameSite?: string;
sameSiteLegacy?: boolean;
}
interface MwCookie {
get( cookieName: string ): string|null
set( cookieName: string, value: string|null, options?: MwCookieOptions ): void;
}
interface MwUri {
extend( parameters: object ): object;
new ( uri?: Object|string, options?: Object|boolean ): MwUri;
query: Record<string, unknown>;
toString(): string;
}
interface MwEventLog {
eventInSample( population: Object ): boolean;
inSample( num: number ): boolean;
logEvent( schema: string, data: Object ): void;
}
type UriConstructor = new( uri: string, options?: Object ) => MwUri;
type mwHookFunction = {
( ...args: any[] ): void;
};
interface mwHookInstance {
add( fn: mwHookFunction ): this;
/**
* Fire an event for logging.
*/
fire( ...args: any[] ): this;
}
interface MwMessage {
/**
* Parse the wikitext message into HTML.
* Requires jqueryMsg to be useful.
*/
parse(): string;
/**
* Parse the message to DOM nodes, rather than HTML string
* This method is only available when jqueryMsg is loaded
*/
parseDom(): JQuery;
/**
* Return the message as plain text.
*/
plain(): string;
/**
* Format the message with text transformations.
* Requires jqueryMsg to be useful.
*/
text(): string;
/**
* text(), HTML-escaped.
*/
escaped(): string;
/**
* Whether the message exists (is loaded) or not.
*/
exists(): boolean;
}
/**
* Possible MwMessage parameter types.
* HTMLElement and JQuery require jqueryMsg.
*/
type MwMessageParam = string | number | HTMLElement | JQuery;
interface MwStorageMap {
get( key: string ): string;
}
interface MwStorage {
session: MwStorageMap
}
interface MwClientPrefs {
get( key: string ): string|boolean;
set( key: string, value: string ): boolean;
}
interface MwUser {
options: MwMap,
id(): string;
getGroups( callback: Function ): JQuery.Promise<any>;
getId(): number;
getName(): string;
isAnon(): boolean;
generateRandomSessionId(): string;
sessionId(): string;
isNamed(): boolean;
isTemp(): boolean;
clientPrefs: MwClientPrefs;
}
interface MwLogger {
warn( ...args: any[] ): void;
}
interface MwErrorLogger {
logError( error: Error, topic?: string ): void;
}
interface MwExperimentBucket {
name: string,
enabled: boolean,
buckets: Record<string, number>
}
interface MwExperiments {
getBucket( bucket: MwExperimentBucket, token: string ): string;
}
interface MwMap {
get( configKey: string|null, fallback?: any|null ): any;
set( configKey: string|null, value: any|null ): void;
}
interface MediaWiki {
cookie: MwCookie,
Map: MwMap,
storage: MwStorage,
echo?: MwEcho,
eventLog?: MwEventLog,
experiments: MwExperiments;
log: MwLogger;
errorLogger: MwErrorLogger;
util: {
/**
* @param {string} expiry
* @return {boolean}
*/
isInfinity( expiry: string ): boolean;
/**
* @param {string} [hash] Hash fragment, without the leading '#'.
*/
getTargetFromFragment( hash?: string ): HTMLElement|null;
/**
* @param {string} parameter name
*/
getParamValue( param: string ): string;
/**
* @param pageName
* @param params
*/
getUrl( pageName?: string, params?: Object ): string;
/**
* @param {string} portletId ID of the target portlet (e.g. 'p-cactions' or 'p-personal')
* @param {string} href Link URL
* @param {string} text Link text
* @param {string} [id] ID of the list item, should be unique and preferably have
* the appropriate prefix ('ca-', 'pt-', 'n-' or 't-')
* @param {string} [tooltip] Text to show when hovering over the link, without accesskey suffix
* @param {string} [accesskey] Access key to activate this link. One character only,
* avoid conflicts with other links. Use `$( '[accesskey=x]' )` in the console to
* see if 'x' is already used.
* @param {HTMLElement|jQuery|string} [nextnode] Element that the new item should be added before.
* Must be another item in the same list, it will be ignored otherwise.
* Can be specified as DOM reference, as jQuery object, or as CSS selector string.
* @fires util_addPortletLink
* @return {HTMLElement|null} The added list item, or null if no element was added.
*/
addPortletLink(
portletId: string, href: string, text: string,
id?: string|null, tooltip?: string|null, accesskey?: string|null,
nextnode?: HTMLElement|JQuery|string|null
): HTMLElement|null;
/**
* @param {string} id of portlet
*/
showPortlet( id: string ): string;
/**
* @param {string} id of portlet
*/
hidePortlet( id: string ): void;
/**
* @param {string} id of portlet
* @return {boolean}
*/
isPortletVisible( id: string ): boolean,
/**
* Return a function, that, as long as it continues to be invoked, will not
* be triggered. The function will be called after it stops being called for
* N milliseconds. If `immediate` is passed, trigger the function on the
* leading edge, instead of the trailing.
*
* Ported from Underscore.js 1.5.2, Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud
* and Investigative Reporters & Editors, distributed under the MIT license, from
* <https://github.com/jashkenas/underscore/blob/1.5.2/underscore.js#L689>.
*
* @since 1.34
* @param {Function} func Function to debounce
* @param {number} [wait=0] Wait period in milliseconds
* @param {boolean} [immediate] Trigger on leading edge
* @return {Function} Debounced function
*/
debounce( callback: Function, delay?: number, immediate?: boolean ): () => void;
/**
* Return a function, that, when invoked, will only be triggered at most once
* during a given window of time. If called again during that window, it will
* wait until the window ends and then trigger itself again.
*
* As it's not knowable to the caller whether the function will actually run
* when the wrapper is called, return values from the function are entirely
* discarded.
*
* Ported from OOUI.
*
* @param {Function} func Function to throttle
* @param {number} wait Throttle window length, in milliseconds
* @return {Function} Throttled function
*/
throttle( func: Function, wait: number ): () => void;
};
Api: MwApiConstructor;
config: MwMap,
loader: {
/**
* Execute a function after one or more modules are ready.
*
* @param moduleName
* @param {Function} ready Callback to execute when all dependencies are
* ready.
* @param {Function} after Callback to execute if one or more dependencies
* failed.
*/
using( moduleName: string|string[]|null, ready?: Function, error?: Function ): JQuery.Promise<Function>;
/**
* Load a given resourceLoader module.
*
* @param moduleName
*/
load( moduleName: string|null ): void;
/**
* Get the loading state of the module.
* On of 'registered', 'loaded', 'loading', 'ready', 'error', or 'missing'.
*
* @param moduleName
*/
getState( moduleName: string|null ): string;
},
/**
* Formats the specified i18n message.
*
* @param key i18n message name
* @param parameters message arguments
*/
message( key: string, ...parameters: MwMessageParam[] ): MwMessage;
/**
* Formats the specified i18n message string.
* Shortcut for `mw.message( key, ...parameters ).text()`.
*
* @param key i18n message name
* @param parameters message arguments
*/
msg( key: string, ...parameters: MwMessageParam[] ): string;
/**
* Get a hook
*
* @param hookname
*/
hook( hookname: string ): mwHookInstance;
/**
* @see mw.notification#notify
* @param {HTMLElement|HTMLElement[]|jQuery|MwMessage|string} message
* @param {Object} [options] See mw.notification#defaults for the defaults.
* @return {jQuery.Promise}
*/
notify(
message: HTMLElement | HTMLElement[] | JQuery | MwMessage | string, options?: Object
): JQuery.Promise<any>;
/**
* Get current timestamp
*/
now(): number,
requestIdleCallback( callback: Function ): number|void;
template: MwTemplate;
/**
* Get a hook
*
* @param event
*/
trackSubscribe( event: string, handler: ( topic: string, data: object ) => void ): void;
/**
* Track an analytic event.
*
* See https://gerrit.wikimedia.org/g/mediawiki/core/+/d7fe1ff0fe52735b1f41e91879c9617b376e807d/resources/src/mediawiki.base/mediawiki.base.js#375.
*
* @param topic The topic name
* @param [data] The data describing the event
*/
track( topic: string, data?: Record<string, unknown>|number|string ): void;
Title: MwTitleConstructor;
user: MwUser;
Uri: UriConstructor;
}
declare const mw: MediaWiki;