Content deleted Content added
fix the script |
Maintenance: mw:RL/MGU - Updated deprecated module name |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1:
/*jshint strict: false, asi: true, eqeqeq: false, curly: false, laxbreak:true, forin:false, boss:true, funcscope:true, noempty: false */
if( mw.config.get( 'wgAction' ) =='edit' || mw.config.get( 'wgAction' ) =='submit' ) $(function(){▼
/*global mw, $, urlDecoderCustom, urlDecoderPrefixes, urlDecoderEngNames */
var btn = newToolbarBtn;
function addUrlDecoderButton(){
btn(
);
}
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 ( mw.user.options.get('usebetatoolbar') ) {▼
▲ if ( $.inArray( mw.config.get( 'wgAction' ), [
mw.loader.using( 'ext.wikiEditor.toolbar', newToolbarBtn );▼
} else {▼
oldToolbarBtn();▼
addUrlDecoderButton();
}
} );
}
// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook( 'ext.lqt.textareaCreated' ).add( addUrlDecoderButton );
} );
function newToolbarBtn(bId, bFunc, bIcon, bTitle){
var msg = {}; msg[bId] = bTitle; mw.messages.set(msg) // mw.usability.addMessages(msg) doesn't work
$('#wpTextbox1').wikiEditor('addToToolbar', {
section:'main', group:'insert', tools: {
Line 37 ⟶ 39:
icon: bIcon
}}})
}
function oldToolbarBtn(bId, bFunc, bIcon, bTitle, bKey){
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 ){
updateTooltipAccessKeys( btn[0] )▼
btn.attr({ accesskey: bKey, title: bTitle + ' ['+bKey+']' })
}
}
/**/
Line 85 ⟶ 82:
var httpRegExp = '((?:https?:)?\\/\\/[^\\]\\[\\n\\r<>" ]+)' // any chars except []<>" and \n and spaces
var localPrefix = WMPrefixes
var oldText, newText, isBeforeCursor, colonNS
var tbox = $('#wpTextbox1').focus()
oldText = tbox.textSelection( 'getSelection' )
var rx
if( oldText ){ //there was selection
newText = oldText.replace(rx, simplifyMatched)
Line 121 ⟶ 118:
//try to find http in oldText
var ma = rx.exec( oldText ) // result: (whole string)' '[', 'http:...', ' name]'
if( !ma ) return
Line 153 ⟶ 150:
var trail = RegExp(
'['
+ ',;
+ ( /\(/.test(url) ? '' : '\\)' ) //also closing bracket without opening bracket
+ ']+$'
Line 178 ⟶ 175:
var decodingFailed //need to skip some strange percent-encoded URIs
//percent-decoding
Line 207 ⟶ 203:
if( link ){
link = link.replace(/%(3f|26|22)/ig, decodeURIComponent) //decode ?&"
if( ( mw.config.get( 'wgNamespaceNumber' ) === 0 || mw.config.get( 'wgNamespaceNumber' ) === 14 ) && isBeforeCursor )
link = link.replace(/^:/,'') //probably user adding interwiki
return '[
}
Line 227 ⟶ 223:
//add bugzilla to user-defined prefixes
window.urlDecoderPrefixes = $.extend( window.urlDecoderPrefixes,
{ 'https://bugzilla.wikimedia.org/show_bug.cgi?id=' : 'mediazilla' } )
Line 323 ⟶ 319:
return [proj, lang]
▲function unSecure(url){
}
Line 353 ⟶ 325:
if( ! colonNS ){ //define list of all possible category and file namespaces
var list = ['file', 'category'] //canonical aliases
var namespaces = mw.config.get( 'wgNamespaceIds' );
for( var name in namespaces )
|