Jump to content

User talk:Minesweeper.007/force edit summary.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Minesweeper.007 (talk | contribs) at 22:00, 27 April 2007 (code). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

// Adapted from: //http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Force_edit_summary // User:Razorclaw/force edit summary.js

// The original value of the edit summary field is stored here var editsummOriginalSummary = new String();

// A global ref to the dropdown with canned edit summaries var editsummDropdown = null;

function editsummInitialize() {

   // TEMPORARY - check window title while testing this code
   // and only do anything if it's the sandbox or a sample CP page
   // var wt = document.title;
   // if ((wt.indexOf('Sandbox')==-1) && (wt.indexOf('Mitch McCon')==-1))
   // {
   //     return;
   // }
   if(!/&action=edit/.test(window.location.href) && !/&action=submit/.test(window.location.href)) return;
   if(/&section=new/.test(window.location.href)) return;
   if(!document.forms.editform) return;
   document.forms.editform.wpSave.onclick = editsummForceSummary;
   // Save the original value of the edit summary field
   editsummOriginalSummary = document.forms.editform.wpSummary.value;
   // For convenience, add a dropdown box with some canned edit
   // summaries to the form.
   // Put in alphabetical order
   var dropdown = document.createElement("select");
   dropdown.onchange = new Function("editsummOnCannedSummarySelected()");
   editsummAddOptionToDropdown(dropdown,"");
   editsummAddOptionToDropdown(dropdown,"add");
   editsummAddOptionToDropdown(dropdown,"add categories");
   editsummAddOptionToDropdown(dropdown,"add category");
   editsummAddOptionToDropdown(dropdown,"add citation");
   editsummAddOptionToDropdown(dropdown,"add external link");
   editsummAddOptionToDropdown(dropdown,"add internal link");
   editsummAddOptionToDropdown(dropdown,"add ref");
   editsummAddOptionToDropdown(dropdown,"add section");
   editsummAddOptionToDropdown(dropdown,"add template");
   editsummAddOptionToDropdown(dropdown,"create redirect page");
   editsummAddOptionToDropdown(dropdown,"create stub article");
   editsummAddOptionToDropdown(dropdown,"delete external link");
   editsummAddOptionToDropdown(dropdown,"delete internal link");
   editsummAddOptionToDropdown(dropdown,"dewikify");
   editsummAddOptionToDropdown(dropdown,"fix");
   editsummAddOptionToDropdown(dropdown,"fix broken link");
   editsummAddOptionToDropdown(dropdown,"fix grammar");
   editsummAddOptionToDropdown(dropdown,"fix punctuation");
   editsummAddOptionToDropdown(dropdown,"fix spelling");
   editsummAddOptionToDropdown(dropdown,"LOL");
   editsummAddOptionToDropdown(dropdown,"make link into plain text (dewikify)");
   editsummAddOptionToDropdown(dropdown,"make existing text into link (wikify)");
   editsummAddOptionToDropdown(dropdown,"minor edit");
   editsummAddOptionToDropdown(dropdown,"miscellaneous");
   editsummAddOptionToDropdown(dropdown,"more");
   editsummAddOptionToDropdown(dropdown,"move");
   editsummAddOptionToDropdown(dropdown,"move section");
   editsummAddOptionToDropdown(dropdown,"move unrefd material to talk page");
   editsummAddOptionToDropdown(dropdown,"new article");
   editsummAddOptionToDropdown(dropdown,"question");
   editsummAddOptionToDropdown(dropdown,"readd");
   editsummAddOptionToDropdown(dropdown,"remove");
   editsummAddOptionToDropdown(dropdown,"remove repetition");
   editsummAddOptionToDropdown(dropdown,"reorder links");
   editsummAddOptionToDropdown(dropdown,"reorder section");
   editsummAddOptionToDropdown(dropdown,"reorder wording");
   editsummAddOptionToDropdown(dropdown,"reply");
   editsummAddOptionToDropdown(dropdown,"request");
   editsummAddOptionToDropdown(dropdown,"request speedy deletion");
   editsummAddOptionToDropdown(dropdown,"test");
   editsummAddOptionToDropdown(dropdown,"welcome");
   editsummAddOptionToDropdown(dropdown,"welcome new user");
   editsummAddOptionToDropdown(dropdown,"welcome to the Himalayas!");
   editsummAddOptionToDropdown(dropdown,"wikify");
   editsummAddOptionToDropdown(dropdown,"you're welcome");
   editsummAddOptionToDropdown(dropdown,"???");
   editsummAddOptionToDropdown(dropdown,"!!!");
   editsummAddOptionToDropdown(dropdown,"...");
   editsummAddOptionToDropdown(dropdown,"*_*");
   var insertBeforeThis = document.forms.editform.wpSummary.nextSibling;
   var theParent = insertBeforeThis.parentNode;
   theParent.insertBefore(dropdown,insertBeforeThis);
   // Store a global ref to it
   editsummDropdown = dropdown;

}

function editsummAddOptionToDropdown(dropdown,optionText) {

   var option = document.createElement("option");
   var optionTextNode = document.createTextNode(optionText);
   option.appendChild(optionTextNode);
   dropdown.appendChild(option);

}

// There's a cross-browser issue when accessing the selected text: // *In Firefox you can use: selectObj.value // *In IE, you have to use: selectObj.options[selectObj.selectedIndex].text // *The latter method also works in Firefox function editsummOnCannedSummarySelected() {

   var idx = editsummDropdown.selectedIndex;
   var canned = editsummDropdown.options[idx].text;
   var newSummary = editsummOriginalSummary;
   if (newSummary.length!=0) newSummary += " ";
   newSummary += canned;
   document.forms.editform.wpSummary.value = newSummary;

}

function editsummForceSummary() {

   if(!document.forms.editform.wpSummary.value.replace(/^(?:\/\\*.*\\*\/)? *(.*) *$/,'$1'))
   {
       alert("Please supply a meaningful summary of this edit");
       document.forms.editform.wpSummary.focus();
       return false;
   }
   // An edit summary has been supplied. So now do the SW/CP auto-prefixing.
   editsummAddSubProjectPrefix();
   return true;

}

// Prefix the edit summary with "SW" or "CP" // depending on whether it's a SourceWatch or Congresspedia page. // To determine this, look for a link to "Template:Congresspedia" // on the edit page.

// To readd SW: put it in the first "" after the var prefix = // To readd CP: put it in the second "" after the prefix =

function editsummAddSubProjectPrefix() {

   // Using the document.links array and the href prop seems to give
   // the best cross-browser results.
   var allAnchors = document.links;
   if (allAnchors)
   {
       var prefix = "";
       for (i = 0; i < allAnchors.length; i++)
       {
            var anchorHref = allAnchors[i].href;
            if (anchorHref)
            {
                if (anchorHref.indexOf('Template:Congresspedia') != -1)
                {
                   prefix = "";
                }
            }
       }
       document.forms.editform.wpSummary.value =
           prefix + document.forms.editform.wpSummary.value;
   }

}

addOnloadHook(editsummInitialize);