User:Juliancolton/warnings.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/*==Automatic user messages ==
Installing this script as described on the talk page will give you links in the toolbox
for all pages in the User talk: namespace, that say 'Please tag', 'Please name', and
'Please link'. Clicking any of the buttons will add one of the following templates to
the user's talk page, signed by you:
*{{tl|attack}}*
// <source lang="javascript">
// Configuration
// Should the edits be saved automatically?
if(window.template_autosave == false){}else{ template_autosave = true; }
// String constants
var uTemplate = new Array(33)
uTemplate[0] = 'Please don't attack people"
var uText = new Array(33)
uText[0] = "Personal attacks
var uHelp = new Array(33)
uHelp[0] = "Reminding user not to attack other people
template_lang = "en";
// Site info
scriptPath = "/w/index.php";
prettyPath = "/wiki/";
wikiHostname = "meta.wikimedia.org";
// From [[en:Wikipedia:WikiProject User scripts/Scripts/addLink]]
function addLink(where, url1, name1, id, title, key, after, url2, name2)
{
//* where is the id of the toolbar where the button should be added;
// i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
//
//* url1 is the URL which will be called when the button is clicked.
// javascript: urls can be used to do more complex things.
//
//* name1 is what will appear as the name of the button.
//
//* id is the id of the button; it's best to define one.
// Use a prefix to make sure its unique. Optional.
//
//* title is the tooltip title that gives a longer description
// of the button; if you define a accesskey, mention it here. Optional.
//
//* key is the char you want for the accesskey. Optional.
//
//* after is the id of the button you want to follow this one. Optional.
//
//* url2 is a second url to add. Optional
//
//*name2 is the name of the second url; defaults to name1. Optional
var na = document.createElement('a');
na.href = url1;
na.appendChild(document.createTextNode(name1));
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
if (url2) { //Another link, brother of the previous.
var na = document.createElement('a');
na.href = url2;
na.appendChild(document.createTextNode(name2 ? name2 : name1));
li.appendChild(document.createTextNode(" · ")); //separate them a bit
li.appendChild(na);
}
var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
if(after) {
tabs.insertBefore(li,document.getElementById(after));
} else {
tabs.appendChild(li);
}
if(id) {
if(key && title) { ta[id] = [key, title]; }
else if(key) { ta[id] = [key, '']; }
else if(title) { ta[id] = ['', title];}
}
// re-render the title and accesskeys from existing code in wikibits.js
akeytt();
return li;
}
// Add the template
function template_mark(talkpage_fakeaction, message_lang) {
if (!message_lang) return; //User pressed cancel
var pagename = encodeURIComponent(mw.config.get('wgPageName'));
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
document.location = editlk + '&fakeaction=' + talkpage_fakeaction + '&template_lang=' + message_lang + '&template_type=1';
}
// Add template to user talk page
function template_addTemplate(template) {
if (getParamValue('template_lang')) {
template = template + '/' + getParamValue('template_lang');
}
var txt = '{{subst:' + template + '}}';
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + '\n' + txt + ' ~~~~';
// the edit summary for when you mark the image. You can change it if you want.
document.editform.wpSummary.value = 'Adding template \"' + template + '\" to inform user.';
if (template_autosave) document.editform.wpSave.click();
}
// Add the template
function template_mark2(talkpage_fakeaction, media_name, can_handle_empty_parameter, add_namespace) {
if (media_name == null) return; // User pressed cancel
if (media_name == '' && can_handle_empty_parameter != 1) return; // User did not supply parameter and template cannot handle that
// Parameter handling for special cases
if (add_namespace && media_name.length > 0) media_name = 'File:' + media_name;
var pagename = encodeURIComponent(mw.config.get('wgPageName'));
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
document.location = editlk + '&fakeaction=' + talkpage_fakeaction + '&media_name=' + encodeURIComponent (media_name) + '&template_type=2';
}
// Add template to user talk page
function template_addTemplate2(template) {
if (getParamValue('media_name')) {
template = template + '|' + getParamValue('media_name');
}
var txt = '{{subst:' + template + '}}';
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + '\n' + txt + ' ~~~~';
// the edit summary for when you mark the image. You can change it if you want.
document.editform.wpSummary.value = 'Adding template \"' + template + '\" to inform user.';
if (template_autosave) document.editform.wpSave.click();
}
function template_onload() {
if (wgNamespaceNumber == 3) { //NS_USERTALK
addLink('p-tb', 'javascript:template_mark(\'0\', \'en\')', uText[0], 'mark-please', uHelp[0], null, null, 'javascript:template_mark(\'0\', prompt(\'' + template_langquery + '\', wgUserLanguage))', template_lang);
var fakeaction = getParamValue('fakeaction');
var template_type = getParamValue('template_type'); // Fetch what template to add
var action_idx = -1;
try {
action_idx = parseInt (fakeaction, 10);
} catch (some_error) {
action_idx = -1;
}
var add_idx = -1;
try {
add_idx = parseInt (template_type, 10);
} catch (some_error) {
add_idx = -1;
}
if (add_idx >= 1 && add_idx <= 2 && action_idx >= 0 && action_idx < uTemplate.length) {
if (add_idx == 1)
template_addTemplate (uTemplate[action_idx]);
else
template_addTemplate2 (uTemplate[action_idx]);
}
}
$(template_onload);
// </source>
*/