Module:FindYDCportal
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 342,000 pages, or roughly 1% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
A helper module to find the most specific chronology portal which actually exists for a given year or decade. Used to simplify linking to a chronology portal.
- October 2019 update
All by-year and by-century portals have been deleted. There are now only 8 decade portals, listed in Category:Decades portals.
So all checking for century and year portals has been disabled.
If any of the decade portals are deleted, then this module should be edited to remove that decade from the table existingDecadePortals
Parameters
Takes one parameter, which must be either a year (e.g. "1879", "1123") or a decade (e.g. "1940s", "730s").
If the parameter is missing, empty, or does not fit the required format, an empty string is returned.
Output
If a portal is found, returns its name without the namespace prefix, e.g.
- for "Portal:1980s" return
1980s
- for "Portal:19th century" return
19th century
If no portal is found, it returns an empty string.
Usage
- Year parameter
{{#invoke: FindYDCportal | findydcportal |YYYY}}
... where YYYY
is a 3- or 4-digit year
- Decade parameter
{{#invoke: FindYDCportal | findydcportal |YYY0s}}
... where YYY0s
is a 3- or 4-digit decade
Examples
- Years
{{#invoke: FindYDCportal | findydcportal |2018}}
→ Script error: The function "findydcportal" does not exist.{{#invoke: FindYDCportal | findydcportal |1935}}
→ Script error: The function "findydcportal" does not exist.{{#invoke: FindYDCportal | findydcportal |1857}}
→ Script error: The function "findydcportal" does not exist.{{#invoke: FindYDCportal | findydcportal |736}}
→ Script error: The function "findydcportal" does not exist.{{#invoke: FindYDCportal | findydcportal |1800}}
→ Script error: The function "findydcportal" does not exist.
- Decades
{{#invoke: FindYDCportal | findydcportal |2000s}}
→ Script error: The function "findydcportal" does not exist.{{#invoke: FindYDCportal | findydcportal |1940s}}
→ Script error: The function "findydcportal" does not exist.{{#invoke: FindYDCportal | findydcportal |560s}}
→ Script error: The function "findydcportal" does not exist.
- Missing parameter
{{#invoke: FindYDCportal | findydcportal}}
→ Script error: The function "findydcportal" does not exist.
- Empty parameter
{{#invoke: FindYDCportal | findydcportal | }}
→ Script error: The function "findydcportal" does not exist.
- Invalid parameter
{{#invoke: FindYDCportal | findydcportal | 1927-related}}
→ Script error: The function "findydcportal" does not exist.{{#invoke: FindYDCportal | findydcportal | Swedish chef}}
→ Script error: The function "findydcportal" does not exist.
Logic
If the parameter is a year:
- If the year portal exists, return its name.
Otherwise try the decade. - If the decade portal exists, return its name.
Otherwise try the century - If the century portal exists, return its name.
Otherwise return an empty string
If the parameter is a decade:
- If the decade portal exists, return its name.
Otherwise try the century - If the century portal exists, return its name.
Otherwise return an empty string
See also
local p = {}
function p.navyear(frame)
--Expects one paramter
-- {{{1}}}= a 3- or 4-digit year or deacde
-- e.g. 1916
-- 1504
-- 1630s
-- 920s
local arg1 = frame.args[1]
if arg1 == nil
then
return ""
end
if (mw.ustring.match(arg1, "^%d%d%d%d?$")) then
return checkYear(tonumber(arg1))
elseif (mw.ustring.match(arg1, "^%d%d%d?0s$")) then
return checkDecade(mw.ustring.gsub(arg1, "^(%d%d%d?0)s$"), "%1")
end
return ""
end
return p