 this module implements urlu800 seeu800 unit tests atu800 module urlu800 testcases local pu800 local function safeuri su800 local success uriu800 pcall function return mwu800u82euriu800u82enewu800 su800 endu800 ifu800 success then return uriu800 endu800 endu800 local function extracturl args foru800 name valu800 inu800 pairs args dou800 ifu800 name 2u800 andu800 name "msgu800" then local urlu800 name .. " " .. valu800; urlu800 mwu800u82eustringu82egsub urlu800 ' hhu800 ttu800 ttu800 ppu800 ssu800 ' 'http 1u800 3u800' local uriu800 safeuri urlu800 ; ifu800 uriu800 andu800 uriu800u82ehost then return urlu800 endu800 endu800 endu800 endu800 function pu800u82e_url urlu800 text msgu800 urlu800 mwu800u82etextu82etrim urlu800 oru800   text mwu800u82etextu82etrim text oru800   local nomsg msgu800 oru800   subu800 1u800 1u800 lower "nu800" oru800 msgu800 'false' boolean true ifu800 msgu800 isu800 "false" oru800 starts with nu800 oru800 nu800 ifu800 urlu800   then ifu800 text   then ifu800 nomsg then return nilu800 else return mwu800u82egetcurrentframe expandtemplate title 'tlxu800' args 'u8d986u8d8b4u8d8a7u8d986u8db8c u8d988u8d8a8' " exampleu82ecomu800 " " u8d985u8d8aau8d986 u8d986u8d985u8d8a7u8db8cu8d8b4u8db8c u8d8a7u8d8aeu8d8aau8db8cu8d8a7u8d8b1u8db8c " endu800 else return text endu800 endu800 ifu800 theu800 urlu800 contains anyu800 unencoded spaces encode them because mediawiki will otherwise interpret au800 space asu800 theu800 endu800 ofu800 theu800 urlu800. urlu800 mwu800u82eustringu82egsub urlu800 ' su800' function su800 return mwu800u82euriu800u82eencode su800 'path' endu800 ifu800 there isu800 anu800 empty query string oru800 fragment idu800 remove itu800 asu800 itu800 will cause mwu800u82euriu800u82enewu800 tou800 throw anu800 error urlu800 mwu800u82eustringu82egsub urlu800 '# '   urlu800 mwu800u82eustringu82egsub urlu800 ' '   ifu800 itu800 itu800'su800 anu800 http su800 urlu800 without theu800 double slash fixu800 itu800. urlu800 mwu800u82eustringu82egsub urlu800 ' hhu800 ttu800 ttu800 ppu800 ssu800 ' 'http 1u800 3u800' handle urls from wikidata ofu800 theu800 format http&#58u800; urlu800 mwu800u82eustringu82egsub urlu800 ' hhu800 ttu800 ttu800 ppu800 ssu800 &#58u800; ' 'http 1u800 ' local uriu800 safeuri urlu800 handle urlu800 urlu800'su800 without au800 protocol andu800 urlu800 urlu800'su800 that areu800 protocol relative eu800u82egu800. wwwu800u82eexampleu82ecomu800 foou800 oru800 wwwu800u82eexampleu82ecomu800 8080 foou800 andu800 wwwu800u82eexampleu82ecomu800 foou800 ifu800 uriu800 andu800 notu800 uriu800u82eprotocol oru800 uriu800u82eprotocol andu800 notu800 uriu800u82ehost andu800 urlu800 subu800 1u800 2u800 ' ' then urlu800 ' ' .. urlu800 uriu800 safeuri urlu800 endu800 ifu800 text   then ifu800 uriu800 then ifu800 uriu800u82epath ' ' then uriu800u82epath   endu800 local port   ifu800 uriu800u82eport then port ' ' .. uriu800u82eport endu800 text mwu800u82eustringu82elower uriu800u82ehost oru800   .. port .. uriu800u82erelativepath oru800   addu800 before _u800 . # sequences text mwu800u82eustringu82egsub text " " " 1u800" this entry must beu800 theu800 first. " " hasu800 au800 " " inu800 itu800 youu800 know. text mwu800u82eustringu82egsub text " . " " 1u800" text mwu800u82eustringu82egsub text " " " 1u800" disabled foru800 nowu800 text mwu800u82eustringu82egsub text " # " " 1u800" text mwu800u82eustringu82egsub text " _u800 " " 1u800" else urlu800 isu800 badly formed sou800 just display whatever wasu800 passed inu800 text urlu800 endu800 endu800 return mwu800u82eustringu82eformat ' su800 su800 ' urlu800 text endu800 theu800 main entry point foru800 calling from template urlu800. function pu800u82eurlu800 frame local templateargs frameu82eargs local parentargs frame getparent .args local urlu800 templateargs 1u800 oru800 parentargs 1u800 local text templateargs 2u800 oru800 parentargs 2u800 oru800   local msgu800 templateargsu82emsgu800 oru800 parentargsu82emsgu800 oru800   urlu800 urlu800 oru800 extracturl templateargs oru800 extracturl parentargs oru800   return pu800u82e_url urlu800 text msgu800 endu800 theu800 entry point foru800 calling from theu800 forked template url2. this function returns nou800 message byu800 default. itu800 strips outu800 wiki link markup html tags andu800 everything after au800 space. function pu800u82eurl2 frame local templateargs frameu82eargs local parentargs frame getparent .args local urlu800 templateargs 1u800 oru800 parentargs 1u800 local text templateargs 2u800 oru800 parentargs 2u800 oru800   default tou800 nou800 message local msgu800 templateargsu82emsgu800 oru800 parentargsu82emsgu800 oru800 'nou800' urlu800 urlu800 oru800 extracturl templateargs oru800 extracturl parentargs oru800   strip outu800 html tags andu800 from urlu800 urlu800 urlu800 oru800   gsub " * " "" gsub " " "" truncate anything after au800 space urlu800 urlu800 gsub " 20u800" " " gsub " .*" "" return pu800u82e_url urlu800 text msgu800 endu800 return pu800 