MediaWiki:Gadget-EditZeroth.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.
/**
 * AddEditSection0
 *
 * Permet de modifier la première section d'une page (en-tête)
 *
 * {{Projet:JavaScript/Script|EditZeroth}}
 *
 */
/* global mw, $ */
/* eslint-env browser */

if ( mw.config.get( 'wgNamespaceNumber' ) >= 0 ) {

	mw.loader.using( [ 'user', 'mediawiki.util' ], function () {
		$( function ( $ ) {
			'use strict';

			var lang = mw.config.get( 'wgUserLanguage' ),
				messages = {
					fr: {
						'editZeroth-portlet-name': 'En-tête',
						'editZeroth-summary-prefix': '/* Introduction */ ',
						'editZeroth-portlet-description': 'Modifier l’en-tête de la page'
					},
					en: {
						'editZeroth-portlet-name': 'Lead',
						'editZeroth-summary-prefix': '/* Lead section */ ',
						'editZeroth-portlet-description': 'Edit the lead section of this page'
					}
				},
				$editPortlet = $( '#ca-edit' ),
				skin = mw.config.get( 'skin' ),
				summaryPrefix,
				portletLink,
				$editZeroPortlet;

			mw.messages.set( messages.en );
			if ( lang !== 'en' && lang in messages ) {
				mw.messages.set( messages[ lang ] );
			}

			if ( !mw.config.get( 'wgIsProbablyEditable' ) ) {
				return;
			}

			if ( typeof window.EditZeroth_summary !== 'undefined' ) {
				summaryPrefix = window.EditZeroth_summary;
			} else {
				summaryPrefix = mw.msg( 'editZeroth-summary-prefix' );
			}

			portletLink = mw.util.addPortletLink(
				( skin === 'vector' || skin === 'timeless' || skin === 'vector-2022' ) ? 'p-views' : 'p-cactions',
				mw.util.getUrl( null, { action: 'edit', section: 0, summary: summaryPrefix } ),
				mw.msg( 'editZeroth-portlet-name' ),
				'ca-edit-0',
				mw.msg( 'editZeroth-portlet-description' ),
				'',
				( $editPortlet.length > 0 && $editPortlet.next().length > 0 ) ? $editPortlet.next() : null
			);
			$editZeroPortlet = $( portletLink );

			if ( skin === 'monobook' ) {
				$editZeroPortlet.after( ' ' );
			}
			
			$editZeroPortlet.addClass( 'collapsible vector-tab-noicon' );

			if ( $editPortlet.hasClass( 'istalk' ) ) {
				$editZeroPortlet.addClass( 'istalk' );
			}

			if ( $editPortlet.hasClass( 'selected' ) ) {
				if ( mw.util.getParamValue( 'section' ) === '0' ) {
					$editPortlet.removeClass( 'selected' );
					$editZeroPortlet.addClass( 'selected' );
				}
			}

		} );
	} );
}