Diferencia entre revisiones de «MediaWiki:Gadget-Versalitas.js»
De EIFA - Estudios Interdisciplinares de las Fuentes Avilistas
Etiqueta: Revertido |
Etiquetas: Reversión manual Revertido |
||
Línea 1: | Línea 1: | ||
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 | ||
function UnlinkYearsCommand() { | |||
UnlinkYearsCommand.parent.call( this, 'unlinkYears' ); | |||
} | |||
OO.inheritClass( UnlinkYearsCommand, ve.ui.Command ); | |||
ve. | 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; | |||
}; | |||
//Create and | 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'; | |||
function | 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.ui.toolFactory.register( | |||
ve.init.mw.DesktopArticleTarget.static.actionGroups[ 1 ].include.push( 'unlinkYears' ); | |||
} | |||
// Initialize | // Initialize | ||
mw. | mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).then( function () { | ||
addPlugin( | mw.libs.ve.addPlugin( function () { | ||
return mw.loader.using( [ 'ext.visualEditor.core' ] ) | |||
.then( function () { | |||
makeUnlinkYearsTool(); | |||
} ); | |||
} ); | |||
} ); | } ); |
Revisión del 12:58 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();
} );
} );
} );