Module:Redirect: Difference between revisions

Trying a bracket option after all. But only if chosen
(arg.)
(Trying a bracket option after all. But only if chosen)
Line 8: Line 8:
   if parent then pargs = parent.args else pargs={} end
   if parent then pargs = parent.args else pargs={} end
   local rname=args[1] or pargs[1] or ""
   local rname=args[1] or pargs[1] or ""
  local bracket=args.bracket or pargs.bracket
  local bb = "";local be= "" -- store brackets if restoring to an output if bracket option is set
   if rname then
   if rname then
       if mw.ustring.gsub(rname,"%s","") == "" then return "" end
       if mw.ustring.gsub(rname,"%s","") == "" then return "" end
       else return "" end
      if bracket then
          local strip=mw.ustring.gsub(rname,"%[%[(.+)%]%]")
          if strip then rname=strip;bb="[[";be="]]" end
      end
       else return ""
  end
   local rpage=mw.title.new(rname)
   local rpage=mw.title.new(rname)
   local err=""
   local err=""
Line 17: Line 24:
       --  if rpage.fileExists then
       --  if rpage.fileExists then
             if rpage.isRedirect then
             if rpage.isRedirect then
               return (tostring(mw.ustring.match(tostring(rpage.getContent(rpage)),"REDIRECT.-%[%[(.-)%]%]")) or [=[<span style="text-color:red;">[[Module:redirect]] error: failed to understand - [[]=] .. rname .. [=[]]</span]=])
               return (bb.. tostring(mw.ustring.match(tostring(rpage.getContent(rpage)),"REDIRECT.-%[%[(.-)%]%]")) or [=[<span style="text-color:red;">[[Module:redirect]] error: failed to understand - [[]=] .. rname .. [=[]]</span]=] .. be)
             else return rname -- not a redirect so leave the original text (for some general-purpose template use)
             else return rname -- not a redirect so leave the original text (for some general-purpose template use)
             end
             end
Anonymous user