Skip to content

Commit

Permalink
lint; update readme; bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed May 31, 2021
1 parent f0b8817 commit 52d1826
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 183 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[![NPM version](https://img.shields.io/npm/v/types-mediawiki.svg)](https://www.npmjs.com/package/types-mediawiki)
![Linter](https://github.com/wikimedia-gadgets/types-mediawiki/workflows/Lint/badge.svg)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

# types-mediawiki

Expand Down Expand Up @@ -60,6 +59,8 @@ Since it is just a type import, it doesn't generate any JavaScript. Hence, such
---

TODO:
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

- Add doc comments for everything. Presently they are rarely there.
- Add doc comments for mw.Title, mw.Uri, mw.storage, mw.language and mw.loader.
- Add types for more jQuery plugins.
- Add types for mw.experiments
8 changes: 4 additions & 4 deletions mw/Api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ declare global {
*/
constructor(options?: ApiOptions);

/**
* @private
*/
defaults: ApiOptions;
/**
* @private
*/
defaults: ApiOptions;

/**
* Abort all unfinished requests issued by this Api object.
Expand Down
137 changes: 68 additions & 69 deletions mw/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,71 @@
declare global {
namespace mw {

/**
* Map of configuration values.
*
* Check out [the complete list of configuration values](https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config)
* on mediawiki.org.
*
* If `$wgLegacyJavaScriptGlobals` is true, this Map will add its values to the
* global `window` object.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-property-config
*/
const config: mw.Map<{
debug: boolean;
skin: string;
stylepath: string;
wgArticlePath: string;
wgCaseSensitiveNamespaces: string[];
wgContentLanguage: string;
wgContentNamespaces: number[];
wgDBname: string;
wgEnableAPI: boolean;
wgEnableWriteAPI: boolean;
wgExtensionAssetsPath: string;
wgFormattedNamespaces: Record<number, string>;
wgNamespaceIds: Record<string, number>;
wgScript: string;
wgScriptPath: string;
wgServer: string;
wgSiteName: string;
wgVariantArticlePath: string | false;
wgVersion: string;
wgAction: string;
wgArticleId: number;
wgCanonicalNamespace: string;
wgCanonicalSpecialPageName: string | false;
wgCategories: string[];
wgCurRevisionId: number;
wgIsArticle: boolean;
wgIsProbablyEditable: boolean;
wgNamespaceNumber: number;
wgPageContentLanguage: string;
wgPageContentModel: string;
wgPageName: string;
wgRedirectedFrom: string;
wgRelevantPageName: string;
wgRelevantUserName: string;
wgRelevantPageIsProbablyEditable: boolean;
wgRestrictionEdit: string[];
wgRestrictionMove: string[];
wgRevisionId: number;
wgSearchType: string;
wgTitle: string;
wgUserEditCount: number;
wgUserGroups: string[];
wgUserId: number;
wgUserLanguage: string;
wgUserName: string;
wgUserRegistration: number;
wgIsMainPage: boolean;
wgUserVariant: string;
wgPostEdit: string;
wgDiffOldId: number | false;
wgDiffNewId: number;
wgWikibaseItemId: string;
[key: string]: unknown; // more config keys can be added by extensions
}>;
}
namespace mw {
/**
* Map of configuration values.
*
* Check out [the complete list of configuration values](https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config)
* on mediawiki.org.
*
* If `$wgLegacyJavaScriptGlobals` is true, this Map will add its values to the
* global `window` object.
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-property-config
*/
const config: mw.Map<{
debug: boolean;
skin: string;
stylepath: string;
wgArticlePath: string;
wgCaseSensitiveNamespaces: string[];
wgContentLanguage: string;
wgContentNamespaces: number[];
wgDBname: string;
wgEnableAPI: boolean;
wgEnableWriteAPI: boolean;
wgExtensionAssetsPath: string;
wgFormattedNamespaces: Record<number, string>;
wgNamespaceIds: Record<string, number>;
wgScript: string;
wgScriptPath: string;
wgServer: string;
wgSiteName: string;
wgVariantArticlePath: string | false;
wgVersion: string;
wgAction: string;
wgArticleId: number;
wgCanonicalNamespace: string;
wgCanonicalSpecialPageName: string | false;
wgCategories: string[];
wgCurRevisionId: number;
wgIsArticle: boolean;
wgIsProbablyEditable: boolean;
wgNamespaceNumber: number;
wgPageContentLanguage: string;
wgPageContentModel: string;
wgPageName: string;
wgRedirectedFrom: string;
wgRelevantPageName: string;
wgRelevantUserName: string;
wgRelevantPageIsProbablyEditable: boolean;
wgRestrictionEdit: string[];
wgRestrictionMove: string[];
wgRevisionId: number;
wgSearchType: string;
wgTitle: string;
wgUserEditCount: number;
wgUserGroups: string[];
wgUserId: number;
wgUserLanguage: string;
wgUserName: string;
wgUserRegistration: number;
wgIsMainPage: boolean;
wgUserVariant: string;
wgPostEdit: string;
wgDiffOldId: number | false;
wgDiffNewId: number;
wgWikibaseItemId: string;
[key: string]: unknown; // more config keys can be added by extensions
}>;
}
}

export {};
export {};
204 changes: 103 additions & 101 deletions mw/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,114 +25,116 @@ declare global {
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw
*/
namespace mw {
/**
* Format a string. Replace $1, $2 ... $N with positional arguments.
*
* Used by Message#parser().
*
* @since 1.25
* @param {string} formatString Format string
* @param {...Mixed} parameters Values for $N replacements
* @return {string} Formatted string
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-method-format
*/
function format(formatString: string, ...parameters: unknown[]): string;

/**
* Format a string. Replace $1, $2 ... $N with positional arguments.
*
* Used by Message#parser().
*
* @since 1.25
* @param {string} formatString Format string
* @param {...Mixed} parameters Values for $N replacements
* @return {string} Formatted string
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw-method-format
*/
function format(formatString: string, ...parameters: unknown[]): string;
/**
* Get the current time, measured in milliseconds since January 1, 1970 (UTC).
*
* On browsers that implement the Navigation Timing API, this function will produce
* floating-point values with microsecond precision that are guaranteed to be monotonic.
* On all other browsers, it will fall back to using `Date`.
*
* @return {number} Current time
*/
function now(): number;

/**
* Get the current time, measured in milliseconds since January 1, 1970 (UTC).
*
* On browsers that implement the Navigation Timing API, this function will produce
* floating-point values with microsecond precision that are guaranteed to be monotonic.
* On all other browsers, it will fall back to using `Date`.
*
* @return {number} Current time
*/
function now(): number;
/**
* Schedule a deferred task to run in the background.
*
* This allows code to perform tasks in the main thread without impacting
* time-critical operations such as animations and response to input events.
*
* Basic logic is as follows:
*
* - User input event should be acknowledged within 100ms per [RAIL].
* - Idle work should be grouped in blocks of upto 50ms so that enough time
* remains for the event handler to execute and any rendering to take place.
* - Whenever a native event happens (e.g. user input), the deadline for any
* running idle callback drops to 0.
* - As long as the deadline is non-zero, other callbacks pending may be
* executed in the same idle period.
*
* See also:
*
* - <https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback>
* - <https://w3c.github.io/requestidlecallback/>
* - <https://developers.google.com/web/updates/2015/08/using-requestidlecallback>
* [RAIL]: https://developers.google.com/web/fundamentals/performance/rail
*
* @member mw
* @param {Function} callback
* @param {Object} [options]
* @param {number} [options.timeout] If set, the callback will be scheduled for
* immediate execution after this amount of time (in milliseconds) if it didn't run
* by that time.
*/
function requestIdleCallback(callback: (...args: any[]) => any): void;

/**
* Schedule a deferred task to run in the background.
*
* This allows code to perform tasks in the main thread without impacting
* time-critical operations such as animations and response to input events.
*
* Basic logic is as follows:
*
* - User input event should be acknowledged within 100ms per [RAIL].
* - Idle work should be grouped in blocks of upto 50ms so that enough time
* remains for the event handler to execute and any rendering to take place.
* - Whenever a native event happens (e.g. user input), the deadline for any
* running idle callback drops to 0.
* - As long as the deadline is non-zero, other callbacks pending may be
* executed in the same idle period.
*
* See also:
*
* - <https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback>
* - <https://w3c.github.io/requestidlecallback/>
* - <https://developers.google.com/web/updates/2015/08/using-requestidlecallback>
* [RAIL]: https://developers.google.com/web/fundamentals/performance/rail
*
* @member mw
* @param {Function} callback
* @param {Object} [options]
* @param {number} [options.timeout] If set, the callback will be scheduled for
* immediate execution after this amount of time (in milliseconds) if it didn't run
* by that time.
*/
function requestIdleCallback(callback: ((...args: any[]) => any)): void;
/**
* Track an analytic event.
*
* This method provides a generic means for MediaWiki JavaScript code to capture state
* information for analysis. Each logged event specifies a string topic name that describes
* the kind of event that it is. Topic names consist of dot-separated path components,
* arranged from most general to most specific. Each path component should have a clear and
* well-defined purpose.
*
* Data handlers are registered via `mw.trackSubscribe`, and receive the full set of
* events that match their subscription, including those that fired before the handler was
* bound.
*
* @param {string} topic Topic name
* @param {Object|number|string} [data] Data describing the event.
*/
function track(topic: string, data?: object | number | string): void;

/**
* Track an analytic event.
*
* This method provides a generic means for MediaWiki JavaScript code to capture state
* information for analysis. Each logged event specifies a string topic name that describes
* the kind of event that it is. Topic names consist of dot-separated path components,
* arranged from most general to most specific. Each path component should have a clear and
* well-defined purpose.
*
* Data handlers are registered via `mw.trackSubscribe`, and receive the full set of
* events that match their subscription, including those that fired before the handler was
* bound.
*
* @param {string} topic Topic name
* @param {Object|number|string} [data] Data describing the event.
*/
function track(topic: string, data?: object | number | string): void;
/**
* Track an early error event via mw.track and send it to the window console.
*
* @private
* @param {string} topic Topic name
* @param {Object} data Data describing the event, encoded as an object; see mw#logError
*/
function trackError(topic: string, data: object): void;

/**
* Track an early error event via mw.track and send it to the window console.
*
* @private
* @param {string} topic Topic name
* @param {Object} data Data describing the event, encoded as an object; see mw#logError
*/
function trackError(topic: string, data: object): void;
/**
* Register a handler for subset of analytic events, specified by topic.
*
* Handlers will be called once for each tracked event, including any events that fired before the
* handler was registered; 'this' is set to a plain object with a topic' property naming the event, and a
* 'data' property which is an object of event-specific data. The event topic and event data are
* also passed to the callback as the first and second arguments, respectively.
*
* @param {string} topic Handle events whose name starts with this string prefix
* @param {Function} callback Handler to call for each matching tracked event
* @param {string} callback.topic
* @param {Object} [callback.data]
*/
function trackSubscribe(
topic: string,
callback: (topic: string, data: object) => any
): void;

/**
* Register a handler for subset of analytic events, specified by topic.
*
* Handlers will be called once for each tracked event, including any events that fired before the
* handler was registered; 'this' is set to a plain object with a topic' property naming the event, and a
* 'data' property which is an object of event-specific data. The event topic and event data are
* also passed to the callback as the first and second arguments, respectively.
*
* @param {string} topic Handle events whose name starts with this string prefix
* @param {Function} callback Handler to call for each matching tracked event
* @param {string} callback.topic
* @param {Object} [callback.data]
*/
function trackSubscribe(topic: string, callback: ((topic: string, data: object) => any)): void;
/**
* Stop handling events for a particular handler
*
* @param {Function} callback
*/
function trackUnsubscribe(callback: (topic: string, data: object) => any): void;

/**
* Stop handling events for a particular handler
*
* @param {Function} callback
*/
function trackUnsubscribe(callback: Function): void;

// types for mw.widgets are out of scope!
const widgets: any;
// types for mw.widgets are out of scope!
const widgets: any;
}
}

Expand Down
Loading

0 comments on commit 52d1826

Please sign in to comment.