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

De EIFA - Estudios Interdisciplinares de las Fuentes Avilistas
Etiqueta: Revertido
Línea 1: Línea 1:
function makeUnlinkYearsTool() {
/**
// Function to modify wikitext
* Adds direction mark tool to VE (for adding RLM)
function unlinkYears( wikitext ) {
*/
return wikitext.replace( /\[\[(\d+)\]\]/g, '$1' )
(function () {
.replace( /\[\[\d+\|(.*?)\]\]/g, '$1' );
// localization for button name
}
if(!mw.messages.exists('DirectionTool-toolname')){
mw.messages.set('DirectionTool-toolname', 'תו כיווניות');
}
// localization for rlm template name
if(!mw.config.exists('rlmTemplateName')){
mw.config.set('rlmTemplateName', 'כ');
}
//end of localization
 
function DirectionTool( toolGroup, config ) {
OO.ui.Tool.call( this, toolGroup, config );
}
OO.inheritClass( DirectionTool, OO.ui.Tool );


// Create and register command
DirectionTool.static.name = 'DirectionTool';
function UnlinkYearsCommand() {
DirectionTool.static.title = mw.msg('DirectionTool-toolname');
UnlinkYearsCommand.parent.call( this, 'unlinkYears' );
}
OO.inheritClass( UnlinkYearsCommand, ve.ui.Command );


UnlinkYearsCommand.prototype.execute = function ( surface ) {
DirectionTool.prototype.onSelect = function () {
var surfaceModel, fragment, wikitext, data = [], onCompleteText;
this.toolbar.getSurface().getModel().getFragment().collapseToEnd().insertContent([{
// Get fragment to work on
'type': 'mwTransclusionInline',
surfaceModel = surface.getModel();
'attributes': {
fragment = surfaceModel.getFragment();
'mw': {
if ( fragment.getSelection().isCollapsed() ) {
parts: [ {
surfaceModel.setLinearSelection(
template: {
new ve.Range( 0, surfaceModel.getDocument().data.getLength() )
target: {
);
href:  mw.config.get('wgFormattedNamespaces')[10]+ ':'+ mw.config.get('rlmTemplateName'),
fragment = surfaceModel.getFragment();
wt: mw.config.get('rlmTemplateName')
onCompleteText = true;
},
}
params: {}
// 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 = 'textStyle';
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 () {
DirectionTool.prototype.onUpdateState = function () {
UnlinkYearsTool.parent.prototype.onUpdateState.apply( this, arguments );
this.setActive( false );
this.setActive( false );
};
};


ve.ui.toolFactory.register( UnlinkYearsTool );
ve.ui.toolFactory.register( DirectionTool );
 
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();
} );
} );
} );

Revisión del 12:19 22 ene 2022

/**
 * Adds direction mark tool to VE (for adding RLM) 
 */
(function () {
// localization for button name
if(!mw.messages.exists('DirectionTool-toolname')){
	mw.messages.set('DirectionTool-toolname', 'תו כיווניות');
}
// localization for rlm template name
if(!mw.config.exists('rlmTemplateName')){
	mw.config.set('rlmTemplateName', 'כ');
}
//end of localization

function DirectionTool( toolGroup, config ) {
	OO.ui.Tool.call( this, toolGroup, config );
}
OO.inheritClass( DirectionTool, OO.ui.Tool );

DirectionTool.static.name = 'DirectionTool';
DirectionTool.static.title = mw.msg('DirectionTool-toolname');

DirectionTool.prototype.onSelect = function () {
	this.toolbar.getSurface().getModel().getFragment().collapseToEnd().insertContent([{
		'type': 'mwTransclusionInline',
		'attributes': {
			'mw': {
				parts: [ {
					template: {
						target: {
							href:  mw.config.get('wgFormattedNamespaces')[10]+ ':'+ mw.config.get('rlmTemplateName'),
							wt: mw.config.get('rlmTemplateName')
						},
						params: {}
					}
				}]
			}
		}
	}]);
};

DirectionTool.prototype.onUpdateState = function () {
	this.setActive( false );
};

ve.ui.toolFactory.register( DirectionTool );

})();