Module:Excerpt/portals/sandbox explained

-- ATTENTION !-- This version of Excerpt is designed specifically for the portal namespace and its associated templates-- Prefer Module:Excerpt whenever possible

-- Name of the category to track content pages with errorslocal errorCategory = "Articles with broken excerpts"

-- Error messageslocal errorMessages =

-- Regular expressions to match all aliases of the file namespacelocal fileNamespaces =

-- Regular expressions to match all image parameterslocal imageParams =

-- Regular expressions to match all infobox parameters for image captionslocal captionParams =

-- List of file types that are allowed to be transcludedlocal fileTypes =

-- Regular expressions to match all inline templates that are undesirable in excerptslocal unwantedInlineTemplates =

-- Regular expressions to match all block templates that are desirable in excerptslocal wantedBlockTemplates =

local Transcluder = require("Module:Transcluder/sandbox")local escapeString = require("Module:String")._escapePatternlocal yesno = require('Module:Yesno')local p =

-- Helper function to test for truthy and falsy valueslocal function is(value) if not value or value

"" or value

"0" or value

"false" or value

"no" then return false end return trueend

-- Error handling function-- Throws a Lua error or returns an empty string if error reporting is disabledlocal errors = true -- show errors by defaultlocal function luaError(message, value) if not is(errors) then return end -- error reporting is disabled message = errorMessages[message] or message or message = mw.ustring.format(message, value) error(message, 2)end

-- Error handling function-- Returns a wiki friendly error or an empty string if error reporting is disabledlocal function wikiError(message, value) if not is(errors) then return end -- error reporting is disabled message = errorMessages[message] or message or message = mw.ustring.format(message, value) message = errorMessages.prefix .. message if mw.title.getCurrentTitle.isContentPage then local errorCategory = mw.title.new(errorCategory, 'Category') if errorCategory then message = message .. '' .. errorCategory.prefixedText .. '' end end message = mw.html.create('div'):addClass('error'):wikitext(message) return messageend

-- Helper function to match from a list regular expressions-- Like so: match pre..list[1]..post or pre..list[2]..post or ...local function matchAny(text, pre, list, post, init) local match = for i = 1, #list do match = if match[1] then return unpack(match) end end return nilend

-- Helper function to convert imagemaps into standard imageslocal function convertImageMap(imagemap) local image = matchAny(imagemap, "[>\n]%s*", fileNamespaces, "[^\n]*") if image then return "" .. mw.ustring.gsub(image, "[>\n]%s*", "", 1) .. "" else return "" -- remove entire block if image can't be extracted endend

-- Helper function to convert a comma-separated list of numbers or min-max ranges into a list of booleans-- For example: "1,3-5" to local function numberFlags(str) if not str then return end local flags = local ranges = mw.text.split(str, ",") -- parse ranges: "1,3-5" to for _, r in pairs(ranges) do local min, max = mw.ustring.match(r, "^%s*(%d+)%s*[-–—]%s*(%d+)%s*$") -- "3-5" to min=3 max=5 if not max then min, max = mw.ustring.match(r, "^%s*((%d+))%s*$") end -- "1" to min=1 max=1 if max then for p = min, max do flags[p] = true end end end return flagsend

-- Helper function to convert template arguments into an array of arguments fit for getlocal function parseArgs(frame) local args = for key, value in pairs(frame:getParent.args) do args[key] = value end for key, value in pairs(frame.args) do args[key] = value end -- args from a Lua call have priority over parent args from template args.paraflags = numberFlags(args["paragraphs"] or "") -- parse paragraphs: "1,3-5" to args.fileflags = numberFlags(args["files"] or "") -- parse file numbers return argsend

-- simulate without the footnote, given "N|485US|," or similarlocal function airreg(p) local s = mw.text.split(p, "%s*|%s*") if s[1] ~= "N" and s[1] ~= "HL" and s[1] ~= "JA" then s[1]=s[1] .. "-" end return table.concat(s, "")end

-- Helper function to remove unwanted templates and pseudo-templates such as #tag:ref and DEFAULTSORTlocal function stripTemplate(t) -- If template is unwanted then return "" (gsub will replace by nothing), else return nil (gsub will keep existing string) if matchAny(t, "^