|
|
| (32 tussenliggende versies door dezelfde gebruiker niet weergegeven) |
| Regel 1: |
Regel 1: |
| --[[ | | --[[ |
| | @deprecated - renamed to Class/Title |
|
| |
|
| Module for taking and processing parameters for set in Template:Title
| |
| Work in progress -
| |
|
| |
| {{#invoke:Title/SMW |set
| |
| |page={{FULLPAGENAME}}
| |
| |slot=ws-page-props
| |
|
| |
| |ID={{{ID|}}}
| |
| |TitelBiblio={{{TitelBiblio|}}}
| |
| |TitelGew={{{TitelGew|}}}
| |
| |OrigTitel={{{OrigTitel|}}}
| |
| |SchrijverNr={{{SchrijverNr|}}}
| |
| |Type={{{Type|}}}
| |
| |Titelreeks={{{Titelreeks|}}}
| |
| |Reeks={{{Reeks|}}}
| |
| |ReeksNr={{{ReeksNr|}}}
| |
| |Behoord={{{Behoord|}}}
| |
| |Soort={{{Soort|}}}
| |
| |Wereld={{{Wereld|}}}
| |
| |Medium vorm={{{Medium vorm|}}}
| |
| |ZieOokBij={{{ZieOokBij|}}}
| |
| |subcategorie={{{subcategorie|}}}
| |
| |KInhoud={{{KInhoud|}}}
| |
| |GUID={{{GUID|}}}
| |
| |Verwijderd={{{Verwijderd|}}}
| |
| |Opmerking={{{Opmerking|}}}
| |
| |Aantekening={{{Aantekening|}}}
| |
| }}
| |
|
| |
| ]]--
| |
|
| |
| local p = {}
| |
| local mCspFunctions = require('Module:CspFunctions')
| |
|
| |
| p.set = function(frame)
| |
| local page = frame.args.page or nil
| |
| local slot = frame.args.slot or "ws-page-props"
| |
| local debugmode = frame.args.debugmode or "false"
| |
|
| |
| -- Wiki template argumentsa
| |
| local ID = frame.args.ID or nil
| |
| local TitelBiblio = frame.args.TitelBiblio or nil
| |
| local TitelGew = frame.args.TitelGew or ""
| |
| local OrigTitel = frame.args.OrigTitel or nil
| |
| local SchrijverNr = frame.args.SchrijverNr or nil
| |
| local Type = frame.args.Type or nil
| |
| local Titelreeks = frame.args.Titelreeks or nil
| |
| local Reeks = frame.args.Reeks or nil
| |
| local ReeksNr = frame.args.ReeksNr or nil
| |
| local Behoord = frame.args.Behoord or nil
| |
| local Soort = frame.args.Soort or nil
| |
| local Wereld = frame.args.Wereld or nil
| |
| local Mediumvorm = frame.args["Medium vorm"] or nil
| |
| local ZieOokBij = frame.args.ZieOokBij or nil
| |
| local subcategorie = frame.args.subcategorie or nil
| |
| local KInhoud = frame.args.KInhoud or nil
| |
| local GUID = frame.args.GUID or nil
| |
| local Verwijderd = frame.args.Verwijderd or nil
| |
| local Opmerking = frame.args.Opmerking or nil
| |
| local Aantekening = frame.args.Aantekening or nil
| |
|
| |
| -- processing
| |
| local titleBiblioFlattened = p.flattenBibliographicTitle( TitelBiblio )
| |
| local initial = p.getUppercaseInitial( titleBiblioFlattened )
| |
|
| |
| local authors = {}
| |
| if SchrijverNr ~= nil then
| |
| authors = mw.text.split( SchrijverNr, "," )
| |
| end
| |
| local authorNameTbl = p.buildAuthorNameTbl( authors ) or {}
| |
| local authorNameStrInTitle = p.formatAuthorNameString( #authors, authorNameTbl, "---" )
| |
|
| |
| -- {{lc:{{#var:@titelbiblio}} - {{#var:@naamgew}} }}
| |
| local sortLabel = string.lower( titleBiblioFlattened .. " - " .. authorNameStrInTitle )
| |
| -- {{lc:{{#var:@naambiblioschrijver1}} - {{#var:@titelbiblio}} }}
| |
| local firstAuthorBiblioName = ""
| |
| if authorNameTbl[1] ~= nil then firstAuthorBiblioName = authorNameTbl[1]["NaamBiblio"] or "" end
| |
| local sortLabelByAuthor = string.lower( firstAuthorBiblioName .. " - " .. titleBiblioFlattened )
| |
|
| |
| -- set
| |
| local set = {}
| |
| -- Dutch-language label
| |
| set["Klasse"] = "Titel"
| |
| set["Has ID"] = ID or ""
| |
| set["Title"] = TitelGew .. " - " .. authorNameStrInTitle
| |
| --|Title plain={{{TitelGew|}}} - {{#var:@naamgew|---}}
| |
| set["Title plain"] = TitelGew .. " - " .. authorNameStrInTitle
| |
| set["Has title"] = TitelGew
| |
| set["Has bibliographic title"] = titleBiblioFlattened
| |
| -- |Has sort label={{#sub:{{#var:@sort title}}|0|150}}¶
| |
| set["Has sort label"] = string.sub( sortLabel, 1, 150 ) .. "¶"
| |
| -- |Has sort label by author={{#sub:{{#var:@sort title 2}}|0|200}}¶<!-- author first -->
| |
| set["Has sort label by author"] = string.sub( sortLabelByAuthor, 1, 200 ) .. "¶"
| |
| if Type ~= nil then labelType = " (" .. Type .. ")" else labelType = "" end
| |
| set["Has label for form"] = TitelGew .. " - " .. authorNameStrInTitle .. labelType
| |
| set["Has original title"] = OrigTitel or ""
| |
|
| |
| if debugmode == "true" then
| |
| return "<pre>" .. mw.text.jsonEncode( set ) .. "</pre>"
| |
| end
| |
|
| |
| if mw.smw then
| |
| local setResult = mw.smw.set( set )
| |
| end
| |
|
| |
| end
| |
|
| |
| p.flattenBibliographicTitle = function( titelBiblio )
| |
| if titleBiblio == nil then return "" end
| |
| -- {{Strip title for sorting|{{#sub:{{{TitelBiblio|}}}|0|75}} }}
| |
| -- {{#sub:{{{TitelBiblio|}}}|0|75}}
| |
| local subbed = string.sub( titelBiblio, 1, 75 )
| |
| -- todo use Format for sorting module instead
| |
| local stripped = frame:expandTemplate{ title = 'Strip title for sorting', args = { subbed } }
| |
| return stripped
| |
| end
| |
|
| |
| p.getUppercaseInitial = function( str )
| |
| local initial = string.sub( str, 1, 1 )
| |
| return string.upper(initial)
| |
| end
| |
|
| |
| --[[
| |
| Create table with names for no more than two authors
| |
| @SchrijverNr string|nil - table of author pages
| |
| @return table
| |
| ]]--
| |
| p.buildAuthorNameTbl = function( authors )
| |
| if authors == nil or #authors == 0 then
| |
| return {}
| |
| end
| |
|
| |
| local res = {}
| |
| res[1] = {
| |
| ["page"] = authors[1],
| |
| ["NaamGew"] = p.getValueFromTemplateParam( authors[1], "Person", "NaamGew" ) or "",
| |
| ["NaamBiblio"] = p.getValueFromTemplateParam( authors[1], "Person", "NaamBiblio" ) or ""
| |
| }
| |
|
| |
| if authors[2] ~= nil then
| |
| res[2] = {
| |
| ["page"] = authors[2],
| |
| ["NaamGew"] = p.getValueFromTemplateParam( authors[2], "Person", "NaamGew" ) or "",
| |
| ["NaamBiblio"] = p.getValueFromTemplateParam( authors[2], "Person", "NaamBiblio" ) or ""
| |
| }
| |
| end
| |
|
| |
| return res
| |
| end
| |
|
| |
| --[[
| |
| Format name string for no more than two authors
| |
| @authorCount int - total number of authors
| |
| @authors table - one or two authors
| |
| @return string
| |
| ]]-- | | ]]-- |
| p.formatAuthorNameString = function( authorCount, authors, defaultStr )
| |
| local authorNameStr = defaultStr
| |
|
| |
| if ( authorCount > 0 ) and type(authors[1]["NaamGew"]) == nil then
| |
| mw.log( "Author name could not be retrieved" )
| |
| end
| |
|
| |
| if ( authorCount == 1 ) then
| |
| authorNameStr = authors[1]["NaamGew"]
| |
| elseif ( authorCount == 2 ) then
| |
| authorNameStr = authors[1]["NaamGew"] .. " & " .. authors[2]["NaamGew"]
| |
| elseif ( authorCount > 2 ) then
| |
| authorNameStr = authors[1]["NaamGew"] .. " & " .. authors[2]["NaamGew"] .. ", e.a."
| |
| end
| |
| return authorNameStr
| |
| end
| |
|
| |
| --[[
| |
| UNUSED
| |
| titleBiblioFlattened
| |
| @title 'flattened' title
| |
| ]]--
| |
| p.getSortkeyByTitleAndAuthor = function( title, firstAuthorName )
| |
| local firstAuthorName = ""
| |
| local str = title .. " - " .. firstAuthorName
| |
| -- {{lc:{{#var:@titelbiblio}} - {{#var:@naamgew}} }}
| |
| -- string.lowercase( )
| |
| end
| |
|
| |
| p.getValueFromTemplateParam = function( pagename, templateName, templateParam )
| |
| local slotContent = p.getSlotContent( pagename, "ws-page-props", templateName )
| |
| if slotContent == nil or slotContent[1] == nil or slotContent[1][templateParam] == nil then
| |
| mw.log( "No value retrieved from page. Template param: " .. templateParam )
| |
| return ""
| |
| end
| |
| if type( slotContent[1][templateParam] ) == "string" then
| |
| return slotContent[1][templateParam]
| |
| elseif type( slotContent[1][templateParam] ) == "table" then
| |
| local test = "<pre>" .. mw.text.jsonEncode( slotContent[1][templateParam] ) .. "</pre>"
| |
| -- slotContent[1][templateParam]
| |
| return test
| |
| end
| |
| end
| |
|
| |
| p.getSlotContent = function( page, slot, template )
| |
| template = template or nil
| |
| if ( template == "" or template == nil ) then
| |
| -- Assuming JSON
| |
| if slot == "main" then
| |
| --loadJsonData does not alway work. Use WSSlots instead
| |
| --return mw.loadJsonData( page )
| |
| end
| |
| local str = mw.slots.slotContent( slot, page )
| |
| if type(str) == "table" then
| |
| -- @todo VERY unlikely
| |
| return str
| |
| end
| |
| if str ~= nil then
| |
| return mw.text.jsonDecode( str )
| |
| else
| |
| return {}
| |
| end
| |
| end
| |
|
| |
| -- template
| |
| slotData = mw.slots.slotData( slot, page )
| |
| if ( slotData == nil ) then
| |
| return type(slotData)
| |
| end
| |
| return slotData[template]
| |
|
| |
| end
| |
|
| |
| return p
| |