UNPKG

mediawiki-sdk

Version:

TypeScript SDK for generating and working with WikiText and MediaWiki API. Allows to get pages from wiki projects built on mediawiki.

1,496 lines 125 kB
export interface Cookie { name: string; value: string; domain: string; path: string; expires?: Date; secure?: boolean; httpOnly?: boolean; sameSite?: "Strict" | "Lax" | "None"; hostOnly?: boolean; creationTime: Date; } export declare class CookieStore { private store; parseSetCookie(setCookieHeader: string, originHost: string): void; private storeCookie; getCookieHeader(url: string): Cookie[]; } /** * Possible output formats for the MediaWiki API. */ export type formatOutput = "json" | "none" | "php" | "rawfm" | "xml"; /** * Possible format versions for the MediaWiki API output. */ export type formatVersion = 1 | 2; /** * Possible values for the 'prop' parameter in the 'query' action. * These specify which properties to retrieve for pages. */ export type MediaWikiPageOptionsProp = "categories" | "categoryinfo" | "contributors" | "deletedrevisions" | "duplicatefiles" | "extlinks" | "extracts" | "fileusage" | "imageinfo" | "images" | "info" | "infobox" | "iwlinks" | "langlinks" | "links" | "linkshere" | "pageprops" | "redirects" | "revisions" | "stashimageinfo" | "templates" | "transcludedin" | "transcodestatus" | "videoinfo"; /** * Possible values for the 'list' parameter in the 'query' action. * These specify which lists of pages/data to retrieve. */ export type MediaWikiPageOptionsList = "allcategories" | "alldeletedrevisions" | "allfileusages" | "allimages" | "allinfoboxes" | "alllinks" | "allpages" | "allredirects" | "allrevisions" | "alltransclusions" | "allusers" | "backlinks" | "blocks" | "categorymembers" | "embeddedin" | "exturlusage" | "filearchive" | "imageusage" | "iwbacklinks" | "langbacklinks" | "linterrors" | "logevents" | "messagecollection" | "mystashedfiles" | "pagepropnames" | "pageswithprop" | "prefixsearch" | "protectedtitles" | "querypage" | "random" | "recentchanges" | "search" | "tags" | "usercontribs" | "users" | "watchlist" | "watchlistraw"; /** * Possible values for the 'meta' parameter in the 'query' action. * These specify which meta information about the wiki or user to retrieve. */ export type MediaWikiPageOptionsMeta = "allmessages" | "authmanagerinfo" | "filerepoinfo" | "languageinfo" | "languagestats" | "linterstats" | "managemessagegroups" | "messagegroups" | "messagegroupstats" | "messagetranslations" | "notifications" | "siteinfo" | "tokens" | "unreadnotificationpages" | "userinfo" | "oath"; export type MediaWikiSearchOptions = "nearmatch" | "text" | "title"; export type MediaWikiTokensOptions = "*" | "createaccount" | "csrf" | "login" | "patrol" | "rollback" | "userrights" | "watch"; export type MediaWikiSearchSrPropOptions = "categorysnippet" | "extensiondata" | "hasrelated" | "isfilematch" | "redirectsnippet" | "redirecttitle" | "score" | "sectionsnippet" | "sectiontitle" | "size" | "snippet" | "timestamp" | "titlesnippet" | "wordcount"; /** * Options for initializing the MediaWiki client. */ export interface MediaWikiOptions { /** * The base URL of the MediaWiki API (e.g., "https://en.wikipedia.org/w/api.php" or "https://en.wikipedia.org/w"). * Required. */ baseURL: string; /** * A string identifying the server responding to the request. (API parameter `servedby`) */ servedby?: boolean | null; /** * Include the current timestamp in the response. (API parameter `curtimestamp`) */ curtimestamp?: boolean | null; /** * Provide information about the response's language. (API parameter `responselanginfo`) */ responselanginfo?: boolean | null; /** * Any request ID to be included in the response. (API parameter `requestid`) */ requestid?: string | null; /** * The format of the output. Defaults to "json". (API parameter `format`) */ format?: formatOutput | null; /** * The version of the format to use. Defaults to 2. (API parameter `formatversion`) */ formatversion?: formatVersion | null; /** * If set, replace non-ASCII characters with escape sequences. (API parameter `ascii`) */ ascii?: boolean | null; /** * If set, encode response in UTF-8. (API parameter `utf8`) */ utf8?: boolean | null; } /** * Internal options for the fetchData method. */ export interface fetchDataOptions { /** * HTTP method for the request (e.g., "GET", "POST"). */ method: "GET" | "POST"; /** * URL for the request. */ url: string; /** * Request parameters. */ params?: Record<string, any>; /** * Request headers. */ headers?: Record<string, string>; /** * Request body data (for methods like POST). */ data?: any; } /** * Options for the 'query' action. Specifies what data to retrieve. */ export interface MediaWikiPageOptions { action?: "query"; /** * A single page title to query. * Note: Prefer `titles` for multiple pages or more complex queries. * @example "Main Page" * @example "Wikipedia" */ title?: string; /** * Which properties to get for the queried pages. (API parameter `prop`) * @example ["info", "extracts"] * @example ["categories", "revisions"] * @example ["contributors", "revisions", "images"] */ prop?: MediaWikiPageOptionsProp[]; /** * Which lists to get. (API parameter `list`) * @example ["allcategories", "recentchanges"] * @example ["allimages", "alllinks"] * @example ["allusers", "allpages"] */ list?: MediaWikiPageOptionsList[]; /** * Which meta information to get. (API parameter `meta`) * @example ["siteinfo"] * @example ["userinfo", "tokens"] * @example ["languageinfo", "linterstats"] */ meta?: MediaWikiPageOptionsMeta[]; /** * Add the page ID to the response at the top level. (API parameter `indexpageids`) * @example true * @example false */ indexpageids?: boolean; /** * Export the queried pages in XML format. (API parameter `export`) * @example true * @example false */ export?: boolean; /** * A list of page titles to query. (API parameter `titles`) * @example ["Main Page", "Wikipedia"] * @example ["Albert Einstein", "Quantum mechanics"] * @example ["World War II", "Cold War"] */ titles?: string[]; /** * A list of page IDs to query. (API parameter `pageids`) * Note: API expects numbers, but your type is string[]. * @example ["1", "5", "1337"] * @example ["500", "1024", "9001"] */ pageids?: string[]; /** * Resolve redirects in titles and pageids. (API parameter `redirects`) * @example true * @example false * @example "from" // Resolve redirects from the given page * @example "to" // Resolve redirects to the final page */ redirects?: boolean | string; /** * Search term to look for in page titles or content. * Depending on the search engine used by the server, special search functions may be supported. * @example "artificial intelligence" * @example "intitle:Machine learning" * @example "deep learning insource:/neural/" */ srsearch?: string; /** * Specify namespaces to search within. * @example ["0", "1", "2"] * @example ["Main", "Talk"] * @example ["User", "Wikipedia"] */ srnamespace?: string[]; srlimit?: number; sroffset?: number; srwhat?: MediaWikiSearchOptions; rvlimit?: number; exintro?: boolean; explaintext?: boolean; uiprop?: string; type?: any; srinfo?: "totalhits" | "suggestion" | "rewrittenquery"; srprop?: MediaWikiSearchSrPropOptions[]; } export interface MediaWikiErrorCodeResponse { code: string; info: string; docref?: string; [key: string]: any; } /** * Base structure for common MediaWiki API response elements. */ export interface MediaWikiBaseResponse { /** Indicates if the batch is complete. API might return "" which coerces to true/false. */ batchcomplete: boolean; /** Warnings returned by the API, possibly related to specific modules like 'extracts'. */ warnings?: { /** Warnings specific to the 'extracts' module. */ extracts?: { /** A general warning message. */ warning: string; /** Another field for warnings (structure seems redundant based on type, kept as per your definition). */ warnings: string; }; /** Other modules might also produce warnings. */ [module: string]: any; }; errors?: any; error?: MediaWikiErrorCodeResponse; } /** Defines the general continuation token. */ export interface GeneralContinue { continue: string; } /** Defines the continuation token for page content. */ export interface PageContentContinue { pccontinue: string; } /** Defines the continuation token for external links. */ export interface ExternalLinksContinue { elcontinue: string; } /** Defines the continuation token for interwiki links. */ export interface InterwikiLinksContinue { iwcontinue: string; } /** Defines the continuation token for page links. */ export interface PageLinksContinue { plcontinue: string; } /** Defines the continuation token for links here. */ export interface LinksHereContinue { lhcontinue: string; } /** Defines the continuation token for templates. */ export interface TemplatesContinue { tlcontinue: string; } /** * Describes the comprehensive 'continue' block that may be returned by the MediaWiki API. * Fields are based on common continuation parameters. All listed are required as per your example. */ export interface MediaWikiComprehensiveContinueBlock extends GeneralContinue, PageContentContinue, ExternalLinksContinue, InterwikiLinksContinue, PageLinksContinue, LinksHereContinue, TemplatesContinue { /** * Allows for other module-specific continuation tokens (e.g., rncontinue, srcontinue, etc.) * @example { "rncontinue": "abcdef", "srcontinue": "12345" } */ [key: string]: string | number | undefined; } /** * Information about a normalized title from a MediaWiki API query. * @example { "fromencoded": false, "from": "main page", "to": "Main Page" } */ export interface MediaWikiQueryNormalizedItem { /** Indicates if the source title was encoded. */ fromencoded: boolean; /** The original title. */ from: string; /** The normalized title. */ to: string; } /** * Information about a redirected title from a MediaWiki API query. * @example { "from": "USA", "to": "United States" } */ export interface MediaWikiQueryRedirectItem { /** Original title. */ from: string; /** Target title. */ to: string; /** Optional fragment on the to link */ tofragment?: string; } /** * Item representing an image linked on a page. * @example { "ns": 6, "title": "File:Example.jpg" } */ export interface MediaWikiQueryPageImageItem { /** Namespace ID of the image. */ ns: number; /** Title of the image file. */ title: string; } /** * Item representing a category the page belongs to. * @example { "ns": 14, "title": "Category:Examples" } */ export interface MediaWikiQueryPageCategoryItem { /** Namespace ID of the category. */ ns: number; /** Title of the category page. */ title: string; } /** * Item representing a contributor to the page. * @example { "userid": 123, "name": "ExampleUser" } */ export interface MediaWikiQueryPageContributorItem { /** User ID of the contributor. */ userid: number; /** User name of the contributor. */ name: string; } /** * Item representing an external link from the page. * @example { "url": "https://www.example.com" } */ export interface MediaWikiQueryPageExtlinkItem { /** The URL of the external link. */ url: string; } /** * Information about the flagged revisions status of a page. */ export interface MediaWikiQueryPageFlaggedDetails { /** Stable revision ID. */ stable_revid: number; /** Review level. */ level: number; /** Text representation of the review level. */ level_text: string; /** Page protection level. */ protection_level: string; /** Expiry timestamp for protection. */ protection_expiry: string; } /** * Item representing an interwiki link from the page. * @example { "prefix": "wikt", "title": "example" } */ export interface MediaWikiQueryPageInterwikiLinkItem { /** Prefix of the interwiki link. */ prefix: string; /** Title of the page on the other wiki. */ title: string; } /** * Item representing a language link from the page. * @example { "lang": "de", "title": "Beispiel" } */ export interface MediaWikiQueryPageLangLinkItem { /** Language code. */ lang: string; /** Title of the page in the other language. */ title: string; } /** * Item representing an internal link from the page. * @example { "ns": 0, "title": "Another Page" } */ export interface MediaWikiQueryPageInternalLinkItem { /** Namespace ID of the target page. */ ns: number; /** Title of the target page. */ title: string; } /** * Item representing a page that links to the current page. * @example { "pageid": 456, "ns": 0, "title": "Linking Page", "redirect": false } */ export interface MediaWikiQueryPageLinkHereItem { /** Page ID of the linking page. */ pageid: number; /** Namespace ID of the linking page. */ ns: number; /** Title of the linking page. */ title: string; /** Indicates if the link is a redirect. (Marked as optional as per common API behavior) */ redirect?: boolean; } /** * Page properties obtained via `prop=pageprops`. * @example { "page_image": "Example.jpg", "wikibase_item": "Q42" } */ export interface MediaWikiQueryPagePropsDetails { /** The page image. */ page_image: string; /** Wikibase badge information (example key). */ 'wikibase-badge-Q17437796': string; /** Wikibase item ID. */ wikibase_item: string; /** Allows for other page properties. */ [key: string]: any; } /** * Terms associated with the page (e.g., labels, descriptions from Wikibase). * @example { "label": ["Example Label"], "description": ["An example description."] } */ export interface MediaWikiQueryPageTermsDetails { /** Labels associated with the page. */ label: string[]; /** Descriptions associated with the page. */ description: string[]; } /** * Page view data, keyed by date. * @example { "2023-01-01": 100, "2023-01-02": 150 } */ export interface MediaWikiQueryPageViewsDetails { [date: string]: number | null; } /** * Details of a single page revision. */ export interface MediaWikiQueryPageRevisionItem { /** * The unique identifier for this revision. * @example 123456789 */ revid: number; /** * The revision ID of the parent revision (the one this revision was based on). * `0` if this is the first revision of the page. * @example 123456780 */ parentid: number; /** * Indicates if the revision was marked as a minor edit. * `true` for minor, `false` for major. * @example true */ minor: boolean; /** * The username of the user who made this revision. * For anonymous users, this will be their IP address. * @example "Jimbo Wales" * @example "192.168.1.100" */ user: string; /** * The timestamp when this revision was made, in ISO 8601 format (UTC). * @example "2023-10-26T10:30:00Z" */ timestamp: string; /** * The edit summary (comment) provided by the user for this revision. * Can be empty if no summary was provided. * @example "Fixed a typo" * @example "" */ comment: string; /** * Allows for other revision properties based on the `rvprop` parameter * used in the API query (e.g., `content`, `size`, `tags`, `sha1`). * @see https://www.mediawiki.org/wiki/API:Revisions#Parameters * @example { "size": 1234, "tags": ["mobile edit", "visualeditor"] } */ [key: string]: any; } /** * Item representing a template used on the page. * @example { "ns": 10, "title": "Template:Example" } */ export interface MediaWikiQueryPageTemplateItem { /** Namespace ID of the template. */ ns: number; /** Title of the template page. */ title: string; } /** * Item representing a page that transcludes the current page. * @example { "pageid": 789, "ns": 0, "title": "Transcluding Page", "redirect": false } */ export interface MediaWikiQueryPageTranscludedInItem { /** Page ID of the transcluding page. */ pageid: number; /** Namespace ID of the transcluding page. */ ns: number; /** Title of the transcluding page. */ title: string; /** Indicates if the transclusion is via a redirect. (Marked as optional) */ redirect?: boolean; } export interface MediaWikiQueryCategoriesItem { pageid: number; ns: number; title: string; categories: MediaWikiQueryPageTemplateItem[]; } export interface MediaWikiQueryRevisionsItem { pageid: number; ns: number; title: string; revisions: MediaWikiQueryPageRevisionItem[]; } export interface MediaWikiQuerySummaryItem { pageid: number; ns: number; title: string; extract: string; } /** Target title information for CirrusSearch suggestions. */ export interface MediaWikiQueryCirrusTargetTitle { title: string; namespace: number; } /** Suggestion input and weight for CirrusSearch. */ export interface MediaWikiQueryCirrusSuggestInput { input: string[]; weight: number; } /** Deeply nested score detail item for CirrusSearch score explanation. */ export interface MediaWikiQueryCirrusScoreDetailItem { value: number; description: string; details?: MediaWikiQueryCirrusScoreDetailItem[]; } /** Represents the score explanation structure in CirrusSearch suggestions. */ export interface MediaWikiQueryCirrusScoreExplanation { value: number; description: string; details?: MediaWikiQueryCirrusScoreDetailItem[]; } /** Structure for an item in the `cirruscompsuggestbuilddoc` record. */ export interface MediaWikiQueryCirrusCompSuggestBuildDocItem { batch_id: number; source_doc_id: string; target_title: MediaWikiQueryCirrusTargetTitle; suggest: MediaWikiQueryCirrusSuggestInput; "suggest-stop": MediaWikiQueryCirrusSuggestInput; score_explanation: MediaWikiQueryCirrusScoreExplanation; } /** Detailed structure for `cirrusbuilddoc`. */ export interface MediaWikiQueryCirrusBuildDocDetails { version: number; wiki: string; page_id: number; namespace: number; namespace_text: string; title: string; timestamp: string; create_timestamp: string; redirect: any[]; category: string[]; external_link: string[]; outgoing_link: string[]; template: string[]; text: string; text_bytes: number; content_model: string; coordinates: any[]; wikibase_item: string; language: string; heading: string[]; opening_text: string; auxiliary_text: string[]; defaultsort: any; file_text: any; display_title: any; [key: string]: any; } /** No-operation hints for CirrusSearch build document metadata. */ export interface MediaWikiQueryCirrusBuildDocMetadataNoopHints { version: string; [key: string]: any; } /** Mandatory reduction stats for CirrusSearch size limiter. */ export interface MediaWikiQueryCirrusBuildDocMetadataSizeLimiterMandatoryReduction { opening_text: number; [key: string]: any; } /** Document size stats for CirrusSearch size limiter. */ export interface MediaWikiQueryCirrusBuildDocMetadataSizeLimiterDocument { original_length: number; new_length: number; [key: string]: any; } /** Size limiter stats for CirrusSearch build document metadata. */ export interface MediaWikiQueryCirrusBuildDocMetadataSizeLimiterStats { mandatory_reduction: MediaWikiQueryCirrusBuildDocMetadataSizeLimiterMandatoryReduction; document: MediaWikiQueryCirrusBuildDocMetadataSizeLimiterDocument; [key: string]: any; } /** Metadata for CirrusSearch build document. */ export interface MediaWikiQueryCirrusBuildDocMetadataDetails { cluster_group: string; noop_hints: MediaWikiQueryCirrusBuildDocMetadataNoopHints; size_limiter_stats: MediaWikiQueryCirrusBuildDocMetadataSizeLimiterStats; index_name: string; [key: string]: any; } /** * Detailed information about a single page, as it appears in the `query.pages` object. * Uses the decomposed types for its properties. * All fields are kept as in your "full" example, many are effectively optional depending on `prop`. */ export interface MediaWikiQueryPageFullDetails { /** The unique identifier for the page. */ pageid: number; /** The namespace ID of the page. */ ns: number; /** The full title of the page. */ title: string; /** The content model of the page (e.g., "wikitext"). */ contentmodel: string; /** The language code of the page content. */ pagelanguage: string; /** The HTML language code for the page. */ pagelanguagehtmlcode: string; /** The direction of the page language script (e.g., "ltr"). */ pagelanguagedir: string; /** Timestamp of the last time the page was touched. */ touched: string; /** The revision ID of the last revision. */ lastrevid: number; /** The length of the page content in bytes. */ length: number; /** List of images included in the page. */ images: MediaWikiQueryPageImageItem[]; /** List of categories the page belongs to. */ categories: MediaWikiQueryPageCategoryItem[]; /** Number of anonymous contributors to the page (requires appropriate rights). */ anoncontributors: number; /** List of contributors to the page (requires appropriate rights). */ contributors: MediaWikiQueryPageContributorItem[]; /** List of external links from the page. */ extlinks: MediaWikiQueryPageExtlinkItem[]; /** Extracted text content of the page (requires `prop=extracts`). */ extract: string; /** Information about the flagged revisions status (requires `prop=flagged`). */ flagged: MediaWikiQueryPageFlaggedDetails; /** List of interwiki links from the page. */ iwlinks: MediaWikiQueryPageInterwikiLinkItem[]; /** List of language links from the page. */ langlinks: MediaWikiQueryPageLangLinkItem[]; /** Count of language links. */ langlinkscount: number; /** List of internal links from the page. */ links: MediaWikiQueryPageInternalLinkItem[]; /** List of pages that link to this page. */ linkshere: MediaWikiQueryPageLinkHereItem[]; /** Page properties (requires `prop=pageprops`). */ pageprops: MediaWikiQueryPagePropsDetails; /** Terms associated with the page (e.g., labels, descriptions from Wikibase). */ terms: MediaWikiQueryPageTermsDetails; /** Page view data, keyed by date. */ pageviews: MediaWikiQueryPageViewsDetails; /** List of revisions for the page (requires `prop=revisions`). */ revisions: MediaWikiQueryPageRevisionItem[]; /** List of templates used on the page. */ templates: MediaWikiQueryPageTemplateItem[]; /** List of pages that transclude this page (e.g., templates). */ transcludedin: MediaWikiQueryPageTranscludedInItem[]; /** Short description of the page (requires `prop=description`). */ description: string; /** Source of the short description. */ descriptionsource: string; /** CirrusSearch component suggestion build document data. */ cirruscompsuggestbuilddoc: Record<string, MediaWikiQueryCirrusCompSuggestBuildDocItem> & Record<string, any>; /** CirrusSearch build document data. */ cirrusbuilddoc: MediaWikiQueryCirrusBuildDocDetails; /** CirrusSearch build document metadata. */ cirrusbuilddoc_metadata: MediaWikiQueryCirrusBuildDocMetadataDetails; /** Comment related to the CirrusSearch build document. */ cirrusbuilddoc_comment: string; /** Optional fields like 'missing' or 'invalid' for pages. */ missing?: boolean | string; invalid?: boolean | string; invalidreason?: string; /** Allows other properties added by `prop` modules. */ [key: string]: any; } /** * Item returned by `list=random`. * @example { "id": 123, "ns": 0, "title": "Random Page" } */ export interface MediaWikiListRandomItem { id: number; ns: number; title: string; } /** * Item returned by `list=search`. * @example { "ns": 0, "title": "Search Result", "pageid": 456, "snippet": "A snippet of the page..." } */ export interface MediaWikiListSearchItem { ns: number; title: string; pageid?: number; size?: number; wordcount?: number; timestamp?: string; snippet?: string; titlesnippet?: string; redirecttitle?: string; redirectsnippet?: string; sectiontitle?: string; sectionsnippet?: string; isfilematch?: boolean; categorysnippet?: string; [key: string]: any; } /** * Metadata for `list=search` results. * @example { "totalhits": 100, "suggestion": "corrected search query" } */ export interface MediaWikiListSearchInfo { totalhits: number; suggestion?: string; suggestionsnippet?: string; } /** * Represents a single metadata field returned from MediaWiki's `imageinfo.metadata`. */ export interface MediaWikiImageMetadata { /** * The internal name/key of the metadata field (e.g., "DateTimeOriginal", "Artist"). */ name: string; /** * The raw value of the metadata field (can be string, number, or even base64-encoded data). */ value: string; /** * Optional human-readable label, if available (e.g., "Original date/time"). */ label?: string; /** * Optional human-readable value with formatting or localization. */ formattedvalue?: string; /** * Optional source of the metadata (e.g., "exif", "iptc", "xmp"). */ source?: string; /** * Optional name of the metadata space (e.g., "EXIF", "IPTC"). */ space?: string; } /** * Represents simplified metadata returned from `commonmetadata`. * Typically includes width, height, resolution, and unit data. */ export interface MediaWikiSimpleMetadata { /** * Name of the metadata field (e.g., "ImageWidth", "XResolution"). */ name: string; /** * The value of the metadata field (e.g., "1920", "72"). */ value: string; /** * Optional source of the field (e.g., "exif"). */ source?: string; } /** * The main `query` object within a MediaWiki API response, using decomposed types. */ export interface MediaWikiQueryStructure { /** Information about normalized titles. */ normalized?: MediaWikiQueryNormalizedItem[]; /** Information about redirected titles. */ redirects?: MediaWikiQueryRedirectItem[]; /** * Information about the queried pages, keyed by page ID. * Populated by `prop` queries. Field itself is optional as not present for all list queries. */ pages?: { [pageId: string]: MediaWikiQueryPageFullDetails; }; /** Results from `list=random`. */ random?: MediaWikiListRandomItem[]; /** Search results from `list=search`. */ search?: MediaWikiListSearchItem[]; /** Metadata about search results from `list=search`. */ searchinfo?: MediaWikiListSearchInfo; /** * Allows other data added by `list` or `meta` actions. * @example { "allpages": [...], "userinfo": {...} } */ [key: string]: any; } /** * The complete structure of a response from the MediaWiki API's 'query' action. * This combines base elements, continuation data, and the specific query payload. */ export interface MediaWikiQueryResponse extends MediaWikiBaseResponse { /** * Continuation data for paginated results. * The presence of this block and its specific fields depend on the query and results. */ continue?: MediaWikiComprehensiveContinueBlock; /** * The main query results payload. Optional as it might be missing on errors. */ query?: MediaWikiQueryStructure; /** Server that responded to the request (if `servedby` parameter was used). */ servedby?: string; /** Current timestamp (if `curtimestamp` parameter was used). */ curtimestamp?: string; /** Language information about the response (if `responselanginfo` parameter was used). */ responselanginfo?: { lang: string; dir: string; uselang: string; }; /** Request ID (if `requestid` parameter was used). */ requestid?: string; /** General errors returned by the API at the top level (as per your original structure). */ errors?: any; /** Standard MediaWiki API error object, often returned at the top level for critical errors. */ error?: MediaWikiErrorCodeResponse; } export interface MediaWikiQuerySearchResponse extends MediaWikiBaseResponse { query: { searchInfo: MediaWikiListSearchInfo; search: MediaWikiListSearchItem[]; }; } /** * Defines the structure of the 'query' object specifically for responses * from the `client.page` method, which typically requests page properties. * This structure expects a 'pages' object. */ export interface MediaWikiQueryForPageMethod { /** Information about normalized titles, if any. */ normalized?: MediaWikiQueryNormalizedItem[]; /** Information about redirected titles, if any. */ redirects?: MediaWikiQueryRedirectItem[]; /** * Information about the queried pages, keyed by page ID. * This is expected to be present and populated. */ pages: Record<string, MediaWikiQueryPageFullDetails>; /** * Allows other data that might theoretically be added by MediaWiki * alongside `pages` in a prop query, though `pages` is the primary focus. */ [key: string]: any; } /** * The specific response structure for the `client.page` method. * It extends the base response and includes a query structure focused on page details. */ export interface MediaWikiQueryPageResponse extends MediaWikiBaseResponse { /** * Continuation data for paginated results, if any. */ continue?: MediaWikiComprehensiveContinueBlock; /** * The main query results payload, specifically structured for page data. */ query: MediaWikiQueryForPageMethod; /** Server that responded to the request (if `servedby` parameter was used). */ servedby?: string; /** Current timestamp (if `curtimestamp` parameter was used). */ curtimestamp?: string; /** Language information about the response (if `responselanginfo` parameter was used). */ responselanginfo?: { lang: string; dir: string; uselang: string; }; /** Request ID (if `requestid` parameter was used). */ requestid?: string; /** General errors returned by the API at the top level. */ errors?: any; /** Standard MediaWiki API error object. */ error?: MediaWikiErrorCodeResponse; } export declare class MediaWikiQueryPageResponseClass implements MediaWikiQueryPageResponse { batchcomplete: boolean; query: MediaWikiQueryForPageMethod; private wiki; private pageDetails; constructor(data: MediaWikiQueryPageResponse, wikiInstance: MediaWiki); /** * Returns the HTML content of the page. * @example "<p>Hello <strong>world</strong>!</p>" */ html(): string; /** * Returns the title of the page. * @example "Main Page" */ title(): string; /** * Returns the page ID of the parsed page. * @example 123456 */ categories(): string[]; /** * Edits this page. * @param options - Options for editing, like new text and summary. * @returns A promise resolving to the edit page response. */ edit(options: MediaWikiQueryEditPageOptions): Promise<MediaWikiQueryEditPageResponseClass>; } /** * Represents the response from the MediaWiki API's `action=query&meta=siteinfo` endpoint. * Provides general information about the site such as main page, server settings, and configurations. * * @see https://www.mediawiki.org/wiki/API:Siteinfo */ export interface MediaWikiQuerySiteInfoResponse extends MediaWikiBaseResponse { query: { /** * General information about the wiki site. */ general: { /** * The name of the main page of the site. * @example "Main Page" */ mainpage: string; /** * The full URL to the main page. * @example "https://en.wikipedia.org/wiki/Main_Page" */ base: string; /** * The name of the site (e.g., Wikipedia). * @example "Wikipedia" */ sitename: string; /** * True if the main page is located at the root of the domain. * @example false */ mainpageisdomainroot: boolean; /** * URL to the site's logo image. * @example "//en.wikipedia.org/static/images/project-logos/enwiki.png" */ logo: string; /** * The version of the MediaWiki software the site is running on. * @example "MediaWiki 1.44.0-wmf.28" */ generator: string; /** * The version of PHP used by the server. * @example "8.1.32" */ phpversion: string; /** * The PHP SAPI (Server API) being used by the server. * @example "fpm-fcgi" */ phpsapi: string; /** * The database type used by the site. * @example "mysql" */ dbtype: string; /** * The version of the database used by the site. * @example "10.6.20-MariaDB-log" */ dbversion: string; /** * Whether image whitelist is enabled. * @example false */ imagewhitelistenabled: boolean; /** * Whether language conversion is enabled. * @example true */ langconversion: boolean; /** * Whether link conversion (e.g., converting URLs to links) is enabled. * @example true */ linkconversion: boolean; /** * Whether title conversion is enabled. * @example true */ titleconversion: boolean; /** * Charset for link prefixes. * @example "" */ linkprefixcharset: string; /** * The prefix for links on the site. * @example "" */ linkprefix: string; /** * The regular expression used to match link trails. * @example "/^([a-z]+)(.*)$/sD" */ linktrail: string; /** * Characters allowed in page titles. * @example " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+" */ legaltitlechars: string; /** * Characters not allowed in usernames. * @example "@:>=" */ invalidusernamechars: string; /** * Whether all Unicode fixes are enabled. * @example false */ allunicodefixes: boolean; /** * Whether Arabic Unicode fix is enabled. * @example true */ fixarabicunicode: boolean; /** * Whether Malayalam Unicode fix is enabled. * @example true */ fixmalayalamunicode: boolean; /** * The Git commit hash for the current version. * @example "d4283b99aa40c4726f9ec2dc0a033bf30628eeee" */ "git-hash": string; /** * The Git branch for the current version. * @example "wmf/1.44.0-wmf.28" */ "git-branch": string; /** * The case used for page titles (e.g., first-letter). * @example "first-letter" */ case: string; /** * The language code for the site (e.g., "en" for English). * @example "en" */ lang: string; /** * An array of fallback languages if the primary language isn't available. * @example [{ code: "fr" }] */ fallback: Array<{ code: string; }>; /** * Whether the site is RTL (Right-to-Left). * @example false */ rtl: boolean; /** * The encoding used for 8-bit characters in fallbacks. * @example "windows-1252" */ fallback8bitEncoding: string; /** * Whether the site is in read-only mode. * @example false */ readonly: boolean; /** * Whether the site has the write API enabled. * @example true */ writeapi: boolean; /** * The maximum allowed article size in bytes. * @example 2097152 */ maxarticlesize: number; /** * The site's timezone. * @example "UTC" */ timezone: string; /** * The time offset for the site's timezone. * @example 0 */ timeoffset: number; /** * The path to articles on the site. * @example "/wiki/$1" */ articlepath: string; /** * The path to the script used for the site. * @example "/w" */ scriptpath: string; /** * The script used for the site. * @example "/w/index.php" */ script: string; /** * Whether the site has variant article paths enabled. * @example false */ variantarticlepath: boolean; /** * The base server URL of the site. * @example "//en.wikipedia.org" */ server: string; /** * The server name for the site. * @example "en.wikipedia.org" */ servername: string; /** * The unique identifier for the wiki. * @example "enwiki" */ wikiid: string; /** * The current server time. * @example "2025-05-14T20:37:02Z" */ time: string; /** * Whether "miser mode" is enabled (a mode for low resources). * @example true */ misermode: boolean; /** * Whether file uploads are enabled. * @example true */ uploadsenabled: boolean; /** * The maximum allowed upload size in bytes. * @example 5368709120 */ maxuploadsize: number; /** * The minimum upload chunk size in bytes. * @example 1024 */ minuploadchunksize: number; /** * Options related to image galleries. */ galleryoptions: { /** * The number of images to display per row. * @example 0 */ imagesPerRow: number; /** * The width of images in the gallery. * @example 120 */ imageWidth: number; /** * The height of images in the gallery. * @example 120 */ imageHeight: number; /** * Whether to show the caption length in the gallery. * @example true */ captionLength: boolean; /** * Whether to show the file size of images. * @example true */ showBytes: boolean; /** * The mode of the gallery (e.g., traditional). * @example "traditional" */ mode: string; /** * Whether to show image dimensions in the gallery. * @example true */ showDimensions: boolean; }; /** * Limits for thumbnail sizes. */ thumblimits: Record<string, number>; /** * Image size limits for different resolutions. */ imagelimits: Record<string, { width: number; height: number; }>; /** * URL to the site's favicon. * @example "https://en.wikipedia.org/static/favicon/wikipedia.ico" */ favicon: string; /** * The provider for the central user authentication system. * @example "CentralAuth" */ centralidlookupprovider: string; /** * A list of all available central user authentication providers. * @example ["CentralAuth", "local"] */ allcentralidlookupproviders: string[]; /** * Whether interwiki magic is enabled. * @example true */ interwikimagic: boolean; /** * Magic links configurations for different types. */ magiclinks: { /** * Whether ISBN magic links are enabled. * @example false */ ISBN: boolean; /** * Whether PMID magic links are enabled. * @example false */ PMID: boolean; /** * Whether RFC magic links are enabled. * @example false */ RFC: boolean; }; /** * The collation for categories on the site. * @example "uca-default-u-kn" */ categorycollation: string; /** * Whether nofollow links are enabled for external links. * @example true */ nofollowlinks: boolean; /** * Exceptions to nofollow links (list of domains). * @example ["mediawiki.org", "wikibooks.org"] */ nofollownsexceptions: string[]; /** * Whether the site uses the Unicode normalization form C. * @example true */ unicodeNormalization: boolean; /** * Options related to the parsing and display of mathematical expressions. */ math: { enabled: false; } | { enabled: true; tex: string; svg: string; png: string; }; }; }; } /** * Represents the options for the MediaWiki API's `action=opensearch` endpoint. * Used to perform a search query on the wiki with specific parameters. * * @see https://www.mediawiki.org/wiki/API:Opensearch */ export interface MediaWikiQueryOpenSearchOptions { /** * The search query string to be used for the search. * @example "JavaScript" */ search: string; /** * A list of namespace IDs to filter the search results. * @example [0, 1, 2] */ namespace: number[]; /** * The maximum number of search results to return. * @example 10 */ limit: number; } /** * Represents the response from the MediaWiki API's `action=opensearch` endpoint. * Provides search results based on a query string. * * @see https://www.mediawiki.org/wiki/API:Opensearch */ export type MediaWikiQueryOpenSearchResponse = [ /** * The search query string that was used to perform the search. * @example "Hello World" */ query: string, /** * An array of search results titles. * @example ["Hello World", "\"Hello, World!\" program", "Hello World (film)", ...] */ results: string[], /** * An array of descriptions corresponding to each search result. * @example ["", "", "", ...] */ descriptions: string[], /** * An array of URLs corresponding to each search result. * @example ["https://en.wikipedia.org/wiki/Hello_World", "https://en.wikipedia.org/wiki/%22Hello,_World!%22_program", ...] */ urls: string[] ]; /** * Options for parsing wikitext or page content using the MediaWiki `action=parse` API. */ export interface MediaWikiQueryParseOptions { /** * Title of the page used to interpret the text. * Required when using `text`. * @example "Main_Page" */ title?: string; /** * Raw wikitext to parse. * Cannot be used together with `page` or `pageid`. * @example "Hello '''world'''!" */ text?: string; /** * Title of an existing page to parse. * Cannot be used together with `text` or `title`. * @example "Project:Sandbox" */ page?: string; /** * Page ID of an existing page to parse. * Overrides `page` if both are provided. * @example 174652 */ pageid?: number; /** * Whether to automatically resolve redirects for `page` or `pageid`. * @example true */ redirects?: boolean; /** * Custom CSS class used to wrap the parsed HTML output. * @example "mw-parser-output" */ wrapoutputclass?: string; } /** * Result returned by the MediaWiki `action=parse` API. */ export interface MediaWikiQueryParseResponse { warnings?: { parse?: { warnings: string; }; }; parse: { title: string; pageid: number; text: string; langlinks?: Array<{ lang: string; url: string; langname: string; autonym: string; title: string; }>; categories?: any[]; links?: any[]; templates?: any[]; images?: string[]; externallinks?: string[]; sections?: any[]; showtoc?: boolean; parsewarnings?: string[]; displaytitle?: string; iwlinks?: any[]; properties?: Record<string, string>; }; } /** * A helper class to wrap the parse response and provide convenience methods. */ export declare class MediaWikiQueryParseResponseClass implements MediaWikiQueryParseResponse { warnings?: { parse?: { warnings: string; }; }; parse: MediaWikiQueryParseResponse["parse"]; constructor(data: MediaWikiQueryParseResponse); /** * Returns the parsed text content of the page. * @example "Hello '''world'''!" */ text(): string; /** * Returns the parsed HTML content of the page. * @example "<p>Hello <strong>world</strong>!</p>" */ html(): string; /** * Returns the title of the page. * @example "Main Page" */ title(): string; /** * Returns a list of categories for the parsed page. * @example ["Living people", "Software developers", "Ukrainians"] */ categories(): string[]; } /** */ export interface MediaWikiQueryCategoriesOptions { /** * @example "Main_Page" */ title?: string; } /** * Result returned by the MediaWiki `action=parse` API. */ export interface MediaWikiQueryCategoriesResponse { /** * Continuation token for pagination. * This is optional and may not be present in all responses. */ continue: MediaWikiComprehensiveContinueBlock; /** * The main query result. * This contains the categories associated with the specified page. */ query: { normalized: MediaWikiQueryNormalizedItem[]; pages: MediaWikiQueryCategoriesItem[]; }; } /** * Represents the options for the MediaWiki API's `action=query&prop=revisions` endpoint. * Used to retrieve revision history for a specific page. */ export interface MediaWikiQueryRevisionsOptions { /** * The title of the page to retrieve revisions for. * @example "JavaScript" */ title: string; /** * The number of revisions to retrieve. * @example 5 */ rvlimit: number; } /** * Result returned by the MediaWiki `action=parse` API. * This contains the revisions associated with the specified page. */ export interface MediaWikiQueryRevisionsResponse extends MediaWikiBaseResponse { /** * Continuation token for pagination. * This is optional and may not be present in all responses. */ query: { /** * Information about normalized titles. */ normalized: MediaWikiQueryNormalizedItem[]; /** * Information about the revisions of the page. */ pages: MediaWikiQueryRevisionsI