User:Rocket000/monobook.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
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.
//<nowiki>

window.skipAutodelConfirm=true;

// interwiki-to-VN
importScript('User:Rocket000/iw2vn.js');

// DR archiver
importScript('User:Lupo/da.js');

// User messages
importScript('User:Lupo/u.js');
  template_autosave=false;

// Quick-delete
importScript('MediaWiki:Quick-delete.js');

if(wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Log'){
  hookEvent('load',
    function(){
      var lks = getElementsByTagNameStatic('a', document.getElementById('bodyContent'));
      DelReqHandler.addDelKeepLinks(lks, false, false, true);
    }
  );
}

// For Cropbot
function addcroplink(){
  if(wgNamespaceNumber == 6){
    if(wgTitle.match(/(.*)\.(jpg|jpeg)/gi)){
      var croplink = "http://toolserver.org/~luxo/cropbot/cropbot.php?img="+wgTitle;
      mw.util.addPortletLink('p-tb', croplink, 'Crop', 'p-crop', 'Crop this image', 'o', false);
    }
  }
}
$(addcroplink);

// Replacer
function wpTextboxReplace(){
  var s = prompt('Search regexp:');
  if(s){
    var r = prompt('Replace /'+s+'/ with:');
    if(!r && r != '') return;
    var txt = document.editform.wpTextbox1;
    txt.value = txt.value.replace(new RegExp(s, 'mg'), r);
  }
}
$(function(){
  if(document.forms.editform){
    mw.util.addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace',
                   'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
  }
});

// Customized [[MediaWiki:Gadget-autodel.js]]
$(function(){
  mw.util.addPortletLink('p-cactions','javascript:deleteLinkify()','autodelete','ca-dellink','generate deletion links');
})
 
function deleteLinkify(){
  var reason = prompt('Enter default delete reason','');
  if(!reason) return;
  var links = document.getElementById('bodyContent').getElementsByTagName('a');
  var arp = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace(/\$1/,'');
  if(links.length == 0) return
  for(var i=0; i<links.length; i++){
    if(links[i].href.indexOf(arp) == 0 && links[i].href.indexOf('action=delete') == -1 && links[i].href.indexOf('/Special:') == -1){
      links[i].href += '?action=delete&submitdelete=true&deletetalkalso=true&wpReason=' + encodeURIComponent(reason);
      links[i].innerHTML += ' (delete)';
    }
  }
}

if(queryString('submitdelete') == 'true') addOnloadHook(function(){
  if(document.getElementById('ca-talk').className.indexOf('new') == -1 && queryString('deletetalkalso') == 'true' && (wgNamespaceNumber % 2 == 0)){
     document.getElementById('deleteconfirm').action += '&deletetalk=true&wpReason=' + queryString('wpReason');
  }
  var sub = (document.getElementById('wpConfirmB')) ? document.getElementById('wpConfirmB') : document.getElementById('mw-filedelete-submit')
  sub.click();
});

if(wgAction == 'delete' && queryString('deletetalk') == 'true') addOnloadHook(function(){
  var url = document.getElementById('ca-talk').getElementsByTagName('a')[0].href + '?action=delete&submitdelete=true&wpReason=' + queryString('wpReason');
  document.location.href = url;
});

function queryString(p){
  var re = RegExp('[&?]' + p + '=([^&]*)');
  var matches;
  if(matches = re.exec(document.location)){
    try{
      return decodeURI(matches[1]);
    } catch(e){
    }
  }
  return null;
}


// highlight redirects
if(wgCanonicalNamespace != 'Special'){
  var hlr = {
    run : function(){
      appendCSS('a.mw-redirect{color:green} a.mw-redirect:visited{color:#063}');
    },
    install : function(){
      with(hlr){
        mw.util.addPortletLink('p-cactions', 'javascript:hlr.run();', 'redirects', 'ca-redirects');
      }
    }
  };
$(hlr.install);
}

// Custom edit buttons
if(mwCustomEditButtons) {

  var g = wgTitle.split(' ')[0];
  var s = wgTitle.split(' ')[1];
  if(s != undefined) s1 = '|'+s; else s1 = '';
  if(s != undefined) s2 = '\n|species='+s; else s2 = '';

  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/9/99/Button_reflink_advanced_2.png',
   'speedTip': 'Gallery-to-category redirect',
   'tagOpen': '#REDIRECT [[:Category:',
   'tagClose': ']]',
   'sampleText': wgTitle
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/f/ff/Button_arrow_right.png',
   'speedTip': 'move cat',
   'tagOpen': '{{move cat|',
   'tagClose': '|}}',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/b/b0/Button_category02.png',
   'speedTip': 'Species category',
   'tagOpen': '[[Category:'+g+s1+']]',
   'tagClose': '',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/2/26/Button_plainlinks.png',
   'speedTip': 'Plainlinks',
   'tagOpen': '<span class="plainlinks">',
   'tagClose': '</span>',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/1/1e/Button_font_color.png',
   'speedTip': 'Colored text',
   'tagOpen': '<span style="color:#COLOR">',
   'tagClose': '</span>',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/4/49/Button_br_2.png',
   'speedTip': 'Line break',
   'tagOpen': '<br/>',
   'tagClose': '',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/6/6d/Button_sig.png',
   'speedTip': 'unsigned',
   'tagOpen': '{{Unsigned|1=|2=',
   'tagClose': '|3=}}',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/c/c0/Knop_onzijdig.png',
   'speedTip': 'VN',
   'tagOpen': '{{VN\n|en=',
   'tagClose': '\n}}',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/9/97/Button_S_italic.png',
   'speedTip': 'Start SN',
   'tagOpen': "{{SN\n|''",
   'tagClose': '\n}}',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/c/c2/Button_L.png',
   'speedTip': '{{Lepidoptera}}',
   'tagOpen': '{{Lepidoptera\n|familia=\n|subfamilia=\n|tribus=\n',
   'tagClose': '',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/5/58/Button_C.png',
   'speedTip': '{{Coleoptera}}',
   'tagOpen': '{{Coleoptera\n|familia=\n|subfamilia=\n',
   'tagClose': '',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/9/97/Template_button.png',
   'speedTip': 'Bottom half of custom taxo templates',
   'tagOpen': '|species='+wgTitle+'\n|auth=',
   'tagClose': '\n}}',
   'sampleText': ''
  };
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
   'imageFile': 'http://upload.wikimedia.org/wikipedia/commons/9/97/Template_button.png',
   'speedTip': 'Bottom half of custom taxo templates',
   'tagOpen': '|genus='+g+s2+'\n|auth=',
   'tagClose': '\n}}',
   'sampleText': ''
  };
 
}

// Replace upload link
importScript('MediaWiki:Replaceuploadlink.js');

// Customize sidebar
// reference: mw.util.addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode)
$(function(){
  var c = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=';
  var ts = 'http://toolserver.org/'
  var bTitle = wgTitle.split('/')[0];
  var bPageName = wgPageName.split('/')[0];

  // == navigation ==
  // remove
  var wel = document.getElementById('n-welcome');
  var prt = document.getElementById('n-portal');
  if(wel) wel.parentNode.removeChild(wel);
  if(prt) prt.parentNode.removeChild(prt);

  // add
  mw.util.addPortletLink('p-navigation', c+'COM:AN', "Admins' noticeboard", 'n-an');
  mw.util.addPortletLink('p-navigation', c+'COM:AN/B', "Blocks and protections", 'n-an/b');
  mw.util.addPortletLink('p-navigation', c+'COM:AN/V', 'Vandalism', 'n-an/v');
  mw.util.addPortletLink('p-navigation', c+'COM:AN/U', 'User problems', 'n-an/u');
  mw.util.addPortletLink('p-navigation', c+'COM:RV', 'Requests and votes', 'n-rfx');
  mw.util.addPortletLink('p-navigation', c+'COM:DR', 'Deletion requests', 'n-dr');
  mw.util.addPortletLink('p-navigation', c+'CAT:CSD', 'Speedy deletions', 'n-csd');
  mw.util.addPortletLink('p-navigation', c+'CAT:PER', 'Prot. edit requests', 'n-per');
  mw.util.addPortletLink('p-navigation', c+'User:CommonsDelinker/commands', 'CommonsDelinker', 'n-comdelinker');

  // == participate ==
  // remove
  var hlp = document.getElementById('n-help');
  var con = document.getElementById('n-contact');
  var ran = document.getElementById('n-randomimage');
  var don = document.getElementById('n-sitesupport');
  if(hlp) hlp.parentNode.removeChild(hlp);
  if(con) con.parentNode.removeChild(con);
  if(ran) ran.parentNode.removeChild(ran);
  if(don) don.parentNode.removeChild(don);

  // add
  mw.util.addPortletLink('p-participate', c+'Special:NewPages&namespace=0&hidepatrolled=1&limit=500', 'New unpatrolled', 'n-newunpatrolled');
  mw.util.addPortletLink('p-participate', c+'Special:AbuseLog', 'Abuse log', 'n-abuselog');
  mw.util.addPortletLink('p-participate', c+'Special:SpecialPages', 'Special pages', 'n-specialpages');

  // == toolbox ==
  // remove / reorder
  var wlh = document.getElementById('t-whatlinkshere');
  var prn = document.getElementById('t-print');
  var spp = document.getElementById('t-specialpages');
  var rcl = document.getElementById('t-recentchangeslinked');
  var per = document.getElementById('t-permalink');
  if(wlh) wlh.parentNode.removeChild(wlh);
  if(prn) prn.parentNode.removeChild(prn);
  if(spp) spp.parentNode.removeChild(spp);
  if(rcl) rcl.parentNode.removeChild(rcl);
  if(per) per.parentNode.removeChild(per);

  // add
  mw.util.addPortletLink('p-tb', c+'Special:WhatLinksHere/'+wgPageName, 'What links here', 't-wlh');
  mw.util.addPortletLink('p-tb', c+'Special:WhatLinksHere/'+wgPageName+'&hidetrans=1&hidelinks=1', 'What redirects here', 't-redirects');
  mw.util.addPortletLink('p-tb', c+'Special:PrefixIndex/'+wgPageName+'/', 'Subpages', 't-subpages');
  mw.util.addPortletLink('p-tb', c+'Special:RecentChangesLinked/'+wgPageName, 'Related changes', 't-relatedchanges');
  mw.util.addPortletLink('p-tb', mw.config.get('wgServer')+mw.config.get('wgScript')+'?oldid='+wgCurRevisionId, 'Permanent link', 't-permalink');

  if(wgNamespaceNumber == 2 || wgNamespaceNumber == 3){
    mw.util.addPortletLink('p-tb', c+'Special:UserRights/'+bTitle, 'User rights', 't-userrights');
    mw.util.addPortletLink('p-tb', ts+'~vvv/yaec.php?user='+bTitle+'&wiki=commonswiki_p', 'Edit counter', 't-editcounter');
    mw.util.addPortletLink('p-tb', ts+'~vvv/sulutil.php?user='+bTitle, 'SUL util', 't-sulutil');
  }

});

// </nowiki>