Content deleted Content added
add digits with ordinal |
back |
||
(36 intermediate revisions by the same user not shown) | |||
Line 198:
-- Digits with letters
local foundPositionStart, foundPositionEnd, foundMatch, foundMatch2 = mw.ustring.find(seekString, '^([0-9]
if (foundPositionStart) then
-- Additionally check how many digits we actually have, as arbitrary number isn't valid
if (#foundMatch <= 2) then -- most likely a day number
if (foundMatch2 == 'st' or foundMatch2 == 'nd' or foundMatch2 == 'rd' or foundMatch2 == 'th') then -- won't bother checking against a number, no false positives that I saw in 120k cases
currentPosition = foundPositionEnd + 1 -- this is our new start ___location (forced to do this here, since we don't always return)
return ELEMENT_ONETWODIGITSWITHORDINAL, tonumber(foundMatch), (currentPosition > mw.ustring.len(seekString))
--else -- let it capture digits again, this time '10am' '8p.m.' will be separate
else▼
-- return ELEMENT_INVALID -- not a valid ordinal indicator
end
--else -- let it capture digits again, this time '10am' '8p.m.' will be separate
-- return ELEMENT_INVALID -- just the invalid, the number of digits (3+) won't match any patterns
end
end
Line 382 ⟶ 383:
if (elements[3] == ELEMENT_MONTHWORD) then -- '3 May'
if (numberOfElements == 3) then return checkAndOutput(nil, values[3], values[1], nil, nil, nil) end
if (elements[4] == ELEMENT_WHITESPACE or elements[4] == ELEMENT_PERIODWHITESPACE or elements[4] == ELEMENT_COMMA) then -- '3 May ' or '3 Feb. ' or '3 May, '
if (elements[5] == ELEMENT_FOURDIGITS) then -- '3 May 2013'
if (numberOfElements == 5) then return checkAndOutput(values[5], values[3], values[1], nil, nil, nil) end
Line 406 ⟶ 407:
end
elseif (elements[6] == ELEMENT_DASH or elements[6] == ELEMENT_DATESEPARATOR) then -- '3 May 2013 - '
if (elements[7] == ELEMENT_ONETWODIGITS or elements[
if (elements[8] == ELEMENT_WHITESPACE) then -- '3 May 2013 - 12 '
if (elements[9] == ELEMENT_MONTHWORD) then -- '3 May 2013 - 12 February'
Line 678 ⟶ 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[ %-]date')) then return true end
return false▼
end
Line 702 ⟶ 720:
if (result == PARSERESULT_FAIL) then if (frame.args[2] == 'pretty') then return frame:preprocess('\'\'{{gray|Failed parse}}\'\'') else return 'Failed parse' end end
if (result == PARSERESULT_UNRECOGNIZED) then
local s
if (hasMetadataTemplates(input)) then s = 'Has metadata template' else s = 'Unrecognized pattern' end
if (frame.args[2] == 'pretty') then return frame:preprocess('\'\'{{gray|'..s..'}}\'\'') else return s end
end
if (result == PARSERESULT_INVALID) then if (frame.args[2] == 'pretty') then return frame:preprocess('\'\'{{maroon|Invalid date/time}}\'\'') else return 'Invalid date/time' end end
if (result == PARSERESULT_INVALIDRANGE) then if (frame.args[2] == 'pretty') then return frame:preprocess('\'\'{{maroon|Invalid date range}}\'\'') else return 'Invalid date range' end end
Line 721 ⟶ 743:
function stripFieldExtras(value)
-- todo: do progressive scan like with that seek string just for ref tags and such
-- 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
if (
if (
if (
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)
▲end
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)
▲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('^{{[Ff]lag ?icon[^}]+}}%s*{{[Ff]lag ?icon[^}]+}}(.+)$') -- 2 flag icons (also more common than one would think)
▲ return false
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[^}]+}}$') -- after as well
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^([^<]-){{[Ff]lag ?icon[^}]+}}$')
if (matchStrip) then return mw.text.trim(matchStrip) end
matchStrip = value:match('^{{[Nn]o ?wrap *%|([^}%|]+)}}$') -- no-wrapped value
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 761 ⟶ 807:
end
input = stripFieldExtras(mw.text.trim(input))
-- If there is nothing but whitespace, don't bother
Line 811 ⟶ 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])))
▲ else
▲ return mw.text.decode(mw.text.unstrip(frame.args[1])) .. '[[Category:Dummy]]'
----[[
-- frame.args[1]
-- frame:getParent().args[1]
-- frame:getArgument(1)
--do return frame:getArgument(1):expandTo('text/plain') end
s = 'Len=' .. #input .. ' '
Line 827 ⟶ 881:
s = s .. string.sub(input, i, i) .. ' '
end
return s--]]
end
|