MediaWiki:Gadget-edit-summaries.js

Z Wikisłownika – wolnego słownika wielojęzycznego

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
/**
 * Automatyczne opisy zmian
 * @author [[w:pl:User:Adziura|Adam Dziura]]
 * @author (fixes) [[w:pl:User:Nux|Maciej Jaros]]
 * @author (migration to plwikt) [[wikt:pl:User:Peter Bowman]]
 */

var config = mw.config.get( [
		'wgAction',
		'wgNamespaceNumber'
	] ),
	modules = [ 'ext.gadget.style-summary-buttons' ],
	editformHook = mw.hook( 'wikipage.editform' ),
	usbHook = mw.hook( 'user-summary-buttons.configured' );

function configureUserButtons( $container, $textarea ) {
	$container.on( 'click', '.userSummaryButtonsElement', function ( e ) {
		var action = $( this ).data( 'action' );
		
		if ( typeof action === 'string' ) {
			addSummary( $textarea, action );
		} else {
			action( $container );
		}
		
		return false;
	} );
	
	$( '<a>' )
		.text( 'zwiń/rozwiń' )
		.addClass( 'userSummaryButtonsToggle' )
		.attr( 'title', 'Rozwiń skróty opisów zmian' )
		.on( 'click', function ( e ) {
			$container.children( '.userSummaryButtonsElement' ).each( function ( i, button ) {
				var $button = $( button ),
					currentText = $button.text();
				
				$button.text( $button.data( 'toggle' ) ).data( 'toggle', currentText );
			} );
			
			return false;
		} )
		.appendTo( $container );
	
	// różne merytoryczne
	addButton( 'nowe hasło', 'Dodano nowe hasło' );
    addButton( 'ort.', 'Poprawiono błąd ortograficzny' );
	addButton( 'lit.', 'Poprawiono literówkę' );
    addButton( 'int.', 'Poprawiono interpunkcję' );
	addButton( 'format.', 'Formatowanie tekstu', 'formatowanie tekstu' );
	addButton( 'szablon', 'Dodano/poprawiono szablon' );
	
	// drobne inne
	addButton( 'dr.meryt.', 'Drobne zmiany merytoryczne', 'drobne merytoryczne' );
	addButton( 'dr.red.', 'Drobne zmiany redakcyjne', 'drobne redakcyjne' );
	addButton( 'dr.tech.', 'Drobne zmiany techniczne', 'drobne techniczne' );
	addButton( 'linkfix', 'Poprawienie linków', 'poprawa linków' );
	addButton( 'ilustr.', 'Dodanie ilustracji', 'ilustracja' );
	addButton( 'tłum.', 'Dodanie tłumaczeń', 'tłumaczenia' );
	addButton( 'wikip.', 'Dodanie linku do Wikipedii', 'wikipedia' );
	
	// Meta strony Wikisłownika
	addButton( 'witaj', 'Dodano powitanie dla użytkownika' );
	addButton( 'komentarz', 'Dodano komentarz' );
	addButton( 'głos', 'Oddano głos' );	
	addButton( 'pyt.', 'Zadano pytanie', 'pytanie' );	
	addButton( 'odp.', 'Odpowiedziano', 'odpowiedź' );	
	
	addButton( 'ek', 'Zgłoszono artykuł do ekspresowego (s)kasowania', '[[:Kategoria:Ekspresowe kasowanie|ek]]' );
	addButton( 'rev.', 'przywrócenie poprzedniej wersji', 'przywrócenie poprzedniej wersji' );
}

function addButton( text, title, action, cssClass ) {
	usbHook.add( function ( $container ) {
		$( '<a>' )
			.text( text )
			.attr( 'title', title )
			.addClass( 'userSummaryButtonsElement' )
			.addClass( cssClass )
			.data( {
				action: action || text,
				toggle: title
			} )
			.appendTo( $container.append( '&#8203;' ) );
	} );
}

function addSummary( $textarea, summary ) {
	var content = $textarea.val().trim();
	
	if ( content.indexOf( summary ) !== -1 ) {
		return;
	}
	
	if ( content ) {
		if ( content.charAt( content.length - 1 ) === '/' ) {
			content += ' ' + summary;
		} else {
			content += ', ' + summary;
		}
	} else {
		content += summary;
	}
	
	$textarea.val( content ).trigger( 'change' );
}

function editformHookCallback( $editform ) {
	var $container;
	
	if ( $editform.find( '#wpSummaryLabel' ).closest( '.editOptions' ).length ) {
		$container = $( '<div>' ).attr( 'id', 'userSummaryButtons' );
		configureUserButtons( $container, $editform.find( '#wpSummary' ) );
		$editform.find( '#wpSummaryWidget' ).append( $container );
		usbHook.fire( $container );
	}
	
	editformHook.remove( editformHookCallback );
}

if ( [ 'edit', 'submit' ].indexOf( config.wgAction ) !== -1 ) {
	mw.loader.using( modules ).done( function () {
		editformHook.add( editformHookCallback );
	} );
}

mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).done( function () {
	mw.libs.ve.addPlugin( function () {
		return mw.loader.using( [].concat( modules, 'ext.visualEditor.mwcore' ) ).done( function () {
			var realInitialize = ve.ui.MWSaveDialog.prototype.initialize;
			
			ve.ui.MWSaveDialog.prototype.initialize = function () {
				var $container = $( '<span>' ).attr( 'id', 'userSummaryButtons' );
				realInitialize.call( this );
				$container.insertAfter( this.editSummaryInput.$element );
				configureUserButtons( $container, this.editSummaryInput.$element.children( 'textarea' ) );
				usbHook.fire( $container );
			};
		} );
	} );
} );

module.exports = {
	addButton: addButton
};