// Guided Tour for adding your username to the list of users who completed the training for students: Wikipedia:Training/For_students
 
( function ( window, document, $, mw, gt ) {
 
//automatic api:edit function to send yourself messages
function sendMessage( targetPage, msgPage ) {
	var api = new mw.Api();
	api.get( {
		'action' : 'query',
		'titles' : msgPage,
		'prop'   : 'revisions',
		'meta'   : 'tokens',
		'type'   : 'csrf',
		'rvprop' : 'content',
		'indexpageids' : 1
	} ).done( function (result) {
		result = result.query;
		var page = result.pages];
		var text = page.revisions;
		api.post( {
			'action' : 'edit',
			'title' : targetPage,
			'appendtext' : "\n" + text,
			'summary' : 'automatic post to indicate completion of training for students',
			'token' : result.tokens.csrftoken
		} );
	} );
}
 
gt.defineTour( {
        name: 'StudentTrainingComplete',
        shouldLog: true,
        steps: [ {
                //1
                title: 'Certification',
                description: 'Project:Training/tour/student_training_complete1',
                onShow: gt.getPageAsDescription,
                overlay: true,
                closeOnClickOutside: false,
	            buttons: [ {
                        name: 'I completed the training.',
                        onclick: function()  {
                        	if(!mw.config.get('wgUserName')){  alert( "Please login." );
                        	return;
                        }
                        sendMessage( 'Project:Training/For_students/Training_feedback', 'Project:Training/tour/educator_training_complete_preload' );
                        sendMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Project:Training/tour/training_completion_award' );
                        mw.libs.guiders.next(); }
					} ],
                allowAutomaticOkay: false
                
} , {
                //2
                title: 'Feedback',
                description: 'Project:Training/tour/student_training_complete2',
                onShow: gt.getPageAsDescription,
                overlay: false,
                closeOnClickOutside: false,
	            buttons: [ {
                        name: 'Leave feedback',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:Training/For_students/Leave_feedback' ) + '?action=edit&preload=Wikipedia%3ATraining%2FFor+students%2FTraining+feedback%2Fpreload&editintro=Wikipedia:Training/For_students/Training_feedback/editintro&preloadtitle=Training+feedback&section=new&tour=StudentTrainingComplete&step=4'
					}, {
                        name: 'No thanks',
                        onclick: function() { mw.libs.guiders.next(); } 
                }],
                allowAutomaticOkay: false

} , {
                //3
                title: 'Thanks!',
                description: 'Project:Training/tour/student_training_complete3',
                onShow: gt.getPageAsDescription,
                overlay: false,
                closeOnClickOutside: false,
	            buttons: [ {
	            	    name: 'Okay',
                        action: 'end'
                } ],
                allowAutomaticOkay: false
             
} , {
                //4
                title: 'Thanks!',
                description: 'Project:Training/tour/student_training_complete4',
                onShow: gt.getPageAsDescription,
                overlay: false,
                closeOnClickOutside: false,
	            buttons: [ {
	            	    name: 'Okay',
                        action: 'end'
                } ],
                allowAutomaticOkay: false

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