Module:Links/sandbox

-- Creates links and changes wikitext when it detects external links -- Syntax -- local p = {}

function p.link(url,desc,typ) local url = url or "" local lenUrl = mw.ustring.len(url) local uMatch = mw.ustring.match

if typ == "ext" and (not uMatch(url, "%.") or lenUrl < 3) or lenUrl < 1 then return end

local prefix = ""   local suffix = "" local separator = "|"

if url:match("^[Cc]ategory:") and typ ~= "ext" then prefix = "[[:"   end

-- Adapt if url is external if typ ~= "local" and (uMatch(url, "www%.") or uMatch(url, "^http")) or typ == "ext" then prefix = "[//"

if uMatch(url, "^http") then prefix = "[" end

suffix = "]" separator = " " end

local desc = desc or ""

if mw.ustring.len(desc) < 1 then separator = "" end

return prefix .. url .. separator .. desc .. suffix end

function p.main(frame) local args = require("Dev:Arguments").getArgs(frame) return p.link(args[1] or args.page, args[2] or args.desc,args.type) end

function p.batch(frame) local args = require("Dev:Arguments").getArgs(frame) return p.createLinkBatch(args) end

function p.createLinkBatch(links) local linkTable = {} local linkBatch,linkUrl,linkLabel,linkType = "","","","" local separator = " • " for _, linkData in ipairs(links) do       linkTable = mw.text.split(linkData,"%s") linkUrl = linkTable[1] linkLabel = linkTable[2] linkType = linkTable[3] linkBatch = linkBatch .. p.link(linkUrl,linkLabel,linkType) .. separator end return linkBatch end

return p