MediaWiki:Gadget-UserMessages.js
Appearance
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
try { // containerize gadget, to protect other gadgets if this one goes wrong
/*
==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|Welcome}}
Main code by [[User:Siebrand]], derived from [[MediaWiki:Quick-delete.js]] by
[[:en:User:Jietse Niesen|Jietse Niesen]], [[User:pfctdayelise|pfctdayelise]] and
[[User:Alphax|Alphax]].
Code stolen from Commons by [[User:ShakataGaNai]] for Wikinews (Fixed by Bawolff)
* [[:Category:Block templates]]
* [[:Category:User_talk_templates]]
===TODO===
* Do not add a trailing /<langcode> at the end of the subst'ed template, as they now (almost) all use the autotranslation mechanism (see [[Commons:Template_i18n/User_templates]])
*/
// <source lang="javascript">
//moved here from commons
function getParamValue(paramName, url) { if (typeof url == "undefined") { url = document.location.href; } var cmdRe = RegExp("[&?]" + paramName + "=([^&]*)"); var m = cmdRe.exec(url); if (m) { try { return decodeURIComponent(m[1]); } catch (someError) { } } return null; }
//end moved here from commons
// Configuration
// Should the edits be saved automatically?
if(window.template_autosave == false){}else{ template_autosave = true; }
// Template Name
var uTemplate = new Array(24)
uTemplate[0] = 'Welcome'
uTemplate[1] = 'Stop'
uTemplate[2] = 'Stop1'
uTemplate[3] = 'Stop2'
uTemplate[4] = 'Spam warning'
uTemplate[5] = 'Test'
uTemplate[6] = 'Yourarticlegone'
uTemplate[7] = 'Only news'
uTemplate[8] = 'Notanencyclopedia'
uTemplate[9] = 'Nothanks'
uTemplate[10] = 'Oldnews'
uTemplate[11] = 'Proxyblock'
uTemplate[12] = 'Usernameblock'
uTemplate[13] = 'Schoolblock'
uTemplate[14] = 'Sharedip'
uTemplate[15] = 'Block'
uTemplate[16] = 'Indefblocked'
uTemplate[17] = 'Replied'
uTemplate[18] = 'Sofixit'
uTemplate[19] = 'Reviewer message'
uTemplate[20] = 'Signyourposts'
uTemplate[21] = 'Thanks-anon'
uTemplate[22] = 'howdy-anon'
uTemplate[23] = 'welcome-comment'
uTemplate[24] = 'vandal warning'
// Text to be shown in Toolbox
var uText = new Array(24)
uText[0] = "Welcome"
uText[1] = "Stop"
uText[2] = "Stop block"
uText[4] = "Spam Warning"
uText[5] = "Test"
uText[6] = "Articles Deleted"
uText[7] = "Only News"
uText[8] = "Not Wikipedia"
uText[9] = "No Thanks"
uText[10] = "Old News"
uText[11] = "Proxy Block"
uText[12] = "Username Block"
uText[13] = "School Block"
uText[14] = "Shared IP"
uText[15] = "Blocked"
uText[16] = "Indef Blocked"
uText[17] = "Replied"
uText[18] = "So Fix It"
uText[19] = "New Reviewer"
uText[20] = "Sign Your Posts"
uText[21] = "Thanks Anon"
uText[22] = 'Howdy anon'
uText[23] = 'Welcome comment'
uText[24] = 'Vandal warning'
// Mouseover help text for Toolbox
var uHelp = new Array(24)
uHelp[0] = "Welcome a new user"
uHelp[1] = "Final warning before block"
uHelp[2] = "Temporarily blocked"
uHelp[4] = "Warning that edits were considered spam"
uHelp[5] = "Alert of test edits, reminder of basics"
uHelp[6] = "User submitted article deleted due to Speedy"
uHelp[7] = "We only accept English News"
uHelp[8] = "Wikinews is not an Encyclopedia"
uHelp[9] = "A very nice copyvio warning"
uHelp[10] = "Submitted article was too old"
uHelp[11] = "IP Blocked due to open proxy"
uHelp[12] = "Account blocked because of Username"
uHelp[13] = "IP Blocked of school blocked due to Vandalism"
uHelp[14] = "Notice of Shared IP (Not Blocked)"
uHelp[15] = "Generic block"
uHelp[16] = "Account indefinitely blocked"
uHelp[17] = "Alert user of reply elsewhere"
uHelp[18] = "Thanks for the suggestion, Fix it yourself"
uHelp[19] = "For users promoted to Editor class"
uHelp[20] = "Reminder a user to sign their posts"
uHelp[21] = "Thanks (For IP editor)"
uHelp[22] = 'Howdy to anon users'
uHelp[23] = 'Welcome for people who left a message on the comment page'
uHelp[24] = 'Stop being stupid or you will be blocked'
template_reason = "The reason?";
template_pagename = "The page name?";
template_who = "Who does this IP belong to?";
// Site info
scriptPath = "/w/index.php";
prettyPath = "/wiki/";
wikiHostname = "en.wikinews.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);
}
//akeytt is deprected and does nothing. who cares about access keys anyhow.
/*if(id && ta) { //ta does not exist in vector?
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
//Now we assume message templates to be properly autotranslated
if (message_lang) langparam='&template_lang=' + message_lang;
else langparam='';
var pagename = encodeURIComponent(mw.config.get('wgPageName'));
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
document.location = editlk + '&fakeaction=' + talkpage_fakeaction + langparam + '&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 + '\n~~~~';
// 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. ([[MediaWiki:Gadget-UserMessages.js|using js]])';
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 + '\n~~~~';
// 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. ([[MediaWiki:Gadget-UserMessages.js|using js]])';
if (template_autosave) document.editform.wpSave.click();
}
// Do the thing with the stuff here.
function template_onload() {
if (mw.config.get('wgNamespaceNumber') == 3) { //NS_USERTALK
// new section
try {
if (skin === 'vector') {
if (window.useFancyVectorDropdown || window.useFancyVectorDropdown === undefined) {
try {
makeVectorFancySection();
useFancyVectorDropdown = 'done'; //this is for debug. can remove
}
catch (e) {
document.getElementById('panel').innerHTML += '<div id="p-Notify" class="portal"><h5 lang="en" xml:lang="en">Notify</h5><div class="body">\n <ul> </ul> </div> </div>';
}
}
else {
document.getElementById('panel').innerHTML += '<div id="p-Notify" class="portal"><h5 lang="en" xml:lang="en">Notify</h5><div class="body">\n <ul> </ul> </div> </div>';
}
}
if (skin === 'monobook') {
document.getElementById('column-one').innerHTML += '<div id="p-Notify" class="portlet"> <h5 lang="en" xml:lang="en">Notify</h5> <div class="pBody"> <ul></ul></div> </div>';
}
} catch (e) {} //ignore errors and just use tb if they happen.
var portlet = (document.getElementById('p-Notify') ? 'p-Notify' : 'p-tb');
addLink(portlet, 'javascript:template_mark(\'0\')', uText[0], 'mark-warn', uHelp[0], null, null);
addLink(portlet, 'javascript:template_mark(\'1\')', uText[1], 'mark-warn', uHelp[1], null, null);
addLink(portlet, 'javascript:template_mark(\'2\')', uText[2], 'mark-warn', uHelp[2], null, null);
addLink(portlet, 'javascript:template_mark(\'4\')', uText[4], 'mark-warn', uHelp[4], null, null);
addLink(portlet, 'javascript:template_mark(\'5\')', uText[5], 'mark-warn', uHelp[5], null, null);
addLink(portlet, 'javascript:template_mark2(\'6\', prompt(\'' + template_pagename + '\', \'\'), 0, false)', uText[6], 'mark-warn', uHelp[6]);
addLink(portlet, 'javascript:template_mark(\'7\')', uText[7], 'mark-warn', uHelp[7], null, null);
addLink(portlet, 'javascript:template_mark(\'8\')', uText[8], 'mark-warn', uHelp[8], null, null);
addLink(portlet, 'javascript:template_mark2(\'9\', prompt(\'' + template_pagename + '\', \'\'), 0, false)', uText[9], 'mark-warn', uHelp[9]);
addLink(portlet, 'javascript:template_mark2(\'10\', prompt(\'' + template_pagename + '\', \'\'), 0, false)', uText[10], 'mark-warn', uHelp[10]);
addLink(portlet, 'javascript:template_mark(\'11\')', uText[11], 'mark-warn', uHelp[11], null, null);
addLink(portlet, 'javascript:template_mark2(\'12\', prompt(\'' + template_reason + '\', \'\'), 0, false)', uText[12], 'mark-warn', uHelp[12]);
addLink(portlet, 'javascript:template_mark(\'13\')', uText[13], 'mark-warn', uHelp[13], null, null);
addLink(portlet, 'javascript:template_mark2(\'14\', prompt(\'' + template_who + '\', \'\'), 0, false)', uText[14], 'mark-warn', uHelp[14]);
addLink(portlet, 'javascript:template_mark2(\'15\', prompt(\'' + template_reason + '\', \'\'), 0, false)', uText[15], 'mark-warn', uHelp[15]);
addLink(portlet, 'javascript:template_mark(\'16\')', uText[16], 'mark-warn', uHelp[16], null, null);
addLink(portlet, 'javascript:template_mark2(\'17\', prompt(\'' + template_pagename + '\', \'\'), 0, false)', uText[17], 'mark-warn', uHelp[17]);
addLink(portlet, 'javascript:template_mark(\'18\')', uText[18], 'mark-warn', uHelp[18], null, null);
addLink(portlet, 'javascript:template_mark(\'19\')', uText[19], 'mark-warn', uHelp[19], null, null);
addLink(portlet, 'javascript:template_mark(\'20\')', uText[20], 'mark-warn', uHelp[20], null, null);
addLink(portlet, 'javascript:template_mark(\'21\')', uText[21], 'mark-warn', uHelp[21], null, null);
addLink(portlet, 'javascript:template_mark(\'22\')', uText[22], 'mark-warn', uHelp[23], null, null);
addLink(portlet, 'javascript:template_mark(\'23\')', uText[23], 'mark-warn', uHelp[23], null, null);
addLink(portlet, 'javascript:template_mark(\'24\')', uText[24], 'mark-warn', uHelp[24], null, null);
}
// Important thing and stuff above.
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) {
//may i take this moment to mention, this script is very very confusing - bawolff
if (mw.config.get('wgNamespaceNumber') !== 3) {
alert("The user notify script has been disabled in this namespace for security reasons. If you see this message, please tell [[User:Bawolff]] what linked you clicked on to get here.");
throw new Error("Security error: wrong namespace for user notify gadget.");
}
if (add_idx == 1)
template_addTemplate (uTemplate[action_idx]);
else
template_addTemplate2 (uTemplate[action_idx]);
}
}
$(template_onload);
function makeVectorFancySection() {
//wrap this in a try. this might be somewhat delicate at the moment.
var pNotify = document.createElement('div');
pNotify.id = 'p-Notify'
pNotify.className = 'vectorMenu'
pNotify.innerHTML = ' <h5><span>Notify</span><a href="#" style="background-image:none;"/></h5> <div class="menu"> <ul lang="en" xml:lang="en"> </ul> </div>';
var rightNav = document.getElementById('right-navigation');
var pViews = document.getElementById('p-views');
pViewsCont = document.createElement('div');
pViewsCont.id = 'p-views-continued';
pViewsCont.className = 'vectorTabs';
var pViewsUL = document.createElement('ul');
pViewsCont.appendChild(pViewsUL);
var pivot = (document.getElementById('ca-history') ? document.getElementById('ca-history') : document.getElementById('ca-addsection'));
pivot = (pivot ? pivot : document.getElementById('ca-edit'));
pViewsUL.appendChild(pivot);
rightNav.insertBefore(pNotify, pViews.nextSibling)
rightNav.insertBefore(pViewsCont, pNotify.nextSibling);
}
// </source>
} catch (e) { // containerize gadget, to protect other gadgets if this one goes wrong
// ignore
}