« Module:Utilisateur » : différence entre les versions

De ESCR
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Aucun résumé des modifications
 
Ligne 25 : Ligne 25 :
     local rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
     local rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
     local rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
     local rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
     local vcard = 'http://www.w3.org/2006/vcard/'
     local vcard = 'http://www.w3.org/2006/vcard/ns#'


     local subject = f.args.iri or linkedwiki.getCurrentIRI();  --find the iri of the current page
     local subject = f.args.iri or linkedwiki.getCurrentIRI();  --find the iri of the current page

Version actuelle datée du 4 octobre 2020 à 17:24

La documentation pour ce module peut être créée à Module:Utilisateur/doc

local p = {}

--[[ For test
frame = mw.getCurrentFrame() -- Get a frame object
newFrame = frame:newChild{ -- Get one with args
	title = 'Dupond Bertrand' ,
	 args = {
		iri = 'https://data.escr.fr/wiki/Utilisateur:Dupond_Bertrand' ,
		["nom"] = 'Dupond' ,
		["prénom"] = 'Bertrand',
		["type"] = 'Enseignant',
		["demo"] = '1'
	    }
}
mw.log(p.infobox( newFrame ) )
--]]

function p.infobox(f)
    local capiunto = require 'capiunto'
    local linkedwiki = require 'linkedwiki'
    
	linkedwiki.setCurrentFrame(mw.getCurrentFrame())
	
    -- init the prefix
    local rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    local rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
    local vcard = 'http://www.w3.org/2006/vcard/ns#'

    local subject = f.args.iri or linkedwiki.getCurrentIRI();  --find the iri of the current page

    local object = linkedwiki.new(subject,"https://data.escr.fr/data")
    --object:setDebug(true)
    
    if linkedwiki.isEmpty(f.args['demo']) then
		object:removeSubject() -- delete all triples of this subject
    
	    -- Save the data in the infobox in a knowledge base
	    mw.log(object:addPropertyWithIri(rdf .. 'type', vcard .. 'Individual'))
	    mw.log(object:addPropertyString(vcard .. 'fn', f.args['nom']..' '.. f.args['prénom']))
	    mw.log(object:addPropertyString(vcard .. 'family-name', f.args['nom']))
	    mw.log(object:addPropertyString(vcard .. 'given-name', f.args['prénom']))
    end

    --Make infobox with capiunto
    local infobox = capiunto.create({
        title = f.args['activité'],
        top = f.args['nom']..' '.. f.args['prénom'],
        topStyle = 'background: #dfedff;  font-size: 1.4em; padding: 15px;'
    })

    return infobox
    --return 	mw.logObject( f.args )
end

return p