Extension:ImageProtection

Overview
One of our mediawiki based research projects requires login to read articles, but also needs to prevent people linking to documents and images that are uploaded into the Image: namespace. This extension addresses the second of these issues.

Installation
Add this line to your LocalSettings.php: require_once("extensions/ImageProtection.php");

Copy this code and create a file inside extensions called ImageProtection.php. <? function fnImageAction($output, $article, $title, $user, $request, $wiki) { global $IP, $wgScriptPath; #print_r($request); if( isset($request->data['action']) && 			($request->data['action'] == 'image') && 			$user->isLoggedIn ) { $output->disable; wfResetOutputBuffers;

$image_path = "$IP/images/".$request->data['image']; preg_match("/.+\/(.+?)$/", $image_path, $result);

$image = Image::newFromTitle($result[1]); if($file = @file_get_contents($image_path)) { header('Content-Type: '.$image->mime); print $file; }			return false; }

return true; }

$wgHooks['MediaWikiPerformAction'][] = 'fnImageAction';

?> Create an .htaccess file inside the images directory in your wiki. Apache will need to have the directive AllowOverride All set for the images directory so it will read and execute the .htaccess file.