Skip to content

Latest commit

 

History

History
320 lines (248 loc) · 9.22 KB

PAGE.md

File metadata and controls

320 lines (248 loc) · 9.22 KB

Page

Highlights

Class Members

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

Functions

The page object has the following methods available on it :

summary()

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>
//example
const page = await wiki.page('Batman');
const summary = await page.summary({redirect: false});

intro()

Returns the introduction of the page as string

intro(pageOptions: pageOptions | undefined): Promise<string>
//example
const page = await wiki.page('Batman');
const intro = await page.intro({redirect: false});

images()

Returns the images present in the page.

For a main image, use the summary endpoint

images(listOptions: listOptions | undefined): Promise<Array<imageResult>>
//example
const page = await wiki.page('Batman');
const images = await page.images({redirect: true, limit: 5});

html()

Returns the html content of the page as a string

html = async (pageOptions?: pageOptions): Promise<string>
//example
const page = await wiki.page('Batman');
const html = await page.intro({redirect: false});

related()

Returns the related pages given for a a page.

related = async (pageOptions?: pageOptions): Promise<relatedResult>
//example
const page = await wiki.page('Batman');
const related = await page.intro({redirect: false});

media()

Gets the list of media items present in the page

media = async (pageOptions?: pageOptions): Promise<wikiMediaResult>
//example
const page = await wiki.page('Batman');
const related = await page.intro({redirect: false});

content()

Returns the plain text content of a page.

content = async (pageOptions?: pageOptions): Promise<string>
//example
const page = await wiki.page('Batman');
const content = await page.intro({redirect: false});

categories()

Returns the categories as an array of string

categories = async (listOptions?: listOptions): Promise<Array<string>>
//example
const page = await wiki.page('Batman');
const categories = await page.categories({redirect: false, , limit: 5});

links()

Returns the links present in the page

links = async (listOptions?: listOptions): Promise<Array<string>>
//example
const page = await wiki.page('Batman');
const links = await page.links({redirect: false, , limit: 5});

references()

Returns the references and external links in a page.

references = async (listOptions?: listOptions): Promise<Array<string>>
//example
const page = await wiki.page('Batman');
const references = await page.references({redirect: false, , limit: 5});

coordinates()

Returns the coordinates of a page

coordinates = async (pageOptions?: pageOptions): Promise<coordinatesResult>
//example
const page = await wiki.page('Batman');
const coordinates = await page.coordinates({redirect: false});

langLinks()

Returns the language links present in the page

langLinks = async (listOptions?: listOptions): Promise<Array<langLinksResult>>
//example
const page = await wiki.page('Batman');
const langLinks = await page.langLinks({redirect: false, , limit: 5});

infobox()

The infobox data(if present), as a JSON object.

infobox = async (pageOptions?: pageOptions): Promise<any>
//example
const page = await wiki.page('Batman');
const info = await page.infobox({redirect: false});

tables()

The tables data in the page, if present as an array of json objects.

tables = async (pageOptions?: pageOptions): Promise<Array<any>>
//example
const page = await wiki.page('Batman');
const tables = await page.tables({redirect: false});

mobileHtml()

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

pdf()

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>
//example
const page = await wiki.page('Batman');
const pdf = await page.pdf({type:'mobile', format: 'legal'});