Utilisateur:Tomybrz/defaultsummaries.js

Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === copy gagdet ===                                      |
 * |                  Original : [[w:MediaWiki:Gadget-defaultsummaries.js]]      |                  
 * |https://en.wikipedia.org/wiki/MediaWiki:Gadget-defaultsummaries.js           |
 * |_____________________________Ceci est une traduction_________________________|
 *
 * Imported as of 09/06/2011 from [[User:ErrantX/defaultsummaries.js]]
 * Edited version from [[User:MC10/defaultsummaries.js]]
 * Implements default edit summary dropdown boxes
 */

/* global mediaWiki, ve */

( function ( $, mw ) { // Wrap with anonymous function
	var $summaryBox = $( '#wpSummary' ),
		minorSummaries = [
			'Correction typo/ortho',
			'Correction de modèle/style',
			'[[Aide:RV|Revert]] [[Wikipedia:Vandalisme|Vandalisme]]/Bac à sable',
			'[[Aide:RV|Revert]] Suppression de texte injustifiée',
			'Copyedit (mineur)',
			'Correction erreur de bot'
		],
		articleSummaries = [
			'Correction erreur de bot',
			'✔️',
			'❌',
			'Suppression de texte non sourcée',
			'Suppression de [[WP:SPAM|lien spam]] concernant [[WP:LE]]',
			'Nettoyage',
			'Copyedit (important)',
			'Réponse ',
			'Commentaire ',
			'Suggestion ',
			'orthographe ',
			'typographie ',
			'catégorisation ',
			'wikification ',
			'image ',
			'mise en page ',
			'redirection ',
			'relecture ',
			'style ',
			'revert ',
			'réorganisation ',
			'maintenance ',
			'bandeau ',
			'retouche de la modification précédente ',
		],
		nonArticleSummaries = [
			'✔️',
			'❌',
			'Réponse ',
			'Commentaire ',
			'typographie ',
			'catégorisation ',
			'wikification ',
			'image ',
			'mise en page ',
			'redirection ',
			'relecture ',
			'style ',
			'revert ',
			'réorganisation ',
			'maintenance ',
			'bandeau ',
			'retouche de la modification précédente '
		],
		talkPageSummaries = [
			'[[Projet:Accueil|Projet]] notification',
			'[[Projet:Accueil|Projet]] évaluation'
		];

	function addOptionsToDropdown( dropdown, optionTexts ) {
		dropdown.menu.addItems( optionTexts.map( function ( optionText ) {
			return new OO.ui.MenuOptionWidget( { label: optionText } );
		} ) );
	}

	function onSummarySelect( option ) {
		// Save the original value of the edit summary field
		var editsummOriginalSummary = $summaryBox.val(),
			canned = option.getLabel(),
			newSummary = editsummOriginalSummary;

		// Append old edit summary with space, if exists,
		// and last character != space
		if ( newSummary.length !== 0 && newSummary.charAt( newSummary.length - 1 ) !== ' ' ) {
			newSummary += ' ';
		}
		newSummary += canned;
		$summaryBox.val( newSummary ).trigger( 'change' );
	}

	function insertSummaryOptions( $insertBeforeThis, dropdownWidth ) {
		// For convenience, add a dropdown box with some canned edit
		// summaries to the form.
		var namespace = mw.config.get( 'wgNamespaceNumber' ),
			dropdown = new OO.ui.DropdownWidget( {
				label: 'Résumé de modification'
			} ),
			minorDropdown = new OO.ui.DropdownWidget( {
				label: 'Résumé de modification mineur'
			} );

		dropdown.$element.css( 'width', dropdownWidth );
		dropdown.menu.on( 'select', onSummarySelect );

		minorDropdown.$element.css( 'width', dropdownWidth );
		minorDropdown.menu.on( 'select', onSummarySelect );

		addOptionsToDropdown( minorDropdown, minorSummaries );

		if ( namespace === 0 ) {
			addOptionsToDropdown( dropdown, articleSummaries );
		} else {
			addOptionsToDropdown( dropdown, nonArticleSummaries );
			if ( namespace % 2 !== 0 && namespace !== 3 ) {
				addOptionsToDropdown( dropdown, talkPageSummaries );
			}
		}

		$insertBeforeThis.before( dropdown.$element );
		$insertBeforeThis.before( minorDropdown.$element );
	}
	// VisualEditor
	mw.hook( 've.saveDialog.stateChanged' ).add( function () {
		var target, $saveOptions;
		// .ve-init-mw-viewPageTarget-saveDialog-checkboxes
		if ( $( 'body' ).data( 'wppresent' ) ) { return; }
		$( 'body' ).data( 'wppresent', 'true' );

		target = ve.init.target;
		$saveOptions = target.saveDialog.$saveOptions;
		$summaryBox = target.saveDialog.editSummaryInput.$input;
		if ( !$saveOptions.length ) {
			return;
		}
		insertSummaryOptions( $saveOptions );
	} );
	// WikiEditor
	$.when( mw.loader.using( 'oojs-ui-core' ), $.ready ).then( function () {
		var $editCheckboxes = $( '.editCheckboxes' );

		// If we failed to find the editCheckboxes class
		if ( !$editCheckboxes.length ) {
			return;
		}
		insertSummaryOptions( $editCheckboxes, '48%' );
	} );
}( jQuery, mediaWiki ) ); // End wrap with anonymous function