unused functions accept_value() and comp_val(), sort expanded args
This commit is contained in:
parent
2161da1eff
commit
6015a48178
1 changed files with 29 additions and 38 deletions
|
|
@ -46,8 +46,11 @@ local function is_set( var )
|
|||
end
|
||||
|
||||
--[[--------------------------< I N _ A R R A Y >--------------------------------------------------------------
|
||||
|
||||
Whether needle is in haystack (taken from Module:Citation/CS1/Utilities)
|
||||
|
||||
]]
|
||||
|
||||
local function in_array( needle, haystack )
|
||||
if needle == nil then
|
||||
return false
|
||||
|
|
@ -60,37 +63,19 @@ local function in_array( needle, haystack )
|
|||
return false
|
||||
end
|
||||
|
||||
|
||||
--[[--------------------------< T A B L E S E T _ A D D >------------------------------------------------------
|
||||
|
||||
Add needle to the haystack if it's not already there.
|
||||
|
||||
]]
|
||||
|
||||
local function tableset_add(haystack, needle)
|
||||
if needle == nil or in_array(needle, haystack) then return false end
|
||||
table.insert(haystack, needle)
|
||||
return true
|
||||
end
|
||||
|
||||
--[[--------------------------< A C C E P T _ V A L U E >-------------------------------------------------------
|
||||
Accept WD value by framing in ((...)) if param_val is equal to keyword; else pass-through WD value as is.
|
||||
]]
|
||||
local function accept_value( param_val, wd_val )
|
||||
local val = param_val
|
||||
|
||||
if val then
|
||||
if in_array (val, {'accept', '))((', ':d:'}) then
|
||||
val = '((' .. wd_val .. '))'
|
||||
elseif '((accept))' == val then
|
||||
val = 'accept'
|
||||
elseif '(())(())' == val then
|
||||
val = '))(('
|
||||
elseif '((:d:))' == val then
|
||||
val = ':d:'
|
||||
else
|
||||
val = wd_val
|
||||
end
|
||||
end
|
||||
|
||||
return val
|
||||
end
|
||||
|
||||
-- Split string of comma-separated first names into a table of initials
|
||||
-- 2026-10-10: corrected for UTF-8 by [[User:Pengo]].
|
||||
|
|
@ -540,30 +525,36 @@ local function getIdentifierAccess(qid, args, identifier)
|
|||
return nil
|
||||
end
|
||||
|
||||
-- sort sequence table whose values are key-value pairs by key
|
||||
local function comp_key(a, b)
|
||||
local param_a, enum_a = a[1]:match ('(%D+)(%d+)$'); -- get param name and enumerator from <a>
|
||||
local param_b, enum_b = b[1]:match ('(%D+)(%d+)$'); -- get param name and enumerator from <b>
|
||||
|
||||
if enum_a and enum_b then -- if both parameters have neumerators
|
||||
--[[--------------------------< P A R A M E T E R _ N A M E _ C O M P A R E >----------------------------------
|
||||
|
||||
function to sort a sequence table whose values are {<parameter>, <value>} sequences by the <parameter> name; used
|
||||
when rendering an expanded cs1|2 template (|expand= has any value)
|
||||
|
||||
]]
|
||||
|
||||
local function parameter_name_compare (a, b)
|
||||
local param_a, enum_a = a[1]:match ('(%D+)(%d+)$'); -- get parameter name and enumerator from <a>
|
||||
local param_b, enum_b = b[1]:match ('(%D+)(%d+)$'); -- get parameter name and enumerator from <b>
|
||||
|
||||
if enum_a and enum_b then -- if both parameters have enumerators
|
||||
if param_a == param_b then -- are parameter names the same?
|
||||
return tonumber (enum_a) < tonumber (enum_b); -- yes: compare enumerators
|
||||
end
|
||||
end
|
||||
|
||||
return a[1] < b[1]; -- alpha sort if here
|
||||
return a[1] < b[1]; -- alpha sort by parameter name if here
|
||||
end
|
||||
|
||||
-- sort sequence table whose values are key-value pairs by value
|
||||
local function comp_val(a, b)
|
||||
return a[2] < b[2]
|
||||
end
|
||||
|
||||
--[[-------------------------< C I T E _ Q >------------------------------------------------------------------
|
||||
Takes standard CS1|2 template parameters and passes all to {{citation}}. If neither of |author= and |author1=
|
||||
are set, calls get_authors() to try to get an author name-list from Wikidata. The result is passed to
|
||||
{{citation}} for rendering.
|
||||
--]]
|
||||
--[[--------------------------< C I T E _ Q >------------------------------------------------------------------
|
||||
|
||||
Takes standard CS1|2 template parameters and passes all to an appropriate cs1|2 template. If neither of |author=
|
||||
and |author1= are set, calls get_authors() to try to get an author name-list from Wikidata. The result is passed
|
||||
to Module:Citation/CS1 for rendering.
|
||||
|
||||
]]
|
||||
|
||||
local function _cite_q (citeq_args)
|
||||
local frame = mw.getCurrentFrame()
|
||||
|
||||
|
|
@ -1041,7 +1032,7 @@ local function _cite_q (citeq_args)
|
|||
for param, val in pairs (citeq_args) do
|
||||
table.insert(sorttable, {param, val})
|
||||
end
|
||||
table.sort(sorttable, comp_key)
|
||||
table.sort(sorttable, parameter_name_compare) -- sort parameter names by alpha or enumerator
|
||||
-- add contents to expand_args
|
||||
for idx, val in ipairs(sorttable) do
|
||||
table.insert(expand_args, val[1] .. '=' .. val[2])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue