「モジュール:Wd」の版間の差分

en:Module:Wd 2017年2月9日 (木) 20:48(UTC)より
template>K-iczn
編集の要約なし
template>K-iczn
(en:Module:Wd 2017年2月9日 (木) 20:48(UTC)より)
69行目: 69行目:
cfg.bestRank = true
cfg.bestRank = true
cfg.foundRank = 3
cfg.ranks = {true, true, false}  -- preferred = true, normal = true, deprecated = false
cfg.maxRank = nil
cfg.foundRank = #cfg.ranks
cfg.minRank = nil
cfg.flagBest = false
cfg:setRankBoundaries("best")
cfg.flagRank = false
cfg.period = 0
cfg.period = 0
271行目: 271行目:


function convertRank(rank)
function convertRank(rank)
if (rank == "preferred") then
if rank == "preferred" then
return 1
return 1
elseif (rank == "normal") then
elseif rank == "normal" then
return 2
return 2
elseif (rank == "deprecated") then
elseif rank == "deprecated" then
return 3
return 3
else
else
806行目: 806行目:
end
end


function Config:setRankBoundaries(rank)
function Config:setRank(rank)
local rankPos
local rankPos
self.foundRank = 3  -- must equal the lowest possible rank
if rank == "best" then
if (rank == "best") then
self.bestRank = true
self.bestRank = true
self.flagBest = true  -- mark that 'best' flag was given
return
return
else
self.bestRank = false
end
end
if (rank:sub(1,9) == "preferred") then
if rank:sub(1,9) == "preferred" then
rankPos = 1
rankPos = 1
elseif (rank:sub(1,6) == "normal") then
elseif rank:sub(1,6) == "normal" then
rankPos = 2
rankPos = 2
elseif (rank:sub(1,10) == "deprecated") then
elseif rank:sub(1,10) == "deprecated" then
rankPos = 3
rankPos = 3
else
return
end
end
if (rank:sub(-1) == "+") then
-- one of the rank flags was given, check if another one was given before
self.maxRank = 1
if not self.flagRank then
self.minRank = rankPos
self.ranks = {false, false, false}  -- no other rank flag given before, so unset ranks
elseif (rank:sub(-1) == "-") then
self.bestRank = self.flagBest      -- unsets bestRank only if 'best' flag was not given before
self.maxRank = rankPos
self.flagRank = true                -- mark that a rank flag was given
self.minRank = 3
end
if rank:sub(-1) == "+" then
for i = rankPos, 1, -1 do
self.ranks[i] = true
end
elseif rank:sub(-1) == "-" then
for i = rankPos, #self.ranks do
self.ranks[i] = true
end
else
else
self.maxRank = rankPos
self.ranks[rankPos] = true
self.minRank = rankPos
end
end
end
end
864行目: 871行目:
return true
return true
elseif flag == "best" or flag:match('^preferred[+-]?$') or flag:match('^normal[+-]?$') or flag:match('^deprecated[+-]?$') then
elseif flag == "best" or flag:match('^preferred[+-]?$') or flag:match('^normal[+-]?$') or flag:match('^deprecated[+-]?$') then
self:setRankBoundaries(flag)
self:setRank(flag)
return true
return true
elseif flag == "future" then
elseif flag == "future" then
926行目: 933行目:
function Config:rankMatches(rankPos)
function Config:rankMatches(rankPos)
if self.bestRank then
if self.bestRank then
return self.foundRank >= rankPos
return (self.ranks[rankPos] and self.foundRank >= rankPos)
else
else
return (self.maxRank <= rankPos and rankPos <= self.minRank)
return self.ranks[rankPos]
end
end
end
end
1,017行目: 1,024行目:
local done = false
local done = false
-- a rankPos should only apply to complete claims, not to its individual qualifiers or references;
-- a rankPos should only apply to complete claims, NOT to its individual qualifiers or references;
-- for the latter two, no rankPos should be given and their default rankPos must be the highest possible (i.e. 1)
-- for the latter two, no rankPos should be given and their default rankPos must be the highest possible (i.e. 1)
if rankPos then
if rankPos then
if (self.conf.bestRank or self.singleValue) and self.conf.foundRank > rankPos then
-- must NOT be reached when appending individual qualifiers or references
self.conf.foundRank = rankPos
if self.conf.foundRank > rankPos then
self.conf.foundRank = rankPos -- must NOT be overwritten when appending individual qualifiers or references
-- found a better rank, reset worse rank outputs
if self.conf.bestRank or self.singleValue then
if self.conf.foundRank == 1 then
-- found a better rank, reset worse rank outputs
self.outNormal = {}
if self.conf.foundRank == 1 then
self.outDeprecated = {}
self.outNormal = {}
elseif self.conf.foundRank == 2 then
self.outDeprecated = {}
self.outDeprecated = {}
elseif self.conf.foundRank == 2 then
self.outDeprecated = {}
end
end
end
end
end
else
else
rankPos = 1
-- must be reached when appending individual qualifiers or references
rankPos = 1 -- must be the highest possible (i.e. 1)
end
end
if rankPos == 1 then
if rankPos == 1 then
-- must always be reached when appending individual qualifiers or references
self.outPreferred[#self.outPreferred + 1] = result
self.outPreferred[#self.outPreferred + 1] = result
1,044行目: 1,056行目:
self.outNormal[#self.outNormal + 1] = result
self.outNormal[#self.outNormal + 1] = result
if self.singleValue and not self.conf.bestRank and self.conf.maxRank == 2 then
if self.singleValue and not self.conf.ranks[1] then
done = true
done = true
end
end
1,050行目: 1,062行目:
self.outDeprecated[#self.outDeprecated + 1] = result
self.outDeprecated[#self.outDeprecated + 1] = result
if self.singleValue and not self.conf.bestRank and self.conf.maxRank == 3 then
if self.singleValue and not self.conf.ranks[1] and not self.conf.ranks[2] then
done = true
done = true
end
end
1,670行目: 1,682行目:
f = mw.text.trim(frame.args[1] or "")
f = mw.text.trim(frame.args[1] or "")
assert(p["_"..f], 'ファンクション"' .. f .. '"が存在しません。')
if f == "main" then
if f == "main" then
error('ファンクション"main"は2度も呼び出せません。')
error('ファンクション"main"は2度も呼び出せません。')
end
end
assert(p["_"..f], 'ファンクション"' .. f .. '"が存在しません。')
args = {}
args = {}
匿名利用者