Buscamos un coordinador del proyecto.
Actualmente, esta versión lingüística necesita un punto de contacto principal. Si tiene interés en ayudar a gestionar este proyecto, por favor contáctenos.

Módulo:Cita

La Plantilla:Citas usa este módulo para generar citas basadas en el título de un libro. Ver la plantilla para más información.


local p = {}

function p.generateCitation(frame)
    local userInput = frame.args[1] or ""
    local pageNumbers = frame.args[2] or ""
    local itemNumber = nil
    local category = "[[Categoría:Artículos que requieren Bahaidata]]"

    -- Check if the input is a valid Wikibase item ID (like Q123)
    if mw.wikibase.isValidEntityId(userInput) then
        itemNumber = userInput
    else
        itemNumber = mw.wikibase.getEntityIdForTitle(userInput)
        if not itemNumber then
            local page = mw.title.new(userInput)
            if page then
                local rtarget = page.redirectTarget
                if rtarget then
                    itemNumber = mw.wikibase.getEntityIdForTitle(rtarget.fullText)
                end
            end
        end
    end

    if not itemNumber then
        return "''" .. userInput .. "''" .. (pageNumbers ~= "" and ", p." .. pageNumbers or "") .. " " .. category
    end

    -- Retrieve and store data
    local entity = mw.wikibase.getEntity(itemNumber)

    -- Retrieve and format each property
    local titleValue = entity.claims['P47'] and entity.claims['P47'][1].mainsnak.datavalue.value.text or ""
    if titleValue == "" then
        return "''" .. userInput .. "''" .. (pageNumbers ~= "" and ", p." .. pageNumbers or "") .. " " .. category
    end

    local authorValue = entity.claims['P10'] and mw.wikibase.getLabel(entity.claims['P10'][1].mainsnak.datavalue.value.id) or ""
    local translatorValue = entity.claims['P32'] and mw.wikibase.getLabel(entity.claims['P32'][1].mainsnak.datavalue.value.id) or ""
    local publicationDate = entity.claims['P29'] and mw.text.split(entity.claims['P29'][1].mainsnak.datavalue.value.time, '-')[1]:gsub('^%+', '') or ""
    local publisherValue = entity.claims['P26'] and mw.wikibase.getLabel(entity.claims['P26'][1].mainsnak.datavalue.value.id) or ""
    local countryValue = entity.claims['P48'] and mw.wikibase.getLabel(entity.claims['P48'][1].mainsnak.datavalue.value.id) or ""
    local isbn10Value = entity.claims['P31'] and entity.claims['P31'][1].mainsnak.datavalue.value or ""
    local isbn13Value = entity.claims['P49'] and entity.claims['P49'][1].mainsnak.datavalue.value or ""

    -- Determine page citation format
    local pagePrefix = "p."
    if pageNumbers:find(",") or pageNumbers:find("-") then
        pagePrefix = "pp."
    end

    -- Construct the citation
    local citation = ""
    if authorValue ~= "" then
        citation = authorValue .. " (" .. publicationDate .. "). "
    end
    
    citation = citation .. "''" .. titleValue .. "''"
    
    if translatorValue ~= "" then
        citation = citation .. ", trans. " .. translatorValue
    end
    
    if countryValue ~= "" and publisherValue ~= "" then
        citation = citation .. ". " .. countryValue .. ": " .. publisherValue
    end
    
    if publicationDate ~= "" and authorValue == "" then
        citation = citation .. ". " .. publicationDate
    end
    
    if pageNumbers ~= "" then
        citation = citation .. ". " .. pagePrefix .. " " .. pageNumbers
    end

    if isbn10Value ~= "" or isbn13Value ~= "" then
        citation = citation .. ". ISBN " .. (isbn10Value ~= "" and isbn10Value or isbn13Value)
    end
    
    citation = citation .. "."

    -- Return the final citation
    return citation
end

return p