Jump to content

MediaWiki:Guidedtour-tour-twa5sandbox.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 5

( function ( window, document, $, mw, gt ) {
 
//automatic api:edit function to send yourself messages
function sendTalkMessage( targetPage, msgPage, linkTo, overwrite, isTalkPost) {
	if(!mw.config.get('wgUserName')) {  
		alert( "Please login." );   
		return;
	}
    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) {
            		// Preserve the banner for talk posts
	                text = srcText.replace("</div></div></div>","") + "\n" + text + "</div></div></div>"; 
            	} else {
            		// Otherwise just add for badges
            		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: 'twa5sandbox',
});
var steps = [{
                //1
                title: 'We\'re on! ',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>SocraTease riddled us with a puzzling question: How do we know if information on Wikipedia is true?<br><br>This is a special question--that needs a special place to get a wise answer.<br><br>'),
                overlay: true,
                buttons: [ {
                        name: 'Check out the Teahouse',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse' ) + '?tour=twa5&step=2'      
                } ],
		allowAutomaticOkay: false

        },  {
                //2
                title: 'What\'s this Teahouse place?',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>The Teahouse is a social space for asking questions about Wikipedia--and getting simple, clear answers from smart, welcoming helpers--any time you need it.<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/5/Start' ) + '?tour=twa5&step=1' 
                } , { 
                	    name: 'Drink some Tea',
                        action:'next',          
                } ],

                allowAutomaticOkay: false,
                
        },  {
                //3
                title: 'Teahouse = Awesome.',
                description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>Asking for help is part of becoming a great editor.  There\'s a lot to learn here, and lots of people who will lend you a hand.<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
                allowAutomaticOkay: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse' ) + '?tour=twa5&step=2' 
                } , { 
                	   name: 'Share the riddle with Teahouse',
                       action: 'next',
                } ],     
                
        },  {

                //4
                title: 'Ask away!',
                description: new gt.WikitextDescription('<br>Truth and Wikipedia<br><br>"Hi, I\'m new here and trying to learn more about Wikipedia. I was wondering, how do you know that anything on Wikipedia is *true*?"<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
	            allowAutomaticOkay: false,
		        buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse' ) + '?tour=twa5&step=3' 
                } , { 
                        name: 'Post it!',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse/1' ) + '?tour=twa5&step=5'
                        } ],
},  {
                //5
                title: 'Asking is Awesome',
                description: new gt.WikitextDescription('NEW TOOL EARNED:  <b>Researcher Badge</b><div class="center">[[File:TWA badge 7.png|250px|link=]]</div><br>Hey, you got a notification that someone replied to your Teahouse question<br>'),
                attachTo: '#content.mw-body',
                position: 'topRight',
                autoFocus: 'yes',
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse' ) + '?tour=twa5&step=4' 
                } , { 
                        name: 'Check out the reply',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse/2' ) + '?tour=twa5&step=6'
                        } ],
                allowAutomaticOkay: false,
                
        },  {
                //6
                title: 'This is important',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>So, we only write what we can verify in a published source.  Not your own experience, original research, or personal opinions.  Just published info.<br><br>'),
                overlay: false,
                attachTo: '#content.mw-body',
                position: 'bottomRight',
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse/1' ) + '?tour=twa5&step=5' 
                } , { 
                        name: 'Dig into Verifiability*',
                        onclick: function()  {  sendTalkMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Wikipedia:TWA/Badge/7template2' , mw.util.getUrl( 'Wikipedia:TWA/5/V' ) + '?tour=twa5&step=7', false, false); }
                } ],      
                allowAutomaticOkay: false

},  {
                //7
                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!',
                overlay: false,
                closeOnClickOutside: false,
	            allowAutomaticOkay: false,
	            buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/Teahouse/2' ) + '?tour=twa5&step=6' 
                } ]

} , {
                //8
                title: 'You\'ve got Verifi-ability',
                description: new gt.WikitextDescription('NEW TOOL EARNED:  <b>Verifiability Badge</b><div class="center">[[File:TWA badge 8.png|250px|link=]]</div><br>Let\'s put this new knowledge to use!<br>'),
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/5/V' ) + '?tour=twa5&step=7' 
                } , { 
                        name: 'Check your messages*',
                        onclick: function()  {  sendTalkMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA', 'Wikipedia:TWA/MyTalk/5' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa5&step=9', false, true); }           
                } ],
                allowAutomaticOkay: false

} , {
                //9
                title: 'Seeking sources',
                description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>Let\'s see what GaiaGirl came up with</br>'),
                overlay: false,
                attachTo: '#content.mw-body',
                position: 'bottom',
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/5/Start' ) + '?tour=twa5&step=8' 
                } , { 
                        name: 'Head to Earth\'s talk page*',
                        onclick: function()  {  sendTalkMessage( 'User talk:' + mw.config.get( 'wgUserName' ) + '/TWA/Earth', 'Wikipedia:TWA/Earth/Talk/1' , mw.util.getUrl( 'Special:MyTalk/TWA/Earth' ) + '?tour=twa5&step=10', true, true); }           
                } ],
                allowAutomaticOkay: false
				
} , {
                //10
                title: '3 Sources',
                description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>It looks like GaiaGirl gave you some options.<br><br>Verifiability tells us we want published reliable sources with a reputation for fact-checking and accuracy. Sources we can rely on.<br><br> '),
                overlay: false,
                attachTo: '#content.mw-body',
                position: 'bottom',
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/5/Start' ) + '?tour=twa5&step=9' 
                } , { 
                        name: 'Which one of these would be best??',
                        onclick: function()  {  sendTalkMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Wikipedia:TWA/Badge/8template2' , mw.util.getUrl( 'Wikipedia:TWA/5/RS' ) + '?tour=twa5&step=11', false, true); }
                } ],      

                allowAutomaticOkay: false

},  {
                //11
                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/Earth' ) + '?tour=twa5&step=10' 
                }],

}, {
                //12
                title: 'You\'re getting pretty reliable yourself',
                description: new gt.WikitextDescription('NEW TOOL EARNED:  <b>Sourcer Badge</b><div class="center">[[File:TWA badge 9.png|250px|link=]]</div><br>'),
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/5/RS' ) + '?tour=twa5&step=11' 
                } , { 
                             name: 'Reply to GaiaGirl*',
                             onclick: function()  {  sendTalkMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Wikipedia:TWA/Badge/9template2' , mw.util.getUrl( 'Wikipedia:TWA/5/Start' ) + '?tour=twa5&step=13', false, false); }
                } ],    
                allowAutomaticOkay: false

}, {
                //13
                title: 'What now?',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Now that we have the source, what do we do with it?<br><br>First, let\'s leave a note on the talk page telling GaiaGirl86 about our thoughts.<br><br>Hmm... what to say?<br><br>'),
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Special:MyTalk/TWA/Earth' ) + '?tour=twa5&step=12' 
                },{
                        name: 'Reply to GaiaGirl',
                        action: 'externalLink',
                        url: mw.util.getUrl( 'Wikipedia:TWA/5/Reply' ) + '?tour=twa5&step=14'
                        } ],
                allowAutomaticOkay: false

} , {
                //14
                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( 'Wikipedia:TWA/5/Start' ) + '?tour=twa5&step=13' 
                }],

        },  {
                //15
                title: 'Reply to GaiaGirl',
                description: new gt.WikitextDescription('<br>Click REPLY so you can leave your reply to GaiaGirl<br><br>'),
                attachTo: '.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/5/Reply' ) + '?tour=twa5&step=14' 
                }],
                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;
                }
 
        },  {
                //16
                title: 'Copy your message into the textbox',
                description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Nature Reviews Earth and Environment looks like a solid and relevant source with a good reputation. I think we can rely on it more than the others for this article. Nice research!<br>'),
                overlay: false,
                attachTo: '.ext-discussiontools-ui-replyWidget-bodyWrapper', 
                position: 'top',
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'back',
                } , {
                        name: 'Copied',
                        action: 'next',
                        } ],
 
} , {
                //17
                title: 'Publish',
                description: new gt.WikitextDescription('<br>Click REPLY to make it live.<br><br>'),
                attachTo: '.ext-discussiontools-ui-replyWidget-actions',
                position: 'top',
                autoFocus: 'yes',
                overlay: false,
                closeOnClickOutside: false,
	            allowAutomaticOkay: false,
	            buttons: [ {
                        name: '<big>←</big>',
                        action: 'back',
                } ], 
	            skip: gt.isPostEdit
} , {
                //18
                title: 'Rock on!',
                description: new gt.WikitextDescription('NEW TOOL EARNED:  <b>Advisor Badge</b><div class="center">[[File:TWA badge 10.png|250px|link=]]</div><br><br>I took a look at Earth\'s talk page and GaiaGirl added some awesome content.  Check it out!'),
                overlay: false,
                closeOnClickOutside: false,
                buttons: [ {
                        name: '<big>←</big>',
                        action: 'back',
                } , {
                        name: 'Journey deeper*',
                        onclick: function()  { sendTalkMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Wikipedia:TWA/Badge/10template2' , mw.util.getUrl( 'Wikipedia:TWA/5/End' ) + '?tour=twa5&step=19', false, false); }
                } ], 
                allowAutomaticOkay: false

} , {
                //19
                title: 'Mission 5 complete!',
                description: new gt.WikitextDescription('<br>[[File:Northern mountains (short).ogg]]<br><b>Journey on to mission 6...</b>'),
                overlay: false,
                closeOnClickOutside: false,
	            buttons: [ {
	            	    name: 'Congrats me!',
                        action: 'end'
                } ],
                allowAutomaticOkay: false
}];
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) {
		stepBuilders[j].back(stepBuilders[j-1]);
	}
	if (j < steps.length - 1) {
		stepBuilders[j].next(stepBuilders[j+1]);
	}
}
 
} (window, document, jQuery, mediaWiki, mediaWiki.guidedTour ) ) ;