MediaWiki:Guidedtour-tour-wikiedcitingsources.js

// Guided Tour for practicing citations in visual editor, as an interactive interlude in https://dashboard.wikiedu.org/training/students/sources ( function ( window, document, $, mw, gt ) {

//automatic api:edit function to send yourself messages mw.loader.using( 'mediawiki.Title', function {

function sendMessage( targetPage, msgPage, linkTo ) { var api = new mw.Api; api.get( {		'action' : 'query',		'titles' : msgPage,		'prop'  : 'revisions|info',		'meta' : 'tokens',		'rvprop' : 'content',		'rvslots' : 'main',		'indexpageids' : 1	} ).done( function (result) {		result = result.query;		var page = result.pages[result.pageids[0]];		var text = page.revisions[0].slots.main['*'];		api.post( { 'action' : 'edit', 'title' : targetPage, 'appendtext' : "\n" + text, 'summary' : 'automatic post as part of sandbox guided tour', 'token' : result.tokens.csrftoken } ).done( function { window.location.href = linkTo; } );	} ); }

var tour;

tour = new gt.TourBuilder( {   name: 'wikiedcitingsources' } );

tour.firstStep( {	name: 'welcome',	title: "Let's practice citing a source",   description: 'Project:Wiki_Ed/tour/citing_sources1',    onShow: gt.getPageAsDescription,	buttons: [ {        name: ' ← ',        action: 'externalLink',        url: 'https://dashboard.wikiedu.org/training/students/sources/add-a-citation-tutorial'            }, {	    name: 'Okay!',	    onclick: function {	if(!mw.config.get('wgUserName')){  alert( "Please login." );  return;   }	    						sendMessage(	'User:' + mw.config.get( 'wgUserName' ) + '/citing_sources', 'Project:Wiki_Ed/tour/citing_sources_preload', mw.util.getUrl( 'Special:MyPage/citing_sources' ) + '?tour=wikiedcitingsources&step=editButton&vehidebetadialog=1');							}   } ],    overlay: true,	closeOnClickOutside: false,    allowAutomaticOkay: false,    allowAutomaticNext: false } ) .next( 'editButton' );

tour.step( {	name: 'editButton',	title: 'Citation needed!',   description: 'Project:Wiki_Ed/tour/citing_sources2',    attachTo: '#ca-edit',    position: 'bottom',    onShow: gt.getPageAsDescription,    overlay: false,    closeOnClickOutside: false,    allowAutomaticOkay: false,    allowAutomaticNext: false, } ) .listenForMwHooks( 've.activationComplete' ) .transition( function { if ( gt.isEditing ) { return 'citeSource'; } } ) .next( 'citeSource' );

tour.step( {	name: 'citeSource',	title: 'Add a citation at the end of the first sentence',	description: 'Project:Wiki_Ed/tour/citing_sources3',	onShow: gt.getPageAsDescription,	attachTo: '#content',	position: 'bottom',	overlay: false,	buttons: [ {		name: 'I added the citation.',		onclick: function { mw.libs.guiders.next; } 	} ],	closeOnClickOutside: false,   allowAutomaticOkay: false,    allowAutomaticNext: false } ) .listenForMwHooks( 've.deactivationComplete' ) .transition( function { if ( gt.isPostEdit ) { return 'afterFirstEdit'; } } ) .next( 'saveFirstEdit' );

tour.step( {	name: 'saveFirstEdit',	title: 'Edit summary, and Publish',	onShow: gt.getPageAsDescription,	description: 'Project:Wiki_Ed/tour/citing_sources7',	attachTo: '.ve-ui-toolbar-saveButton',	position: 'bottomLeft',	autoFocus: 'yes',	overlay: false,	closeOnClickOutside: false,   allowAutomaticOkay: false,    allowAutomaticNext: false } ) .listenForMwHooks( 've.deactivationComplete' ) .transition( function { if ( gt.isPostEdit ) { return 'afterFirstEdit'; } } ) .next( 'afterFirstEdit' );

tour.step( {	name: 'afterFirstEdit',	title: 'Did it work?',   description: 'Project:Wiki_Ed/tour/citing_sources4',    onShow: gt.getPageAsDescription,	buttons: [ {        name: 'Try again.',        action: 'externalLink',        url: mw.util.getUrl( 'Special:MyPage/citing_sources' ) + '?tour=wikiedcitingsources&step=editButton&vehidebetadialog=1'    }, {	    name: 'Move on.',        action: 'externalLink',        url: mw.util.getUrl( 'Special:MyPage/citing_sources' ) + '?tour=wikiedcitingsources&step=reuseCitation&vehidebetadialog=1'    } ],    overlay: true,	closeOnClickOutside: false,    allowAutomaticOkay: false,    allowAutomaticNext: false } ) .next( 'reuseCitation' );

tour.step( {	name: 'reuseCitation',	title: 'Reusing a source',   description: 'Project:Wiki_Ed/tour/citing_sources5',    attachTo: '#ca-edit',    position: 'bottom',    onShow: gt.getPageAsDescription,    overlay: false,    closeOnClickOutside: false,    allowAutomaticOkay: false,    allowAutomaticNext: false, } ) .listenForMwHooks( 've.activationComplete' ) .transition( function { if ( gt.isEditing ) { return 'reuse'; } } ) .next( 'reuse' );

