User:Gryllida/js/processExternalLinks.js

/* Author : Svetlana Tkachenko svetlana@members.fsf.org Licence: GPLv3+ Description: [beta] removes external links from article body TODO: [ ]

technical details of customizing the toolbar snippets of code for common additions to the toolbar
 * http://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar customization
 * http://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar customization/Library



mw.loader.using(['mediawiki.api'], function {	"use strict";	var getRidOfExternalLinks= function{		var text = $( '#wpTextbox1' ).val;		alert(text);		alert('1');		var re = new RegExp('\[(http://[^\ ]*)\ (.*)\]', 'gi');		alert('2');		text = text.replace(re, 'Bla $1 $2 Foo');		alert('3');	};	var customizeToolbar = function  {		$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { 'section': 'main', 'group': 'insert', 'tools': { 'getRidOfExternalLinks': { label: 'get Rid Of External Links', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/thumb/f/f9/Remove_document_icon_%28the_Noun_Project_27892%29.svg/22px-Remove_document_icon_%28the_Noun_Project_27892%29.svg.png', 'action': { 'type': 'callback', execute: function(context){ getRidOfExternalLinks; }					},				}			}		});	};	/* 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 ) {		mw.loader.using( 'user.options' ).then( function { // This can be the string "0" if the user disabled the preference (T54542) if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) { $.when(					mw.loader.using( 'ext.wikiEditor' ), $.ready				).then( customizeToolbar ); }		} );	} });