Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
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() | |||
while f do | |||
local v = f:getArgument(name) | |||
if v and v ~= "" then return v end | |||
f = f:getParent() | |||
end | |||
return nil | |||
end | end | ||
local function resolve_project(pagePath) | local function resolve_project(pagePath) | ||
if pagePath and pagePath ~= "" then return pagePath end | |||
if CURRENT_PROJECT and CURRENT_PROJECT ~= "" then return CURRENT_PROJECT end | |||
local v = get_page_var() | |||
if v and v ~= "" then CURRENT_PROJECT = v; return v end | |||
local candidate = find_ancestor_arg("Название") or find_ancestor_arg("project") or find_ancestor_arg("path") | |||
if candidate and candidate ~= "" then CURRENT_PROJECT = candidate; return candidate end | |||
return nil | |||
end | end | ||
local function get_module_name(pagePath) | local function get_module_name(pagePath) | ||
local project = resolve_project(pagePath) or "default" | |||
return "Module:" .. BASE_USER .. project .. "/data" | |||
end | end | ||