User:Minesweeper.007/force edit summary.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Minesweeper.007/force edit summary. |
// 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(/§ion=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);