From 996aa4cecfacd6628e901bbde27294aabaada614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20LES=C3=89N=C3=89CHAL?= Date: Fri, 8 Mar 2024 18:43:44 +0100 Subject: [PATCH] Add types for `mediawiki.debug` --- mw/debug.d.ts | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ mw/index.d.ts | 1 + 2 files changed, 120 insertions(+) create mode 100644 mw/debug.d.ts diff --git a/mw/debug.d.ts b/mw/debug.d.ts new file mode 100644 index 0000000..7349dbf --- /dev/null +++ b/mw/debug.d.ts @@ -0,0 +1,119 @@ +type LogEntryType = "deprecated" | "log" | "warn"; + +interface Data { + debugLog: string[]; + gitBranch: string | false; + gitRevision: string | false; + gitViewUrl: string | false; + includes: File[]; + log: LogEntry[]; + memory: string; + memoryPeak: string; + mwVersion: string; + phpVersion: string; + queries: Query[]; + time: number; +} + +interface File { + name: string; + size: string; +} + +interface LogEntry { + caller: string; + msg: string; + type: LogEntryType; + typeText?: string; +} + +interface Query { + function: string; + sql: string; + time: number; +} + +declare global { + namespace mw { + /** + * Debug toolbar. + * + * Enabled server-side through `$wgDebugToolbar`. + * + * @since 1.19 + */ + namespace Debug { + /** + * Toolbar container element. + */ + const $container: JQuery; + + /** + * Object containing data for the debug toolbar. + */ + const data: Data; + + /** + * Build the console panel. + * + * @returns {JQuery} Console panel + */ + function buildConsoleTable(): JQuery; + + /** + * Build legacy debug log pane. + * + * @returns {JQuery} + */ + function buildDebugLogTable(): JQuery; + + /** + * Construct the HTML for the debugging toolbar. + */ + function buildHtml(): void; + + /** + * Build included files pane. + * + * @returns {JQuery} + */ + function buildIncludesPane(): JQuery; + + /** + * Build query list pane. + * + * @returns {JQuery} + */ + function buildQueryTable(): JQuery; + + /** + * Build request information pane. + * + * @returns {JQuery} + */ + function buildRequestPane(): JQuery; + + /** + * Initialize the debugging pane. + * + * Shouldn't be called before the document is ready + * (since it binds to elements on the page). + * + * @param {Data} [data] Defaults to 'debugInfo' from {@link mw.config} + */ + function init(data?: Data): void; + + /** + * Switch between panes. + * + * Should be called with an HTMLElement as its thisArg, + * because it's meant to be an event handler. + * + * @param {JQuery.Event} e + */ + function switchPane(e: JQuery.Event): void; + } + } +} + +export {}; diff --git a/mw/index.d.ts b/mw/index.d.ts index f5534da..e5ff165 100644 --- a/mw/index.d.ts +++ b/mw/index.d.ts @@ -2,6 +2,7 @@ import "./Api"; import "./config"; import "./confirmCloseWindow"; import "./cookie"; +import "./debug"; import "./ForeignApi"; import "./ForeignRest"; import "./global";