tour.step( {	name: 'reuse',	title: 'Reuse the same citation to cite the last sentence',	description: 'Project:Wiki_Ed/tour/citing_sources6',	onShow: gt.getPageAsDescription,	attachTo: '#content', 	position: 'bottomLeft',	buttons: [ {		name: 'I added the re-used citation.',		onclick: function { mw.libs.guiders.next; } 	} ],	overlay: false,	closeOnClickOutside: false,   allowAutomaticOkay: false,    allowAutomaticNext: false } ) .listenForMwHooks( 've.deactivationComplete' ) .transition( function { if ( gt.isPostEdit ) { return 'looksGood'; } } ) .next( 'editSummary' );

tour.step( {	name: 'editSummary',	title: 'Edit summary, and Publish',	onShow: gt.getPageAsDescription,	description: 'Project:Wiki_Ed/tour/citing_sources7',	attachTo: '.ve-ui-toolbar-saveButton',	position: 'bottomLeft',	autoFocus: 'yes',	overlay: false,	closeOnClickOutside: false,   allowAutomaticOkay: false,    allowAutomaticNext: false } ) .listenForMwHooks( 've.deactivationComplete' ) .transition( function { if ( gt.isPostEdit ) { return 'looksGood'; } } ) .next( 'looksGood' );

tour.step( {	name: 'looksGood',	title: 'How was that?',   description: 'Project:Wiki_Ed/tour/citing_sources8',    onShow: gt.getPageAsDescription,	buttons: [ {        name: 'Try again.',        action: 'externalLink',        url: mw.util.getUrl( 'Special:MyPage/citing_sources' ) + '?tour=wikiedcitingsources&step=reuseCitation&vehidebetadialog=1'    }, {	    name: 'Move on.',        onclick: function { mw.libs.guiders.next; }     } ],    overlay: true,	closeOnClickOutside: false,    allowAutomaticOkay: false,    allowAutomaticNext: false } ) .next( 'referencesSection' );

tour.step( {	name: 'referencesSection',	title: 'Now let\'s create the References section.',   description: 'Project:Wiki_Ed/tour/citing_sources9',    attachTo: '#ca-edit',    position: 'bottom',    onShow: gt.getPageAsDescription,    overlay: false,    closeOnClickOutside: false,    allowAutomaticOkay: false,    allowAutomaticNext: false, } ) .listenForMwHooks( 've.activationComplete' ) .transition( function { if ( gt.isEditing ) { return 'addHeader'; } } ) .next( 'addHeader' );

tour.step( {	name: 'addHeader',	title: 'Make a "References" header.',	description: 'Project:Wiki_Ed/tour/citing_sources10',	onShow: gt.getPageAsDescription,	attachTo: '#content', 	position: 'bottomLeft',	buttons: [ {		name: 'I added the header.',		onclick: function { mw.libs.guiders.next; } 	} ],	overlay: false,	closeOnClickOutside: false,   allowAutomaticOkay: false,    allowAutomaticNext: false } ) .next( 'addReflist' );

tour.step( {	name: 'addReflist',	title: 'Optional: add the "Reflist" template',	description: 'Project:Wiki_Ed/tour/citing_sources11',	onShow: gt.getPageAsDescription,	attachTo: '#content', 	position: 'bottomLeft',	buttons: [ {		name: 'Okay.',		onclick: function { mw.libs.guiders.next; } 	} ],	overlay: false,	closeOnClickOutside: false,   allowAutomaticOkay: false,    allowAutomaticNext: false } ) .transition( function { if ( gt.isPostEdit ) { return 'returnToTraining'; } } ) .next( 'saveHeader' );

tour.step( {	name: 'saveHeader',	title: 'Publish changes again.',	description: '',	attachTo: '.ve-ui-toolbar-saveButton',	position: 'bottomLeft',	autoFocus: 'yes',	overlay: false,	closeOnClickOutside: false,   allowAutomaticOkay: false,    allowAutomaticNext: false } ) .listenForMwHooks( 've.deactivationComplete' ) .transition( function { if ( gt.isPostEdit ) { return 'returnToTraining'; } } ) .next( 'returnToTraining' );

tour.step( {	name: 'returnToTraining',	title: 'That\'s it!',   description: 'Project:Wiki_Ed/tour/citing_sources13',    onShow: gt.getPageAsDescription,	buttons: [ {        name: 'Try it again.',        action: 'externalLink',        url: mw.util.getUrl( 'Special:MyPage/citing_sources' ) + '?tour=wikiedcitingsources&step=editButton&vehidebetadialog=1'    }, {	    name: 'Return to training.',        action: 'externalLink',        url: 'https://dashboard.wikiedu.org/training/students/sources/add-a-citation-tutorial'            } ],    overlay: true,	closeOnClickOutside: false,    allowAutomaticOkay: false,    allowAutomaticNext: false } );

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