mwn
Version:
JavaScript & TypeScript MediaWiki bot framework for Node.js
132 lines (131 loc) • 3.56 kB
TypeScript
/**
*
* This class is a substantial copy of mw.Title in the MediaWiki on-site
* JS interface.
*
* Adapted from <https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/master/resources/src/mediawiki.Title/>
* (GNU GPL v2)
*
*/
export interface MwnTitleStatic {
new (title: string, namespace?: number): MwnTitle;
idNameMap: {
[namespaceId: number]: string;
};
nameIdMap: {
[namespaceName: string]: number;
};
legaltitlechars: string;
caseSensitiveNamespaces: Array<number>;
processNamespaceData(json: SiteInfoQueryResponse): void;
checkData(): void;
newFromText(title: string, namespace?: number): MwnTitle | null;
makeTitle(namespace: number, title: string): MwnTitle | null;
isTalkNamespace(namespaceId: number): boolean;
phpCharToUpper(chr: string): string;
}
export interface MwnTitle {
title: string;
namespace: number;
fragment: string;
/**
* Get the namespace number
*
* Example: 6 for "File:Example_image.svg".
*/
getNamespaceId(): number;
/**
* Get the namespace prefix (in the content language)
*
* Example: "File:" for "File:Example_image.svg".
* In #NS_MAIN this is '', otherwise namespace name plus ':'
*/
getNamespacePrefix(): string;
/**
* Get the main page name
*
* Example: "Example_image.svg" for "File:Example_image.svg".
*/
getMain(): string;
/**
* Get the main page name (transformed by #text)
* Example: "Example image.svg" for "File:Example_image.svg".
*/
getMainText(): string;
/**
* Get the full page name
*
* Example: "File:Example_image.svg".
* Most useful for API calls, anything that must identify the "title".
*/
getPrefixedDb(): string;
/**
* Get the full page name (transformed by #text)
*
* Example: "File:Example image.svg" for "File:Example_image.svg".
*/
getPrefixedText(): string;
/**
* Get the fragment (if any).
*
* Note that this method (by design) does not include the hash character and
* the value is not url encoded.
*/
getFragment(): string | null;
/**
* Check if the title is in a talk namespace
*/
isTalkPage(): boolean;
/**
* Get the title for the associated talk page
* Returns null if not available
*/
getTalkPage(): MwnTitle | null;
/**
* Get the title for the subject page of a talk page
* Returns null if not available
*/
getSubjectPage(): MwnTitle | null;
/**
* Check if the title can have an associated talk page
*/
canHaveTalkPage(): boolean;
/**
* Get the extension of the page name (if any)
*/
getExtension(): string | null;
/**
* Shortcut for appendable string to form the main page name.
*
* Returns a string like ".json", or "" if no extension.
*/
getDotExtension(): string;
/**
* @alias #getPrefixedDb
* @method
*/
toString(): string;
/**
* @alias #getPrefixedText
* @method
*/
toText(): string;
}
export type SiteInfoQueryResponse = {
query: {
general: {
legaltitlechars: string;
};
namespaces: Record<string, {
name: string;
id: number;
canonical: string;
case: string;
}>;
namespacealiases: {
alias: string;
id: number;
}[];
};
};
export default function (): MwnTitleStatic;