Implement an instance of MWStake\MediaWiki\Component\GenericTagHandler\ITag
interface and register it:
// By global
$GLOBALS['mwsgGenericTagRegistry'] = [
'class' => 'MyClass',
'services' => [ '...' ]
];
// By hook
$wgHooks['MWStakeGenericTagHandlerInitTags'][] = function ( &$tags ) {
$tags[] = new MyTag(...);
};
// By registry
$registry = \MediaWiki\MediaWikiServices::getInstance()->getService( 'MWStake.GenericTagHandler.TagFactory' );
$registry->register( new MyTag( ... ) );
You can return a MWStake\MediaWiki\Component\GenericTagHandler\ClientTagSpecification
from your tag implementation
to automatically register a tag in VisualEditor.
Pass null
to $formSpecification
param to let the default form be used.
Pass a MWStake\MediaWiki\Component\FormEngine\StandaloneFormSpecification
object to $formSpecification
param to use a custom form.
$formSpec = new StandaloneFormSpecification();
$formSpec->setItems( [
[
'type' => 'text',
'name' => 'field',
'label' => 'My field',
],
[
'type' => 'checkbox',
'name' => 'framed',
'label' => 'Is framed'
],
] );
You can implement an instance of mw.ext.forms.standalone.Form
client-side and use it in the ClientTagSpecification
For that you would pass a MWStake\MediaWiki\Component\FormEngine\FormLoaderSpecification
as $formSpecification
param.
$formSpec = new FormLoaderSpecification( 'my.form.class', [ 'modules.loading.the.form.class' ] );
In very specific cases you may want to override the default VisualEditor tag definition class
Load a JS file using getResourceLoaderModules
method, that will override the tag class
mw.hook( 'ext.visualEditorPlus.tags.getTagDefinition' ).add( ( definitionData, tagDefinition ) => {
if ( definitionData.tagname !== 'myfancytag' ) {
return;
}
// definition data contains the info from `ClientTagSpecification`
tagDefinition = new my.class.inheriting.from.ext.visualEditorPlus.ui.tags.Definition( {
... data
} );
};
In this case, you would likely pass null
to $formSpecification
param in the PHP class.