Skip to content
Engelbert Niehaus edited this page May 1, 2019 · 20 revisions

Applications of wtf_wikipedia

Wiki2Reveal - on the fly cross compilation into a Presentation

Download of Wiki Markdown

If you just want the source text of an MediaWiki article, call the API in the browser. The following example just downloads an article about Toronto from the english Wikipedia and the learning resource about Water from english Wikiversity.

var wtf = require('wtf_wikipedia');

//call the API and process the  markup 'pWikiSource' in the callback function of the API
wtf.fetch('Toronto', 'en', function(err, doc) {
  // do something with parsed document in doc returned by the callback function 
  console.log("JSON: doc="+JSON.stringify(doc,null,2))
});

You can fetch article e.g. from Wikiversity from the url: [https:// en.wikiversity.org/wiki/Water](https:// en.wikiversity.org/wiki/Water) with

wtf.fetch('Water', 'enwikiversity', function(pError, pDoc) {
  // do something with parsed document in doc 
  // returned by the callback function
  if (pError) {
    console.error("ERROR: "+pError)
  } else {
    console.log("JSON: doc="+JSON.stringify(pDoc,null,2))
  }
});

Remark: To distinguish local variables from parameters of functions a preceeding p can used to indicate that (e.g. pWikiSource). This denomination of parameters variables is just a support for reading the code without any impact on the Javascript interpretation of code.

WikiID: Language and Domainname

You can retrieve the Wiki markdown from different MediaWiki products of the WikiFoundation. The domain name includes the Wiki product (e.g. Wikipedia or Wikiversity) and a language. The WikiID encoded the language and the domain determines the API that is called for fetching the source Wiki. The following WikiIDs are referring to the following domain name.

If you use just the language identifier en then wtf_wikipedia assumes that the wiki is Wikipedia. The same is applied if you just use enwiki. Due to the fact that the Wiki Foundation has severval MediaWikis with a different content scope, also enwiki is mapped to the english Wikipedia.

var wtf = require('wtf_wikipedia');

// Fetch the article about '3D Modelling' in english Wikiversity from the domain https://en.wikiversity.org
// call the API and process the  markup 'pWikiSource' in the callback function of the API
wtf.fecth('3D Modelling', 'enwikiversity', function(pWikiSource) {
  // do something with wiki markup return by the callback function in the parameter pWikiSource (String)
});

If you want to fetch Wiki markdown with a different language (e.g. german Wikiversity) use the appropriate language ID (e.g. de for german).

Extended Wiki ID in site_map.js

In previous versions of wtf_wikipedia the wiki identifier (wikiid) used for Wikipedia the domain specification wiki. To be consistent with wiki product specification part in the domain name wikipedia the following wiki IDs are added to list of Wiki ID mapping (defined in the file /src/data/site_map.js as hash).

The additional entries for a consistent WikiID mapping are added with a regular expression (Perl-like)

Fetch with an Wiki URL

If you can set up you own Media Wiki or want to fetch from an other Media Wiki which was not hosted by the Wiki Foundation, then you have to pass the wikiURL as options to wtf.fetch

Clone this wiki locally