MediaWiki:Gadget-visual-editor-page-transclusion-support.js

De Wikimedica

Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

/* This gadget overrides behaviors in the Visual Editor to inform the user he is modifying a transclusion from a page. */
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init', function () { mw.libs.ve.addPlugin( function (target) {

	console.log("Loading visual-editor-page-transclusion-support");
	
	new mw.Api().loadMessages( [ 'visualeditor-dialog-transclusion-from-page' ] ); // This will be needed later, but loaded asynchronously now.
	
	/* Override template form to indicate the user he his modifying a transclusion from a page.
	 * Should override constructor, but it breaks inheritance for some reason. */
	parentMethod = ve.ui.MWTemplatePage.prototype.setOutlineItem;
	ve.ui.MWTemplatePage.prototype.setOutlineItem = function() {
		// Parent method
		parentMethod.call(this);

		 // If the template does not have a description and is a transclusion call.
		if(!this.spec.getDescription() && this.template.target.href && this.template.target.href.indexOf("Modèle:") == -1) {
			this.$description.html('')
				.addClass( 've-ui-mwTemplatePage-description' )
				.append(mw.message('visualeditor-dialog-transclusion-from-page', this.template.target.href).parseDom());
				
			this.infoFieldset.$element.find(".oo-ui-labelElement-label").append(" (page incluse)");
		}
	};
} ); } );