Difference between revisions of "Codebase"

From Wikidocumentaries
Jump to navigation Jump to search
(Wikidocumentaries-API)
(Wikidocumentaries-API)
Line 88: Line 88:
 
==Wikidocumentaries-API==
 
==Wikidocumentaries-API==
 
get
 
get
* /wiki
+
== /wiki ==
** var language = req.query.language
+
* var language = req.query.language
** var topic = req.query.topic
+
* var topic = req.query.topic
** var wikidata = req.query.wikidata
+
* var wikidata = req.query.wikidata
** var wikidataByItemIdPromise(wikidata)
+
* var wikidataByItemIdPromise(wikidata)
*** var requestConfig
 
**** baseURL: "https://www.wikidata.org/w/api.php"
 
**** method: "get"
 
**** responseType: 'json'
 
**** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
 
**** params: action: "wbgetentities", ids: wikidata, format: "json"
 
*** return axios.request(requestConfig).then((response) =>
 
**** var item=response.data.entities[wikidata]
 
**** combineResults(res, language, wikidata, item)
 
** var getWikidataItemIDPromise()
 
*** var requestConfig
 
**** baseURL: "https://" + language + ".wikipedia.org/w/api.php"
 
**** method: "get"
 
**** responseType: 'json'
 
**** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
 
**** params: action: "query", prop: "pageprops", ppprop: "wikibase_item", redirects: "resolve", titles: topic, format: "json"
 
*** return axios.request(requestConfig).then((response) =>
 
**** if (response.data.query != undefined)
 
***** var key=Object.keys(response.data.query.pages)[0]
 
***** var page=response.data.query.pages[key]
 
***** if (page["pageprops"] != undefined && page["pageprops"]["wikibase_item"]!=undefined)
 
****** wikidata=page["pageprops"]["wikibase_item"]
 
****** wikidataByItemIdPromise(wikidata)
 
* /wiki/items/by/latlon
 
** var language = req.query.language;
 
** var topic = req.query.topic;
 
 
** var requestConfig
 
** var requestConfig
***baseURL: 'https://query.wikidata.org/'
+
*** baseURL: "https://www.wikidata.org/w/api.php"
*** url: '/bigdata/namespace/wdq/sparql?query=SELECT%3Fitem(SAMPLE(%3Fitem_label)as%3Flabel)(SAMPLE(%3Flocation)as%3Flocation)WHERE%7BSERVICE%20wikibase%3Aaround%7B%3Fitem%20wdt%3AP625%3Flocation.bd%3AserviceParam%20wikibase%3Acenter"Point(' + req.query.lon + '%20' + req.query.lat + ')"%5E%5Egeo%3AwktLiteral.%20bd%3AserviceParam%20wikibase%3Aradius"' + req.query.radius / 1000 + '".%7DOPTIONAL%7B%3Fitem%20rdfs%3Alabel%3Fitem_label.%7D%7DGROUP%20BY%20%3Fitem'
 
*** timeout: 20000
 
 
*** method: "get"
 
*** method: "get"
***params: format: 'json'
+
*** responseType: 'json'
** Response: wikiItems.push for each response.data.results.bindings
+
*** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
*** id: id,
+
*** params: action: "wbgetentities", ids: wikidata, format: "json"
*** title: response.data.results.bindings[i].label.value,
+
** return axios.request(requestConfig).then((response) =>
*** lat: Number(lat)
+
*** var item=response.data.entities[wikidata]
*** lon: Number(lon)
+
*** combineResults(res, language, wikidata, item)
* /images
+
* var getWikidataItemIDPromise()
* /basemaps
+
** var requestConfig
* /geocode
+
*** baseURL: "https://" + language + ".wikipedia.org/w/api.php"
 +
*** method: "get"
 +
*** responseType: 'json'
 +
*** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
 +
*** params: action: "query", prop: "pageprops", ppprop: "wikibase_item", redirects: "resolve", titles: topic, format: "json"
 +
** return axios.request(requestConfig).then((response) =>
 +
*** if (response.data.query != undefined)
 +
**** var key=Object.keys(response.data.query.pages)[0]
 +
**** var page=response.data.query.pages[key]
 +
**** if (page["pageprops"] != undefined && page["pageprops"]["wikibase_item"]!=undefined)
 +
***** wikidata=page["pageprops"]["wikibase_item"]
 +
***** wikidataByItemIdPromise(wikidata)
 +
== /wiki/items/by/latlon ==
 +
* var language = req.query.language;
 +
* var topic = req.query.topic;
 +
* var requestConfig
 +
**baseURL: 'https://query.wikidata.org/'
 +
** url: '/bigdata/namespace/wdq/sparql?query=SELECT%3Fitem(SAMPLE(%3Fitem_label)as%3Flabel)(SAMPLE(%3Flocation)as%3Flocation)WHERE%7BSERVICE%20wikibase%3Aaround%7B%3Fitem%20wdt%3AP625%3Flocation.bd%3AserviceParam%20wikibase%3Acenter"Point(' + req.query.lon + '%20' + req.query.lat + ')"%5E%5Egeo%3AwktLiteral.%20bd%3AserviceParam%20wikibase%3Aradius"' + req.query.radius / 1000 + '".%7DOPTIONAL%7B%3Fitem%20rdfs%3Alabel%3Fitem_label.%7D%7DGROUP%20BY%20%3Fitem'
 +
** timeout: 20000
 +
** method: "get"
 +
**params: format: 'json'
 +
* Response: wikiItems.push for each response.data.results.bindings
 +
** id: id,
 +
** title: response.data.results.bindings[i].label.value,
 +
** lat: Number(lat)
 +
** lon: Number(lon)
 +
== /images ==
 +
== /basemaps ==
 +
== /geocode ==

Revision as of 08:29, 11 January 2019

Navigate the codebase

Global variables

wikidocumentaries

Reads all values at time of page load from Wikipedia and Wikidata and prepares for the app. Stored, updated add addressed at @/store/store.js

  • title - Wikidata title in the user's language. Add a fallback option and create a new property with knowledge about the original value (boolean exists or empty data).
  • description - Wikidata title in the user's language. Add a fallback option and create a new property with knowledge about the original value (boolean exists or empty data).
  • headerImageURL
  • wikipedia
    • excerptHTML - summary part of the Wikipedia article
    • remainingHTML - remaining part of the Wikipedia article as a separate object.
    • wikipediaURL - link to the Wikipedia article in the user's language
  • wikidata
    • id
    • instance_of
      • id
      • value
      • url
    • statements
      • id
      • label
      • value - This returns a string for an object, and the QID is only in the URL. The QID should be extracted already before this?
      • url
      • dates
  • images
    • id
    • source
    • imageURL
    • title
    • authors
    • institutions
    • infoURL
    • location
    • geoLocations
    • year
    • license
  • geo
    • location
    • admin
  • topicStartYear

basemaps

  • id
  • title
  • imageURL
  • year
  • server
  • warperID
  • municipality
  • country

state

Router

  1. path: '/dev'
    name: 'DevPage'
    component: devpage
  2. path: '/'
    name: 'LandingPage'
    component: LandingPage
  3. path: '/wikipedia/:language/:topic'
    component: MainPage
  4. path: '/:wikidata/:language?/:topic?'
    name: 'TopicPage'
    component: MainPage

Wikidocumentaries-API

get

/wiki

  • var language = req.query.language
  • var topic = req.query.topic
  • var wikidata = req.query.wikidata
  • var wikidataByItemIdPromise(wikidata)
    • var requestConfig
      • baseURL: "https://www.wikidata.org/w/api.php"
      • method: "get"
      • responseType: 'json'
      • headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
      • params: action: "wbgetentities", ids: wikidata, format: "json"
    • return axios.request(requestConfig).then((response) =>
      • var item=response.data.entities[wikidata]
      • combineResults(res, language, wikidata, item)
  • var getWikidataItemIDPromise()
    • var requestConfig
      • baseURL: "https://" + language + ".wikipedia.org/w/api.php"
      • method: "get"
      • responseType: 'json'
      • headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
      • params: action: "query", prop: "pageprops", ppprop: "wikibase_item", redirects: "resolve", titles: topic, format: "json"
    • return axios.request(requestConfig).then((response) =>
      • if (response.data.query != undefined)
        • var key=Object.keys(response.data.query.pages)[0]
        • var page=response.data.query.pages[key]
        • if (page["pageprops"] != undefined && page["pageprops"]["wikibase_item"]!=undefined)
          • wikidata=page["pageprops"]["wikibase_item"]
          • wikidataByItemIdPromise(wikidata)

/wiki/items/by/latlon

  • var language = req.query.language;
  • var topic = req.query.topic;
  • var requestConfig
    • baseURL: 'https://query.wikidata.org/'
    • url: '/bigdata/namespace/wdq/sparql?query=SELECT%3Fitem(SAMPLE(%3Fitem_label)as%3Flabel)(SAMPLE(%3Flocation)as%3Flocation)WHERE%7BSERVICE%20wikibase%3Aaround%7B%3Fitem%20wdt%3AP625%3Flocation.bd%3AserviceParam%20wikibase%3Acenter"Point(' + req.query.lon + '%20' + req.query.lat + ')"%5E%5Egeo%3AwktLiteral.%20bd%3AserviceParam%20wikibase%3Aradius"' + req.query.radius / 1000 + '".%7DOPTIONAL%7B%3Fitem%20rdfs%3Alabel%3Fitem_label.%7D%7DGROUP%20BY%20%3Fitem'
    • timeout: 20000
    • method: "get"
    • params: format: 'json'
  • Response: wikiItems.push for each response.data.results.bindings
    • id: id,
    • title: response.data.results.bindings[i].label.value,
    • lat: Number(lat)
    • lon: Number(lon)

/images

/basemaps

/geocode