User:ITechieGamer/welcome.js

$(document).ready(function {

// Add a new link after "Page information" in the toolbox if ($('#t-info').length==0) { alert('Expected element not found.'); return; }; var $welcomeLink = $('Welcome a user').attr( { id: 't-welcome', href: '#', title: 'Welcome a user' } ); var $newUserLink = $('New users').attr( { id: 't-newusers', href: '/index.php?title=Special:ListAllUsers&group=&username=&editsOnly=0&creationSort=1&st=446400', title: 'List of new users' } ); $('#t-info').after($('').html($welcomeLink)).after($('').html($newUserLink));

$('#t-welcome').click( function {

// Notify the user for the username var username = prompt('Who would you like to welcome?'); if(username == '') return;

// Change welcome link to let the user know it's thinking $(this).html('Calculating...');

// Set up variables var editSummary = '/* Welcome! */ new section'; var skipcaptcha = false; var oldpage = false; var edittoken; var succeeded = false; var brace = '{'; var tilde = '~'; var text = '== Welcome! ==\n\nHello, '+username+' and welcome to the '+brace+brace+'subst:SITENAME}}!\n\nHere are some links to get you started:\n* Need help editing? Help:Contents may be of use. \n* If you are already familiar with editing, try the style guide.\n* Make sure to read and follow the rules.\n* The community portal is the community\'s main discussion page. You can talk about anything wiki-related there.\n* You can join or create a community project at Project:Projects.\n* Recent changes will let you see others\' contributions as they happen.\n* You can customize your user page if you like.\n* Any issues that require an admin can be lodged on the admin noticeboard.\n* If you have trouble with anything on the wiki or you\'re not sure about a specific topic, feel free to join the IRC.* If you would like to talk about \'\'Minecraft\'\' for ideas, suggestions, and other general topics, the forums are a great place to start.\n\nWhen posting on a talk page, remember to add onto the end of your post.\n\nAny way you chose, you can be part of the Minecraft Wiki community! '+tilde+tilde+tilde+tilde;

location.href = '/index.php?action=edit&section=new&title=User_talk:'+username+'&preload='+escape(text); return;

// Check if the user is autoconfirmed for (var right in wgUserGroups) if (wgUserGroups[right] == 'autoconfirmed') {skipcaptcha = true};

// Get edit token and check if we'll be creating a new page (in the case of non-autoconfirmed users) console.log($.ajax({ url: '/api.php?action=query&prop=info|revisions&intoken=edit&format=json&titles=User_talk:'+username, dataType: 'json', async: false, success: function(propResponse) { for (var page in propResponse.query.pages) { edittoken = propResponse.query.pages[page].edittoken.replace(/\+\\$/g,'%2B%5C'); if (propResponse.query.pages[page]["revisions"]) oldpage = true; };   }  }).responseJSON);

// If the user is not autoconfirmed and we're creating a new page, kick out of the script if (!skipcaptcha && !oldpage) { alert('Sorry, you\'re not autoconfirmed yet, so captcha is required to make new pages. Go manually welcome '+username+'!'); $(this).html('Error!'); return; };

// Edit the target page with the table console.log($.ajax({ url: '/api.php?action=edit&title=User_talk:'+username+'&summary='+editSummary+'&minor=1&recreate=1&bot=1&text='+escape(text)+'&token='+edittoken, type: 'POST', async: false, success: function { succeeded = true } }).responseText);

// change edit count link to reflect the status of the page save if (succeeded) $(this).html('Done!'); else $(this).html('Error!');

}); });