User:Js/urldecoder.js: Difference between revisions

Content deleted Content added
Js (talk | contribs)
code restructuring, fixes and improvements
Js (talk | contribs)
+ urlDecoderCustom call for user-defined URL processing, e.g. conversion to template
Line 113:
url = unSecure(url)
if (url.indexOf('%') != -1) try { url = decodeURI(url) } catch(e){} //decode %
url = url.replace(/%(3B|2F|2C|3A)/g, function(s){return decodeURIComponent(s)}) //decode ;/,:
url = url.replace(/[ <>"\[\]]/g, function(s){return encodeURIComponent(s)}) //" disallowed chars
if (isBeforeCursor)
for (var n in window.urlDecoderEngNames) //to eng keywords
url = url.replace(RegExp('(title=|wiki\/)('+urlDecoderEngNames[n]+':)'), '$1' + n + ':')
var link = toWikilink(url)
if (!link && window.urlDecoderCustom
if (link){ //(below) usually no need for leading colon in articles (e.g. inserting interwiki or category)
&& (link = urlDecoderCustom(url)) && /^(https?:\/\/|\{\{)/.test(link))
if (wgNamespaceNumber==0 || wgNamespaceNumber==14) link=link.replace(/^:/,'')
{url = link; link = null} //still external
return '[\[' + link + (name?'|'+name:'') + ']]'
if (link){
link = link.replace(/%(3f|26)/ig, decodeURIComponent) //decode ?&
link = link.replace(/%3f/ig,'?') //decode ?
if (wgNamespaceNumber==0 || wgNamespaceNumber==14) link=link.replace(/^:/,'') //interwiki?
return '[\[' + link + (name?'|'+name:'') + ']]'
}else if (typeof name == 'string') return '[' + url + (name?' '+name:'') + ']' //empty name
else return url
Line 208 ⟶ 213:
return RegExp('^('+ns+'|file|category) *:','i').test(pg)
}
 
function requestColonNS(){
Line 227 ⟶ 231:
return ns
}
 
 
function showMsg(htm){