The Page
class has the following properties:
pageid!: number; // id of page
ns!: number;
title!: string; // Title of page
contentmodel!: string;
pagelanguage!: string; // The language of the page
pagelanguagehtmlcode!: string;
pagelanguagedir!: string;
touched!: string;
lastrevid!: number; //The last rev id of the page
length!: number;
fullurl!: string; // The full url of the page
editurl!: string;
canonicalurl!: string;
revid!: number; // The revision id of the page
parentid!: number; // The parent id of the page
_summary!: wikiSummary; // Stores the summary in case it is preloaded or called on the page object earlier
_images!: Array<imageResult>; // Stores the images in case it is preloaded or called on the page object earlier
_content!: string; // Stores the content in case it is preloaded or called on the page object earlier
_html!: string; // Stores the html in case it is preloaded or called on the page object earlier
_categories!: Array<string>; // Stores the categories in case it is preloaded or called on the page object earlier
_references!: Array<string>; // Stores the references in case it is preloaded or called on the page object earlier
_links!: Array<string>; // Stores the links in case it is preloaded or called on the page object earlier
_coordinates!: coordinatesResult; // Stores the coordinates in case it is preloaded or called on the page object earlier
_langLinks!: Array<langLinksResult>; // Stores the langLinks in case it is preloaded or called on the page object earlier
_infobox!: any; // Stores the infobox in case it is preloaded or called on the page object earlier
_tables!: Array<any>; // Stores the tables in case it is preloaded or called on the page object earlier
_intro!: string; // Stores the intro in case it is preloaded or called on the page object earlier
_related!: Array<relatedResult>; // Stores the related info in case it is preloaded or called on the page object earlier
The page object has the following methods available on it :
Returns the summary for the page as wikiSummary object. Summary contains the title, page Id, introduction, main image and content urls for the page.
summary(pageOptions: pageOptions | undefined): Promise<wikiSummary>
- @param pageOptions - the options for the page
- @resultwikiSummary - the summary object for the wiki page
//example
const page = await wiki.page('Batman');
const summary = await page.summary({redirect: false});
Returns the introduction of the page as string
intro(pageOptions: pageOptions | undefined): Promise<string>
- @param pageOptions - the options for the page
//example
const page = await wiki.page('Batman');
const intro = await page.intro({redirect: false});
Returns the images present in the page.
For a main image, use the summary endpoint
images(listOptions: listOptions | undefined): Promise<Array<imageResult>>
- @param listOptions - the options for the page
- @result imageResult - the image results for the page
//example
const page = await wiki.page('Batman');
const images = await page.images({redirect: true, limit: 5});
Returns the html content of the page as a string
html = async (pageOptions?: pageOptions): Promise<string>
- @param pageOptions - the options for the page
//example
const page = await wiki.page('Batman');
const html = await page.intro({redirect: false});
Returns the related pages given for a a page.
related = async (pageOptions?: pageOptions): Promise<relatedResult>
- @param pageOptions - the options for the page
- @resultwikiSummary - the summary object for the wiki page
//example
const page = await wiki.page('Batman');
const related = await page.intro({redirect: false});
Gets the list of media items present in the page
media = async (pageOptions?: pageOptions): Promise<wikiMediaResult>
- @param pageOptions - the options for the page
- @resultwikiMediaResult - the media result object for the wiki page
//example
const page = await wiki.page('Batman');
const related = await page.intro({redirect: false});
Returns the plain text content of a page.
content = async (pageOptions?: pageOptions): Promise<string>
- @param pageOptions - the options for the page
//example
const page = await wiki.page('Batman');
const content = await page.intro({redirect: false});
Returns the categories as an array of string
categories = async (listOptions?: listOptions): Promise<Array<string>>
- @param listOptions - the options for the page
//example
const page = await wiki.page('Batman');
const categories = await page.categories({redirect: false, , limit: 5});
Returns the links present in the page
links = async (listOptions?: listOptions): Promise<Array<string>>
- @param listOptions - the options for the page
//example
const page = await wiki.page('Batman');
const links = await page.links({redirect: false, , limit: 5});
Returns the references and external links in a page.
references = async (listOptions?: listOptions): Promise<Array<string>>
- @param listOptions - the options for the page
//example
const page = await wiki.page('Batman');
const references = await page.references({redirect: false, , limit: 5});
Returns the coordinates of a page
coordinates = async (pageOptions?: pageOptions): Promise<coordinatesResult>
- @param pageOptions - the options for the page
- @resultcoordinatesResult - the coordinates result object for the wiki page
//example
const page = await wiki.page('Batman');
const coordinates = await page.coordinates({redirect: false});
Returns the language links present in the page
langLinks = async (listOptions?: listOptions): Promise<Array<langLinksResult>>
- @param listOptions - the options for the page
- @resultlangLinksResult - the langLinks result object
//example
const page = await wiki.page('Batman');
const langLinks = await page.langLinks({redirect: false, , limit: 5});
The infobox data(if present), as a JSON object.
infobox = async (pageOptions?: pageOptions): Promise<any>
- @param pageOptions - the options for the page
//example
const page = await wiki.page('Batman');
const info = await page.infobox({redirect: false});
The tables data in the page, if present as an array of json objects.
tables = async (pageOptions?: pageOptions): Promise<Array<any>>
- @param pageOptions - the options for the page
//example
const page = await wiki.page('Batman');
const tables = await page.tables({redirect: false});
Returns mobile-optimised HTML for a wiki page, given a title. Follows redirects by default.
mobileHtml = async (redirect?: boolean): Promise<notFound | string>
- @param redirect - whether to redirect in case of 302
const page = await wiki.page('John_Locke');
const htmlJohnLocke = page.mobileHtml();
console.log(htmlJohnLocke); // displays HTML for John Locke's wiki page
const page = await wiki.page('Disco_Stu');
const htmlDiscoStu = page.mobileHtml("Disco_Stu");
console.log(htmlDiscoStu); // redirects to List of recurring The Simpsons characters
const page = await wiki.page('Disco_Stu', {redirect: false});
console.log(page); // no result, as redirect is false
Returns the wikipedia link to pdf. Valid format
are a4
. letter
, legal
. Valid type
are desktop
, mobile
.(by default fetches a4
for desktop
).
pdf = async (pdfOptions?: pdfOptions): Promise<string>
- @param pdfOptions - the options for the pdf
//example
const page = await wiki.page('Batman');
const pdf = await page.pdf({type:'mobile', format: 'legal'});