( function  {

//automatic api:edit function to send yourself messages 
function sendMessage {
	var api = new mw.Api;
	api.get( {
		'action' : 'query',
		'titles' : msgPage,
		'prop' : 'revisions|info',
		'intoken' : 'edit',
		'rvprop' : 'content',
		'indexpageids' : 1
		result = result.query;
		var page = result.pages[result.pageids[0]];
		var text = page.revisions[0]['*'];
		api.post( {
			'action' : 'edit',
			'title' : targetPage,
			'appendtext' : "\n" + text,
			'summary' : 'New Message (simulated automatically as part of The Wikipedia Adventure)',
			'token' : page.edittoken
			window.location.href = linkTo;
 
// Fail gracefully post-save but not postedit
var postEditButtons = [];
if ( mw.config.get( 'wgAction' ) === 'view' && !gt.isPostEdit ) {
 postEditButtons.push( {
 name: 'Click here to go back and make an edit',
 onclick: function {
 window.location.href = new mw.Uri.extend( { action: 'edit' } ).toString;

// Fail gracefully post-save but not postedit for visual editor
var postEditButtonsVisual = [];
if ( mw.config.get( 'wgAction' ) === 'view' && !gt.isPostEdit ) {
 postEditButtonsVisual.push( {
 name: 'Go Back',
 onclick: function {
 window.location.href = window.location.href +
"&veaction=edit";

gt.defineTour( {
 name: 'twa2',
 shouldLog: true,
 steps: [ {
 //1
 title: 'Mission 2 begins!',
 description: '',
 onShow: gt.parseDescription,
 overlay: true,
 closeOnClickOutside: false,
	 buttons: [ {
 name: 'Let\'s dive in',
 action: 'next',
 allowAutomaticOkay: false
 
 //2
 title: 'The Talk page',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
		 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Wikipedia:TWA/2/Start' ) + '?tour=twa2&step=1' 
 name: 'Check your new message*',
 onclick: function { if(!mw.config.get('wgUserName')){ alert( "Please login." ); return; } sendMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA', 'Wikipedia:TWA/MyTalk/1' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=3'); }
 allowAutomaticOkay: false
 
 //3
 title: 'Real people',
 description: '',
 onShow: gt.parseDescription,
 attachTo: '#content.mw-body',
 position: 'bottom',
 overlay: false,
 closeOnClickOutside: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Wikipedia:TWA/2/Start' ) + '?tour=twa2&step=2' 
 name: 'Reply to Will',
 action: 'externalLink',
 url: mw.util.getUrl( 'Wikipedia:TWA/2/Will' ) + '?tour=twa2&step=4'
 allowAutomaticOkay: false				
 
 //4
 title: 'Challenge yourself BELOW...',
 description: 'Hint: you can learn as much from getting it wrong as getting it right. And you can always try again!',
 attachTo:'#contentSub',
 position: 'bottom',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 allowAutomaticOkay: false, 
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=3' 

 //5
 title: 'Write your reply',
 description: '',
 attachTo: '#ca-edit',
 position: 'bottom',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Wikipedia:TWA/2/Will' ) + '?tour=twa2&step=4' 
 shouldSkip: function {
 return gt.hasQuery( { action: 'edit' } );

 //6
 title: 'Copy your message',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
 attachTo: '#wpTextbox1', 
 position: 'bottomRight',
 closeOnClickOutside: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=5' 
 name: 'Copied',
 action: 'next',
 allowAutomaticOkay: false

 //7
 title: 'Three quick things',
 description: '. If you\'re on Will\'s user talk page, it will notify him automatically.',
 attachTo: '#wpTextbox1', 
 position: 'bottomRight',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=6&action=edit' 
 	 name: 'Got it',
 action: 'next'
 allowAutomaticOkay: false,
				
 //8
 title: 'Edit summary and Save',
 description: '',
 attachTo: '#wpSave',
 position: 'bottomRight',
 autoFocus: 'yes',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
	 allowAutomaticOkay: false,
	 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=7&action=edit' 
	 shouldSkip: function {
 return gt.isPostEdit;
 buttons: postEditButtons

 //9
 title: 'Indented, signed, and notified!',
 description: 'NEW TOOL EARNED: ', 
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=8&action=edit' 
 name: 'Keep on talking*',
 onclick: function { if(!mw.config.get('wgUserName')){ alert( "Please login." ); return; } sendMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Wikipedia:TWA/Badge/3template2' , mw.util.getUrl( 'Wikipedia:TWA/2/Start' ) + '?tour=twa2&step=10'); } 
 allowAutomaticOkay: false
		
 //10
 title: 'Communication power!',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=9' 
 	 name: 'A good problem to have...',
 action: 'next'

 //11
 title: 'A solution',
 description: 'Click WATCHLIST.',
 attachTo: '#pt-watchlist',
 position: 'bottom', 
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=10' 
	 shouldSkip: function {
 return gt.isPage( 'Special:Watchlist' );
 
 
 //12
 title: 'Check out your watchlist',
 description: '',
 onShow: gt.parseDescription,
 attachTo: '#content.mw-body',
 position: 'bottom',
 overlay: false,
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
	 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=11' 
	 	 name: 'Our Motto',
 action: 'next'

 //13
 title: 'Be Bold',
 description: 'It\'s also really difficult to mess anything up here, because you can always just switch back to an older version of a page.',
 onShow: gt.parseDescription,
 overlay: true,
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:Watchlist' ) + '?tour=twa2&step=12' 
 	 name: 'Beyond the watchlist',
 action: 'next'
 
 //14
 title: 'Track your contributions',
 description: 'Click CONTRIBUTIONS.',
 onShow: gt.parseDescription,
 overlay: false,
 attachTo: '#pt-mycontris',
 position: 'bottomLeft',
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:Watchlist' ) + '?tour=twa2&step=13' 
 shouldSkip: function {
 return gt.isPage( 'Special:Contributions/' + mw.config.get( 'wgUserName' ).replace );
 
 //15
 title: 'All your work',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
	 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl( 'Special:Watchlist' ) + '?tour=twa2&step=14' 
 name: 'Check your new message*',
 onclick: function { if(!mw.config.get('wgUserName')){ alert( "Please login." ); return; } sendMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA', 'Wikipedia:TWA/MyTalk/2' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=16'); }
 allowAutomaticOkay: false

 //16
 title: 'An invitation',
 description: '',
 onShow: gt.parseDescription,
 attachTo: '#content.mw-body',
 position: 'bottom',
 overlay: false,
 closeOnClickOutside: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl ('Special:Contributions/' ) + mw.config.get( 'wgUserName' ) + '?tour=twa2&step=15' 
 name: 'Reply to GaiaGirl',
 action: 'externalLink',
 url: mw.util.getUrl( 'Wikipedia:TWA/2/Gaia' ) + '?tour=twa2&step=17'
 allowAutomaticOkay: false				
 
 //17
 title: 'Challenge yourself BELOW...',
 description: 'Hint: you can learn as much from getting it wrong as getting it right. And you can always try again!',
 attachTo:'#contentSub',
 position: 'bottom',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 allowAutomaticOkay: false, 
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl ( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=16' 
				
 //18
 title: 'Reply',
 description: '',
 attachTo: '#ca-edit',
 position: 'bottom',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl ( 'Wikipedia:TWA/2/Gaia' ) + '?tour=twa2&step=17' 
 shouldSkip: function {
 return gt.hasQuery( { action: 'edit' } );
				
 //19
 title: 'Write your message',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
 attachTo: '#wpTextbox1', 
 position: 'bottomRight',
 closeOnClickOutside: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl ( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=18' 
 	 name: 'Copied',
 action: 'next'
 allowAutomaticOkay: false

 //20
 title: 'Edit summary and Save',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
	 attachTo: '#wpSave',
 position: 'bottomRight',
	 autoFocus: 'yes',
 closeOnClickOutside: false,
 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl ( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=19&action=edit' 
	 shouldSkip: function {
 return gt.isPostEdit;
 buttons: postEditButtons

 //21
 title: 'Tic, toc, tic, toc',
 description: 'Hey, let\'s reload the page to see if GaiaGirl responded!',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
	 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl ( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=20&action=edit' 
 name: 'Spin Earth around*',
 onclick: function { if(!mw.config.get('wgUserName')){ alert( "Please login." ); return; } sendMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA', 'Wikipedia:TWA/MyTalk/3' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=22'); }

 //22
 title: 'Directions?',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
 attachTo: '#content.mw-body',
 position: 'bottom',
 closeOnClickOutside: false,
	 allowAutomaticOkay: false,
 buttons: [ {
 name: '',
 action: 'externalLink',
 url: mw.util.getUrl ( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=21' 
 name: 'Head to Earth',
 action: 'externalLink',
 url: mw.util.getUrl( 'Wikipedia:TWA/2/End' ) + '?tour=twa2&step=23'

 //23
 title: 'You\'ve reached the end of mission 2!',
 description: '',
 onShow: gt.parseDescription,
 overlay: false,
 closeOnClickOutside: false,
	 buttons: [ {
	 	 name: 'Congrats me!',
 action: 'end'