User:Dschwen/vector.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.
// enhance user contributions view
function ucEnhance() {
 var p = {};
 $('#mw-content-text>ul>li').each(function(){
  var e = $(this), t=e.find('.mw-uctop').length>0, l=e.find('.mw-contributions-title').attr('title');
  if( !(l in p) && !t ) {
   e.css('background-color','pink');
  }
  p[l]=true;
 });
}
if( mw.config.get('wgAction') == 'view' && mw.config.get('wgPageName') === "Special:Contributions/Dschwen" ) {
 $(document).ready(ucEnhance);
}

// delete reason helper
$(function(){
var reason, storage=sessionStorage,filled=false;
if( mw.config.get('wgAction') == 'delete' ) { 
 if(/\{\{[Bb]ad\s?name\s*\||[Ww]rong|[Ii]ncorrect/.test($('#wpReason').val())) {
  $('#wpDeleteReasonList').val('Improperly named');
  filled=true;
 }
 else if (/[Ee]mpty|[Ee]mptied/.test($('#wpReason').val())) {
  $('#wpDeleteReasonList').val('Empty [[COM:CAT|category]]');
  filled=true;
 }
 else if (/[Rr]ename|[Mm]oved|[Mm]erged/.test($('#wpReason').val())) {
  $('#wpDeleteReasonList').val('Renamed [[COM:CAT|category]]');
  filled=true;
 }
 else {
  reason=storage.getItem("delreason_"+mw.config.get('wgPageName'));
  if(reason) {
   $('#wpReason').val(reason);
   if( /[Pp]romotion/.test(reason) && (!/[Ss]elf [Pp]romotion/.test(reason))) {
   	$('#wpDeleteReasonList').val('Out of [[COM:PS|project scope]]: [[COM:ADVERT|promotional content]]');
   } else if( /[Ss]cope/.test(reason) ) {
   	$('#wpDeleteReasonList').val('Out of [[COM:PS|project scope]]');
   } else {
   	$('#wpDeleteReasonList').val('[[COM:L|Copyright violation]]');
   }
  }
 }
 
 // TEMPORARY
 if (!filled) {
 	$('#wpDeleteReasonList').val('Empty [[COM:CAT|category]]');
 	filled=true;
 }

 if(filled) {
  var action = $('#deleteconfirm').attr('action');
  $('#deleteconfirm').attr('action',action+'&soosclose'); 
  $('#deleteconfirm').submit();
 } 
}

// fetch and store speedy delete reasons
if (mw.config.get('wgAction') == 'view') {
 var rl = ['This file is a copyright violation for the following reason:', 'The given reason is:', 'This file is a copyright violation because it comes from:'], rt='';
 for( var i=0; i<rl.length; i++) {
  reason=$('b:contains("'+rl[i]+'")').parent();
  if (reason.length>0) { 
   // reveal URLs
   reason.find('a.external').each(function(i,e){
    var t = $(e).text();
    if(t.indexOf($(e).attr('href'))<0) {
     $(e).text('['+ $(e).attr('href') + ' ' + t+']');
    }
   });
   rt+=reason.text().substr(rl[i].length);
  }
 }
 storage.setItem("delreason_" + mw.config.get('wgPageName'), rt );
}
});


stockphoto_prevent=true;

// I want a big WikiMiniAtlas to use the new image preview feature
var wma_settings =
{
 //quicklink : true,
 height : 500,
 width : 800
}

function addSOOSLinks()
{
 $( "div.gallerytext > a" ).each( function( i, link ) {
  name = link.href.substr(35);
  $(link).after('<a href="/w/index.php?title='+name+'&action=delete&soos" target="_blank">[CopyVio]</p>');
 } );
}
function executeSOOS()
{
 //$('#wpDeleteReasonList').val('[[COM:L|Copyright violation]]');
 //$('#wpReason').val('Speedy');
 $('#wpDeleteReasonList').val('other');
 //$('#wpDeleteReasonList').val('Uploader requested deletion of a recently uploaded unused file');
 //$('#wpDeleteReasonList').val('Recreation of content deleted per community consensus');
 //$('#wpReason').val('Uploader requested deletion of a recently uploaded unused file.');
 $('#wpReason').val('Deprecated redirect. All usage has been replaced (except at user pages).');
 //$('#wpReason').val('Mass delete images by serial copyright violator.');
 //$('#wpReason').val('crap during batch upload, blurry, no EV');
 var action = $('#deleteconfirm').attr('action');
 $('#deleteconfirm').attr('action',action+'&soosclose'); 
 $('#deleteconfirm').submit();
}

if( mw.config.get('wgAction') == 'view' && ( $.inArray(mw.config.get('wgNamespaceNumber'), [14 , 0 ]) !== -1) ) {
 $(document).ready(addSOOSLinks);
}
if( mw.config.get('wgAction') == 'delete' && document.location.href.substr(-5) == '&soos' ) {
 $(document).ready(executeSOOS);
} 
if( mw.config.get('wgAction') == 'delete' && document.location.href.substr(-10) == '&soosclose' ) {
 $(document).ready(function(){ window.close()});
} 

importScript( 'MediaWiki:Delete.js' );         //[[MediaWiki:Delete.js]]

// [[User:Dschwen/coordinates.js]] - please include this line 
//importScript( 'User:Dschwen/coordinates2.js' );
importScript( 'User:Dschwen/coordinates.js' );


// ignorance is bliss
ignoreUserList = 
{
 'User talk:Penyulap': '<span style="text-shadow:#c5C3e3 0.2em 0.2em 0.2em;"><a href="/wiki/User:Penyulap" title="User:Penyulap"><b>Penyulap</b></a></span> <a href="/wiki/User_talk:Penyulap" title="User talk:Penyulap"><span style="font-size: 1.2em;color:transparent;text-shadow:green 0em 0.2em 0.02em;">☏</span></a>',
 'User:Dtobias' : true,
 'User:Malcolm Schosha' : true,
 'User:Durova' : true 
};
importScript('User:Dschwen/ignore.js');


// [[User:Dschwen/coordupdate.js]] - please include this line 
//importScript( 'User:Dschwen/coordupdate.js' );


//
// Insert a personalized Texttemplate into the Special:Upload edit box.
//
function delayedUpdateSpecialUpload()
{
 var editbox = document.getElementById('wpUploadDescription');
 editbox.value = "{"+"{Information\n"
               + "|Description={"+"{de|}"+"} {"+"{en|}"+"}\n"
               + "|Source={"+"{own}"+"}\n"
               + "|Date=\n"
               + "|Author=[[User:Dschwen|Daniel Schwen]]\n"
               + "|Permission=See license\n"
               + "|other_versions=\n"
               + "}"+"}\n\n"
               + "== {" + "{int:license}" + "} ==\n"
               + "{"+"{self|cc-by-sa-4.0|author=I, [[User:Dschwen|Daniel Schwen]]}"+"}";
}
function setSpecialUploadTemplate()
{
 var uploadURL = 'https://commons.wikimedia.org/w/index.php?title=Special:Upload&uselang=ownwork';

 // I upload mostly my own work
 $('#n-uploadbtn>a').attr('href',uploadURL);

 // preload input form
 if(window.location.href == uploadURL) setTimeout( "delayedUpdateSpecialUpload()", 100 );
}
$(document).ready(function(){setTimeout(setSpecialUploadTemplate,500);});


//
// Calculate Megapixels on image pages
//
function calculateMegapixels() {
 var data = $('.fileInfo').text();
 pixel_filter = /([\d,]+) × ([\d,]+)/;
 if(pixel_filter.test(data)) {
  pixel_filter.exec(data);
  var wt = RegExp.$1, ht = RegExp.$2
    , w = parseFloat( wt.replace(/,/,'') )
    , h = parseFloat( ht.replace(/,/,'') );
  $('.fileInfo').append( $('<span></span>').text(' (' + ((w*h)/(1024.0*1024.0)).toFixed(2) + ' Megapixel)' ) );
 }
}
if( mw.config.get('wgAction') == 'view' && mw.config.get('wgNamespaceNumber') == 6 ) $(document).ready(calculateMegapixels);


//
// Pano360 wrap check
//
function pano360wrap()
{
 var file = document.getElementById('file');
 if( document.getElementById('pano360template') )
 {
  var images = file.getElementsByTagName('IMG');
  var image = images[0];
  var rot = document.createElement('DIV');
  rot.style.width = images[0].width + 'px';
  rot.style.height = images[0].height + 'px';
  rot.style.backgroundImage = "url('" + images[0].src + "')";
  rot.style.backgroundRepeat = 'repeat-x';
  rot.style.backgroundPosition = ( images[0].width/2) + 'px 0px';
  rot.style.border = '1px solid red';
  rot.appendChild( document.createTextNode('Warp preview!') );
  file.appendChild(rot);
 }
 else
   $(file).append( '<a href="javascript:pano360wrap()" id="pano360template">show warp</a>' );
}
//if( mw.config.get('wgAction') == 'view' && mw.config.get('wgNamespaceNumber') == 6 ) $(document).ready(pano360wrap);

//
// 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);
  }
}
$(document).ready( 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'));
  }
});

//catALot///////////////////////////////////////
////////// Cat-A-Lot user preferences //////////
window.catALotPrefs = {"watchlist":"preferences","minor":false,"editpages":true,"docleanup":false,"subcatcount":50};
////////////////////////////////////catALotEnd//
//</nowiki>