Модуль:АвторВУЕ

Документацію для цього модуля можна створити у Модуль:АвторВУЕ/документація

local p = {}

-- Extract author links from == Автор ВУЕ == section of the current page
local function extractAuthorsFromText(text)
    if not text or text == "" then
        return {}
    end
    -- Find == Автор ВУЕ == or == Автор == section
    local section = mw.ustring.match(text, "==+%s*Автор[^=\n]*==+%s*(.-)%f[=]==+")
    if not section then
        section = mw.ustring.match(text, "==+%s*Автор[^=\n]*==+%s*(.*)")
    end
    if not section then
        return {}
    end

    -- Stop before templates like {{Цитування_автор}} or {{Оприлюднено}} or categories [[Категорія:...]]
    local clean = mw.ustring.gsub(section, "{{%s*Цитування.-}}", "")
    clean = mw.ustring.gsub(clean, "{{%s*Оприлюднено.*", "")

    local authors = {}
    local seen = {}

    -- Match all [[...]] links in the author section
    for link in mw.ustring.gmatch(clean, "%[%[(.-)%]%]") do
        -- Ignore Category / File links
        local lower = mw.ustring.lower(link)
        if not mw.ustring.find(lower, "^категорія:")
           and not mw.ustring.find(lower, "^category:")
           and not mw.ustring.find(lower, "^файл:")
           and not mw.ustring.find(lower, "^file:") then

            -- Strip optional SMW property prefix like or 
            local afterProp = mw.ustring.gsub(link, "^%s*[Аа]втор[_ ]ВУЕ%s*::%s*", "")
            local target, label = mw.ustring.match(afterProp, "^([^|]+)|(.*)$")
            if not target then
                target = afterProp
                label = afterProp
            end
            target = mw.text.trim(target)
            label = mw.text.trim(label)
            -- Normalize underscores in target name for display if needed
            local targetClean = mw.ustring.gsub(target, "_", " ")
            if targetClean ~= "" and not seen[targetClean] then
                seen[targetClean] = true
                table.insert(authors, {
                    target = targetClean,
                    label = label ~= "" and label or targetClean
                })
            end
        end
    end
    return authors
end

local function getAuthors(frame)
    local args = frame.args or {}
    local pframe = frame:getParent()
    local pargs = pframe and pframe.args or {}

    local explicit = args[1] or args["автор"] or pargs[1] or pargs["автор"]
    if explicit and mw.text.trim(explicit) ~= "" then
        explicit = mw.text.trim(explicit)
        return { { target = explicit, label = explicit } }
    end

    local title = mw.title.getCurrentTitle()
    if not title then
        return {}
    end
    local content = title:getContent()
    return extractAuthorsFromText(content)
end

-- Outputs wiki links for citation line: [[Вечерський В. В.|Вечерський В. В.]], ...
-- AND automatically registers  so SMW always indexes the author
-- even if VisualEditor stripped from the article wikitext!
function p.citation(frame)
    local authors = getAuthors(frame)
    if #authors == 0 then
        return ""
    end
    local links = {}
    for _, a in ipairs(authors) do
        -- In DSTU 8302:2015 citation, author name is Surname Initials (target)
        table.insert(links, "[[" .. a.target .. "|" .. a.target .. "]]")
    end
    local out = table.concat(links, ", ")
    -- Call #set if Semantic MediaWiki is active
    if frame and frame.callParserFunction then
        pcall(function()
            local setArgs = {}
            for _, a in ipairs(authors) do
                table.insert(setArgs, "Автор_ВУЕ=" .. a.target)
            end
            frame:callParserFunction("#set", setArgs)
        end)
    end
    return out
end

-- Outputs plain text author names for Schema.org microdata and Zotero COinS
function p.plain(frame)
    local authors = getAuthors(frame)
    if #authors == 0 then
        return "Редакція ВУЕ"
    end
    local names = {}
    for _, a in ipairs(authors) do
        table.insert(names, a.target)
    end
    return table.concat(names, ", ")
end

-- Outputs URL-encoded author names for Zotero COinS rft.au
function p.urlencode(frame)
    local plainText = p.plain(frame)
    return mw.uri.encode(plainText, "QUERY")
end

return p
Увага! Опитування читачів ВУЕ. Заповнити анкету ⟶