Difference between revisions of "Codebase"

From Wikidocumentaries
Jump to navigation Jump to search
(Calls)
 
(57 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Navigate the codebase
 
Navigate the codebase
  
Components
+
==Global variables==
* method '''wikidocumentaries'''
+
===wikidocumentaries===
** $store.state.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
  
store/store.js
+
===basemaps===
 +
* id
 +
* title
 +
* imageURL
 +
* year
 +
* server
 +
* warperID
 +
* municipality
 +
* country
  
<pre>
+
===state===
const wikidocumentaries = {
+
* wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
    title: 'Vapaamuurarin hauta',
+
* wikidocumentaries: [[#wikidocumentaries|wikidocumentaries]]
    description: 'Muistomerkki Helsingissä',
+
* shownImages (array)
    headerImageURL: 'https://upload.wikimedia.org/wikipedia/commons/b/bf/Helsinki_Kaisaniemi_Freemason%27s_grave_1908_I_K_Inha.png',
+
* timelineImages (array)
    wikipedia: {
+
* historicalMapSearchPageMap (array)
        excerptHTML: null,
+
* historicalMaps (array)
        remainingHTML: null,
+
* basemaps: [[#basemaps|basemaps]]
        wikipediaURL: 'https://fi.wikipedia.org/wiki/Vapaamuurarin_hauta'
+
** selectedBasemaps (array)
    },
+
** selectedBasemapOpacity (float)
    wikidata: {
+
** shouldFitMapToBasemap (boolean)
        id: 'Q5501061',
+
** photoOfTheDay (string) "https://upload.wikimedia.org/wikipedia/commons/a/ad/Kulutusosuuskuntien_Keskusliiton_kokoelma_D1974_11333A_%2830804608561%29.jpg",
        instance_of: {
+
** mapOfTheDay
            id: 'Q5003624',
+
*** id (string) "File:1900_Plan_af_Helsingfors_stad.tif"
            value: 'muistomerkki',
+
*** warperID (integer) 148
            url: 'https://www.wikidata.org/wiki/Q5003624'
+
*** server (string) "http://warper.wmflabs.org/"
        },
+
*** coordinates (array) [24.9351, 60.1658]
        statements: [
+
** nearbyWikiItems (array)
            {
 
                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({
+
==Router==
    state: {
+
#
        wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
+
#: path: '/dev'
        wikidocumentaries: wikidocumentaries,
+
#: name: 'DevPage'
        shownImages: [],
+
#: component: devpage
        timelineImages: [],
+
#
        historicalMapSearchPageMap: null,
+
#: path: '/'
        historicalMaps: [],
+
#: name: 'LandingPage'
        basemaps: basemaps,
+
#: component: LandingPage
        selectedBasemaps: [],
+
#
        selectedBasemapOpacity: 0.7,
+
#: path: '/wikipedia/:'''language'''/:'''topic''''
        shouldFitMapToBasemap: false,
+
#: component: MainPage
        photoOfTheDay: "https://upload.wikimedia.org/wikipedia/commons/a/ad/Kulutusosuuskuntien_Keskusliiton_kokoelma_D1974_11333A_%2830804608561%29.jpg",
+
#
        mapOfTheDay: {
+
#: path: '/:'''wikidata'''/:'''language'''?/:'''topic'''?'
            id: "File:1900_Plan_af_Helsingfors_stad.tif",
+
#: name: 'TopicPage'
            warperID: 148,
+
#: component: MainPage
            server: "http://warper.wmflabs.org/",
 
            coordinates: [24.9351, 60.1658],
 
        },
 
        nearbyWikiItems: [],
 
    },
 
    getters: {
 
        topicStartYear: state => {
 
           
 
            var startYear = (new Date()).getFullYear();
 
  
            if (state.wikidocumentaries.topicStartYear != undefined) {
+
==Wikidocumentaries-API==
                startYear = state.wikidocumentaries.topicStartYear;
+
get
            }
+
=== /wiki ===
            if (state.wikidocumentaries.images.length > 0) {
+
app.get('/wiki', function(req, '''res''')
                for (var i = 0; i < state.wikidocumentaries.images.length; i++) {
+
* var '''language''' = req.query.language
                    if (state.wikidocumentaries.images[i].year != null &&
+
* var '''topic''' = req.query.topic
                        startYear > state.wikidocumentaries.images[i].year) {
+
* var '''wikidata''' = req.query.wikidata
                        if (!isWikidataBasedUnchangableStartYear(state.wikidocumentaries)) {
+
* var wikidataByItemIdPromise('''wikidata''') - ''Retrieve all data from Wikidata based on a QID''
                            startYear = state.wikidocumentaries.images[i].year;
+
** 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''
  
            return startYear;
+
====Functions====
        }
+
* combineResults('''res''', '''language''', wikidataItemID, wikidataItemResponse)
    },
+
** wikipediaSummaryPromise()
    mutations: {
+
** wikipediaHTMLPromise()
        resetState(state) {
+
** axios.all([wikipediaSummaryPromise(), wikipediaHTMLPromise(), wikidataItemResponse ])
 +
*** .then(axios.spread(function (wikipediaSummaryResponse, wikipediaHTMLResponse, wikidataItemResponse )
 +
*** .then((responseData)
 +
* convertToWikidocumentariesHTML(origHTML, '''topic''', '''language''')
 +
* findLabel(entities, id, language)
  
            state.wikidocumentariesDataState = WIKI.STATES.UNINITIALIZED;
+
=== /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)
  
            state.wikidocumentaries = {
+
=== /images ===
                title: null,
 
                description: null,
 
                headerImageURL: null,
 
                wikipedia: {
 
                    excerptHTML: null,
 
                    remainingHTML: null,
 
                    wikipediaURL: null,
 
                },
 
                wikidata: {
 
                    id: null,
 
                    instance_of: {
 
                        id: null,
 
                        value: null,
 
                        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;
 
        }
 
  
    },
+
Parameters
    actions: {
+
* language
        updateWikidocumentaries({dispatch, commit}, params) {
+
* topic
        },
+
* commons_category
        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) {
+
Not in use
}
+
* lat
 +
* lon
 +
* maxradius
  
function calculateTopicStartYearFromWikidata(wikidata, currentStartYear) {
+
====Called from====
}
 
  
function createGetCommonsMapInfoTask(fileName) {
+
====Calls====
}
+
 
</pre>
+
=== /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