Diferencia entre revisiones de «MediaWiki:Gadget-Versalitas.js»

De EIFA - Estudios Interdisciplinares de las Fuentes Avilistas
Etiqueta: Revertido
Etiqueta: Reversión manual
Línea 1: Línea 1:
function makeMyTool() {
function makeUnlinkYearsTool() {
// Function to modify wikitext
function unlinkYears( wikitext ) {
return wikitext.replace( /\[\[(\d+)\]\]/g, '$1' )
.replace( /\[\[\d+\|(.*?)\]\]/g, '$1' );
}


//Create and register command
// Create and register command
var inicio = 'PRUEBA UNO';
function UnlinkYearsCommand() {
UnlinkYearsCommand.parent.call( this, 'unlinkYears' );
}
OO.inheritClass( UnlinkYearsCommand, ve.ui.Command );


ve.ui.commandRegistry.register(
UnlinkYearsCommand.prototype.execute = function ( surface ) {
new ve.ui.Command( 'mycommand', 'mwWikitext', 'toggleWrapSelection',  
var surfaceModel, fragment, wikitext, data = [], onCompleteText;
{ args: [ '<nowiki>', '</nowiki>', nowikiLabel ], supportedSelections: [ 'linear' ] }
// Get fragment to work on
)
surfaceModel = surface.getModel();
);
fragment = surfaceModel.getFragment();
if ( fragment.getSelection().isCollapsed() ) {
surfaceModel.setLinearSelection(
new ve.Range( 0, surfaceModel.getDocument().data.getLength() )
);
fragment = surfaceModel.getFragment();
onCompleteText = true;
}
// Visual mode
if ( ve.init.target.getSurface().getMode() !== 'source' ) {
fragment.annotateContent(
'clear',
fragment.getAnnotations( true ).filter( function ( annotation ) {
return annotation.getType() === 'link/mwInternal' &&
/^\d+$/.test( annotation.getAttribute( 'normalizedTitle' ) );
} )
);
return true;
}
// Source mode
wikitext = fragment.getText( true ).replace( /^\n/, '' ).replace( /\n\n/g, '\n' );
wikitext = unlinkYears( wikitext );
wikitext.split( '' ).forEach( function ( c ) {
if ( c === '\n' ) {
data.push( { type: '/paragraph' } );
data.push( { type: 'paragraph' } );
} else {
data.push( c );
}
} );
if ( onCompleteText ) {
fragment.insertContent( wikitext );
} else {
fragment.insertContent( data );
}
if ( onCompleteText ) {
fragment.collapseToStart().select();
}
return true;
};


//Create and register wikitext command
ve.ui.commandRegistry.register( new UnlinkYearsCommand() );
if ( ve.ui.wikitextCommandRegistry ) {
 
ve.ui.wikitextCommandRegistry.register(
// Create, register and insert tool
new ve.ui.Command( 'mycommand', 'mwWikitext', 'wrapSelection', {
function UnlinkYearsTool() {
args: [ '{{MyTemplate|', '}}', 'my parameter' ],
UnlinkYearsTool.parent.apply( this, arguments );
supportedSelections: [ 'linear' ]
} )
);
}
}
OO.inheritClass( UnlinkYearsTool, ve.ui.Tool );


//Create and register tool
UnlinkYearsTool.static.name = 'unlinkYears';
function MyTool() {
UnlinkYearsTool.static.group = 'utility';
MyTool.parent.apply( this, arguments );
UnlinkYearsTool.static.title = 'Unlink years';
}
UnlinkYearsTool.static.icon = 'noWikiText';
OO.inheritClass( MyTool, ve.ui.MWTransclusionDialogTool );
UnlinkYearsTool.static.commandName = 'unlinkYears';
UnlinkYearsTool.static.autoAddToCatchall = false;
UnlinkYearsTool.static.deactivateOnSelect = false;
 
UnlinkYearsTool.prototype.onUpdateState = function () {
UnlinkYearsTool.parent.prototype.onUpdateState.apply( this, arguments );
this.setActive( false );
};


MyTool.static.name = 'mytool';
ve.ui.toolFactory.register( UnlinkYearsTool );
MyTool.static.group = 'textStyle';
MyTool.static.title = 'My tool';
MyTool.static.commandName = 'mycommand';
ve.ui.toolFactory.register( MyTool );


ve.init.mw.DesktopArticleTarget.static.actionGroups[ 1 ].include.push( 'unlinkYears' );
}
}


