From 6712c9c3f696a938f0c0a8402dc634df6b4bb50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20LES=C3=89N=C3=89CHAL?= Date: Tue, 28 May 2024 19:47:17 +0200 Subject: [PATCH] Compatibility with 1.39 (LTS) - add various `@since`/`@deprecated` annotations for declarations added/modified/deprecated/removed with 1.40/1.41/1.42 - add `isoDate`/`url` tablesorter parsers, removed since 1.40 - add `jquery.tipsy` RL module, removed since 1.41 - add `mw.language.commafy`, removed since 1.40 - add missing `script` property of a RL module (not added recently, just an oversight) --- jquery/colorUtil.d.ts | 1 + jquery/tablesorter.d.ts | 8 +++++ jquery/tipsy.d.ts | 78 +++++++++++++++++++++++++++++++++++++++++ mw/Api.d.ts | 3 +- mw/Rest.d.ts | 1 + mw/Title.d.ts | 2 ++ mw/language.d.ts | 22 ++++++++++++ mw/loader.d.ts | 13 ++++++- mw/storage.d.ts | 1 + mw/tempUserCreated.d.ts | 1 + mw/user.d.ts | 5 +++ mw/util.d.ts | 9 ++++- 12 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 jquery/tipsy.d.ts diff --git a/jquery/colorUtil.d.ts b/jquery/colorUtil.d.ts index 8585faf..84d1941 100644 --- a/jquery/colorUtil.d.ts +++ b/jquery/colorUtil.d.ts @@ -1,6 +1,7 @@ declare global { interface JQueryStatic { /** + * @deprecated Removed since 1.41. * @see https://doc.wikimedia.org/mediawiki-core/REL1_40/js/#!/api/jQuery.colorUtil */ colorUtil: ColorUtil; diff --git a/jquery/tablesorter.d.ts b/jquery/tablesorter.d.ts index f8262dc..b87bbe0 100644 --- a/jquery/tablesorter.d.ts +++ b/jquery/tablesorter.d.ts @@ -33,9 +33,17 @@ export interface ParserMap { currency: "numeric"; date: "numeric"; IPAddress: "numeric"; + /** + * @deprecated Removed since 1.40. + */ + isoDate: "numeric"; number: "numeric"; text: "text"; time: "numeric"; + /** + * @deprecated Removed since 1.40. + */ + url: "text"; usLongDate: "numeric"; } diff --git a/jquery/tipsy.d.ts b/jquery/tipsy.d.ts new file mode 100644 index 0000000..c7e080d --- /dev/null +++ b/jquery/tipsy.d.ts @@ -0,0 +1,78 @@ +declare global { + interface JQuery { + /** + * @deprecated + * @deprecated Removed since 1.41. + */ + tipsy: JQueryTipsy; + } +} + +type StringProvider = string | ((ctx: T) => string); +type MethodsOf = { + [P in keyof T]: T[P] extends (...args: unknown[]) => void ? P : never; +}[keyof T]; + +type NSDirection = "n" | "s" | ""; +type EWDirection = "e" | "w" | ""; +type Direction = `${NSDirection}${EWDirection}`; + +interface JQueryTipsy { + (options: true): Tipsy; + (options?: MethodsOf | Options): JQuery; + + defaults: Required; + + /** + * Yields a closure of the supplied parameters, producing a function that takes + * no arguments and is suitable for use as an autogravity function like so: + * + * @param {number} margin (int) - distance from the viewable region edge that an + * element should be before setting its tooltip's gravity to be away + * from that edge. + * @param {Direction} prefer (string, e.g. `n`, `sw`, `w`) - the direction to prefer + * if there are no viewable region edges effecting the tooltip's + * gravity. It will try to vary from this minimally, for example, + * if `sw` is preferred and an element is near the right viewable + * region edge, but not the top edge, it will set the gravity for + * that element's tooltip to be `se`, preserving the southern + * component. + */ + autoBounds(margin: number, prefer: Direction): Direction; + autoNS(): boolean; + autoWE(): boolean; + elementOptions(ele: HTMLElement, options: T): T; +} + +interface Options { + center?: boolean; + className?: StringProvider | null; + delayIn?: number; + delayOut?: number; + fade?: boolean; + fallback?: string; + gravity?: StringProvider; + html?: boolean; + live?: boolean; + offset?: number; + opacity?: number; + title?: StringProvider; + trigger?: "hover" | "manual"; +} + +interface Tipsy { + $element: JQuery; + enabled: boolean; + options: Required; + + closeOnEsc(e: KeyboardEvent): void; + getTitle(): string; + fixTitle(): void; + hide(): void; + keyHandler(e: KeyboardEvent): void; + show(): void; + tip(): JQuery; + validate(): void; +} + +export {}; diff --git a/mw/Api.d.ts b/mw/Api.d.ts index 18d8679..a945e65 100644 --- a/mw/Api.d.ts +++ b/mw/Api.d.ts @@ -490,6 +490,7 @@ declare global { * are loaded. If all messages are known, the returned promise is resolved immediately. * * @since 1.27 + * @since 1.42 - accepts a single string message as parameter. * @param {string|string[]} messages Messages to retrieve * @param {ApiQueryAllMessagesParams} [options] Additional parameters for the API call * @returns {JQuery.Promise} @@ -719,7 +720,7 @@ declare global { /** * Convenience method for `action=watch`. * - * @since 1.35 - expiry parameter can be passed when Watchlist Expiry is enabled + * @since 1.35 - expiry parameter can be passed when Watchlist Expiry is enabled. * @param {TypeOrArray} pages Full page name or instance of {@link mw.Title}, or an * array thereof. If an array is passed, the return value passed to the promise will also be an * array of appropriate objects. diff --git a/mw/Rest.d.ts b/mw/Rest.d.ts index e5b15be..a886aa3 100644 --- a/mw/Rest.d.ts +++ b/mw/Rest.d.ts @@ -92,6 +92,7 @@ declare global { * * Note: only sending `application/json` is currently supported. * + * @since 1.42 - body parameter is optional. * @param {string} path * @param {Object.} [body] * @param {Object.} [headers] diff --git a/mw/Title.d.ts b/mw/Title.d.ts index 6db48fc..2941e65 100644 --- a/mw/Title.d.ts +++ b/mw/Title.d.ts @@ -131,6 +131,7 @@ declare global { * Note that this method will work for non-file titles but probably give nonsensical results. * A title like `User:Dr._J._Fail` will be returned as `Dr. J`! Use {@link getMainText} instead. * + * @since 1.40 * @returns {string} * @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Title.html#getFileNameTextWithoutExtension */ @@ -144,6 +145,7 @@ declare global { * Note that this method will work for non-file titles but probably give nonsensical results. * A title like `User:Dr._J._Fail` will be returned as `Dr._J`! Use {@link getMain} instead. * + * @since 1.40 * @returns {string} * @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Title.html#getFileNameWithoutExtension */ diff --git a/mw/language.d.ts b/mw/language.d.ts index 2650130..48c197c 100644 --- a/mw/language.d.ts +++ b/mw/language.d.ts @@ -58,6 +58,28 @@ declare global { */ function bcp47(languageTag: string): string; + /** + * Apply pattern to format value as a string. + * + * Using patterns from {@link https://www.unicode.org/reports/tr35/#Number_Format_Patterns Unicode TR35}. + * + * @private + * @deprecated This function will be made private in a future release; + * it is poorly named, corresponds to a deprecated function in core, and + * its functionality should be rolled into convertNumber(). + * @deprecated Removed since 1.40. + * @param {number} value + * @param {string} pattern Pattern string as described by Unicode TR35 + * @param {number|null} [minimumGroupingDigits=null] + * @throws {Error} If unable to find a number expression in `pattern`. + * @return {string} + */ + function commafy( + value: number, + pattern: string, + minimumGroupingDigits?: number | null + ): string; + /** * Grammatical transformations, needed for inflected languages. * Invoked by putting `{{grammar:case|word}}` in a message. diff --git a/mw/loader.d.ts b/mw/loader.d.ts index cf39a00..6805529 100644 --- a/mw/loader.d.ts +++ b/mw/loader.d.ts @@ -46,13 +46,20 @@ type ModuleScript = | string; interface ModuleRegistryEntry { + /** + * @since 1.41 + */ declarator?: ModuleDeclarator | null; dependencies: string[]; + /** + * @since 1.41 + */ deprecationWarning?: string | null; group: number | null; messages?: ModuleMessages | null; module: Module; packageExports: any; + script?: ModuleScript | null; skip: string | null; source: string; state: "error" | "loaded" | "missing" | "registered" | "ready"; @@ -322,6 +329,7 @@ declare global { * Implement a module given a function which returns the components of the module * * @private + * @since 1.41 * @param {ModuleDeclarator} declarator The declarator should return an array with the following keys: * * - 0. {string} module Name of module and current module version. Formatted @@ -368,6 +376,8 @@ declare global { * Does not support mw.loader.store caching. * * @private + * @since 1.41 - deprecationWarning parameter can be passed. + * @deprecated since 1.41 * @param {string} module * @param {ModuleScript} [script] Module code. This can be a function, * a list of URLs to load via `