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

[отпатрулированная версия][отпатрулированная версия]
Содержимое удалено Содержимое добавлено
Нет описания правки
Нет описания правки
Строка 50:
if options.param == nil then return true end
if frameArgs[options.param] == nil or frameArgs[options.param] == '' then
debLog:write('ret: true', 'isEmptyParam')
return true
end
debLog:write('ret: false', 'isEmptyParam')
return false
end
Строка 77 ⟶ 75 :
 
local namespace = mw.title.getCurrentTitle().namespace
if hasValue( options.namespaces, namespace ) then
return true
end
Строка 567 ⟶ 565 :
end
--- Gets globalsglobal options frome config node and sets them to global table
local function setGlobalssetGlobalOptions(node)
if type(node) ~= 'table' then return nil end
if type(node.global) ~= 'table' then return nil end
for k, voption in pairs(node.global) do
if option == 'ignoreNSChecks' then
globals[k] = v
globals.ignoreNSChecks = globals.ignoreNSChecks or option
else
globals[k] = v
end
end
debLog:write('Globals set: '..mw.dumpObject(globals), 'setGlobalOptions')
return globals
end
 
--- Global options processing
local function entityCheckprocessGlobalOptions(frameArgs)
local fromnocat = frameArgs[globals.fromnocatParamName]
if fromnocat ~= nil and fromnocat ~= '' then
debLog:write('Categorization denied', 'processGlobalOptions')
return false
end
local from = frameArgs[globals.fromParamName]
if from ~= nil and from ~= '' then
if not mw.wikibase.isValidEntityId( from ) then
debLog:write('Entity ID isEntityID not valid: |from=' .. from, 'initChecksprocessGlobalOptions')
return false
end
if not mw.wikibase.entityExists( from ) then
debLog:write('Entity does not exist: |from=' .. from, 'initChecksprocessGlobalOptions')
return truefalse
end
end
return true
end
 
Строка 633 ⟶ 657 :
end
 
--- Loads list of strings with rules' IDs from array 'node', and returns an
-- Check if entity is valid and exists (used for call from another page)
-- array with those of them, which are also exist as indexes in 'ruleMap'
local function entityCheck(frameArgs)
-- @return array with valid rules
local from = frameArgs.from
if from ~= nil and from ~= '' then
if not mw.wikibase.isValidEntityId( from ) then
debLog:write('Entity ID is not valid: |from=' .. from, 'initChecks')
return false
end
if not mw.wikibase.entityExists( from ) then
debLog:write('Entity does not exist: |from=' .. from, 'initChecks')
return false
end
end
return true
end
 
-- загружает список правил для обработки из ноды node и проверяет их соответстие
-- таблце ruleMap. возвращает массив с идентификаторами валидных правил или nil
local function getRules(ruleMap, node)
local rules = getConfigNode(node, 'rules')
if type(rules) ~= 'table' then return nil end
local resultvalidRules = {}
local i = 1
for _, ruleName in ipairs(rules) do
if ruleMap[ruleName] then
resultvalidRules[i] = ruleName
i = i + 1
end
end
if next(resultvalidRules) == nil then
debLog:write('No valid rulenames found', 'getRules', 'warn')
return nil
end
debLog:write('Valid rulenamesrules found: '.. mw.dumpObject(resultvalidRules), 'getRules')
return resultvalidRules
end
 
--- Executes a function, corresponding to rule with id 'ruleName'
-- обработка правила ruleName и вызов соответствующей функции-обработчика
--@param frameArgs table
-- возвращает результат, выданный обработчиком или nil
--@param ruleName string with rule id
local function processRule(frameArgs, ruleName, preset )
--@param preset table with preset
--@param node node with rules
--@return result of a called function or nil
local function processRule(frameArgsruleName, ruleNamenode, presetframeArgs, preset)
local myname = 'processRule'
debLog:write('Invoked with: '..mw.dumpObject tostring(ruleName), myname)
-- check if function name is present
-- Проверка, что в конфиге указано имя функции-обработчика
if isEmpty( config.rulesnode[ruleName].func ) then
debLog:write('No function specified', myname, 'warn')
return nil
end
-- проверки валидности имени функции обработчика из конфига
local funcName = config.rulesnode[ruleName].func
if type( funcName ) ~= 'string' then
debLog:write('Function name is not a string: ' .. funcName, myname, 'warn')
Строка 700 ⟶ 713 :
return ''
end
debLog:write(funcName .. '() returned: '..mw.text.nowiki(funcResult), 'myname', 'warn')
return funcResult
end
Строка 706 ⟶ 719 :
---Processes rules from array of IDs in ruleList
--@return concatenated result of rules
local function processRuleList(ruleList, node, frameArgs, preset)
local result = ''
for _, ruleName in ipairs(ruleList) do
local ruleResult = processRule(frameArgsruleName, ruleNamenode, frameArgs, preset)
if ruleResult == nil then
debLog:write('Rule returned nil', 'processRuleList', 'warn')
Строка 782 ⟶ 795 :
-- inits and checks
getConfig(frameArgs)
setGlobalssetGlobalOptions(config)
if not entityCheckprocessGlobalOptions(frameArgs) then
return nil, 'entityGlobal IDoptions is not validinterruption'
end
 
-- get preset enriched with defaults
local preset = getPreset(config.presets, presetName)
Строка 807 ⟶ 820 :
-- process rules and concat result
local rulesResult = processRuleList(ruleList, config.rules, frameArgs, preset)
if rulesResult == nil then
return nil, 'Rules result is nil'