MediaWiki:VICValidate.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.
$(document).ready( function() {
 // test patterns
 var image_filter = /^[Cc]ommons:[Vv]alued[ _]image[_ ]candidates\/[Ii]mage:/;
 var file_filter = /^[Cc]ommons:[Vv]alued[ _]image[_ ]candidates\/[Ff]ile:/;
 var prefix_filter = /^[Cc]ommons:[Vv]alued[ _]image[_ ]candidates\//;
 var empty_filter = /^[Cc]ommons:[Vv]alued[ _]image[_ ]candidates\/$/;

 function check(e)
 {
  var name = $(this).find('input.createboxInput')[0].value; 
  if( image_filter.test(name) ) {
   alert( "Please remove the 'Image:' prefix." );
   return false;
  }
  if( file_filter.test(name) ) {
   alert( "Please remove the 'File:' prefix." );
   return false;
  }
  if( !prefix_filter.test(name) ) {
   alert( "Please keep the 'Commons:Valued_image_candidates/' prefix." );
   return false;
  }
  if( empty_filter.test(name) ) {
   alert( "Please specify an image name." );
   return false;
  }
 }
 $('form.createbox').submit(check);
} );