kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
48 stars 6 forks source link

README: Question on edit page #10

Closed Cobertos closed 3 years ago

Cobertos commented 3 years ago

In the README, the section on editing a page does something I don't understand.

Here's the snippet in question

// edit page
(async () => {
    const enwiki = new Wikiapi;
    await enwiki.login('bot name', 'password', 'en');
    let page_data = await enwiki.page('Wikipedia:Sandbox');
    await enwiki.edit(function(page_data) {
        return page_data.wikitext
            + '\nTest edit using {{GitHub|kanasimi/wikiapi}}.';
    }, {bot: 1});

    // alternative method
    await enwiki.edit_page('Wikipedia:Sandbox', function(page_data) {
        return page_data.wikitext
            + '\nTest edit using {{GitHub|kanasimi/wikiapi}}.';
    }, {bot: 1, nocreate: 1, minor: 1});

    console.log('Done.');
})();

It first retrieves the page data with let page_data = await enwiki.page('Wikipedia:Sandbox'); but then never uses page_data. Inside all of the edit and edit_page methods, page_data is passed in by the caller and shadows the outer variable.

Does this mean edit will do a .page() call internally for you? Is the await enwiki.page() call not needed then? Or should it be that edit actually doesn't get passed page_data?

kanasimi commented 3 years ago

Hi. I have edit the document and hope this helps understand.