From da371fc0b1d8175c87309068ee0b660b7d2fa251 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Wed, 23 Dec 2020 00:21:07 +0530 Subject: [PATCH] Split into multiple files, add usage instructions --- .gitignore | 2 + README.md | 30 +++- index.d.ts | 356 +------------------------------------- jquery/index.d.ts | 2 + jquery/textSelection.d.ts | 38 ++++ mw/Api.d.ts | 117 +++++++++++++ mw/Title.d.ts | 74 ++++++++ mw/Uri.d.ts | 42 +++++ mw/hook.d.ts | 14 ++ mw/index.d.ts | 45 +++++ mw/language.d.ts | 34 ++++ mw/loader.d.ts | 25 +++ mw/message.d.ts | 31 ++++ mw/notification.d.ts | 31 ++++ mw/storage.d.ts | 17 ++ mw/user.d.ts | 30 ++++ mw/util.d.ts | 52 ++++++ package.json | 2 +- 18 files changed, 580 insertions(+), 362 deletions(-) create mode 100644 .gitignore create mode 100644 jquery/index.d.ts create mode 100644 jquery/textSelection.d.ts create mode 100644 mw/Api.d.ts create mode 100644 mw/Title.d.ts create mode 100644 mw/Uri.d.ts create mode 100644 mw/hook.d.ts create mode 100644 mw/index.d.ts create mode 100644 mw/language.d.ts create mode 100644 mw/loader.d.ts create mode 100644 mw/message.d.ts create mode 100644 mw/notification.d.ts create mode 100644 mw/storage.d.ts create mode 100644 mw/user.d.ts create mode 100644 mw/util.d.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1292f99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/** +node_modules/** diff --git a/README.md b/README.md index 9de9128..69818b8 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,32 @@ # types-mediawiki TypeScript definitions for MediaWiki JS interface. -This project is still a **work in progress**. - -The intention is to cover all functions in the `mw` global object, as well as the custom jQuery plugins used in MediaWiki core. The doc-comments (copied from MW source code) and the types of the function parameters and return values should be included, ideally. +This package covers the functions in the `mw` global object, as well a few jQuery plugins used in MediaWiki core. This is a work in progress. [![Download stats](https://nodei.co/npm/types-mediawiki.png?downloads=true&downloadRank=true)](https://nodei.co/npm/types-mediawiki/) +## Usage + +To use types from this package, run + +```bash +npm i types-mediawiki +``` + +Edit your project's `tsconfig.json` file so that it includes + +``` +"types": [ + "./node_modules/types-mediawiki", +] +``` + +You should be all set! `mw` will be available in the global scope. There is no need to put any import statements in the TypeScript source files. This package includes [@types/jquery](https://www.npmjs.com/package/@types/jquery) as a dependency, so you don't need to install that separately. + +**If you find any errors or have suggestions for more specific typings, please open a PR or file an issue.** + ---- TODO: -- [ ] Add doc comments for everything -- [x] Finish mw.Api -- [ ] Add jQuery plugins (use [@types/jquery](https://www.npmjs.com/package/@types/jquery) as a dependency) -- [x] Publish on NPM. +- Add doc comments for everything. Presently they are not included at all. +- Add types for more jQuery plugins. diff --git a/index.d.ts b/index.d.ts index 1f81f7b..0022b96 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,354 +1,2 @@ -/** - * Type definitions for mediawiki modules - * - * @author Siddharth VP (2020) - */ - -import 'jquery'; - -type title = string | mw.Title -type namespaceId = number - -interface ApiOptions { - parameters?: Record - ajax?: JQuery.AjaxSettings - useUS?: boolean -} - -interface ForeignApiOptions extends ApiOptions { - anonymous: boolean -} - -interface Hook { - add(...handler: ((...args: any[]) => any)[]): Hook - fire(data: any): Hook - remove(handler: ((...args: any[]) => any)): Hook -} - -declare namespace mw { - - class Api { - constructor(options?: ApiOptions) - abort(): void - get(parameters: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise - post(parameters: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise - - preprocessParameters( parameters: any, useUS: boolean ): void - - // index.js - ajax(parameters: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise - postWithToken(tokenType: string, params: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise - getToken(type: string, additionalParams?: any | string): JQuery.Promise - badToken(type: string): void - getErrorMessage(data: any): JQuery - - // edit.js - postWithEditToken(params: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise - getEditToken(): JQuery.Promise - create(title: title, params: any, content: string): JQuery.Promise - edit(title: title, transform: (data: { - timestamp: string, - content: string - }) => any | string): JQuery.Promise - newSection(title: title, header: string, message: string, additionalParams?: any): JQuery.Promise - - // user.js - getUserInfo(): JQuery.Promise<{ - groups: string[], - rights: string[] - }> - assertCurrentUser(query: any): JQuery.Promise<{ - assert: 'anon' | 'user' - assertUser: string - }> - - // options.js - saveOption(name: string, value: string): JQuery.Promise - saveOptions(options: {[optionName: string]: string}): JQuery.Promise - - // watch.js - watch(pages: title | title[]): JQuery.Promise<{ - watch: {title: string, watched: boolean} | {title: string, watched: boolean}[] - }> - unwatch(pages: title | title[]): JQuery.Promise<{ - watch: {title: string, watched: boolean} | {title: string, watched: boolean}[] - }> - - // parse.js - parse(content: string | mw.Title, additionalParams?: any): JQuery.Promise - - // messages.js - getMessages(messages: string[], options?: any): JQuery.Promise - loadMessages(messages: string[], options?: any): JQuery.Promise - loadMessagesIfMissing(messages: string[], options?: any): JQuery.Promise - - // category.js - isCategory(title: title): JQuery.Promise - getCategoriesByPrefix(prefix: string): JQuery.Promise - getCategories(title: title): JQuery.Promise - - // rollback.js - rollback(page: title, user: string, params?: any): JQuery.Promise - - // upload.js - chunkedUpload(file: File, data: any, chunkSize?: number, chunkRetries?: number): JQuery.Promise - chunkedUploadToStash(file, data?, chunkSize?, chunkRetries?): JQuery.Promise - upload(file: File | Blob | HTMLInputElement, data: any): JQuery.Promise - uploadFromStash(filekey: string, data: any): JQuery.Promise - uploadToStash(file: File | HTMLInputElement, data?: any): JQuery.Promise - - // login.js - login(username: string, password: string): JQuery.Promise - - } - - const config: mw.Map - - class ForeignApi extends Api { - constructor(url: string | mw.Uri, options: ForeignApiOptions) - getOrigin(): string | void - } - - function hook(event: string): Hook - - namespace html { - function escape(s: string): string - function element(name: string, attrs?: any, contents?: string): string - } - - namespace language { - function bcp47(languageTag: string): string - function convertGrammar(word: string, form: string): string - function convertNumber(num: number, integer?: boolean): number | string - function convertPlural(count: number, forms: string[], explicitPluralForms?: any): string - function flipTransform(...Transformation: any[]): any - function gender(gender: string, forms: string[]): string - function getData(langCode: string, dataKey: string): any - function getDigitTransformTable(): any - function getFallbackLanguageChain(): string[] - function getFallbackLanguages(): string[] - function getSeparatorTransformTable(): any - function listToText(list: string[]): string - function setData(langCode: string, dataKey: string, value?): void - } - - namespace loader { - function addStyleTag(text: string, nextNode?: Node): HTMLElement - function getModuleNames(): string[] - function getScript(url: string): JQuery.Promise - function getState(module: string): string | null; - function load(modules: string | string[], type?: string): void; - function register(modules: string | string[], version?: string | number, dependencies?: string[], - group?: string, source?: string, skip?: string): void - function state(states: any): void - function using(dependencies: string[] | string, ready?: (() => any), error?: (() => any)): - JQuery.Promise; - } - - class log { - static deprecate(obj: any, key: string, val: any, msg?: string, logName?: string): void - static error(...msg: any[]): void - static warn(...msg: string[]): void - } - - class Map { - get(selection: string | string[], fallback?: any): any - set(selection: string | Record, value?: any): boolean - exists(selection: string): boolean - } - - function message(key: string, ...parameters: string[]): mw.Message - - class Message { - constructor(map: mw.Map, key: string, parameters?: string[]) - escaped(): string - exists(): boolean - params(parameters: string[]): mw.Message - parse(): string - parseDom(): JQuery - parser(): string - plain(): string - text(): string - toString(): string - } - - function msg(key: string, ...parameters: string[]): string; - - function notify(message: string | JQuery | HTMLElement | HTMLElement[], - options?: { tag?: string, type?: string, title?: string }): { - pause: (() => void) - resume: (() => void) - close: (() => void) - }; - - namespace notification { - function pause() - function resume() - function notify() - let defaults: { - autoHide: boolean - autoHideSeconds: 'short' | 'long' - tag: string | null - title: string | null - type: 'info' | 'warn' | 'error' | 'success' - visibleTimeout: boolean - id: string - } - let autoHideLimit: number - } - - namespace storage { - function get(key: string): string | null | boolean - function getObject(key: string): any - function remove(key: string): boolean - function set(key: string, value: string): boolean - function setObject(key: string, value: any): boolean - } - - class Title { - constructor(title: string, namespace?: namespaceId) - static newFromText(title: string, namespace?: namespaceId): mw.Title | null - static makeTitle(title: string, namespace?: namespaceId): mw.Title | null - static newFromUserInput(title: string, namespace?: namespaceId, options?: any): mw.Title - static newFromFileName(uncleanName: string): mw.Title - static newFromImg(img: HTMLElement | JQuery): mw.Title - static isTalkNamespace(namespaceId: namespaceId): boolean - static wantSignatureNamespace(namespaceId: namespaceId): boolean - static exists(title: title): boolean | null - static exist: { - pages: {[title: string]: boolean}, - set: (titles: string | string[], state?: boolean) => boolean - } - static normalizeExtension(extension: string): string - static phpCharToUpper(chr: string): string - - getNamespaceId(): namespaceId - getNamespacePrefix(): string - getName(): string - getNameText(): string - getExtension(): string | null - getDotExtension(): string - getMain(): string - getMainText(): string - getPrefixedDb(): string - getPrefixedText(): string - getRelativeText(namespace: namespaceId): string - getFragment(): string | null - getUrl(params: any): string - isTalkPage(): boolean - getTalkPage(): Title | null - getSubjectPage(): Title | null - canHaveTalkPage(): boolean - exists(): boolean | null - toString(): string - toText(): string - } - - class Uri { - fragment: string | undefined - host: string - password: string | undefined - path: string - port: string | undefined - protocol: string - query: any - user: string | undefined - constructor(uri: string | mw.Uri | any, options?: { - strictMode?: boolean - overrideKeys?: boolean - arrayParams?: boolean - }) - clone(): mw.Uri - extend(parameters: any): mw.Uri - getAuthority(): string - getHostPort(): string - getQueryString(): string - getRelativePath(): string - getUserInfo(): string - toString(): string - static decode(s: string): string - static encode(s: string): string - } - - namespace user { - const options: mw.Map - const tokens: mw.Map - function generateRandomSessionId(): string - function getPageviewToken(): string - function getId(): number - function getName(): string | null - function getRegistration(): boolean | null | Date - function isAnon(): boolean - function sessionId(): string - function id(): string - function getGroups(callback?: Function): JQuery.Promise - function getRights(callback?: Function): JQuery.Promise - } - - namespace util { - const $content: JQuery; - function rawurlencode(str: string): string; - function escapeIdForAttribute(str: string): string; - function escapeIdForLink(str: string): string; - function debounce(delay: number, callback: Function): (...args: any[]) => void; - function wikiUrlencode(str: string): string; - function getUrl(pageName: string, params?: {[param: string]: string}): string; - function wikiScript(str: string): string; - function addCSS(text: string): any; - function getParamValue(param: string, url?: string): string; - function hidePortlet(portletId: string): void; - function isPortletVisible(portletId: string): boolean; - function showPortlet(portletId: string): void; - function addPortletLink(portletId: string, href: string, text: string, id?: string, - tooltip?: string, accesskey?: string, nextnode?: string): HTMLLIElement; - function validateEmail(mailtxt: string): boolean; - function isIPv4Address(address: string, allowBlock?: boolean): boolean; - function isIPv6Address(address: string, allowBlock?: boolean): boolean; - function isIPAddress(address: string, allowBlock?: boolean): boolean; - function parseImageUrl(url: string): { - name: string; - width: number | null; - resizeUrl: (w: any) => string; - } | null; - function escapeRegExp(str: string): string; - } - - // types for mw.widgets are out of scope! - const widgets: any -} - -// XXX: split into multiple files? - -declare global { - interface JQuery { - // one overload for each command - textSelection(command: 'getContents'): string - textSelection(command: 'setContents'): JQuery - textSelection(command: 'getSelection'): string - textSelection(command: 'replaceSelection'): JQuery - textSelection(command: 'encapsulateSelection', commandOptions: { - pre?: string - peri?: string - post?: string - ownline?: boolean - replace?: boolean - selectPeri?: boolean - splitlines?: boolean - selectionStart?: number - selectionEnd?: number - }): JQuery - textSelection(command: 'getCaretPosition', commandOptions?: { - startAndEnd?: false - }): number - textSelection(command: 'getCaretPosition', commandOptions: { - startAndEnd: true - }): [number, number] - textSelection(command: 'setSelection', commandOptions: { - start?: number - end?: number - }): JQuery - textSelection(command: 'scrollToCaretPosition', commandOptions: { - force?: boolean - }): JQuery - } -} +import './mw'; +import './jquery'; diff --git a/jquery/index.d.ts b/jquery/index.d.ts new file mode 100644 index 0000000..a49eba2 --- /dev/null +++ b/jquery/index.d.ts @@ -0,0 +1,2 @@ + +import './textSelection'; diff --git a/jquery/textSelection.d.ts b/jquery/textSelection.d.ts new file mode 100644 index 0000000..0f9ff84 --- /dev/null +++ b/jquery/textSelection.d.ts @@ -0,0 +1,38 @@ + +declare global { + + interface JQuery { + // one overload for each command + textSelection(command: 'getContents'): string + textSelection(command: 'setContents'): JQuery + textSelection(command: 'getSelection'): string + textSelection(command: 'replaceSelection'): JQuery + textSelection(command: 'encapsulateSelection', commandOptions: { + pre?: string + peri?: string + post?: string + ownline?: boolean + replace?: boolean + selectPeri?: boolean + splitlines?: boolean + selectionStart?: number + selectionEnd?: number + }): JQuery + textSelection(command: 'getCaretPosition', commandOptions?: { + startAndEnd?: false + }): number + textSelection(command: 'getCaretPosition', commandOptions: { + startAndEnd: true + }): [number, number] + textSelection(command: 'setSelection', commandOptions: { + start?: number + end?: number + }): JQuery + textSelection(command: 'scrollToCaretPosition', commandOptions: { + force?: boolean + }): JQuery + } + +} + +export {} diff --git a/mw/Api.d.ts b/mw/Api.d.ts new file mode 100644 index 0000000..46ef049 --- /dev/null +++ b/mw/Api.d.ts @@ -0,0 +1,117 @@ +import { title } from './index'; + +interface ApiOptions { + parameters?: Record + ajax?: JQuery.AjaxSettings + useUS?: boolean +} +interface ForeignApiOptions extends ApiOptions { + anonymous: boolean +} + +declare global { + namespace mw { + class Api { + constructor(options?: ApiOptions) + + abort(): void + + get(parameters: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise + + post(parameters: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise + + preprocessParameters(parameters: any, useUS: boolean): void + + // index.js + ajax(parameters: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise + + postWithToken(tokenType: string, params: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise + + getToken(type: string, additionalParams?: any | string): JQuery.Promise + + badToken(type: string): void + + getErrorMessage(data: any): JQuery + + // edit.js + postWithEditToken(params: any, ajaxOptions?: JQuery.AjaxSettings): JQuery.Promise + + getEditToken(): JQuery.Promise + + create(title: title, params: any, content: string): JQuery.Promise + + edit(title: title, transform: (data: { + timestamp: string, + content: string + }) => any | string): JQuery.Promise + + newSection(title: title, header: string, message: string, additionalParams?: any): JQuery.Promise + + // user.js + getUserInfo(): JQuery.Promise<{ + groups: string[], + rights: string[] + }> + + assertCurrentUser(query: any): JQuery.Promise<{ + assert: 'anon' | 'user' + assertUser: string + }> + + // options.js + saveOption(name: string, value: string): JQuery.Promise + + saveOptions(options: { [optionName: string]: string }): JQuery.Promise + + // watch.js + watch(pages: title | title[]): JQuery.Promise<{ + watch: { title: string, watched: boolean } | { title: string, watched: boolean }[] + }> + + unwatch(pages: title | title[]): JQuery.Promise<{ + watch: { title: string, watched: boolean } | { title: string, watched: boolean }[] + }> + + // parse.js + parse(content: string | mw.Title, additionalParams?: any): JQuery.Promise + + // messages.js + getMessages(messages: string[], options?: any): JQuery.Promise + + loadMessages(messages: string[], options?: any): JQuery.Promise + + loadMessagesIfMissing(messages: string[], options?: any): JQuery.Promise + + // category.js + isCategory(title: title): JQuery.Promise + + getCategoriesByPrefix(prefix: string): JQuery.Promise + + getCategories(title: title): JQuery.Promise + + // rollback.js + rollback(page: title, user: string, params?: any): JQuery.Promise + + // upload.js + chunkedUpload(file: File, data: any, chunkSize?: number, chunkRetries?: number): JQuery.Promise + + chunkedUploadToStash(file, data?, chunkSize?, chunkRetries?): JQuery.Promise + + upload(file: File | Blob | HTMLInputElement, data: any): JQuery.Promise + + uploadFromStash(filekey: string, data: any): JQuery.Promise + + uploadToStash(file: File | HTMLInputElement, data?: any): JQuery.Promise + + // login.js + login(username: string, password: string): JQuery.Promise + + } + + class ForeignApi extends mw.Api { + constructor(url: string | mw.Uri, options: ForeignApiOptions) + + getOrigin(): string | void + } + } +} diff --git a/mw/Title.d.ts b/mw/Title.d.ts new file mode 100644 index 0000000..5dd79d5 --- /dev/null +++ b/mw/Title.d.ts @@ -0,0 +1,74 @@ +import { title } from './index'; + +declare global { + namespace mw { + class Title { + constructor(title: string, namespace?: number) + + static newFromText(title: string, namespace?: number): mw.Title | null + + static makeTitle(title: string, namespace?: number): mw.Title | null + + static newFromUserInput(title: string, namespace?: number, options?: any): mw.Title + + static newFromFileName(uncleanName: string): mw.Title + + static newFromImg(img: HTMLElement | JQuery): mw.Title + + static isTalkNamespace(namespaceId: number): boolean + + static wantSignatureNamespace(namespaceId: number): boolean + + static exists(title: title): boolean | null + + static exist: { + pages: { [title: string]: boolean }, + set: (titles: string | string[], state?: boolean) => boolean + }; + + static normalizeExtension(extension: string): string + + static phpCharToUpper(chr: string): string + + getNamespaceId(): number + + getNamespacePrefix(): string + + getName(): string + + getNameText(): string + + getExtension(): string | null + + getDotExtension(): string + + getMain(): string + + getMainText(): string + + getPrefixedDb(): string + + getPrefixedText(): string + + getRelativeText(namespace: number): string + + getFragment(): string | null + + getUrl(params: any): string + + isTalkPage(): boolean + + getTalkPage(): Title | null + + getSubjectPage(): Title | null + + canHaveTalkPage(): boolean + + exists(): boolean | null + + toString(): string + + toText(): string + } + } +} diff --git a/mw/Uri.d.ts b/mw/Uri.d.ts new file mode 100644 index 0000000..cab112a --- /dev/null +++ b/mw/Uri.d.ts @@ -0,0 +1,42 @@ +declare global { + namespace mw { + class Uri { + fragment: string | undefined; + host: string; + password: string | undefined; + path: string; + port: string | undefined; + protocol: string; + query: any; + user: string | undefined; + + constructor(uri: string | mw.Uri | any, options?: { + strictMode?: boolean + overrideKeys?: boolean + arrayParams?: boolean + }) + + clone(): mw.Uri + + extend(parameters: any): mw.Uri + + getAuthority(): string + + getHostPort(): string + + getQueryString(): string + + getRelativePath(): string + + getUserInfo(): string + + toString(): string + + static decode(s: string): string + + static encode(s: string): string + } + } +} + +export {} diff --git a/mw/hook.d.ts b/mw/hook.d.ts new file mode 100644 index 0000000..ec44b63 --- /dev/null +++ b/mw/hook.d.ts @@ -0,0 +1,14 @@ + +interface Hook { + add(...handler: ((...args: any[]) => any)[]): Hook + fire(data: any): Hook + remove(handler: ((...args: any[]) => any)): Hook +} + +declare global { + namespace mw { + function hook(event: string): Hook + } +} + +export {} diff --git a/mw/index.d.ts b/mw/index.d.ts new file mode 100644 index 0000000..5ae5f8e --- /dev/null +++ b/mw/index.d.ts @@ -0,0 +1,45 @@ +import './Api'; +import './language'; +import './util'; +import './user'; +import './loader'; +import './Title'; +import './Uri'; +import './hook'; +import './storage'; +import './notification'; +import './message'; + +type title = string | mw.Title + +declare global { + namespace mw { + const config: mw.Map; + + + namespace html { + function escape(s: string): string + + function element(name: string, attrs?: any, contents?: string): string + } + + class log { + static deprecate(obj: any, key: string, val: any, msg?: string, logName?: string): void + + static error(...msg: any[]): void + + static warn(...msg: string[]): void + } + + class Map { + get(selection: string | string[], fallback?: any): any + + set(selection: string | Record, value?: any): boolean + + exists(selection: string): boolean + } + + // types for mw.widgets are out of scope! + const widgets: any; + } +} diff --git a/mw/language.d.ts b/mw/language.d.ts new file mode 100644 index 0000000..d191eca --- /dev/null +++ b/mw/language.d.ts @@ -0,0 +1,34 @@ + +declare global { + namespace mw { + namespace language { + function bcp47(languageTag: string): string + + function convertGrammar(word: string, form: string): string + + function convertNumber(num: number, integer?: boolean): number | string + + function convertPlural(count: number, forms: string[], explicitPluralForms?: any): string + + function flipTransform(...Transformation: any[]): any + + function gender(gender: string, forms: string[]): string + + function getData(langCode: string, dataKey: string): any + + function getDigitTransformTable(): any + + function getFallbackLanguageChain(): string[] + + function getFallbackLanguages(): string[] + + function getSeparatorTransformTable(): any + + function listToText(list: string[]): string + + function setData(langCode: string, dataKey: string, value?): void + } + } +} + +export {} diff --git a/mw/loader.d.ts b/mw/loader.d.ts new file mode 100644 index 0000000..4d87e70 --- /dev/null +++ b/mw/loader.d.ts @@ -0,0 +1,25 @@ +declare global { + namespace mw { + namespace loader { + function addStyleTag(text: string, nextNode?: Node): HTMLElement + + function getModuleNames(): string[] + + function getScript(url: string): JQuery.Promise + + function getState(module: string): string | null; + + function load(modules: string | string[], type?: string): void; + + function register(modules: string | string[], version?: string | number, dependencies?: string[], + group?: string, source?: string, skip?: string): void + + function state(states: any): void + + function using(dependencies: string[] | string, ready?: (() => any), error?: (() => any)): + JQuery.Promise; + } + } +} + +export {} diff --git a/mw/message.d.ts b/mw/message.d.ts new file mode 100644 index 0000000..9252306 --- /dev/null +++ b/mw/message.d.ts @@ -0,0 +1,31 @@ +declare global { + namespace mw { + function message(key: string, ...parameters: string[]): mw.Message + + class Message { + constructor(map: mw.Map, key: string, parameters?: string[]) + + escaped(): string + + exists(): boolean + + params(parameters: string[]): mw.Message + + parse(): string + + parseDom(): JQuery + + parser(): string + + plain(): string + + text(): string + + toString(): string + } + + function msg(key: string, ...parameters: string[]): string; + } +} + +export {} diff --git a/mw/notification.d.ts b/mw/notification.d.ts new file mode 100644 index 0000000..04fbe1b --- /dev/null +++ b/mw/notification.d.ts @@ -0,0 +1,31 @@ +declare global { + namespace mw { + function notify(message: string | JQuery | HTMLElement | HTMLElement[], + options?: { tag?: string, type?: string, title?: string }): { + pause: (() => void) + resume: (() => void) + close: (() => void) + }; + + namespace notification { + function pause() + + function resume() + + function notify() + + let defaults: { + autoHide: boolean + autoHideSeconds: 'short' | 'long' + tag: string | null + title: string | null + type: 'info' | 'warn' | 'error' | 'success' + visibleTimeout: boolean + id: string + }; + let autoHideLimit: number; + } + } +} + +export {} diff --git a/mw/storage.d.ts b/mw/storage.d.ts new file mode 100644 index 0000000..3bbd604 --- /dev/null +++ b/mw/storage.d.ts @@ -0,0 +1,17 @@ +declare global { + namespace mw { + namespace storage { + function get(key: string): string | null | boolean + + function getObject(key: string): any + + function remove(key: string): boolean + + function set(key: string, value: string): boolean + + function setObject(key: string, value: any): boolean + } + } +} + +export {} diff --git a/mw/user.d.ts b/mw/user.d.ts new file mode 100644 index 0000000..3865df5 --- /dev/null +++ b/mw/user.d.ts @@ -0,0 +1,30 @@ +declare global { + namespace mw { + namespace user { + const options: mw.Map; + const tokens: mw.Map; + + function generateRandomSessionId(): string + + function getPageviewToken(): string + + function getId(): number + + function getName(): string | null + + function getRegistration(): boolean | null | Date + + function isAnon(): boolean + + function sessionId(): string + + function id(): string + + function getGroups(callback?: Function): JQuery.Promise + + function getRights(callback?: Function): JQuery.Promise + } + } +} + +export {} diff --git a/mw/util.d.ts b/mw/util.d.ts new file mode 100644 index 0000000..6e7bd87 --- /dev/null +++ b/mw/util.d.ts @@ -0,0 +1,52 @@ +declare global { + namespace mw { + namespace util { + const $content: JQuery; + + function rawurlencode(str: string): string; + + function escapeIdForAttribute(str: string): string; + + function escapeIdForLink(str: string): string; + + function debounce(delay: number, callback: Function): (...args: any[]) => void; + + function wikiUrlencode(str: string): string; + + function getUrl(pageName: string, params?: { [param: string]: string }): string; + + function wikiScript(str: string): string; + + function addCSS(text: string): any; + + function getParamValue(param: string, url?: string): string; + + function hidePortlet(portletId: string): void; + + function isPortletVisible(portletId: string): boolean; + + function showPortlet(portletId: string): void; + + function addPortletLink(portletId: string, href: string, text: string, id?: string, + tooltip?: string, accesskey?: string, nextnode?: string): HTMLLIElement; + + function validateEmail(mailtxt: string): boolean; + + function isIPv4Address(address: string, allowBlock?: boolean): boolean; + + function isIPv6Address(address: string, allowBlock?: boolean): boolean; + + function isIPAddress(address: string, allowBlock?: boolean): boolean; + + function parseImageUrl(url: string): { + name: string; + width: number | null; + resizeUrl: (w: any) => string; + } | null; + + function escapeRegExp(str: string): string; + } + } +} + +export {} diff --git a/package.json b/package.json index 0c3842e..e730cdd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "types-mediawiki", - "version": "0.2.0", + "version": "0.3.0", "description": "TypeScript definitions for MediaWiki JS interface", "types": "index.d.ts", "repository": {