Jump to content

MediaWiki:Guidedtour-tour-twa2.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// The Wikipedia Adventure Mission 2

 
( function ( window, document, $, mw, gt ) {

// automatic api:edit function to send yourself messages custom for this module
function sendTalkMessage( targetPage, msgPage, linkTo, overwrite, isTalkPost) {
    var api = new mw.Api();
    api.get( {
        'action' : 'query',
        'titles' : msgPage+'|'+targetPage,
        'prop'   : 'revisions',
        'meta'   : 'tokens',
        'type'   : 'csrf',
        'rvprop' : 'content',
        'indexpageids' : 1
    } ).done( function (result) {
        result = result.query;
        var page = result.pages[result.pageids[1]];
        var text = page.revisions[0]['*'];
        text = text.replaceAll("<nowiki/>","");
        if (result.pageids[0] > 0) {
            var targetSrc = result.pages[result.pageids[0]];
            var srcText = targetSrc.revisions[0]['*'];
            if (!overwrite) {
            	// Check for duplicate talk messages with only the first 20 characters in case the messages subst into something different
            	if (isTalkPost && srcText.includes(text.substring(0, 20))) {
        			// Don't send duplicate badges/talk posts
        			window.location.href = linkTo;
        			return;
        		} else if (srcText.includes(text)) {
        			// Check for duplicate badges literally
        			window.location.href = linkTo;
        			return;
        		}
            	if (isTalkPost) {
	                text = srcText.replace("</div></div></div>","") + "\n" + text + "</div></div></div>"; 
            	} else {
            		// Ordinary case
            		text = srcText + "\n" + text;
            	}
           }
        }
        api.post( {
            'action' : 'edit',
            'title' : targetPage,
            'text' : text,
            'summary' : 'New Message (simulated automatically as part of [[WP:The Wikipedia Adventure|The Wikipedia Adventure]])',
            'token' : result.tokens.csrftoken
        } ).done( function () {
        	window.location.href = linkTo;
        } );
    } );
}

var tour = new gt.TourBuilder( {
        name: 'twa2',
});
var steps = [{
                //1
                title: 'Mission 2 begins!',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Great to see you again.  This mission we\'re going on a quest to communicate with other editors.<br><br>'),
                overlay: true,
                closeOnClickOutside: false,
	            buttons: [ {
                        name: 'Let\'s dive in',
                        action: 'next',
                         } ],
                allowAutomaticOkay: false
 
        },  {
                //2
                title: 'The Talk page',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Like the userpage, every editor has their own TALK page.  People can leave you messages.<br><br>Hey, look at that...Someone sent you a  message.<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
                back: true,
		        buttons: [ {
                        name: 'Check your new message*',
                        onclick: function()  {  if(!mw.config.get('wgUserName')){  alert( "Please login." );   return;   } sendTalkMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA', 'Wikipedia:TWA/MyTalk/1' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=3', true, true); }
                } ],
                allowAutomaticOkay: false
 
        },  {
                //3
                title: 'Real people',
                description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>Wow, that was nice. There are real people here like me.<br><br>Let\'s Reply to the talk page message.<br><br>'),
                attachTo: '#content.mw-body',
                position: 'bottom',
                overlay: false,
                closeOnClickOutside: false,
                back: true,
                buttons: [ {
                         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',
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false, 
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=3'          
                } ],

        },  {
                //5
                title: 'Write your reply',
                description: new gt.WikitextDescription('<br>Click REPLY so you can leave your message to Will<br><br>'),
                attachTo: '.ext-discussiontools-init-replylink-buttons',
                position: 'bottom',
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/2/Will' ) + '?tour=twa2&step=4'          
                }],
                hooks: "userjs.replyOpen",
                "onShow": function() {
                	$(".ext-discussiontools-init-replylink-reply").click(function(){
                		setTimeout(function(){
                			mw.hook("userjs.replyOpen").fire();
                		}, 200);
                	});
                },
                skip:function() {
                	return $(".ext-discussiontools-ui-replyWidget-bodyWrapper").length > 0;
                }
        },  {
                //6
                title: 'Copy your message',
                description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>Copy and paste the best reply into the text box:<br><br>Thanks so much for your friendly welcome <nowiki>[[User:WillKomen]]</nowiki>. I can\'t wait to start editing!<br>'), 
                overlay: false,
                attachTo: '.ext-discussiontools-ui-replyWidget-bodyWrapper',
                position: 'top',
                closeOnClickOutside: false,
                buttons: [ 
                	{ // Use externallink for back button here since if you go back when the widget is already open if will confuse the logic above
                		 name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=5'
                	},
                	{
                        name: 'Copied',
                        action: 'next',
                } ],
                allowAutomaticOkay: false
},  {
                //7
                title: 'Notify Will',
                description: new gt.WikitextDescription('<b>Notify</b> Will that you replied by typing his name somewhere in your reply like <code><nowiki>[[User:WillKomen]]</nowiki></code>.  If you\'re on Will\'s user talk page, it will notify him automatically.'),
                attachTo: '.ext-discussiontools-ui-replyWidget-bodyWrapper', 
                position: 'top',
                overlay: false,
                closeOnClickOutside: false,
                back: true,
                buttons: [ {
                	    name: 'Got it',
                        action: 'next'
                } ],
                allowAutomaticOkay: false,
				
} , {
                //8
                title: 'Publish your reply',
                description: new gt.WikitextDescription('Click REPLY when you\'re ready.<br><br>'),
                attachTo: '.ext-discussiontools-ui-replyWidget-actions',
                position: 'top',
                autoFocus: 'yes',
                overlay: false,
                closeOnClickOutside: false,
	            allowAutomaticOkay: false,
	            back: true,
	            buttons: [],
	            skip: gt.isPostEdit
} , {
                //9
                title: 'Replied successfully!',
                description: new gt.WikitextDescription('NEW TOOL EARNED:  <b>Communicator Badge</b><div class="center">[[File:TWA badge 3.png|250px|link=]]</div><br>'),
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ 
                	{
                		name: '<big>←</big>',
                        action: 'externalLink',
                        // Jump all the way back to "click on the reply button" since the steps after it expect the dialog to be open
                        url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=5'
                	},
                	{
                        name: 'Keep on talking*',
                        onclick: function()  {  if(!mw.config.get('wgUserName')){  alert( "Please login." );   return;   } sendTalkMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Wikipedia:TWA/Badge/3template2' , mw.util.getUrl( 'Wikipedia:TWA/2/Start' ) + '?tour=twa2&step=10', false, false); } 
                } ],
               allowAutomaticOkay: false
		
} , {
                //10
                title: 'Communication power!',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Hey, what if you\'re having lots of conversations at once? How can you keep track of them all?<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                buttons: [ {
                        name: '<big>←</big>',
                        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: new gt.WikitextDescription('<br>The Watchlist. Your very own feed of changes to the articles and pages you choose to follow.<br><br>To follow a page just click the [[File:MediaWiki Vector skin white star watchlist icon.svg]] star at the top center of it.  When it turns[[File:MediaWiki Vector skin blue star watchlist icon.svg]] blue, you\'re following! (You can also set your Preferences to automatically follow any page you edit).<br><br>Click WATCHLIST or the [[File:OOjs UI icon watchlist-ltr.svg]] icon.'),
                attachTo: '#pt-watchlist, #pt-watchlist-2',
                position: 'bottomLeft', 
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                back: true,
                buttons: [],
	            skip: function() { return gt.isPage( 'Special:Watchlist' ); }
} , {
                //12
                title: 'Check out your watchlist',
                description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>A <i>very</i> neat part about Wikipedia is that every single edit is recorded. This lets people check out each other\'s work, because we\'re at our best when we have help.<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
	            buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=11'          
                } , {
	            	    name: 'Our Motto',
                        action: 'next'
               } ],
} , {
                //13
                title: 'Be Bold',
                description: new gt.WikitextDescription('It\'s also really difficult to mess anything up here, because you can always just switch back to an older version of a page.<br><br>Kind of a relief, right?<br><br> That\'s why our motto on Wikipedia is to <b>Be Bold!</b><br><br>'),
                overlay: true,
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                back: true,
                buttons: [ {
                	    name: 'Beyond the watchlist',
                        action: 'next'
               } ],
 
} , {
                //14
                title: 'Track your contributions',
                description: new gt.WikitextDescription('<br>In addition to tracking changes on all the pages you follow on your watchlist, you can also keep track of just your edits.<br><br>Click CONTRIBUTIONS. It might be in the the [[File:OOjs UI icon userActive.svg]] menu.'),
                overlay: false,
                attachTo: '#pt-mycontris',
                position: 'bottomLeft',
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                back: true,
                buttons: [ ],
                skip: function() {
                        return gt.isPage( 'Special:Contributions/' + mw.config.get( 'wgUserName' ).replace(/ /g, '_') );
                }
 
} , {
                //15
                title: 'All your work',
                description: new gt.WikitextDescription('<br>Here are your contributions so far.  They\'re all to your userpage and Talk page...<br><br>Let\'s see if we can do something about that.<br><br>Oh, wait a second, it looks like you have a new message.<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
	            buttons: [ {
                        name: '<big>←</big>',
                        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;   } sendTalkMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA', 'Wikipedia:TWA/MyTalk/2' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=16', false, true); }
                } ],       
                allowAutomaticOkay: false

} , {
                //16
                title: 'An invitation',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Neat, something to work on...<br><br>'),
                attachTo: '#content.mw-body',
                position: 'bottom',
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        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',
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false, 
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl ( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=16'          
                } ],
				
        },  {
                //18
                title: 'Reply',
                description: new gt.WikitextDescription('<br>Click REPLY so you can leave your reply to GaiaGirl<br><br>'),
                attachTo: '.gaia .ext-discussiontools-init-replylink-buttons',
                position: 'top',
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl ( 'Wikipedia:TWA/2/Gaia' ) + '?tour=twa2&step=17'          
                }],
                hooks: "userjs.replyOpen",
                "onShow": function() {
                	$(".ext-discussiontools-init-replylink-reply").click(function(){
                		setTimeout(function(){
                			mw.hook("userjs.replyOpen").fire();
                		}, 200);
                	});
                },
                skip:function() {
                	return $(".ext-discussiontools-ui-replyWidget-bodyWrapper").length > 0;
                }
        },  {
                //19
                title: 'Write your message',
                description: new gt.WikitextDescription('Copy your reply into the text box:<br><br>Awesome <nowiki>[[User:GaiaGirl86]]</nowiki>, it\'s my favorite planet! How do I get there?<br>'),
                overlay: false,
                attachTo: '#wpTextbox1', 
                position: 'bottomRight',
                closeOnClickOutside: false,
                buttons: [ 
                	 { // Use externallink for back button here since if you go back when the widget is already open if will confuse the logic above
                		 name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=18'
                	},
                	{
                	    name: 'Copied',
                        action: 'next'
                } ],
                allowAutomaticOkay: false

},  {
                //20
                title: 'Publish your reply',
                description: new gt.WikitextDescription('Click REPLY when you\'re ready.<br><br>'),
                overlay: false,
                attachTo: '.ext-discussiontools-ui-replyWidget-actions',
                position:  'top',
	            autoFocus: 'yes',
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                back: true,
                buttons: [ ],
	            skip: gt.isPostEdit
} , {
                //21
                title: 'Tic, toc, tic, toc',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Hey, let\'s reload the page to see if GaiaGirl responded!'),
                overlay: false,
                closeOnClickOutside: false,
	            allowAutomaticOkay: false,
                buttons: [ 
                	 { // Go back several steps since otherwise it won't find the open dialog
                		 name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=18'
                	},{
                         name: 'Spin Earth around*',
                         onclick: function()  {  if(!mw.config.get('wgUserName')){  alert( "Please login." );   return;   } sendTalkMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA', 'Wikipedia:TWA/MyTalk/3' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=22', false, true); }
                } ],

} , {
                //22
                title: 'Directions?',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>I\'ll take you there.  Follow me to EARTH.<br><br>'),
                overlay: false,
                attachTo: '#content.mw-body',
                position: 'bottom',
                closeOnClickOutside: false,
	            allowAutomaticOkay: false,
	            back: true,
                buttons: [  {
                         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: new gt.WikitextDescription('<br>[[File:Ringtone (3).ogg]]<br><b>Journey on to mission 3...</b>'),
                overlay: false,
                closeOnClickOutside: false,
	            buttons: [ {
	            	    name: 'Congrats me!',
                        action: 'end'
                } ],
 
}];
var stepBuilders = [];
function makeSkip(target, query) {
	return function(event) {
		if (query(event)) {
			return target;
		}
	};
}
for (var i = 0; i < steps.length; i++) {
	var step = steps[i];
	step.allowAutomaticNext = false;
	step.name = (i+1).toString();
	var stepBuilder;
	if (i == 0) {
		stepBuilder = tour.firstStep(step);
	} else {
		stepBuilder = tour.step(step);
	}
	stepBuilders[i] = stepBuilder;
}
for (var j = 0; j < steps.length; j++) {
	if (steps[j].hooks) {
		stepBuilders[j].listenForMwHooks(steps[j].hooks);
	}
	if (steps[j].skip) {
		stepBuilders[j].transition(makeSkip(stepBuilders[j+1], steps[j].skip));
	}
	if (j > 0 && steps[j].back) {
		stepBuilders[j].back(stepBuilders[j-1]);
	}
	if (j < steps.length - 1) {
		stepBuilders[j].next(stepBuilders[j+1]);
	}
}
 
} (window, document, jQuery, mediaWiki, mediaWiki.guidedTour ) ) ;