Modul:ProyekWiki Bahasa/pemeliharaan/peta/rawdata/2

local p = {}
local urlEncode = require('mw.uri').encode

function p.queryLink()
    -- Define the SPARQL query
    local sparqlQuery = [[
        SELECT ?id ?idLabel ?head
        (SAMPLE(?pop) AS ?populasi)
        (SAMPLE(?ison) AS ?iso)
        (SAMPLE(?glotton) AS ?glotto)
        (SAMPLE(?img) AS ?img_)
        (SAMPLE(?gmbr) AS ?gmbr_)
        (MIN(?partyId) AS ?geo)
        (SAMPLE (?idLabel) AS ?title)
        WHERE {
            ?id wdt:P31 wd:Q34770 .
            ?id wdt:P279 ?head .
            ?id wdt:P625 ?geo .
            SERVICE wikibase:label {
                bd:serviceParam wikibase:language 'id' .
                ?head rdfs:label ?headLabel .
                ?id rdfs:label ?idLabel .
            }
            OPTIONAL { ?id wdt:P220 ?ison . }
            OPTIONAL { ?id wdt:P1394 ?glotton . }
            OPTIONAL { ?id wdt:P18 ?img . }
            OPTIONAL { ?id wdt:P1098 ?pop . }
            OPTIONAL { ?id wdt:P1846 ?gmbr . }
            ?link schema:about ?head .
            ?link schema:isPartOf <https://wiki-indonesia.club/> .
            ?link2 schema:about ?id .
            ?link2 schema:isPartOf <https://wiki-indonesia.club/> .
        }
        GROUP BY ?id ?idLabel ?head ?headLabel ?link2 ?link ?geo
    ]]

    -- Create the URL for Wikidata Query Service
    local queryUrl = 'https://query.wikidata.org/#' .. urlEncode(sparqlQuery)

    -- Return a wikitext link to the query
    return '[ ' .. queryUrl .. ' Klik untuk melihat data bahasa di Wikidata Query Service ]'
end

return p