// Initialize
// Initialize
mw.hook( 've.loadModules' ).add( function( addPlugin ) {
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).then( function () {
addPlugin( makeMyTool );
mw.libs.ve.addPlugin( function () {
return mw.loader.using( [ 'ext.visualEditor.core' ] )
.then( function () {
makeUnlinkYearsTool();
} );
} );
} );
} );

Revisión del 13:15 22 ene 2022

function makeUnlinkYearsTool() {
	// Function to modify wikitext
	function unlinkYears( wikitext ) {
		return wikitext.replace( /\[\[(\d+)\]\]/g, '$1' )
			.replace( /\[\[\d+\|(.*?)\]\]/g, '$1' );
	}

	// Create and register command
	function UnlinkYearsCommand() {
		UnlinkYearsCommand.parent.call( this, 'unlinkYears' );
	}
	OO.inheritClass( UnlinkYearsCommand, ve.ui.Command );

	UnlinkYearsCommand.prototype.execute = function ( surface ) {
		var surfaceModel, fragment, wikitext, data = [], onCompleteText;
		// Get fragment to work on
		surfaceModel = surface.getModel();
		fragment = surfaceModel.getFragment();
		if ( fragment.getSelection().isCollapsed() ) {
			surfaceModel.setLinearSelection(
				new ve.Range( 0, surfaceModel.getDocument().data.getLength() )
			);
			fragment = surfaceModel.getFragment();
			onCompleteText = true;
		}
		// Visual mode
		if ( ve.init.target.getSurface().getMode() !== 'source' ) {
			fragment.annotateContent(
				'clear',
				fragment.getAnnotations( true ).filter( function ( annotation ) {
					return annotation.getType() === 'link/mwInternal' &&
						/^\d+$/.test( annotation.getAttribute( 'normalizedTitle' ) );
				} )
			);
			return true;
		}
		// Source mode
		wikitext = fragment.getText( true ).replace( /^\n/, '' ).replace( /\n\n/g, '\n' );
		wikitext = unlinkYears( wikitext );
		wikitext.split( '' ).forEach( function ( c ) {
			if ( c === '\n' ) {
				data.push( { type: '/paragraph' } );
				data.push( { type: 'paragraph' } );
			} else {
				data.push( c );
			}
		} );
		if ( onCompleteText ) {
			fragment.insertContent( wikitext );
		} else {
			fragment.insertContent( data );
		}
		if ( onCompleteText ) {
			fragment.collapseToStart().select();
		}
		return true;
	};

	ve.ui.commandRegistry.register( new UnlinkYearsCommand() );

	// Create, register and insert tool
	function UnlinkYearsTool() {
		UnlinkYearsTool.parent.apply( this, arguments );
	}
	OO.inheritClass( UnlinkYearsTool, ve.ui.Tool );

	UnlinkYearsTool.static.name = 'unlinkYears';
	UnlinkYearsTool.static.group = 'utility';
	UnlinkYearsTool.static.title = 'Unlink years';
	UnlinkYearsTool.static.icon = 'noWikiText';
	UnlinkYearsTool.static.commandName = 'unlinkYears';
	UnlinkYearsTool.static.autoAddToCatchall = false;
	UnlinkYearsTool.static.deactivateOnSelect = false;

	UnlinkYearsTool.prototype.onUpdateState = function () {
		UnlinkYearsTool.parent.prototype.onUpdateState.apply( this, arguments );
		this.setActive( false );
	};

	ve.ui.toolFactory.register( UnlinkYearsTool );

	ve.init.mw.DesktopArticleTarget.static.actionGroups[ 1 ].include.push( 'unlinkYears' );
}

// Initialize
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).then( function () {
	mw.libs.ve.addPlugin( function () {
		return mw.loader.using( [ 'ext.visualEditor.core' ] )
			.then( function () {
				makeUnlinkYearsTool();
			} );
	} );
} );