nodemw icon indicating copy to clipboard operation
nodemw copied to clipboard

getArticle not working with special characters in title

Open Juul opened this issue 8 years ago • 4 comments

The program below works for en.wikipedia.org but for openwetware.org it outputs "Got: undefined" and this is the actual response returned from the server:

{"warnings":{"main":{"*":"Unrecognized parameter: rand."}},"batchcomplete":"","query":{"pages":{"-1":{"title":"Main%20Page","invalidreason":"The requested page title contains invalid characters: \"%20\".","invalid":""}}}}
#!/usr/bin/env node

var mw = require('nodemw');

var client = new mw({
  protocol: "https",
  server: "openwetware.org",
  path: "/w",
  debug: true
});

client.getArticle("Main Page", function(err, data) {
  if(err) {
    console.error(err);
    process.exit(1);
  }

  console.log("Got:", data);
});

Juul avatar Dec 02 '17 00:12 Juul

I believe you have to replace spaces in the title with underscores.

macbre avatar Dec 02 '17 09:12 macbre

It works with spaces. I believe this pull request solves my problems.

Juul avatar Dec 05 '17 05:12 Juul

But it does not work for me (with your fix applied) :)

info:    nodemw v0.12.0 (node.js v6.12.0; linux x64)

macbre avatar Dec 05 '17 17:12 macbre

Ah yes there was another problem. The openwetware.org mediawiki installation has a different script path so the path option had to be set to "/mediawiki".

The script path on a given wiki installation is available via the Special:Version page. It would be really cool if nodemw could auto-detect the script path given e.g. a URL to an arbitrary page on the wiki.

Juul avatar Dec 05 '17 20:12 Juul