Module:Sandbox/Raph Williams65/Link

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
local p = {}

local function makeUrlLink(url, display)
            return string.format('[%s %s]', url, display)
end

function p._main(args)
local url
do
 local title
 if args.page then
     title = mw.titl.new(args.page)
 if not title then
   error (string.format( "'%s' is not a valid page name", args.page ), 2)
             end
       else
  title = mw.title.getCurrentTitle()
             end
     if args.anchor then
  title.fragment = args.anchor
    end
  url = title:fullUrl
'Link' 
local display
if args.page then
 display = args[1] or 'Link'
else
 display = mw.html.create('span')
 display
    :attr('title', 'Link to this page')
 display = tostring(display)
local root = mw.html.create('span')
 root
    :addClass('noprint')
    :addClass('plainlinks')
    :addClass('link')
    :wikitext(makeUrLink(url, display))
       return tostring(root)
end
end
end