dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

Usage with other MediaWiki's #57

Closed ghost closed 6 years ago

ghost commented 6 years ago

Attempting to query http://oldschoolrunescape.wikia.com / http://oldschoolrunescape.wikia.com/api.php

const wiki = require('wikijs').default;
wiki({
    apiUrl: 'http://oldschoolrunescape.wikia.com/api.php',
    origin: null
}).search('Bob').then(data => console.log(data));

/* (node:324) UnhandledPromiseRejectionWarning: Unhandled promise rejection (reject
ion id: 1): TypeError: Cannot read property 'search' of undefined */

Not sure what is wrong. The GoT API works fine for me.

dijs commented 6 years ago

Let me take a look.

dijs commented 6 years ago

Ah ha!

Here is your problem.

{ servedby: 'ap-s140',
  error:
   { code: 'srsearch-text-disabled',
     info: 'text search is disabled' } }

They have text search disabled for their wiki...

dijs commented 6 years ago

I fixed the code to handle errors better though.

https://github.com/dijs/wiki/commit/fb683cfc857e7b40dbaa11f135b1f02dba9fff6a

dijs commented 6 years ago

Pushed that change in v4.2.1

ghost commented 6 years ago

My issue seems to be deeper than that, there is an odd difference in Wikia/MediaWiki/Fandom Wikia, the one I'm trying to access seems to have a different but very similar API, or possibly two API's, one being similar and one the same. I don't know your library is supposed to support whatever this is using, if so then this may be an issue.

To see what I mean, look here: http://oldschoolrunescape.wikia.com/api/v1/
I made my own Wikia on the same platform as the oldschoolrunescape wikia to test if its possible to enable the "Text Search" and I can't find any such option.

Excuse me if im mistaken at all, im a bit confused on the difference between the oldschoolrunescape wikia and the game of thrones one you provide, what I do know is that my one isn't self-hosted by the admins, its hosted by "FANDOM" and the game of thrones one is hosted by the admins.

dijs commented 6 years ago

I am learning the difference myself :/

Let's try to dig into this.

I am betting that they use the same underlying API base, but their configurations are very different.

Were you able to run any wikijs methods successfully on the runescape version?

ghost commented 6 years ago
const wiki = require('wikijs').default;

var osrswiki = wiki({
    apiUrl: 'http://oldschoolrunescape.wikia.com/api.php',
    origin: null
});

osrswiki.page('Quests').then(page => console.log(page));

/* Successful
{ raw:
   { pageid: 6930,
     ns: 0,
     title: 'Quests',
     touched: '2017-09-13T15:23:51Z',
     lastrevid: 4740981,
     length: 9074,
     fullurl: 'http://oldschoolrunescape.wikia.com/wiki/Quests',
     editurl: 'http://oldschoolrunescape.wikia.com/wiki/Quests?action=edit' },
  html: [Function: html],
  content: [Function: content],
  summary: [Function: summary],
  images: [Function: images],
  references: [Function: references],
  links: [Function: links],
  categories: [Function: categories],
  coordinates: [Function: coordinates],
  info: [Function: q],
  backlinks: [Function: backlinks],
  rawImages: [Function: h],
  mainImage: [Function: mainImage],
  rawInfo: [Function: p] }
  */

osrswiki.page('Quests').then(page => console.log(page.pageid));

/* Fail
undefined
*/

osrswiki.random(3).then(results => console.log(results[0]));

/* Successful
Returns 1 Random Page Name, e.g. "Woad seed"
*/

osrswiki.page('Quests').then(page => page.categories()).then(console.log);

/* Successful
[ 'Category:Free-to-play Quests',
  'Category:Interface',
  'Category:Quests' ]
*/

osrswiki.page('Quests').then(page => page.references()).then(console.log);

/* Fail
(node:7356) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): TypeError: Cannot read property 'map' of undefined
*/

osrswiki.page('Quests').then(page => page.summary()).then(console.log);

/* Fail
undefined
*/

osrswiki.page('Quests').then(page => page.mainImage()).then(console.log);

/* Successful
https://vignette.wikia.nocookie.net/2007scape/images/0/05/Quest_icon.png/revisio
n/latest?cb=20130216162745
*/

osrswiki.page('Quests').then(page => page.image()).then(console.log);

/* Fail
(node:7724) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): TypeError: page.image is not a function
*/

//Trying to request a page that doesnt exist
osrswiki.page('batman').then(console.log);

/* Fail
(node:5492) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): Error: No article found
*/

here are some tests I did

dijs commented 6 years ago

This is great work!

At the very least I think I can do better error handling around all of these methods and check if they are supported on each MediaWiki implementation.

dijs commented 6 years ago

But since SOME work and SOME don't, it really leads me to believe that this has everything to do with configuration of the wiki API...

ghost commented 6 years ago

I don't believe the API has been touched in any way at all by the admins/curators, if you create your own one here you can look at the settings/options, the possibilities i can think of is that FANDOM wiki's use an outdated API version (which is unlikely), or that FANDOM limits the API in some way, or perhaps its a modified/different API altogether.

dijs commented 6 years ago

You are probably right.

I am currently going through all the "Falied" methods you just outlined and trying to fix each one.

This way we support these other versions of the API.

ghost commented 6 years ago

Awesome. P.S There is almost definitely other methods/functions which don't work with this API that I haven't included (for full coverage you may want to check them all).

Also, making the library compatible with that API would make it compatible with all of the FANDOM-Wikias which is a pretty good change/update.

dijs commented 6 years ago

Totally agree.

dijs commented 6 years ago

Okay, been doing some research on some of the queries I run.

Here is an example.

In order to extract out the summary from the page, it looks like the query I use is based on a API "Extension". I am guessing these need to be turned on or installed I guess...

https://www.mediawiki.org/wiki/Extension:TextExtracts

dijs commented 6 years ago

I am crawling through this MediaWiki API documentation and am NOT finding any other way to extract text like I do now.... :/ This extension may be our only solution right now.

ghost commented 6 years ago

http://oldschoolrunescape.wikia.com/wiki/Special:Version http://community.wikia.com/wiki/Help:Extensions

There may be some helpful information on these pages, the first one shows the installed extensions and software versions

EDIT: Is this a solution? https://github.com/Wikia/app/tree/dev/extensions/wikia/MercuryApi (This extension is installed by default on FANDOM Wikias and may have what you need)