Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// Add toolbox.
function addToolbox(name, id) {
  var toolboxElement = document.getElementById("p-tb");
  var closeElement = toolboxElement.cloneNode(true);
  closeElement.id = id;
  closeElement.innerHTML = "<h3>" + name + "</h3><div class=body><ul></ul></div>";
  toolboxElement.parentNode.insertBefore(closeElement, toolboxElement.nextSibling);
}

function userWarning(template, summary, focus) {
  var form = document.editform;
  var textBox = form.wpTextbox1;
  if(focus) {
    textBox.value += '{{subst:' + template + '|}} ~~' + '~~';
    textBox.focus();
    var cursor = textBox.value.length-7;
    textBox.setSelectionRange(cursor, cursor);
  } else {
    textBox.value += '{{subst:' + template + '}} ~~' + '~~';
  }

  form.wpSummary.value = summary;
  form.wpWatchthis.checked = false;
  if(form.wpMinoredit)
  {
    form.wpMinoredit.checked = false;
  }
}

function descriptionCleanup() {
  var form = document.editform;
  var desc = form.wpTextbox1.value;
  
  desc = desc.replace(/== *Summary *==/, '== {{int:filedesc}} ==');
  desc = desc.replace(/== *(Licensing|{{int:license}}) *==/, '== {{int:license-header}} ==');
  desc = desc.replace(/== *Original upload log *==/, '== {{Original upload log}} ==');
  desc = desc.replace(/\{\{Date\|([0-9]{4})\|([0-9]{2})\|([0-9]{2})\}\} \(original upload date\)/, '{{original upload date|$1-$2-$3}}');
  desc = desc.replace(/(\|Date.*)([0-9]{2})\/([0-9]{2})\/([0-9]{4})/, '$1$4-$3-$2');
  desc = desc.replace(/([0-9]{4}-[0-9]{2}-[0-9]{2}) \(original upload date\)/, '{{original upload date|$1}}');
  desc = desc.replace(/Original uploader was \[\[:.*User:([^|]*)\|.*\]\] at \[http:\/\/([^.]*)\.([^.]*)\.org.*/, '{{user at project|$1|$3|$2}}');
  desc = desc.replace(/The original description page is\/was \[http:\/\/(.*)\.org\/w\/index.php\?title=(File|Image)%3A(.*) here\]. All following user names refer to .*/, '{{original description|$1|$3}}');

  if(!desc.match(/\{\{int:filedesc\}\}/))
  {
    desc = '== {{int:filedesc}} ==\n' + desc;
  }

  form.wpTextbox1.value = desc;
  if(form.wpSummary.value == '')
  {
    form.wpSummary.value = 'cleanup';
  }
}

jQuery( document ).ready( function( $ ) {

  var pageTitle = document.getElementById('firstHeading').getElementsByTagName('span')[0].innerHTML;

  // Add sandbox link to navigation bar.
  mw.util.addPortletLink('p-navigation', '//commons.wikimedia.org/wiki/User:Jafeluv/Sandbox', 'Sandbox', 'n-sandbox', 'Show user sandbox', '', '');

  // Direct link to upload page
  mw.util.addPortletLink('p-participate', '//commons.wikimedia.org/w/index.php?title=Special:Upload&uploadformstyle=basic', 'Upload (direct)', 'n-direct', 'Go directly to the upload page', '', document.getElementById('n-uploadbtn'));

  // Toolbox menu for deletion tagging and user notification.
  if (pageTitle.match(/(Editing|Creating) User talk:/)) {
    addToolbox("Block notices", "p-block");
    mw.util.addPortletLink("p-block", "javascript:userWarning('blocked', 'block notice', false);", "Block notice");
    mw.util.addPortletLink("p-block", "javascript:userWarning('indefblockeduser', 'block notice', false);", "Indef block notice");
    mw.util.addPortletLink("p-block", "javascript:userWarning('copyviouploadindefblock', 'block notice', false);", "Copyvio upload indef");

    addToolbox("Patrolling tools", "p-patrol");
    mw.util.addPortletLink("p-patrol", "javascript:userWarning('test', 'Please experiment in the sandbox', false);", "Test edit notice");
    mw.util.addPortletLink("p-patrol", "javascript:userWarning('project scope', 'Wikimedia Commons has a specific scope', true);", "Project scope notice");
    mw.util.addPortletLink("p-patrol", "javascript:userWarning('test2', 'Vandalism is not appreciated', false);", "Vandalism notice");
    mw.util.addPortletLink("p-patrol", "javascript:userWarning('no advertising', 'Please do not advertise on the Commons', false);", "Advertising notice");
    mw.util.addPortletLink("p-patrol", "javascript:userWarning('dont overwrite', 'Please do not overwrite files', false);", "Overwriting notice");
    mw.util.addPortletLink("p-patrol", "javascript:userWarning('copyvionote', 'Pay attention to copyright', true);", "Copyvio notice");
    mw.util.addPortletLink("p-patrol", "javascript:userWarning('end of copyvios', 'Copyright violations', false);", "Copyvio final notice");
  }
  else if(pageTitle.match(/Editing File:/)) {
    mw.util.addPortletLink("p-tb", "javascript:descriptionCleanup();", "Description cleanup");
  }
});