UNPKG

mwn

Version:

JavaScript & TypeScript MediaWiki bot framework for Node.js

159 lines (158 loc) 6.11 kB
import type { MwnTitle } from './title'; import type { Mwn, EditTransform } from './bot'; import type { ApiDeleteParams, ApiEditPageParams, ApiMoveParams, ApiPurgeParams, ApiQueryAllPagesParams, ApiQueryLogEventsParams, ApiQueryRevisionsParams, ApiUndeleteParams } from 'types-mediawiki-api'; import { ApiRevision, LogEvent } from './api_response_types'; export interface MwnPageStatic { new (title: MwnTitle | string, namespace?: number): MwnPage; } export interface MwnPage extends MwnTitle { getTalkPage(): MwnPage; getSubjectPage(): MwnPage; /** * Check if page exists. */ exists(): Promise<boolean>; /** * Get page wikitext */ text(): Promise<string>; /** * Get page categories * @returns {Promise<String[]>} Resolved with array of page names */ categories(): Promise<string[]>; /** * Get templates transcluded on the page * @returns {Promise<String[]>} Resolved with array of page names */ templates(): Promise<string[]>; /** * Get links on the page * @returns {Promise<String[]>} Resolved with array of page names */ links(): Promise<string[]>; /** * Get list of pages linking to this page * @returns {Promise<String[]>} */ backlinks(): Promise<string[]>; /** * Get list of pages transcluding this page * @returns {Promise<String[]>} */ transclusions(): Promise<string[]>; /** * Returns list of images on the page * @returns {Promise<String[]>} - array elements don't include File: prefix */ images(): Promise<string[]>; /** * Returns list of external links on the page * @returns {Promise<String[]>} */ externallinks(): Promise<string[]>; /** * Returns list of subpages of the page * @returns {Promise<String[]>} */ subpages(options?: ApiQueryAllPagesParams): Promise<string[]>; /** * Check if page is redirect or not * @returns {Promise<boolean>} */ isRedirect(): Promise<boolean>; /** * Get redirect target. * Returns the same page name if the page is not a redirect. * @returns {Promise<string>} */ getRedirectTarget(): Promise<string>; /** * Get username of the page creator * @returns {Promise<string>} */ getCreator(): Promise<string>; /** * Get username of the last deleting admin (or null) * @returns {Promise<string>} */ getDeletingAdmin(): Promise<string>; /** * Get short description, either the local one (for English Wikipedia) * or the one from wikidata. * @param {Object} customOptions * @returns {Promise<string>} */ getDescription(customOptions?: any): Promise<string>; /** * Get the edit history of the page * @param {string|string[]} props - revision properties to fetch, by default content is * excluded * @param {number} [limit=50] - number of revisions to fetch data about * @param {Object} customOptions - custom API options * @returns {Promise<Object[]>} - resolved with array of objects representing * revisions, eg. { revid: 951809097, parentid: 951809097, timestamp: * "2020-04-19T00:45:35Z", comment: "Edit summary" } */ history(props: ApiQueryRevisionsParams['rvprop'], limit: number, customOptions?: ApiQueryRevisionsParams): Promise<ApiRevision[]>; historyGen(props: ApiQueryRevisionsParams['rvprop'], customOptions?: ApiQueryRevisionsParams): AsyncGenerator<ApiRevision>; /** * Get the page logs. * @param {string|string[]} props - data about log entries to fetch * @param {number} limit - max number of log entries to fetch * @param {string} type - type of log to fetch, can either be an letype or leaction * Leave undefined (or null) to fetch all log types * @param {Object} customOptions * @returns {Promise<Object[]>} - resolved with array of objects representing * log entries, eg. { ns: '0', title: 'Main Page', type: 'delete', user: 'Example', * action: 'revision', timestamp: '2020-05-05T17:13:34Z', comment: 'edit summary' } */ logs(props: ApiQueryLogEventsParams['leprop'], limit?: number, type?: string, customOptions?: ApiQueryLogEventsParams): Promise<LogEvent[]>; logsGen(props: ApiQueryLogEventsParams['leprop'], type?: string, customOptions?: ApiQueryLogEventsParams): AsyncGenerator<LogEvent>; /** * Get page views data (only for Wikimedia wikis) * @see https://wikitech.wikimedia.org/wiki/Analytics/AQS/Pageviews * @param options */ pageViews(options?: PageViewOptions): Promise<PageViewData[]>; /** * Query the top contributors to the article using the WikiWho API. * This API has a throttling of 2000 requests a day. * Supported for EN, DE, ES, EU, TR Wikipedias only * @see https://wikiwho.wmflabs.org/ */ queryAuthors(): Promise<AuthorshipData>; edit(transform: EditTransform): Promise<any>; save(text: string, summary?: string, options?: ApiEditPageParams): Promise<any>; newSection(header: string, message: string, additionalParams?: ApiEditPageParams): Promise<any>; move(target: string, summary: string, options?: ApiMoveParams): Promise<any>; delete(summary: string, options?: ApiDeleteParams): Promise<any>; undelete(summary: string, options?: ApiUndeleteParams): Promise<any>; purge(options?: ApiPurgeParams): Promise<any>; } export default function (bot: Mwn): MwnPageStatic; export interface PageViewOptions { access?: 'all-access' | 'desktop' | 'mobile-app' | 'mobile-web'; agent?: 'all-agents' | 'user' | 'spider' | 'automated'; granularity?: 'daily' | 'monthly'; start?: Date; end?: Date; } export interface PageViewData { project: string; article: string; granularity: string; timestamp: string; access: string; agent: string; views: number; } export interface AuthorshipData { totalBytes: number; users: Array<{ id: number; name: string; bytes: number; percent: number; }>; }