Skip to content

Commit

Permalink
Merge pull request #19 from DFelten/add-read-with-props
Browse files Browse the repository at this point in the history
Add method for read page with props
  • Loading branch information
gesinn-it-gea authored Jan 27, 2019
2 parents cffa577 + a0382b2 commit bf08e73
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ bot.read('Test Page|MediaWiki:Sidebar', {timeout: 8000}).then((response) => {
});
```
#### readWithProps(title, props, redirect, customRequestOptions)
Reads the content and meta-data of one (or many) wikipages based on specific parameters.
To fetch more than one page, separate the page names with `|`. To define multiple props separate them also with `|`.
* See https://www.mediawiki.org/wiki/API:Query
```js
bot.readWithProps('Test Page|MediaWiki:Sidebar', 'user|userid|content', true, {timeout: 8000}).then((response) => {
// Success
console.log(response.query.pages['1']['revisions'][0]['*']);
}).catch((err) => {
// Error
});
```
#### update(title, content, summary, customRequestOptions)
Updates a wiki page. If the page doesn't exist, it will fail.
* See https://www.mediawiki.org/wiki/API:Edit
Expand Down
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,31 @@ class MWBot {
return this.request(params, customRequestOptions);
}

/**
* Reads the content / and meta-data of one (or many) wikipages based on specific parameters
*
* @param {string} title For multiple Pages use: PageA|PageB|PageC
* @param {string} props For multiple Props use: user|userid|content
* @param {boolean} redirect If the page is a redirection, follow it or stay in the page
* @param {object} [customRequestOptions]
*
* @returns {bluebird}
*/
readWithProps(title, props, redirect, customRequestOptions) {
let params = {
action: 'query',
prop: 'revisions',
rvprop: props,
titles: title
}

if (!redirect) {
params.redirect = "redirect"
}

return this.request(params, customRequestOptions);
}

/**
* Edits a new wiki pages. Creates a new page if it does not exist yet.
*
Expand Down

0 comments on commit bf08e73

Please sign in to comment.