MediaWiki:Guidedtour-tour-twa3sandbox.js: Difference between revisions
Content deleted Content added
Tweaks |
Fix |
||
Line 23: | Line 23: | ||
var srcText = targetSrc.revisions[0]['*']; |
var srcText = targetSrc.revisions[0]['*']; |
||
if (!overwrite) { |
if (!overwrite) { |
||
// Check for duplicate talk messages with only the first |
// Check for duplicate talk messages with only the first 20 characters in case the messages subst into something different |
||
if (srcText.includes(text.substring(0, |
if (srcText.includes(text.substring(0, 20))) { |
||
// Don't send duplicate badges/talk posts |
// Don't send duplicate badges/talk posts |
||
window.location.href = linkTo; |
window.location.href = linkTo; |
Revision as of 02:50, 17 May 2024
// The Wikipedia Adventure Mission 3
( function ( window, document, $, mw, gt ) {
//automatic api:edit function to send yourself messages
function sendTalkMessage( targetPage, msgPage, linkTo, overwrite, addDivs) {
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 (srcText.includes(text.substring(0, 20))) {
// Don't send duplicate badges/talk posts
window.location.href = linkTo;
return;
}
if (addDivs) {
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;
} );
} );
}
// 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: 'twa3sandbox',
shouldLog: true,
steps: [ {
//1
title: 'Mission 3 begins!',
description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>GaiaGirl is waiting for us at the Earth article.<br><br>Let\'s go there.<br><br>'),
overlay: true,
closeOnClickOutside: false,
buttons: [ {
name: 'Head to Earth*',
onclick: function() { if(!mw.config.get('wgUserName')){ alert( "Please login." ); return; } sendTalkMessage( 'User:' + mw.config.get( 'wgUserName' ) + '/TWA/Earth', 'Wikipedia:TWA/Earth/1' , mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=2', true, false); }
} ],
allowAutomaticOkay: false
}, {
//2
title: 'So this is Planet Earth!',
description: new gt.WikitextDescription('<br>Articles on Wikipedia give an encyclopedic overview of a subject: they tell readers a little bit about everything that\'s important to know.<br><br>'),
overlay: false,
closeOnClickOutside: false,
buttons: [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Wikipedia:TWA/3/Start' ) + '?tour=twa3&step=1'
} , {
name: 'Check it out',
action: 'next',
} ],
allowAutomaticOkay: false
}, {
//3
title: 'See anything that needs fixing?',
description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>I notice a few spelling edits distracting from the information. How many do you see?<br><br>'),
attachTo: '#content.mw-body',
position: 'bottom',
overlay: false,
closeOnClickOutside: false,
buttons: [ {
name: '<big>←</big>',
action: 'back',
} , {
name: 'Search for typos',
action: 'next'
} ],
allowAutomaticOkay: false
}, {
//4
title: 'Spellcheck.',
description: new gt.WikitextDescription('<br>Did you find all 5?<br><br>thurd -- <b>third</b><br>fore -- <b>four</b><br>tree -- <b>three</b> <br>aminals -- <b>animals</b><br>hughmans -- <b>humans</b>'),
attachTo: '#content.mw-body',
position: 'bottom',
overlay: false,
closeOnClickOutside: false,
allowAutomaticOkay: false,
buttons: [ {
name: '<big>←</big>',
action: 'back',
} , {
name: 'Found them all',
action: 'next',
} ],
}, {
//5
// TODO: Make this bit work with VE
title: 'Typofixing',
description: new gt.WikitextDescription('<br>Let\'s put your editing skills to the test and fix those up. Click EDIT SOURCE.<br><br>'),
attachTo: '#ca-edit',
position: 'bottom',
overlay: false,
closeOnClickOutside: false,
allowAutomaticOkay: false,
buttons: [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=4'
} ],
shouldSkip: function() {
return gt.hasQuery( { action: 'edit' } );
}
}, {
//6
title: '5 fixes',
description: new gt.WikitextDescription('<br>thurd -- <b>third</b><br>fore -- <b>four</b><br>tree -- <b>three</b> <br>aminals -- <b>animals</b><br>hughmans -- <b>humans</b>'),
overlay: false,
attachTo: '#wpTextbox1',
position: 'bottomRight',
closeOnClickOutside: false,
buttons: [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=5'
} , {
name: 'Fixed',
action: 'next',
} ],
allowAutomaticOkay: false
}, {
//7
title: 'Edit summary, and Publish',
description: new gt.WikitextDescription('<br>Let them know that you, "Fixed 5 typos".<br><br>Then PUBLISH when you\'re ready.'),
attachTo: '#wpSave',
position: 'bottomRight',
autoFocus: 'yes',
overlay: false,
closeOnClickOutside: false,
allowAutomaticOkay: false,
buttons: postEditButtons || [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=6&action=edit'
} ],
shouldSkip: function() {
return gt.isPostEdit();
},
} , {
//8
title: 'See boldly!',
description: new gt.WikitextDescription('NEW TOOL EARNED: <b>Copyeditor Badge</b><div class="center">[[File:TWA badge 4.png|250px|link=]]</div><br>Wow. Now the whole world can see the improved version of the article you contributed to...pretty cool!<br><br>Let\'s make a few more changes. Let\'s add bold around the first mention of <b>Earth</b> in the first sentence of the article.<br><br>This lets readers focus quickly on the main subject of the article. Click EDIT SOURCE.<br><br>'),
overlay: false,
attachTo: '#ca-edit',
position: 'bottom',
closeOnClickOutside: false,
allowAutomaticOkay: false,
buttons: [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=7&action=edit'
} ],
shouldSkip: function() {
return gt.hasQuery( { action: 'edit' } );
}
} , {
//9
title: 'Add bold!',
description: new gt.WikitextDescription('<br><div align="right">[[File:TWA_guide_right_top.png|link=]]</div>Just like before, to add bold, highlight the first mention of the word Earth and then click the B on the toolbar.<br><br>'),
attachTo: '#wpTextbox1',
position: 'bottomRight',
autoFocus: 'yes',
overlay: false,
closeOnClickOutside: false,
buttons: [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=8'
} , {
name: 'Bolded',
action: 'next',
} ],
allowAutomaticOkay: false
} , {
//10
title: 'Edit summary, and Publish',
description: new gt.WikitextDescription('<br>Let them know that you, "Added bold"<br><br>Then PUBLISH when you\'re ready.'),
attachTo: '#wpSave',
position: 'bottomRight',
autoFocus: 'yes',
overlay: false,
closeOnClickOutside: false,
allowAutomaticOkay: false,
buttons: postEditButtons || [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=9&action=edit'
} ],
shouldSkip: function() {
return gt.isPostEdit();
},
} , {
//11
title: 'Whew... This is exciting!',
description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>You\'re getting the hang of this. You\'re going to do a lot of good here, I can sense it.<br><br>Hey you also have a new message...<br><br>'),
overlay: false,
closeOnClickOutside: false,
allowAutomaticOkay: false,
buttons: [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=10&action=edit'
} , {
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/3a' , mw.util.getUrl( 'Special:MyTalk/TWA' ) + '?tour=twa3&step=12', false, true); }
} ],
} , {
//12
title: 'New content...',
description: new gt.WikitextDescription('<br><div align="left">[[File:TWA_guide_left_top.png|link=]]</div>Let\'s see what\'s new<br><br>'),
attachTo: '#content.mw-body',
position: 'bottom',
overlay: false,
closeOnClickOutside: false,
buttons: [ {
name: '<big>←</big>',
action: 'externalLink',
url: mw.util.getUrl( 'Special:MyPage/TWA/Earth' ) + '?tour=twa3&step=11'
} , {
name: 'Check out the new content*',
onclick: function() { if(!mw.config.get('wgUserName')){ alert( "Please login." ); return; } sendTalkMessage( 'User:' + mw.config.get( 'wgUserName' ), 'Wikipedia:TWA/Badge/4template2' , mw.util.getUrl( 'Wikipedia:TWA/3/End' ) + '?tour=twa3&step=13', false, false); }
} ],
allowAutomaticOkay: false
} , {
//13
title: 'Mission 3 complete!',
description: new gt.WikitextDescription('<br>[[File:Wesnothmusic.ogg (short).ogg]]<br><b>Journey on to mission 4...</b>'),
overlay: false,
closeOnClickOutside: false,
buttons: [ {
name: 'Congrats me!',
action: 'end'
} ],
allowAutomaticOkay: false
}]
} );
} (window, document, jQuery, mediaWiki, mediaWiki.guidedTour ) ) ;