User:The wub/deletionsorting.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

// Deletion sorting script
// Note this is still under development, and likely to change (and probably break) repeatedly

function deletionsorting_main()
{

  // Add menu for pages with "Editing Wikipedia:Articles for deletion" in the title
  if (document.title.indexOf("Editing Wikipedia:Articles for deletion/") != -1)
    {
     // Create menu and submenus
      var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
      addlimenu(tabs, 'sort', 'sort');
      var sort = document.getElementById('sort').getElementsByTagName('ul')[0];
      addlimenu(sort, 'geographic', 'geosort');
      var geosort = document.getElementById('geosort').getElementsByTagName('ul')[0];
      addlimenu(sort, 'topical', 'topicalsort');
      var topicalsort = document.getElementById('topicalsort').getElementsByTagName('ul')[0];
     // Geographic sorting categories
      addlilink(geosort,'javascript:deletionsorting_sort("Afghanistan")', "Afghanistan");
      addlilink(geosort,'javascript:deletionsorting_sort("Alabama")', "Alabama");
      addlilink(geosort,'javascript:deletionsorting_sort("Albania")', "Albania");
      addlilink(geosort,'javascript:deletionsorting_sort("Antarctica")', "Antarctica");
      addlilink(geosort,'javascript:deletionsorting_sort("Argentina")', "Argentina");
      addlilink(geosort,'javascript:deletionsorting_sort("Arizona")', "Arizona");
      addlilink(geosort,'javascript:deletionsorting_sort("Armenia")', "Armenia");
      addlilink(geosort,'javascript:deletionsorting_sort("Australia")', "Australia");
      addlilink(geosort,'javascript:deletionsorting_sort("Austria")', "Austria");
      addlilink(geosort,'javascript:deletionsorting_sort("Azerbaijan")', "Azerbaijan");
      addlilink(geosort,'javascript:deletionsorting_sort("Bangladesh")', "Bangladesh");
      addlilink(geosort,'javascript:deletionsorting_sort("Belgium")', "Belgium");
      addlilink(geosort,'javascript:deletionsorting_sort("Brazil")', "Brazil");
      addlilink(geosort,'javascript:deletionsorting_sort("Brunei")', "Brunei");
      addlilink(geosort,'javascript:deletionsorting_sort("Bulgaria")', "Bulgaria");
      addlilink(geosort,'javascript:deletionsorting_sort("California")', "California");
      addlilink(geosort,'javascript:deletionsorting_sort("Canada")', "Canada");
      addlilink(geosort,'javascript:deletionsorting_sort("China")', "China");
      addlilink(geosort,'javascript:deletionsorting_sort("Colombia")', "Colombia");
      addlilink(geosort,'javascript:deletionsorting_sort("Colorado")', "Colorado");
      addlilink(geosort,'javascript:deletionsorting_sort("Connecticut")', "Connecticut");
      addlilink(geosort,'javascript:deletionsorting_sort("Croatia")', "Croatia");
      addlilink(geosort,'javascript:deletionsorting_sort("Cuba")', "Cuba");
      addlilink(geosort,'javascript:deletionsorting_sort("Czech Republic")', "Czech Republic");
      addlilink(geosort,'javascript:deletionsorting_sort("Delaware")', "Delaware");
      addlilink(geosort,'javascript:deletionsorting_sort("Denmark")', "Denmark");
      addlilink(geosort,'javascript:deletionsorting_sort("UK")', "UK");
     // Topical sorting categories
      addlilink(topicalsort,'javascript:deletionsorting_sort("Anime and manga")', "Anime and manga");
      addlilink(topicalsort,'javascript:deletionsorting_sort("Music")', "Music");
      addlilink(topicalsort,'javascript:deletionsorting_sort("Lists")', "Lists");
      addlilink(topicalsort,'javascript:deletionsorting_sort("Transportation")', "Transportation");
      addlilink(topicalsort,'javascript:deletionsorting_sort("Websites")', "Websites");
     // Convenient link to list of categories
      addlilink(sort,'http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Deletion_sorting/Flat', "list");
    }
  var action = '';
  var target = '';

  if (location.search)
    {
       var l = location.search.substring(1).split('&');
       for (var i = 0; i < l.length; ++i)
         {
           var eq = l[i].indexOf('=');
           var name = l[i].substring(0, eq);
           if (name == 'fakeaction')
           action = l[i].substring(eq + 1);
           else if (name == 'faketarget')
           target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' ');
         }
    }

  if (action == 'addtolist')
    {
      document.editform.wpTextbox1.value += '{{' + target + '}}\n';
      document.editform.wpSummary.value = 'Adding [[' + target + ']]';
    }
}

function deletionsorting_sort(category)
{
  var target = document.editform.action;
  target = target.substring(target.indexOf('title=') + 6,
                            target.lastIndexOf('&action=submit'));
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value += '\n';
  t.value += "{{subst:"+"delsort|" + category + "}} <small>-- ~" + "~" + "~" + "~</small>";
  f.wpSummary.value = "Deletion sorting -- [[Wikipedia:WikiProject Deletion sorting/" + category + "|" + category + "]]";
  f.submit();
  window.open('/w/index.php?title=Wikipedia:WikiProject_Deletion_sorting/' + category + '&action=edit&fakeaction=addtolist&faketarget=' + target, 'AfdLog ' + unescape(target), 'status,toolbar,location,menubar,directories,resizeable,scrollbars');
}

addOnloadHook(deletionsorting_main);