「モジュール: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. | cfg.ranks = {true, true, false} -- preferred = true, normal = true, deprecated = false | ||
cfg. | cfg.foundRank = #cfg.ranks | ||
cfg. | cfg.flagBest = false | ||
cfg | cfg.flagRank = false | ||
cfg.period = 0 | cfg.period = 0 | ||
271行目: | 271行目: | ||
function convertRank(rank) | function convertRank(rank) | ||
if | if rank == "preferred" then | ||
return 1 | return 1 | ||
elseif | elseif rank == "normal" then | ||
return 2 | return 2 | ||
elseif | elseif rank == "deprecated" then | ||
return 3 | return 3 | ||
else | else | ||
806行目: | 806行目: | ||
end | end | ||
function Config: | function Config:setRank(rank) | ||
local rankPos | local rankPos | ||
if rank == "best" then | |||
if | |||
self.bestRank = true | self.bestRank = true | ||
self.flagBest = true -- mark that 'best' flag was given | |||
return | return | ||
end | end | ||
if | if rank:sub(1,9) == "preferred" then | ||
rankPos = 1 | rankPos = 1 | ||
elseif | elseif rank:sub(1,6) == "normal" then | ||
rankPos = 2 | rankPos = 2 | ||
elseif | elseif rank:sub(1,10) == "deprecated" then | ||
rankPos = 3 | rankPos = 3 | ||
else | |||
return | |||
end | end | ||
if | -- one of the rank flags was given, check if another one was given before | ||
if not self.flagRank then | |||
self.ranks = {false, false, false} -- no other rank flag given before, so unset ranks | |||
elseif | self.bestRank = self.flagBest -- unsets bestRank only if 'best' flag was not given before | ||
self. | self.flagRank = true -- mark that a rank flag was given | ||
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. | self.ranks[rankPos] = true | ||
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: | 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 | 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, | -- 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 | -- 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 | ||
-- found a better rank, reset worse rank outputs | |||
if self.conf.foundRank == 1 then | |||
self.outNormal = {} | |||
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. | 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. | 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 "") | ||
if f == "main" then | if f == "main" then | ||
error('ファンクション"main"は2度も呼び出せません。') | error('ファンクション"main"は2度も呼び出せません。') | ||
end | end | ||
assert(p["_"..f], 'ファンクション"' .. f .. '"が存在しません。') | |||
args = {} | args = {} |