Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parse() method #83

Merged
merged 2 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ Get entries form Special:Log - [read more](http://www.mediawiki.org/wiki/API:Log

Returns XML with preprocessed wikitext - [read more](https://www.mediawiki.org/wiki/API:Parsing_wikitext#expandtemplates)

### bot.parse(content, title, callback)

Returns parsed wikitext - [read more](https://www.mediawiki.org/wiki/API:Parsing_wikitext#parse)

### bot.fetchUrl(url, callback)

Makes a GET request to provided resource and returns its content.
Expand Down
18 changes: 18 additions & 0 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,24 @@ module.exports = (function() {
}, 'POST');
},

parse: function(text, title, callback) {
this.api.call({
action: 'parse',
text: text,
title: title,
contentmodel: 'wikitext',
generatexml: 1
}, function(err, data, next, raw) {
if (err) {
callback(err);
return;
}
var xml = getFirstItem(raw.parse.text);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will raw.parse.text be always set? Even when err is set?

var images = raw.parse.images;
callback(err, xml, images);
}, 'POST');
},

getRecentChanges: function(start, callback) {
var props = [
'title',
Expand Down