Skip to content

Commit

Permalink
Merge pull request wikimedia-gadgets#42 from Derugon/main-next
Browse files Browse the repository at this point in the history
MediaWiki 1.42, online doc. URLs, and fixes
  • Loading branch information
siddharthvp authored May 30, 2024
2 parents 53f80c2 + 4a6203c commit 3796925
Show file tree
Hide file tree
Showing 55 changed files with 2,456 additions and 1,720 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let namespaces = mw.config.get("pageTriageNamespaces") as number[];

### MediaWiki API parameters

This package also provides typings for API request parameters for the [MediaWiki Action API](https://www.mediawiki.org/wiki/API:Main_page). API endpoints defined in MediaWiki core and by a number of common extensions (the ones enabled on English Wikipedia) are covered. These aren't exported to the global scope, however. For usage, you need to import them. For example:
This package also provides typings for API request parameters for the [MediaWiki Action API](https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page). API endpoints defined in MediaWiki core and by a number of common extensions (the ones enabled on English Wikipedia) are covered. These aren't exported to the global scope, however. For usage, you need to import them. For example:

```ts
import type { ApiEditPageParams, ApiParseParams } from "types-mediawiki/api_params";
Expand Down
36 changes: 17 additions & 19 deletions jquery/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
declare global {
interface JQueryStatic {
/**
* User-agent detection
* User-agent detection.
*
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/jQuery.client
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html
*/
client: Client;
}
Expand All @@ -27,19 +27,6 @@ interface Client {
* }
* ```
*
* Example:
*
* ```js
* if ( $.client.profile().layout == 'gecko' ) {
* // This will only run in Gecko browsers, such as Mozilla Firefox.
* }
*
* var profile = $.client.profile();
* if ( profile.layout == 'gecko' && profile.platform == 'linux' ) {
* // This will only run in Gecko browsers on Linux.
* }
* ```
*
* Recognised browser names:
*
* - `android` (legacy Android browser, prior to Chrome Mobile)
Expand Down Expand Up @@ -76,10 +63,21 @@ interface Client {
* - `solaris` (untested)
* - `win`
*
* @example
* ```js
* if ( $.client.profile().layout == 'gecko' ) {
* // This will only run in Gecko browsers, such as Mozilla Firefox.
* }
*
* var profile = $.client.profile();
* if ( profile.layout == 'gecko' && profile.platform == 'linux' ) {
* // This will only run in Gecko browsers on Linux.
* }
* ```
* @param {ClientNavigator} [nav] An object with a 'userAgent' and 'platform' property.
* Defaults to the global `navigator` object.
* @returns {ClientProfile} The client object
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/jQuery.client-method-profile
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.profile
*/
profile(nav?: ClientNavigator): ClientProfile;

Expand Down Expand Up @@ -124,14 +122,14 @@ interface Client {
* @param {boolean} [exactMatchOnly=false] Only return true if the browser is matched,
* otherwise returns true if the browser is not found.
* @returns {boolean} The current browser is in the support map
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/jQuery.client-method-test
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.test
*/
test(map: ClientSupportMap, profile?: ClientProfile, exactMatchOnly?: boolean): boolean;
}

export interface ClientNavigator {
userAgent: string;
platform: string;
userAgent: string;
}

type ClientProfileName =
Expand Down Expand Up @@ -159,9 +157,9 @@ type ClientSupportMap =
| Record<"ltr" | "rtl", UndirectedClientSupportMap>;

interface ClientProfile {
name: ClientProfileName;
layout: "edge" | "gecko" | "khtml" | "presto" | "trident" | "webkit";
layoutVersion: number;
name: ClientProfileName;
platform: "ipad" | "iphone" | "linux" | "mac" | "solaris" | "win";
version: string;
versionBase: string;
Expand Down
33 changes: 19 additions & 14 deletions jquery/collapsibleTabs.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/**
* CollapsibleTabsPlugin used in MediaWiki vector skin
* Copied from https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/skins/Vector/+/master/resources/CollapsibleTabsPlugin.d.ts
*/

declare global {
interface JQueryStatic {
/**
* CollapsibleTabsPlugin used in MediaWiki vector skin
* Copied from {@link https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/skins/Vector/+/master/resources/CollapsibleTabsPlugin.d.ts}
*/
collapsibleTabs: CollapsibleTabsStatic;
}

interface JQuery {
/**
* CollapsibleTabsPlugin used in MediaWiki vector skin
* Copied from {@link https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/skins/Vector/+/master/resources/CollapsibleTabsPlugin.d.ts}
*/
collapsibleTabs(options: Partial<CollapsibleTabsOptions>): void;
}
}

/**
* A jQuery plugin that makes collapsible tabs for the Vector skin.
*
* @see https://doc.wikimedia.org/mediawiki-skins-Vector/master/js/js/CollapsibleTabsOptions.html
*/
interface CollapsibleTabsOptions {
/**
* Optional tab selector. Defaults to `#p-views ul`.
*/
expandedContainer: string;
/**
* Optional menu item selector. Defaults to `#p-cactions ul`.
*/
Expand All @@ -29,12 +30,16 @@ interface CollapsibleTabsOptions {
* Optional selector for tabs that are collapsible. Defaults to `li.collapsible`.
*/
collapsible: string;
shifting: boolean;
/**
* Optional tab selector. Defaults to `#p-views ul`.
*/
expandedContainer: string;
expandedWidth: number;

expandCondition(eleWidth: number): boolean;
shifting: boolean;

collapseCondition(): boolean;

expandCondition(eleWidth: number): boolean;
}

interface CollapsibleTabsStatic {
Expand All @@ -43,15 +48,15 @@ interface CollapsibleTabsStatic {

addData($collapsible: JQuery): void;

calculateTabDistance(): number;

getSettings($collapsible: JQuery): CollapsibleTabsOptions;

handleResize(): void;

moveToCollapsed($moving: JQuery): void;

moveToExpanded($moving: JQuery): void;

calculateTabDistance(): number;
}

interface CollapsibleTabs extends CollapsibleTabsStatic, CollapsibleTabsOptions {}
Expand Down
90 changes: 50 additions & 40 deletions jquery/colorUtil.d.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,67 @@
declare global {
interface JQueryStatic {
/**
* @deprecated Removed since 1.41.
* @see https://doc.wikimedia.org/mediawiki-core/REL1_40/js/#!/api/jQuery.colorUtil
*/
colorUtil: ColorUtil;
}
}

type Color = [number, number, number];

interface ColorUtil {
/**
* Parse CSS color strings looking for color tuples
*
* Based on highlightFade by Blair Mitchelmore
* <http://jquery.offput.ca/highlightFade/>
*
* @param {Color|string} color
* @returns {Color}
*/
getRGB<T extends Color>(color: string | T): T;

/**
* Named color map
*
* Based on Interface by Stefan Petre
* <http://interface.eyecon.ro/>
* {@link http://interface.eyecon.ro/}
*
* @see https://doc.wikimedia.org/mediawiki-core/REL1_40/js/#!/api/jQuery.colorUtil-property-colors
*/
colors: Record<string, Color>;

/**
* Convert an RGB color value to HSL.
* Get a brighter or darker rgb() value string.
*
* Conversion formula based on
* <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
* Usage:
*
* Adapted from <https://en.wikipedia.org/wiki/HSL_color_space>.
* ```js
* $.colorUtil.getColorBrightness( 'red', +0.1 );
* // > "rgb(255,50,50)"
* $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
* // > "rgb(118,29,29)"
* ```
*
* Assumes `r`, `g`, and `b` are contained in the set `[0, 255]` and
* returns `h`, `s`, and `l` in the set `[0, 1]`.
* @param {Color|string} currentColor Current value in css
* @param {number} mod Wanted brightness modification between -1 and 1
* @returns {string} Like `'rgb(r,g,b)'`
* @see https://doc.wikimedia.org/mediawiki-core/REL1_40/js/#!/api/jQuery.colorUtil-method-getColorBrightness
*/
getColorBrightness(
currentColor: string | Color,
mod: number
): `rgb(${number},${number},${number})`;

/**
* Parse CSS color strings looking for color tuples
*
* @param {number} r The red color value
* @param {number} g The green color value
* @param {number} b The blue color value
* @returns {Color} The HSL representation
* Based on highlightFade by Blair Mitchelmore
* {@link http://jquery.offput.ca/highlightFade/}
*
* @param {Color|string} color
* @returns {Color}
* @see https://doc.wikimedia.org/mediawiki-core/REL1_40/js/#!/api/jQuery.colorUtil-method-getRGB
*/
rgbToHsl(r: number, g: number, b: number): Color;
getRGB<T extends Color>(color: string | T): T;

/**
* Convert an HSL color value to RGB.
*
* Conversion formula based on
* <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
* {@link http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript}
*
* Adapted from <https://en.wikipedia.org/wiki/HSL_color_space>.
* Adapted from {@link https://en.wikipedia.org/wiki/HSL_color_space}.
*
* Assumes `h`, `s`, and `l` are contained in the set `[0, 1]` and
* returns `r`, `g`, and `b` in the set `[0, 255]`.
Expand All @@ -59,29 +70,28 @@ interface ColorUtil {
* @param {number} s The saturation
* @param {number} l The lightness
* @returns {Color} The RGB representation
* @see https://doc.wikimedia.org/mediawiki-core/REL1_40/js/#!/api/jQuery.colorUtil-method-hslToRgb
*/
hslToRgb(h: number, s: number, l: number): Color;

/**
* Get a brighter or darker rgb() value string.
* Convert an RGB color value to HSL.
*
* Usage:
* Conversion formula based on
* {@link http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript}
*
* ```js
* $.colorUtil.getColorBrightness( 'red', +0.1 );
* // > "rgb(255,50,50)"
* $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
* // > "rgb(118,29,29)"
* ```
* Adapted from {@link https://en.wikipedia.org/wiki/HSL_color_space}.
*
* @param {Color|string} currentColor Current value in css
* @param {number} mod Wanted brightness modification between -1 and 1
* @returns {string} Like `'rgb(r,g,b)'`
* Assumes `r`, `g`, and `b` are contained in the set `[0, 255]` and
* returns `h`, `s`, and `l` in the set `[0, 1]`.
*
* @param {number} r The red color value
* @param {number} g The green color value
* @param {number} b The blue color value
* @returns {Color} The HSL representation
* @see https://doc.wikimedia.org/mediawiki-core/REL1_40/js/#!/api/jQuery.colorUtil-method-rgbToHsl
*/
getColorBrightness(
currentColor: string | Color,
mod: number
): `rgb(${number},${number},${number})`;
rgbToHsl(r: number, g: number, b: number): Color;
}

export {};
Loading

0 comments on commit 3796925

Please sign in to comment.