User:Js/urldecoder.js: Difference between revisions

Content deleted Content added
m Remove outdated comment about deprecated global wgNamespaceIds, available since MW 1.16 (which is now unsupported)
Maintenance: mw:RL/MGU - Updated deprecated module name
 
(3 intermediate revisions by 3 users not shown)
Line 12:
}
 
mw.loader.using( [ 'user.options', 'jquery.textSelection', 'mediawiki.util' ], function () {
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
$(document).ready( function () {
if ( mw.user.options.get('usebetatoolbar') ) {
mw.loader.using( 'ext.wikiEditor.toolbar', addUrlDecoderButton );
} else {
btn = oldToolbarBtn;
Line 45:
 
var btn = $('<img class=mw-toolbar-custombutton id="' + bId + '">')
.attr({ src: bIcon, title: bTitle, alt: bTitle.substr(0,3) })
.css({ height:'20px', 'background-color':'#bce', border:'1px outset #bce', margin:'0 1px', cursor:'pointer'})
.click(bFunc)
.appendTo('#toolbar')
if( bKey ){
mw.util.updateTooltipAccessKeys( btn[0] )
btn.attr({ accesskey: bKey, title: bTitle + ' ['+bKey+']' })
mw.util .updateTooltipAccessKeys( btn[0] );
}
Line 82:
 
var httpRegExp = '((?:https?:)?\\/\\/[^\\]\\[\\n\\r<>" ]+)' // any chars except []<>" and \n and spaces
var localPrefix = WMPrefixes( unSecure( mw.config.get( 'wgServer' ).replace(/^\/\//,'http://') + mw.config.get( 'wgScript' ) ) )
var oldText, newText, isBeforeCursor, colonNS
 
Line 175:
 
var decodingFailed //need to skip some strange percent-encoded URIs
url = unSecure(url)
 
//percent-decoding
Line 320 ⟶ 319:
return [proj, lang]
 
}
 
 
 
function unSecure(url){
var mm = /https:\/\/secure\.wikimedia\.org\/(\w+)\/(\w+)\/([^\]\|\n\r ]+)/i.exec( url )
if( !mm) return url
var ___domain = mm[1].toLowerCase(), sub = mm[2].toLowerCase()
 
if( ! wmDomainM[___domain] ) return url //___domain not recognized
if( ___domain == 'wikipedia' ) //handle some special cases
switch( sub ){
case 'mediawiki': sub = 'www'; ___domain = 'mediawiki'; break
case 'foundation': sub = ''; ___domain = 'wikimediafoundation'; break
case 'sources': sub = ''; ___domain = 'wikisource'; break
default:
if( wmSubDomains.test(sub) ) ___domain = 'wikimedia' // .../wikipedia/meta -> meta.wikimedia.org
//otherwise: consider it language: .../wikipedia/en
}
return 'https://' + (sub ? sub + '.' : '') + ___domain + '.org/' + mm[3]
}