oliver-moran / mediawiki Goto Github PK
View Code? Open in Web Editor NEWA JavaScript framework for the MediaWiki API.
License: GNU General Public License v3.0
A JavaScript framework for the MediaWiki API.
License: GNU General Public License v3.0
It would be handy if this library handled query continuations when the number of results requested is greater than the max limit for the request on the API's side. Basically, checking the returned parameter "query-continue", re-running the search starting from that identifier, and appending the results until "query-continue" is empty.
{ error: { code: 'mustpostparams', info: 'The following parameter was found in the query string, but must be in the POST body: lgpassword.', '*': 'See http://wiki-test:8080/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.' } }
I am currently working on a Discord Bot, which should send the user the text of a page, if it exists. If it doesn't exist, it should give the user an error message. Sending the text for pages works fine, but if a page doesn't exist, the bot just crashes and prints out
How can I stop the application from crashing and make it do something, if the page doesn't exist?
When I try this:
var MediaWiki = require('mediawiki');
var bot = new MediaWiki.Bot({
endpoint: "https://en.wikipedia.org/w/api.php",
rate: 60e3 / 10,
userAgent: "ExampleBot <https://en.wiktionary.org/wiki/User:Example>",
byeline: "(example bot edit)"
});
bot.login('my_username', 'my_password').complete(function (username) {
console.log(['Username:', username].join(' '));
bot.edit('User:My_Page', 'Testing via API', 'This is a test.')
.complete(function (title, revision, date) {
console.log(title);
console.log(revision);
console.log(date.toString());
}).error(function (err) {
console.log('Error');
console.log(err);
});
});
I get this:
TypeError: Cannot read property 'result' of undefined
at Bot.<anonymous> (/home/username/src/exercises/mediawiki_api/node_modules/mediawiki/mediawiki.js:485:34)
at Bot._processResponse (/home/username/src/exercises/mediawiki_api/node_modules/mediawiki/mediawiki.js:227:29)
at Request._callback (/home/username/src/exercises/mediawiki_api/node_modules/mediawiki/mediawiki.js:179:34)
at Request.self.callback (/home/username/src/exercises/mediawiki_api/node_modules/mediawiki/node_modules/request/request.js:121:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (/home/username/src/exercises/mediawiki_api/node_modules/mediawiki/node_modules/request/request.js:978:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/home/username/src/exercises/mediawiki_api/node_modules/mediawiki/node_modules/request/request.js:929:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
When I console.log
the data variable on line 484 of mediawiki.js, I get:
Username: my_username
{ servedby: 'mw1189',
error:
{ code: 'mustposttoken',
info: 'The \'token\' parameter was found in the query string, but must be in the POST body',
'*': 'See https://en.wikipedia.org/w/api.php for API usage' } }
/home/runner/MyBot/node_modules/mediawiki/mediawiki.js:50
Promise.prototype._onError = function (err) { throw err; };
^
Error: 301
at Request._callback (/home/runner/MyBot/node_modules/mediawiki/mediawiki.js:181:46)
at Request.self.callback (/home/runner/MyBot /node_modules/mediawiki/node_modules/request/request.js:121:22)
at Request.emit (events.js:314:20)
at Request.EventEmitter.emit (domain.js:483:12)
at Request.<anonymous> (/home/runner/MyBot/node_modules/mediawiki/node_modules/request/request.js:978:14)
at Request.emit (events.js:326:22)
at Request.EventEmitter.emit (domain.js:483:12)
at IncomingMessage.<anonymous> (/home/runner/MyBot/node_modules/mediawiki/node_modules/request/request.js:929:12)
at IncomingMessage.emit (events.js:326:22)
at IncomingMessage.EventEmitter.emit (domain.js:483:12)
repl process died unexpectedly: exit status 1
Is my result trying to run:
const MediaWiki = require( 'mediawiki' );
var MyBot = new MediaWiki.Bot( {
endpoint: "https://www.mywiki.com/api.php",
rate: 5000,
userAgent: "MyBot <https://mywiki.com/page/User:MyBot>"
} );
MyBot
.login( process.env.WIKI_USERNAME, process.env.WIKI_PASSWORD )
.complete( function ( username ) {
console.log( 'Logged in to MyWiki as %s', username );
} );
I'm running:
Can you add new functions for move, delete, add/remove watchlist, protect/unprotecting pages? Most importantly, moving and deleting pages. would be very useful.
Whenever I try to add a redirect, I get the following error stack. I can create/overwrite a page just fine, however it fails when I set the content to "#REDIRECT [["+message.gamename+"]]"
(message.gamename
has been sucessfully used previously in the same script as the title of an article, so the problem isn't there). When I escape #
with a \
, I get the same issue.
TypeError: Cannot read property '0' of undefined
at /home/efreak/chatbot-efreak/node_modules/mediawiki/mediawiki.js:480:69
at Array.forEach (native)
at Bot.<anonymous> (/home/efreak/chatbot-efreak/node_modules/mediawiki/mediawiki.js:477:19)
at Bot._processResponse (/home/efreak/chatbot-efreak/node_modules/mediawiki/mediawiki.js:227:29)
at Request._callback (/home/efreak/chatbot-efreak/node_modules/mediawiki/mediawiki.js:179:34)
at Request.self.callback (/home/efreak/chatbot-efreak/node_modules/request/request.js:121:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (/home/efreak/chatbot-efreak/node_modules/request/request.js:978:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/home/efreak/chatbot-efreak/node_modules/request/request.js:929:12)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.