Versie door Dennis Groenewegen (overleg | bijdragen) op 2 okt 2025 om 12:09 (minimalStripForSorting => main)

Module:Class/Book




Luafout in Module:Format_for_sorting op regel 38: attempt to index field 'args' (a nil value)

https://www.fandata.nl/Persoon/1608

Luafout in Module:Format_for_sorting op regel 38: attempt to index field 'args' (a nil value)

Has publication info = (1975), Standaard Uitgeverij, Antwerpen/Amsterdam +

Has publication year = 1975

Has sort label = Tim 2 louis de groof 1975¶

Has sort label by author = Groof, louis de - tim 2¶


local p = {}
local mSlot = require("Module:Slot")
local mFormatForSorting = require("Module:Format for sorting")
local mTitle = require("Module:Class/Title")
local mPerson = require("Module:Class/Person")

p.set = function( frame )
	local uitgeverijnr = frame.args.uitgeverijnr or ""
	local boekpubjaar = frame.args.boekpubjaar or ""
	local boekpubjaarAlt = boekpubjaar
	if boekpubjaar == "" then boekpubjaarAlt = "?" end
	local druk = frame.args.druk or ""
	local titleAddendum = p.createTitleAddendum( boekpubjaar, druk, uitgeverijnr, false )
	local titleAddendumVariant = p.createTitleAddendum( boekpubjaar, druk, uitgeverijnr, true )

	local titelnr = frame.args.titelnr or ""
	--TitelGew
	local titelGew = ""
	local titelBiblio = ""

	local schrijverNrs = ""
	if titelnr ~= "" then
		titelGew = mSlot.getValueFromTemplateData( "ws-page-props", titelnr, "Title", "TitelGew" )
		titelBiblio = mSlot.getValueFromTemplateData( "ws-page-props", titelnr, "Title", "TitelBiblio" )
		if titelBiblio == nil or titelBiblio == "" then titelBiblio = titelGew end
		schrijverNrs = mSlot.getValueFromTemplateData( "ws-page-props", titelnr, "Title", "SchrijverNr" )
	end
	
	local authorNames = ""
	local firstAuthorNameBiblio = ""
	if schrijverNrs ~= "" then
		authorNames = mPerson.getAuthorNames( schrijverNrs )
		firstAuthorNameBiblio = mPerson.getFirstAuthorNameBiblio( schrijverNrs )
	end

	local authorNameString = authorNames
	if authorNames == "" then authorNameString = "---" end
	
	-- <i>{{#var:@titel}}</i> - {{#var:@naamgew|---}} {{#if:{{#var:@title addendum}}|{{#var:@title addendum}}}}
	local labelForTitle = "<i>" .. titelGew .. "</i> - " .. authorNameString .. " " .. titleAddendum
	labelForTitle = mw.text.trim(labelForTitle)
	-- {{#var:@titel}} - {{#var:@naamgew|---}} {{#if:{{#var:@title addendum}}|{{#var:@title addendum}}}} 
	local labelForTitlePlain = titelGew .. " - " .. authorNameString .. " " .. titleAddendum
	labelForTitlePlain = mw.text.trim(labelForTitlePlain)
	-- @sort title = {{lc:{{Strip title for sorting|1={{#var:@titelbiblio}} - {{#var:@naamgew}} {{{BoekPubJaar|}}} {{{Druk|}}} }} }}
	--local stripped = mFormatForSorting.minimalStripForSorting( titelBiblio )
	local labelForSort = mw.ustring.lower(
		titelBiblio .. " - " .. authorNames .. " " .. boekpubjaar .. " " .. druk
	)
	labelForSort = mFormatForSorting.main( mw.text.trim(labelForSort) )
	-- {{uc:{{#sub:{{#var:@titelbiblio|{{#var:@titel}}}}|0|1}}}}
	local initial = mw.ustring.upper(
		mw.ustring.sub( titelBiblio, 1, 1 )
	)
	local sortLabelByAuthor = mTitle.createSortLabelByAuthor( titelBiblio, firstAuthorNameBiblio )

	local set = {
		["Title"] = labelForTitle,
		["Title plain"] = labelForTitlePlain,
		["Has initial"] = initial,
		-- {{#sub:{{#var:@sort title}}|0|150}}¶
		["Has sort label"] = mw.ustring.sub( labelForSort, 1, 150 ) .. "¶",
		-- {{{BoekPubJaar|?}}} {{{Druk|}}}¶
		["Has sort label by year"] = boekpubjaarAlt .. " " .. druk .. "¶",
		["Has sort label by author"] = mw.ustring.sub( sortLabelByAuthor, 1, 200 ) .. "¶",
		["Has publication info"] = titleAddendumVariant
	}

	local debugmode = frame.args.debugmode or "false"
	if debugmode == "true" then
		return "<pre>" .. mw.text.jsonEncode( set ) .. "</pre>"
	end

	-- {{DISPLAYTITLE:{{#var:@label2}} }} 
	mw.ext.displaytitle.set( labelForTitlePlain )
	-- {{DEFAULTSORT:{{#var:@sort title}} }}
	frame:callParserFunction( 'DEFAULTSORT', { labelForSort } )

	--return labelForSort .. " / " .. labelForTitle .. " / " .. authorNames .. " / " .. titelGew .. " / " .. titelBiblio .. " / " .. titleAddendum .. " / " .. titleAddendumVariant
end

--[[
Final string of formatted title
comes in one of two varieties
]]--
p.createTitleAddendum = function( boekpubjaar, druk, uitgeverijnr, variant )
	local str = ""
	local boekpubjaar = boekpubjaar or ""
	if boekpubjaar == "" then boekpubjaar = "?" end

	local drukWeergave = ""
	if druk ~= "" then
		local drukN = tonumber(druk)
		if drukN == nil then
			drukWeergave =  "druk: " .. druk
		else
			drukWeergave =  druk .. "ᵉ druk"
		end
	end

	local uitgeverijnaam = ""
	if uitgeverijnr ~= "" then
		--local slotContent = mSlot.getSlotContent( uitgeverijnr, "ws-page-props", "Publisher" )
		uitgeverijnaam = mSlot.getValueFromTemplateData( "ws-page-props", uitgeverijnr, "Publisher", "Naam" )
	end

	-- concat
	if variant ~= "" and variant == true then
		str = drukWeergave .. " (" .. boekpubjaar .. ")"
		if uitgeverijnaam ~= "" then str = str .. ", " .. uitgeverijnaam end
	else
		str = boekpubjaar
		if drukWeergave ~= "" then str = str .. ", " .. drukWeergave end
		if uitgeverijnaam ~= "" then str = str .. ", " .. uitgeverijnaam end
	end

	return mw.text.trim( str )
end

return p