Модуль:Песочница/Pok: различия между версиями

Нет описания правки
Нет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}
local p = {}
local BASE_USER = "IanComradeBot/"
local BASE_USER = "IanComradeBot/"
local CURRENT_PROJECT
local CURRENT_PROJECT
local function get_page_var()
local frame = mw.getCurrentFrame()
if mw.ext and mw.ext.VariablesLua and mw.ext.VariablesLua.var then
local v = mw.ext.VariablesLua.var("GetFieldPath")
if v and v ~= "" then return v end
end
local v = frame:callParserFunction{ name = '#var', args = { "GetFieldPath" } }
if v and v ~= "" then return v end
return nil
end


local function find_ancestor_arg(name)
local function find_ancestor_arg(name)
    local f = mw.getCurrentFrame()
local f = mw.getCurrentFrame()
    while f do
while f do
        local v = f:getArgument(name)
local v = f:getArgument(name)
        if v and v ~= "" then return v end
if v and v ~= "" then return v end
        f = f:getParent()
f = f:getParent()
    end
end
    return nil
return nil
end
end


local function resolve_project(pagePath)
local function resolve_project(pagePath)
    if pagePath and pagePath ~= "" then return pagePath end
if pagePath and pagePath ~= "" then return pagePath end
    if CURRENT_PROJECT and CURRENT_PROJECT ~= "" then return CURRENT_PROJECT end
if CURRENT_PROJECT and CURRENT_PROJECT ~= "" then return CURRENT_PROJECT end
    local candidate = find_ancestor_arg("Название") or find_ancestor_arg("project") or find_ancestor_arg("path")
local v = get_page_var()
    if candidate and candidate ~= "" then
if v and v ~= "" then CURRENT_PROJECT = v; return v end
        CURRENT_PROJECT = candidate
local candidate = find_ancestor_arg("Название") or find_ancestor_arg("project") or find_ancestor_arg("path")
        return candidate
if candidate and candidate ~= "" then CURRENT_PROJECT = candidate; return candidate end
    end
return nil
    return nil
end
end


local function get_module_name(pagePath)
local function get_module_name(pagePath)
    local project = resolve_project(pagePath) or "default"
local project = resolve_project(pagePath) or "default"
    return "Module:" .. BASE_USER .. project .. "/data"
return "Module:" .. BASE_USER .. project .. "/data"
end
end