Difference between revisions of "Codebase"

From Wikidocumentaries
Jump to navigation Jump to search
(Global variables)
(Calls)
 
(42 intermediate revisions by the same user not shown)
Line 50: Line 50:
 
* country
 
* country
  
==Data flow==
+
===state===
In components e.g.  
+
* wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
* method '''wikidocumentaries'''
+
* wikidocumentaries: [[#wikidocumentaries|wikidocumentaries]]
** $store.state.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)
  
store/store.js
+
==Router==
 +
#
 +
#: path: '/dev'
 +
#: name: 'DevPage'
 +
#: component: devpage
 +
#
 +
#: path: '/'
 +
#: name: 'LandingPage'
 +
#: component: LandingPage
 +
#
 +
#: path: '/wikipedia/:'''language'''/:'''topic''''
 +
#: component: MainPage
 +
#
 +
#: path: '/:'''wikidata'''/:'''language'''?/:'''topic'''?'
 +
#: name: 'TopicPage'
 +
#: component: MainPage
  
<pre>
+
==Wikidocumentaries-API==
const wikidocumentaries = {
+
get
    title: 'Vapaamuurarin hauta',
+
=== /wiki ===
    description: 'Muistomerkki Helsingissä',
+
app.get('/wiki', function(req, '''res''')
    headerImageURL: 'https://upload.wikimedia.org/wikipedia/commons/b/bf/Helsinki_Kaisaniemi_Freemason%27s_grave_1908_I_K_Inha.png',
+
* var '''language''' = req.query.language
    wikipedia: {
+
* var '''topic''' = req.query.topic
        excerptHTML: null,
+
* var '''wikidata''' = req.query.wikidata
        remainingHTML: null,
+
* var wikidataByItemIdPromise('''wikidata''') - ''Retrieve all data from Wikidata based on a QID''
        wikipediaURL: 'https://fi.wikipedia.org/wiki/Vapaamuurarin_hauta'
+
** var requestConfig
    },
+
*** baseURL: "https://www.wikidata.org/w/api.php"
    wikidata: {
+
*** method: "get"
        id: 'Q5501061',
+
*** responseType: 'json'
        instance_of: {
+
*** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
            id: 'Q5003624',
+
*** params: action: "wbgetentities", ids: '''wikidata''', format: "json"
            value: 'muistomerkki',
+
** return axios.request(requestConfig).then((response) =>
            url: 'https://www.wikidata.org/wiki/Q5003624'
+
*** var '''item'''=response.data.entities['''wikidata''']
        },
+
*** combineResults('''res''', '''language''', '''wikidata''', '''item''')
        statements: [
+
* var getWikidataItemIDPromise() - ''Get the QID based on a Wikipedia article name and language''
            {
+
** var requestConfig
                id: 'P361',
+
*** baseURL: "https://" + '''language''' + ".wikipedia.org/w/api.php"
                label: 'osa kohdetta',
+
*** method: "get"
                value: 'Kaisaniemen puisto ja kasvitieteellinen puutarha',
+
*** responseType: 'json'
                url: 'https://www.wikidata.org/wiki/Q30506322'
+
*** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
            },
+
*** params: action: "query", prop: "pageprops", ppprop: "wikibase_item", redirects: "resolve", titles: '''topic''', format: "json"
        dates: [],
+
** return axios.request(requestConfig).then((response) =>
    },
+
*** if (response.data.query != undefined)
    images: [
+
**** var key=Object.keys(response.data.query.pages)[0]
        {
+
**** var page=response.data.query.pages[key]
            id: 'musketti.M012:HK19670603:7117',
+
**** if (page["pageprops"] != undefined && page["pageprops"]["wikibase_item"]!=undefined)
            source: 'finna',
+
***** wikidata=page["pageprops"]["wikibase_item"]
            imageURL: "https://www.finna.fi/Cover/Show?id=musketti.M012:HK19670603:7117&index=0&size=large",
+
***** wikidataByItemIdPromise(wikidata) - ''Loop back to make the Wikidata query''
            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({
+
====Functions====
    state: {
+
* combineResults('''res''', '''language''', wikidataItemID, wikidataItemResponse)
        wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
+
** wikipediaSummaryPromise()
        wikidocumentaries: wikidocumentaries,
+
** wikipediaHTMLPromise()
        shownImages: [],
+
** axios.all([wikipediaSummaryPromise(), wikipediaHTMLPromise(), wikidataItemResponse ])
        timelineImages: [],
+
*** .then(axios.spread(function (wikipediaSummaryResponse, wikipediaHTMLResponse, wikidataItemResponse )
        historicalMapSearchPageMap: null,
+
*** .then((responseData)
        historicalMaps: [],
+
* convertToWikidocumentariesHTML(origHTML, '''topic''', '''language''')
        basemaps: basemaps,
+
* findLabel(entities, id, language)
        selectedBasemaps: [],
 
        selectedBasemapOpacity: 0.7,
 
        shouldFitMapToBasemap: false,
 
        photoOfTheDay: "https://upload.wikimedia.org/wikipedia/commons/a/ad/Kulutusosuuskuntien_Keskusliiton_kokoelma_D1974_11333A_%2830804608561%29.jpg",
 
        mapOfTheDay: {
 
            id: "File:1900_Plan_af_Helsingfors_stad.tif",
 
            warperID: 148,
 
            server: "http://warper.wmflabs.org/",
 
            coordinates: [24.9351, 60.1658],
 
        },
 
        nearbyWikiItems: [],
 
    },
 
    getters: {
 
        topicStartYear: state => {
 
        }
 
    },
 
    mutations: {
 
        resetState(state) {
 
  
            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