MediaWiki:Guidedtour-tour-twa2.js

// 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(" ","");        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("  ","") + "\n" + text + "   "; } else { // Ordinary case text = srcText + "\n" + text; }          }        }        api.post( {            'action' : 'edit',            'title' : targetPage,            'text' : text,            'summary' : 'New Message (simulated automatically as part of 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(' TWA_guide_right_top.png Great to see you again. This mission we\'re going on a quest to communicate with other editors.  '), overlay: true, closeOnClickOutside: false, buttons: [ { name: 'Let\'s dive in', action: 'next', } ],               allowAutomaticOkay: false }, {                //2                title: 'The Talk page', description: new gt.WikitextDescription(' TWA_guide_right_top.png Like the userpage, every editor has their own TALK page. People can leave you messages.  Hey, look at that...Someone sent you a  message.  '), 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(' TWA_guide_left_top.png Wow, that was nice. There are real people here like me. Let\'s Reply to the talk page message.  '), 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: ' ← ', action: 'externalLink', url: mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa2&step=3' } ],

}, {                //5                title: 'Write your reply', description: new gt.WikitextDescription(' Click REPLY so you can leave your message to Will '), attachTo: '.ext-discussiontools-init-replylink-buttons', position: 'bottom', overlay: false, closeOnClickOutside: false, allowAutomaticOkay: false, buttons: [ { name: ' ← ', 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(' Copy and paste the best reply into the text box:  Thanks so much for your friendly welcome User:WillKomen . I can\'t wait to start editing! '), 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: ' ← ', 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('Notify Will that you replied by typing his name somewhere in your reply like .  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. '), 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: Communicator Badge   '), overlay: false, closeOnClickOutside: false, buttons: [ {               		name: ' ← ', 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(' Hey, what if you\'re having lots of conversations at once? How can you keep track of them all?  '), 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: new gt.WikitextDescription(' The Watchlist. Your very own feed of changes to the articles and pages you choose to follow. To follow a page just click the  star at the top center of it.  When it turns blue, you\'re following! (You can also set your Preferences to automatically follow any page you edit).  Click WATCHLIST or the  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(' A very 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.  '), 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: 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. Kind of a relief, right?  That\'s why our motto on Wikipedia is to Be Bold!  '), overlay: true, closeOnClickOutside: false, allowAutomaticOkay: false, back: true, buttons: [ { name: 'Beyond the watchlist', action: 'next' } ], }, {               //14                title: 'Track your contributions', description: new gt.WikitextDescription(' In addition to tracking changes on all the pages you follow on your watchlist, you can also keep track of just your edits. Click CONTRIBUTIONS. It might be in the the  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(' Here are your contributions so far. They\'re all to your userpage and Talk page...  Let\'s see if we can do something about that.  Oh, wait a second, it looks like you have a new message.  '), 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;   } 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(' Neat, something to work on...  '), 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', 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: new gt.WikitextDescription(' Click REPLY so you can leave your reply to GaiaGirl '), attachTo: '.gaia .ext-discussiontools-init-replylink-buttons', position: 'top', overlay: false, closeOnClickOutside: false, allowAutomaticOkay: false, buttons: [ { name: ' ← ', 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: Awesome User:GaiaGirl86, it\'s my favorite planet! How do I get there? '), 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: ' ← ', 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. '), 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(' 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: ' ← ', 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(' I\'ll take you there.  Follow me to EARTH.  '), 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(' Journey on to mission 3...'), 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 ) ) ;