Module:Sandbox/Hellknowz/Test: Difference between revisions

Content deleted Content added
m ws between
back
 
(27 intermediate revisions by the same user not shown)
Line 679:
return PARSERESULT_UNRECOGNIZED -- the combination of elements was not a recognized one
end
 
end
 
function hasMetadataTemplates(input)
-- This is a basic list of the template names for metadata emiting tempaltes, there are inr eality more templates and more redirects
if (string.match(input, '%{%{[Ss]tart[ %-]?date')) then return true end
if (string.match(input, '%{%{[Ee]nd[ %-]?date')) then return true end
if (string.match(input, '%{%{[Bb]irth[ %-]?date')) then return true end
if (string.match(input, '%{%{[Dd]eath[ %-]?date')) then return true end
if (string.match(input, '%{%{[Bb]irth[ %-]?year')) then return true end
if (string.match(input, '%{%{[Dd]eath[ %-]?year')) then return true end
if (string.match(input, '%{%{[Ff]ilm ?date')) then return true end
if (string.match(input, '%{%{[ISO[ %-Rr]elease ?date')) then return true end
if (string.match(input, '%{%{[ISO[ %-]date')) then return true end
 
return false
 
end
Line 723 ⟶ 740:
 
end
 
-- Strips whitespace from an input
function trim(value)
local strip, count = string.gsub(value, '^%s*(.-)%s*$', '%1')
return strip
end
 
function stripFieldExtras(value)
Line 735 ⟶ 746:
-- note that we can't just replace matches with whitespace and catch them all, because it could be like '3 August<!---->20<ref/>12'
local matchStrip = value:match('^([^<]+-)<ref[^>]*>[^<]*</ref><ref[^>]*>[^<]*</ref><ref[^>]*>[^<]*</ref>$') -- basic refs (quite common)
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^([^<]+-)<ref[^>]*>[^<]*</ref><ref[^>]*>[^<]*</ref>$') -- basic refs (quite common)
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^([^<]+-)<ref[^>]*>[^<]*</ref>$') -- basic refs (quite common)
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^([^<]+-)<ref[^>]*/><ref[^>]*/><ref[^>]*/>$') -- basic named ref (quite common)
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^([^<]+-)<ref[^>]*/><ref[^>]*/>$') -- basic named ref (quite common)
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^([^<]+-)<ref[^>]*/>$') -- basic named ref (quite common)
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^<!--.--->([^<].+)$') -- comment before (sometimes used for notes to editors [not yet seen metadata-related comment])
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^([^<]-)<!--.--->$') -- comment after (sometimes used for notes to editors)
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^{{[Ff]lag ?icon[^}]+}}%s*{{[Ff]lag ?icon[^}]+}}([^<].+)$') -- 2 flag icons (also more common than one would think)
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^{{[Ff]lag ?icon[^}]+}}([^<].+)$') -- flag icon (quite common, although against MOS:ICON)
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^([^<]-){{[Ff]lag ?icon[^}]+)<!--.--->}}%s*{{[Ff]lag ?icon[^}]+}}$') -- comment after as (sometimes used for notes to editors)well
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^{{[Ff]lag ?icon[^}]+}}([^<]+)$') -- flag icon (quite common, although against MOS:ICON)
if (matchStrip) then return trim(matchStrip) end
matchStrip = value:match('^{{[Ff]lag ?icon[^}]+}}%s*{{[Ff]lag ?icon[^}]+}}([^<]+)$') -- 2 flag icons (also more common than one would think)
if (matchStrip) then return trim(matchStrip) end
return value -- if we didn't match anything, abort now
end
 
matchStrip = value:match('^([^<]-){{[Ff]lag ?icon[^}]+}}$')
function hasMetadataTemplates(input)
if (matchStrip) then return mw.text.trim(matchStrip) end
-- This is a basic list of the template names for metadata emiting tempaltes, there are inr eality more templates and more redirects
if (string.match(input, '%{%{[Ss]tart[ %-]?date')) then return true end
if (string.match(input, '%{%{[Ee]nd[ %-]?date')) then return true end
if (string.match(input, '%{%{[Bb]irth[ %-]?date')) then return true end
if (string.match(input, '%{%{[Dd]eath[ %-]?date')) then return true end
if (string.match(input, '%{%{[Bb]irth[ %-]?year')) then return true end
if (string.match(input, '%{%{[Dd]eath[ %-]?year')) then return true end
if (string.match(input, '%{%{[Ff]ilm ?date')) then return true end
if (string.match(input, '%{%{[ISO[ %-]date')) then return true end
 
matchStrip = value:match('^{{[Nn]o ?wrap *%|([^}%|]+)}}$') -- no-wrapped value
return false
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^{{[Nn]o ?break *%|([^}%|]+)}}$') -- no-wrapped redirect
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^{{[Nn]obr *%|([^}%|]+)}}$') -- no-wrapped redirect
if (matchStrip) then return mw.text.trim(matchStrip) end
 
matchStrip = value:match('^{{[Jj] *%|([^}%|]+)}}$') -- no-wrapped redirect, yes '{{j|...}}'
if (matchStrip) then return mw.text.trim(matchStrip) end
 
return value -- if we didn't match anything, abort now
end
 
Line 794 ⟶ 807:
end
 
input = stripFieldExtras(mw.text.trim(input))
 
-- If there is nothing but whitespace, don't bother
Line 844 ⟶ 857:
 
function main.outputRawStripped(frame)
return stripFieldExtras(mw.text.trim(mw.text.decode(mw.text.unstrip(frame.args[1]))))
end
 
function main.reoutputme(frame)
--if (frame.args.preprocess and frame.args.preprocess == 'yes') then
-- return frame:preprocess(mw.text.decode(mw.text.unstrip(frame.args[1])))
.. '[[Category:Dummy]]' --else
-- return mw.text.decode(mw.text.unstrip(frame.args[1])) .. '[[Category:Dummy]]'
else
--end
return mw.text.decode(mw.text.unstrip(frame.args[1])) .. '[[Category:Dummy]]'
end
----[[
-- frame.args[1]
-- frame:getParent().args[1]
-- frame:getArgument(1)
--do return frame:getArgument(1):expandTo('text/plain') end
--[[local input = mw.text.decode(mw.text.unstrip(frame.args[1]))
s = 'Len=' .. #input .. ' '
Line 860 ⟶ 881:
s = s .. string.sub(input, i, i) .. ' '
end
return s--]]
end