Difference between revisions of "Codebase"

From Wikidocumentaries
Jump to navigation Jump to search
(Wikidocumentaries)
(Calls)
 
(53 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
==Global variables==
 
==Global variables==
===Wikidocumentaries===
+
===wikidocumentaries===
Reads all values at time of page load from Wikipedia and Wikidata and prepares for the app
+
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).''
+
* '''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).''
+
* '''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
+
* '''headerImageURL'''
 
* wikipedia
 
* wikipedia
** excerptHTML
+
** '''excerptHTML''' - summary part of the Wikipedia article
** remainingHTML
+
** '''remainingHTML''' - remaining part of the Wikipedia article as a separate object.
** wikipediaURL
+
** '''wikipediaURL''' - link to the Wikipedia article in the user's language
* S
+
* wikidata
                id: 'P361',
+
** id
                label: 'osa kohdetta',
+
** instance_of
                value: 'Kaisaniemen puisto ja kasvitieteellinen puutarha',
+
*** id
                url: 'https://www.wikidata.org/wiki/Q30506322'
+
*** 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
  
==Data flow==
+
===basemaps===
In components e.g.
+
* id
* method '''wikidocumentaries'''
+
* title
** $store.state.wikidocumentaries
+
* imageURL
 +
* year
 +
* server
 +
* warperID
 +
* municipality
 +
* country
  
store/store.js
+
===state===
 +
* wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
 +
* wikidocumentaries: [[#wikidocumentaries|wikidocumentaries]]
 +
* shownImages (array)
 +
* timelineImages (array)
 +
* historicalMapSearchPageMap (array)
 +
* historicalMaps (array)
 +
* basemaps: [[#basemaps|basemaps]]
 +
** selectedBasemaps (array)
 +
** selectedBasemapOpacity (float)
 +
** shouldFitMapToBasemap (boolean)
 +
** photoOfTheDay (string) "https://upload.wikimedia.org/wikipedia/commons/a/ad/Kulutusosuuskuntien_Keskusliiton_kokoelma_D1974_11333A_%2830804608561%29.jpg",
 +
** mapOfTheDay
 +
*** id (string) "File:1900_Plan_af_Helsingfors_stad.tif"
 +
*** warperID (integer) 148
 +
*** server (string) "http://warper.wmflabs.org/"
 +
*** coordinates (array) [24.9351, 60.1658]
 +
** nearbyWikiItems (array)
  
<pre>
+
==Router==
const wikidocumentaries = {
+
#
    title: 'Vapaamuurarin hauta',
+
#: path: '/dev'
    description: 'Muistomerkki Helsingissä',
+
#: name: 'DevPage'
    headerImageURL: 'https://upload.wikimedia.org/wikipedia/commons/b/bf/Helsinki_Kaisaniemi_Freemason%27s_grave_1908_I_K_Inha.png',
+
#: component: devpage
    wikipedia: {
+
#
        excerptHTML: null,
+
#: path: '/'
        remainingHTML: null,
+
#: name: 'LandingPage'
        wikipediaURL: 'https://fi.wikipedia.org/wiki/Vapaamuurarin_hauta'
+
#: component: LandingPage
    },
+
#
    wikidata: {
+
#: path: '/wikipedia/:'''language'''/:'''topic''''
        id: 'Q5501061',
+
#: component: MainPage
        instance_of: {
+
#
            id: 'Q5003624',
+
#: path: '/:'''wikidata'''/:'''language'''?/:'''topic'''?'
            value: 'muistomerkki',
+
#: name: 'TopicPage'
            url: 'https://www.wikidata.org/wiki/Q5003624'
+
#: component: MainPage
        },
 
        statements: [
 
            {
 
                id: 'P361',
 
                label: 'osa kohdetta',
 
                value: 'Kaisaniemen puisto ja kasvitieteellinen puutarha',
 
                url: 'https://www.wikidata.org/wiki/Q30506322'
 
            },
 
        dates: [],
 
    },
 
    images: [
 
        {
 
            id: 'musketti.M012:HK19670603:7117',
 
            source: 'finna',
 
            imageURL: "https://www.finna.fi/Cover/Show?id=musketti.M012:HK19670603:7117&index=0&size=large",
 
            title: "Vapaamuurarin hauta Kaisaniemessä",
 
            authors: "Pietinen",
 
            institutions: "Museovirasto",
 
            infoURL: "https://www.finna.fi/Record/musketti.M012:HK19670603:7117",
 
            location: "Helsinki,",
 
            geoLocations: ["POLYGON((24.7828131 60.0999549, 24.8356577 60.130414, 24.8513844 60.2249765, 24.8419098 60.2212043, 24.8347825 60.2585099, 24.8677628 60.2523073, 24.9473908 60.2784652, 24.9731653 60.2643801, 25.0209862 60.2893227, 25.0882105 60.2713417, 25.0823359 60.2496391, 25.1358461 60.2372286, 25.1598757 60.2488133, 25.1425242 60.2697779, 25.2545116 60.2952274, 25.2509121 60.2734979, 25.2273451 60.2611057, 25.240926 60.246305, 25.2014099 60.2181613, 25.2204176 60.1997262, 25.1800446 60.0987408, 25.1693516 59.9434386, 24.9423061 59.922486, 24.7828131 60.0999549))"],
 
            year: 1932,
 
            license: "CC BY 4.0"
 
        },
 
    ],
 
    geo: {
 
        location: "POINT(24.943752 60.176013)",
 
        admin: "Helsinki"
 
    },
 
    topicStartYear: 1784,
 
}
 
  
export default new Vuex.Store({
+
==Wikidocumentaries-API==
    state: {
+
get
        wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
+
=== /wiki ===
        wikidocumentaries: wikidocumentaries,
+
app.get('/wiki', function(req, '''res''')
        shownImages: [],
+
* var '''language''' = req.query.language
        timelineImages: [],
+
* var '''topic''' = req.query.topic
        historicalMapSearchPageMap: null,
+
* var '''wikidata''' = req.query.wikidata
        historicalMaps: [],
+
* var wikidataByItemIdPromise('''wikidata''') - ''Retrieve all data from Wikidata based on a QID''
        basemaps: basemaps,
+
** var requestConfig
        selectedBasemaps: [],
+
*** baseURL: "https://www.wikidata.org/w/api.php"
        selectedBasemapOpacity: 0.7,
+
*** method: "get"
        shouldFitMapToBasemap: false,
+
*** responseType: 'json'
        photoOfTheDay: "https://upload.wikimedia.org/wikipedia/commons/a/ad/Kulutusosuuskuntien_Keskusliiton_kokoelma_D1974_11333A_%2830804608561%29.jpg",
+
*** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
        mapOfTheDay: {
+
*** params: action: "wbgetentities", ids: '''wikidata''', format: "json"
            id: "File:1900_Plan_af_Helsingfors_stad.tif",
+
** return axios.request(requestConfig).then((response) =>
            warperID: 148,
+
*** var '''item'''=response.data.entities['''wikidata''']
            server: "http://warper.wmflabs.org/",
+
*** combineResults('''res''', '''language''', '''wikidata''', '''item''')
            coordinates: [24.9351, 60.1658],
+
* var getWikidataItemIDPromise() - ''Get the QID based on a Wikipedia article name and language''
        },
+
** var requestConfig
        nearbyWikiItems: [],
+
*** baseURL: "https://" + '''language''' + ".wikipedia.org/w/api.php"
    },
+
*** method: "get"
    getters: {
+
*** responseType: 'json'
        topicStartYear: state => {
+
*** 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) =>
    mutations: {
+
*** if (response.data.query != undefined)
        resetState(state) {
+
**** 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) - ''Loop back to make the Wikidata query''
  
            state.wikidocumentariesDataState = WIKI.STATES.UNINITIALIZED;
+
====Functions====
 +
* combineResults('''res''', '''language''', wikidataItemID, wikidataItemResponse)
 +
** wikipediaSummaryPromise()
 +
** wikipediaHTMLPromise()
 +
** axios.all([wikipediaSummaryPromise(), wikipediaHTMLPromise(), wikidataItemResponse ])
 +
*** .then(axios.spread(function (wikipediaSummaryResponse, wikipediaHTMLResponse, wikidataItemResponse )
 +
*** .then((responseData)
 +
* convertToWikidocumentariesHTML(origHTML, '''topic''', '''language''')
 +
* findLabel(entities, id, language)
  
            state.wikidocumentaries = {
+
=== /wiki/items/by/latlon ===
                title: null,
+
* var '''language''' = req.query.language;
                description: null,
+
* var '''topic''' = req.query.topic;
                headerImageURL: null,
+
* var requestConfig
                wikipedia: {
+
**baseURL: 'https://query.wikidata.org/'
                    excerptHTML: null,
+
** 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'
                    remainingHTML: null,
+
** timeout: 20000
                    wikipediaURL: null,
+
** method: "get"
                },
+
**params: format: 'json'
                wikidata: {
+
* Response: wikiItems.push for each response.data.results.bindings
                    id: null,
+
** id: id,
                    instance_of: {
+
** title: response.data.results.bindings[i].label.value,
                        id: null,
+
** lat: Number(lat)
                        value: null,
+
** lon: Number(lon)
                        url: null
 
                    },
 
                    statements: [],
 
                    dates: [],
 
                },
 
                images: [],
 
                geo: {
 
                    location: null,
 
                    scale: null,
 
                    admin: null
 
                },
 
                topicStartYear: null
 
            };
 
            state.shownImages = [];
 
            state.timelineImages = [];
 
            state.historicalMapSearchPageMap = null;
 
            state.historicalMaps = [];
 
            state.basemaps = basemaps;
 
            state.selectedBasemaps = [];
 
            state.selectedBasemapOpacity = 0.7;
 
            state.shouldFitMapToBasemap = false;
 
            state.nearbyWikiItems = [];
 
        },
 
        setImagesShownOnMap(state, images) {
 
            state.shownImages = images;
 
        },
 
        setImagesShownOnTimeline(state, images) {
 
            state.timelineImages = images;
 
        },
 
        setHistoricalMapSearchPageMap(state, map) {
 
            state.historicalMapSearchPageMap = map;
 
        },
 
        setHistoricalMaps(state, maps) {
 
            state.historicalMaps = maps;
 
        },
 
        setSelectedBasemap(state, mapInfo) {
 
            state.selectedBasemaps = [mapInfo];
 
        },
 
        setSelectedBasemaps(state, mapInfos) {
 
            state.selectedBasemaps = mapInfos;
 
        },
 
        setSelectedBasemapOpacity(state, opacity) {
 
            state.selectedBasemapOpacity = opacity;
 
        },
 
        setShouldFitMapToBasemap(state, value) {
 
            state.shouldFitMapToBasemap = value;
 
        },
 
        setWikidocumentariesTopicTitle(state, title) {
 
            state.wikidocumentaries.title = title;
 
        },
 
        setWikidocumentariesTopicDescription(state, description) {
 
            state.wikidocumentaries.description = description;
 
        },
 
        setWikidata(state, wikidata) {
 
            state.wikidocumentaries.wikidata = wikidata;
 
        },
 
        setWikidataId(state, wikidataId) {
 
            state.wikidocumentaries.wikidataId = wikidataId;
 
        },
 
        setHeaderImageURL(state, URL) {
 
            state.wikidocumentaries.headerImageURL = URL;
 
        },
 
        setWikipediaExcerptHTML(state, html) {
 
            state.wikidocumentaries.wikipedia.excerptHTML = html;
 
        },
 
        setWikipediaRemainingHTML(state, html) {
 
            state.wikidocumentaries.wikipedia.remainingHTML = html;
 
        },
 
        setWikipediaURL(state, URL) {
 
            state.wikidocumentaries.wikipedia.wikipediaURL = URL;
 
        },
 
        setTopicGeoLocation(state, coordinates) {
 
            state.wikidocumentaries.geo.location = "POINT(" + coordinates.lon + " " + coordinates.lat + ")"
 
        },
 
        setWikidocumentariesDataState(state, value) {
 
            state.wikidocumentariesDataState = value;
 
        },
 
        setWikidocumentariesImages(state, images) {
 
            state.wikidocumentaries.images = images;
 
        },
 
        setTopicStartYear(state, year) {
 
            state.wikidocumentaries.topicStartYear = year;
 
        },
 
        setHistoricalBasemaps(state, basemaps) {
 
            state.basemaps = basemaps;
 
            if (basemaps.length > 0) {
 
                state.selectedBasemaps = [basemaps[0]];
 
            }
 
        },
 
        setNearbyWikiItems(state, items) {
 
            state.nearbyWikiItems = items;
 
        }
 
  
    },
+
=== /images ===
    actions: {
 
        updateWikidocumentaries({dispatch, commit}, params) {
 
        },
 
        async getWikiDocumentariesData(context, params) {
 
        },
 
        async getTopicImages({dispatch, commit}, params) {
 
        },
 
        async getHistoricalMaps({dispatch, commit}, locationParams) {
 
        },
 
        async getHistoricalMapsFromCommons(context, params) {
 
        },
 
        async getHistoricalMapsFromFinna(context, params) {
 
        },
 
        async getNearbyPlaces(context, params) {
 
        }
 
    }
 
});
 
  
function isWikidataBasedUnchangableStartYear(wikidocumentaries) {
+
Parameters
}
+
* language
 +
* topic
 +
* commons_category
  
function calculateTopicStartYearFromWikidata(wikidata, currentStartYear) {
+
Not in use
}
+
* lat
 +
* lon
 +
* maxradius
  
function createGetCommonsMapInfoTask(fileName) {
+
====Called from====
}
+
 
</pre>
+
====Calls====
 +
 
 +
=== /basemaps ===
 +
=== /geocode ===

Latest revision as of 10:04, 12 February 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

app.get('/wiki', function(req, res)

  • var language = req.query.language
  • var topic = req.query.topic
  • var wikidata = req.query.wikidata
  • var wikidataByItemIdPromise(wikidata) - Retrieve all data from Wikidata based on a QID
    • 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() - Get the QID based on a Wikipedia article name and language
    • 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) - Loop back to make the Wikidata query

Functions

  • combineResults(res, language, wikidataItemID, wikidataItemResponse)
    • wikipediaSummaryPromise()
    • wikipediaHTMLPromise()
    • axios.all([wikipediaSummaryPromise(), wikipediaHTMLPromise(), wikidataItemResponse ])
      • .then(axios.spread(function (wikipediaSummaryResponse, wikipediaHTMLResponse, wikidataItemResponse )
      • .then((responseData)
  • convertToWikidocumentariesHTML(origHTML, topic, language)
  • findLabel(entities, id, language)

/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

Parameters

  • language
  • topic
  • commons_category

Not in use

  • lat
  • lon
  • maxradius

Called from

Calls

/basemaps

/geocode