====== Change default behavior of inserted images so they don't link ====== For a few sites I created, the users don't ever remember to use the ?nolink syntax when adding images. Without "?nolink", an inserted image will default to link to its media page. For many users, this isn't desired. ===== Method 1 ===== To make it the default when using the Media Selection page that inserted images have the ?nolink automatically appended, we can redefine the mediaSelect javascript function. It'll take an argument to determine if the media file type is an image, and if so, it'll add the "?nolink" text. in ''lib/scripts/script.js'' edit the function mediaSelect /* * Edited to accomodate a default where no images are linked */ function mediaSelect(file,image){ if (image == 'yes') { opener.insertTags('wiki__text','{{'+file+'?nolink|','}}',file); } else { opener.insertTags('wiki__text','{{'+file+'|','}}',file); } window.close(); } Then we just change where mediaSelect is called to reflect this. in ''inc/template.php'' edit the function tpl_mediafilelist: ptln('
  • ',4); // added to remove image links by default if($item['isimg']){ // remove link from images ptln(''. utf8_decodeFN($item['file']). '',6); } else { ptln(''. utf8_decodeFN($item['file']). '',6); } (...) //edited to remove image links by default print ''; --[[ian@subcultured.org|ian]] ===== Method 2 ===== If you already have an established site and wish to turn off image linking by default, make the following change:\\ Open **inc/parser/handler.php** and change the block at line 686 to look like //get linking command if(preg_match('/nolink/i',$param)){ $linking = 'nolink'; }else if(preg_match('/direct/i',$param)){ $linking = 'direct'; }else if(preg_match('/details/i',$param)){ $linking = 'details'; }else{ $linking = 'nolink'; } This would make a good option to add into the core.\\ --- //[[mezell1@ece.utk.edu|Matt Ezell]] 2007-02-11 21:56// >IIRC, this will actually make **all** inserted media default to nolink, which may not be desirable (think PDF links, for example) --[[ian@subcultured.org|ian]] >>It is possible to make the code above work for //images only// by using on extra ''preg_match''. Again, substitute starting at line 686 (check the comment line below to find the correct spot)\\ //get linking command if(preg_match('/nolink/i',$param)){ $linking = 'nolink'; }else if(preg_match('/direct/i',$param)){ $linking = 'direct'; }else if(preg_match('/linkonly/i',$param)){ $linking = 'linkonly'; }else{ $imageformats='/\.(gif|jpg|jpeg|png)/i'; if (preg_match($imageformats,$src) ) $linking = 'nolink'; else $linking = 'details'; } \\ This will allow for the handler to apply nolinking only to known image formats (you can, of course, change the expression in the ''$imageformats'' variable, I have used a very simple one). --- //[[luis.machuca@gulix.cl|Luis Machuca Bezzaza]] 2009/09/21 03:19//