Jump to content
Wikipedia The Free Encyclopedia

User:NKohli (WMF)/defaultsummaries.js

From Wikipedia, the free encyclopedia
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:NKohli (WMF)/defaultsummaries.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
 /* _____________________________________________________________________________
  * | |
  * | === WARNING: GLOBAL GADGET FILE === |
  * | Changes to this page affect many users. |
  * | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
  * |_____________________________________________________________________________|
  *
  * Imported as of 09/06/2011 from [[User:ErrantX/defaultsummaries.js]]
  * Edited version from [[User:MC10/defaultsummaries.js]]
  * Implements default edit summary dropdown boxes
  */

 (function($){// Wrap with anonymous function
 var$summaryBox=$('#wpSummary');

 functioneditsummAddOptionToDropdown(dropdown,optionText){
 varoption=document.createElement("option");
 varoptionTextNode=document.createTextNode(optionText);
 option.appendChild(optionTextNode);
 dropdown.appendChild(option);
 }

 functioneditsummAddCatToDropdown(dropdown,catText){
 varoption=document.createElement("option");
 option.disabled=true;
 option.selected=true;
 varoptionTextNode=document.createTextNode(catText);
 option.appendChild(optionTextNode);
 dropdown.appendChild(option);
 }

 functioneditsummOnCannedSummarySelected(){
 // Save the original value of the edit summary field
 vareditsummOriginalSummary=$summaryBox.val();

 varidx=this.selectedIndex;
 varcanned=this.options[idx].text;

 varnewSummary=editsummOriginalSummary;

 // Append old edit summary with space, if exists,
 // and last character != space
 if(newSummary.length!==0&&newSummary.charAt(newSummary.length-1)!==" "){
 newSummary+=" ";
 }
 newSummary+=canned;
 $summaryBox.val(newSummary).trigger('change');
 }

 functioninsertSummaryOptions($insertBeforeThis,dropdownWidth){
 // For convenience, add a dropdown box with some canned edit
 // summaries to the form.
 vardropdown=document.createElement("select");
 dropdown.style.width=dropdownWidth;
 dropdown.style.margin="0 4px 0 0";
 dropdown.onchange=editsummOnCannedSummarySelected;

 varminorDropdown=document.createElement("select");
 minorDropdown.style.width=dropdownWidth;
 minorDropdown.onchange=editsummOnCannedSummarySelected;

 editsummAddCatToDropdown(minorDropdown,"Common minor edit summaries – click to use");
 editsummAddCatToDropdown(dropdown,"Common edit summaries – click to use");

 editsummAddOptionToDropdown(minorDropdown,"Spelling/grammar correction");
 editsummAddOptionToDropdown(minorDropdown,"Fixing style/layout errors");
 editsummAddOptionToDropdown(minorDropdown,"[[Help:Reverting|Reverting]] [[Wikipedia:Vandalism|vandalism]] or test edit");
 editsummAddOptionToDropdown(minorDropdown,"[[Help:Reverting|Reverting]] unexplained content removal");
 editsummAddOptionToDropdown(minorDropdown,"Copyedit (minor)");

 if(mw.config.get('wgNamespaceNumber')===0){
 editsummAddOptionToDropdown(dropdown,"Expanding article");
 editsummAddOptionToDropdown(dropdown,"Adding/improving reference(s)");
 editsummAddOptionToDropdown(dropdown,"Adding/removing category/ies");
 editsummAddOptionToDropdown(dropdown,"Adding/removing external link(s)");
 editsummAddOptionToDropdown(dropdown,"Adding/removing wikilink(s)");
 editsummAddOptionToDropdown(dropdown,"Removing unsourced content");
 editsummAddOptionToDropdown(dropdown,"Removing [[WP:SPAM|linkspam]] per [[WP:EL]]");
 editsummAddOptionToDropdown(dropdown,"Clean up");
 editsummAddOptionToDropdown(dropdown,"Copyedit (major)");
 }else{
 editsummAddOptionToDropdown(dropdown,"Reply");
 editsummAddOptionToDropdown(dropdown,"Comment");
 editsummAddOptionToDropdown(dropdown,"Suggestion");
 if((mw.config.get('wgNamespaceNumber')%2!==0)&(mw.config.get('wgNamespaceNumber')!==3)){
 editsummAddOptionToDropdown(dropdown,"[[Wikipedia:WikiProject|WikiProject]] tagging");
 editsummAddOptionToDropdown(dropdown,"[[Wikipedia:WikiProject|WikiProject]] assessment");
 }
 }

 $insertBeforeThis.before(dropdown);
 $insertBeforeThis.before(minorDropdown);
 }
 mw.hook('ve.saveDialog.stateChanged').add(function(){
 //.ve-init-mw-viewPageTarget-saveDialog-checkboxes
 if($('body').data('wppresent')){return;}
 $('body').data('wppresent','true');
 vartarget=ve.init.target,
 $insertBeforeThis=target.saveDialog.$saveOptions;
 $summaryBox=target.saveDialog.editSummaryInput.$input;
 if(!$insertBeforeThis.length){
 return;
 }
 insertSummaryOptions($insertBeforeThis,"98%");
 });
 $(function(){
 var$insertBeforeThis=$('.editCheckboxes');

 // If we failed to find the editCheckboxes class
 if(!$insertBeforeThis.length){
 return;
 }
 insertSummaryOptions($insertBeforeThis,"38%");
 });
 }(jQuery));// End wrap with anonymous function

AltStyle によって変換されたページ (->オリジナル) /