MediaWiki:Guidedtour-tour-tuto5.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.
/*
* Tutoriel 5 de Aide:Wikipédia pas à pas
* Annuler une modification
*
* Voir [[:mw:Extension:GuidedTour]] pour plus d'informations
*
* Auteur : [[User:0x010C]]
* Création : 25 octobre 2016
* Dernière révision : 18 janvier 2018 / fonctionne (Chrome Windows 7) au 2 avril 2019
* [[Catégorie:Guided tour]]
*/
//<nowiki>

( function ( window, document, $, mw, gt ) {
	var tour;

	tour = new gt.TourBuilder( {
		name: 'tuto5',
		shouldLog: false
	} );

	// 1
	// TODO: ajouter quelques lignes d'historique via l'API
	tour.firstStep( {
		name: 'bienvenue',
		title: 'Tutoriel #5',
		description: new mw.Title( 'Aide:Wikipédia pas à pas/Textes/T5E1' ),
		overlay: true,
		closeOnClickOutside: false,
	} )
	.next( 'brouillon' )
	.transition( function() {
		// Si l'apprenant n'est pas connecté
		if ( mw.user.getId() === 0 ) {
			return 'connectetoi';
		}
	} );
	
	// 2
	tour.step( {
		name: 'brouillon',
		title: 'Allons sur le brouillon',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/2' ),
		overlay: false,
		attachTo: '#pt-sandbox',
		position: 'bottom',
		closeOnClickOutside: false,
		onShow: function() {
			// Faire quelques modifications sur le brouillon de l'apprenant, que celui-ci poura alors annuler.
			var api = new mw.Api();
			api.get({
				action: 'query',
				format: 'json',
				prop: 'revisions',
				titles: 'Utilisateur:' + mw.config.get( 'wgUserName' ) + '/Brouillon',
				rvprop: 'timestamp',
				rvlimit: '25',
			//	rvtag: 'wikimooc2017'
			} )
			.then( function( data ) {
				// Si le brouillon de l'apprenant possède déjà au moins deux éditions bidon, on ne fait rien d'autre
				if ( data.query.pages[ Object.keys( data.query.pages )[ 0 ] ].revisions !== undefined ) {
					if ( data.query.pages[ Object.keys( data.query.pages )[ 0 ] ].revisions.length >= 2 ) {
						return;
					}
				}
				
				// Sinon, on réalise les-dites éditions bidons d'exemple
				api.postWithToken( 'csrf', {
					action: 'edit',
					title: 'Utilisateur:' + mw.config.get( 'wgUserName' ) + '/Brouillon',
					summary: 'Modification d\'exemple réalisée automatiquement par le tutoriel, pour pouvoir tester l\'outil d\'annulation.',
				//	tags: 'wikimooc2017',
					appendtext: '\nLigne d\'exemple, à annuler',
					format: 'json',
				} )
				.then( function() {
					return api.postWithToken( 'csrf', {
						action: 'edit',
						title: 'Utilisateur:' + mw.config.get( 'wgUserName' ) + '/Brouillon',
						summary: 'Modification d\'exemple réalisée automatiquement par le tutoriel, pour pouvoir tester l\'outil d\'annulation.',
					//	tags: 'wikimooc2017',
						appendtext: '\nLigne d\'exemple, à annuler',
						format: 'json',
					} );
				} );
			} );
		},
	} )
	.back( 'bienvenue' )
	.transition( function() {
		// Si l'apprenant est sur son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' ) {
			return 'onglethisto';
		}
	} );
	
	// 3
	tour.step( {
		name: 'onglethisto',
		title: 'Onglet historique',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/3' ),
		overlay: false,
		attachTo: '#ca-history',
		position: 'bottomLeft',
		closeOnClickOutside: false,
	} )
	.back( function() {
		gt.setTourCookie( 'tuto5', 'brouillon' );
		window.location.href = mw.util.getUrl( 'Aide:Wikipédia_pas_à_pas/Tutoriel_5' );
	} )
	.transition( function() {
		// Si l'apprenant est sur l'historique de son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && mw.config.get( 'wgAction' ) === 'history' ) {
			return 'annuler';
		}
		// S'il s'est perdu et qu'il n'est même plus sur son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) !== mw.config.get( 'wgUserName' ) || mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] !== 'Brouillon' ) {
			return 'brouillon';
		}
	} );
	
	// 4
	tour.step( {
		name: 'annuler',
		title: 'Lien annuler',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/4' ),
		overlay: false,
		attachTo: '#pagehistory .selected.before .mw-history-undo',
		position: 'top',
		closeOnClickOutside: false,
	} )
	.back( function() {
		gt.setTourCookie( 'tuto5', 'onglethisto' );
		window.location.href = mw.util.getUrl( 'User:' + mw.config.get( 'wgUserName' ) + '/Brouillon' );
	} )
	.transition( function() {
		// Si l'apprenant est sur une page de diff d'annulation de son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && $( '.mw-undo-success' ).length ) {
			return 'diffanulation';
		}
		// S'il est sur une autre page de son brouillon qu'un diff d'annulation ou l'historique
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && mw.config.get( 'wgAction' ) !== 'history' ) {
			return 'onglethisto';
		}
		// S'il s'est perdu et qu'il n'est même plus sur son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) !== mw.config.get( 'wgUserName' ) || mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] !== 'Brouillon' ) {
			return 'brouillon';
		}
	} );
	
	// 5
	tour.step( {
		name: 'diffanulation',
		title: 'Différentiel d\'annulation',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/5' ),
		overlay: false,
		closeOnClickOutside: false,
	} )
	.next( 'enregistrer' )
	.back( function() {
		gt.setTourCookie( 'tuto5', 'annuler' );
		window.location.href = mw.util.getUrl( 'User:' + mw.config.get( 'wgUserName' ) + '/Brouillon' ) + '?action=history';
	} )
	.transition( function() {
		// S'il est parti du diff d'annulation mais qu'il est toujours sur son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && !$( '.mw-undo-success' ).length ) {
			// S'il est retourné sur l'historique de son brouillon
			if ( mw.config.get( 'wgAction' ) === 'history' ) {
				return 'annuler';
			}
			// S'il est ailleur sur son brouillon
			else {
				return 'onglethisto';
			}
		}
		// S'il s'est perdu et qu'il n'est même plus sur son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) !== mw.config.get( 'wgUserName' ) || mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] !== 'Brouillon' ) {
			return 'brouillon';
		}
	} );
	
	// 6
	tour.step( {
		name: 'enregistrer',
		title: 'Enregistrer',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/6' ),
		overlay: false,
		attachTo: '#wpSave',
		position: 'topRight',
		closeOnClickOutside: false,
	} )
	.back( 'diffanulation' )
	.transition( function() {
		// S'il vient d'annuler la modif
		if ( gt.isPostEdit() ) {
			return 'finpremierepartie';
		}
		// S'il est parti du diff d'annulation mais qu'il est toujours sur son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && !$( '.mw-undo-success' ).length ) {
			// S'il est retourné sur l'historique de son brouillon
			if ( mw.config.get( 'wgAction' ) === 'history' ) {
				return 'annuler';
			}
			// S'il est ailleur sur son brouillon
			else {
				return 'onglethisto';
			}
		}
		// S'il s'est perdu et qu'il n'est même plus sur son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) !== mw.config.get( 'wgUserName' ) || mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] !== 'Brouillon' ) {
			return 'brouillon';
		}
	} );
	
	// 7
	tour.step( {
		name: 'finpremierepartie',
		title: 'Félicitations',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/7' ),
		overlay: false,
		closeOnClickOutside: false,
		buttons: [ {
			name: '<span class="guidedtour-back-button"><span aria-label="Retour" class="guider_button_icon"></span></span>',
			action: 'externalLink',
			onclick: function() {
				gt.resumeTour( 'tuto5', 'onglethisto' );
			},  
		}, {
			name: 'Finir ici',
			action: 'externalLink',
			onclick: function() {
				gt.endTour();
				setTimeout( function() {
					window.location.href = mw.util.getUrl( 'Aide:Wikipédia pas à pas/Tutoriel 5' );
				}, 1000 );
			},  
		},{
			name: 'En apprendre plus',
			action: 'externalLink',
			type: 'progressive',
			onclick: function() {
				gt.resumeTour( 'tuto5', 'backhisto' );
			},  
		} ],
		allowAutomaticOkay: false,
	} )
	.transition( function() {
		// Si l'apprenant est sur l'historique de son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && mw.config.get( 'wgAction' ) === 'history' ) {
			return 'modifpotable';
		}
	} );

	// 7b
	tour.step( {
		name: 'backhisto',
		title: 'Retournons dans l\'historique',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/7b' ),
		overlay: false,
		attachTo: '#ca-history',
		position: 'bottom',
		closeOnClickOutside: false,
	} )
	.back( 'finpremierepartie' )
	.transition( function() {
		// Si l'apprenant est sur l'historique de son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && mw.config.get( 'wgAction' ) === 'history' ) {
			return 'modifpotable';
		}
	} );
	
	// 8
	tour.step( {
		name: 'modifpotable',
		title: 'Choisir une version',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/8' ),
		overlay: false,
		closeOnClickOutside: false,
	} )
	.back( function() {
		gt.setTourCookie( 'tuto5', 'backhisto' );
		window.location.href = mw.util.getUrl( 'User:' + mw.config.get( 'wgUserName' ) + '/Brouillon' );
	} )
	.transition( function() {
		// Si l'apprenant est sur une page archivé de son brouillon
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && $( '.mw-revision' ).length ) {
			return 'modifier';
		}
		// S'il est sur une autre page de son brouillon qu'un diff d'annulation ou l'historique
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && mw.config.get( 'wgAction' ) !== 'history' ) {
			return 'backhisto';
		}
	} );
	
	// 9
	tour.step( {
		name: 'modifier',
		title: 'Modifions cette version',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/9' ),
		overlay: false,
		attachTo: '#ca-edit',
		position: 'bottom',
		closeOnClickOutside: false,
	} )
	.back( function() {
		gt.setTourCookie( 'tuto5', 'modifpotable' );
		window.location.href = mw.util.getUrl( 'User:' + mw.config.get( 'wgUserName' ) + '/Brouillon' ) + '?action=history';
	} )
	.transition( function() {
		// S'il est sur son brouillon et qu'il modifie une ancienne version, c'est bien, on continue
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && $( '.mw-revision' ).length && gt.isEditingWithWikitext() ) {
			return 'enregistrerbis';
		}
		// Si l'apprenant est sur son brouillon mais pas sur une ancienne version
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && !$( '.mw-revision' ).length ) {
			// S'il est revenu sur l'historique
			if ( mw.config.get( 'wgAction' ) === 'history' ) {
				return 'modifpotable';
			}
			// Ou s'il est ailleur sur son brouillon
			else {
				return 'backhisto';
			}
		}
	} );
	
	// 10
	tour.step( {
		name: 'enregistrerbis',
		title: 'Enregistrons cette version',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/2.1/B/10' ),
		overlay: false,
		attachTo: '#wpSave',
		position: 'topRight',
		closeOnClickOutside: false,
	} )
	.transition( function() {
		// S'il vient d'annuler les modifs
		if ( gt.isPostEdit() ) {
			return 'fin';
		}
		// Si l'apprenant est sur son brouillon mais pas sur la page de modification d'une ancienne version
		if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgPageName' ).split( '/' )[ 1 ] === 'Brouillon' && !gt.isEditingWithWikitext() ) {
			// S'il est retourné à la version archivé de l'article
			if ( $( '.mw-revision' ).length ) {
				return 'modifier';
			}
			// S'il est revenu sur l'historique
			if ( mw.config.get( 'wgAction' ) === 'history' ) {
				return 'modifpotable';
			}
			// Ou s'il est ailleur sur son brouillon
			else {
				return 'backhisto';
			}
		}
	} );
	
	// 11
	tour.step( {
		name: 'fin',
		title: 'Fin du tutoriel',
		description: new mw.Title( 'Aide:Wikipédia pas à pas/Textes/T5E11' ),
		overlay: false,
		closeOnClickOutside: false,
		buttons: [ {
			action: 'okay',
			onclick: function() {
				gt.endTour();
				setTimeout( function() {
					window.location.href = mw.util.getUrl( 'Aide:Wikipédia pas à pas/Tutoriel 5' );
				}, 1000 );
			},
		} ],
		allowAutomaticOkay: false,
	} )
	.back( 'backhisto' );



	// 0
	tour.step( {
		name: 'connectetoi',
		title: 'Connectez-vous',
		description: new mw.Title( 'Projet:WikiMOOC/2017/GT/0' ),
		autoFocus: true,
		overlay: true,
		closeOnClickOutside: false,
	} )
	.transition( function() {
		// Si l'apprenant s'est connecté
		if ( mw.user.getId() !== 0 )
			return 'bienvenue';
	} );
	
	//Ajout d'un bouton en bas à droite pour permettre de réafficher une étape accidentellement fermé
	mw.loader.using( [ 'oojs-ui' ], function () {
		var reloadButton = new OO.ui.ButtonWidget( {
			label: 'Réafficher l\'étape courante',
			icon: 'redo',
			title: 'Réafficher'
		} );
		reloadButton.on( 'click', function() {
			gt.launchTourFromUserState();
		} );
		var container = $( '<div>' );
		container.append( reloadButton.$element[ 0 ] );
		container.css( 'position', 'fixed' ).css( 'bottom', '0px' ).css( 'right', '0px' ).css( 'z-index', '3000' ).appendTo( 'body' );
	} );

} ( window, document, jQuery, mediaWiki, mediaWiki.guidedTour ) );

//</nowiki>