3 * Image download authorisation script
5 * To use, in LocalSettings.php set $wgUploadDirectory to point to a non-public
6 * directory, and $wgUploadPath to point to this file. Also set $wgWhitelistRead
7 * to an array of pages you want everyone to be able to access. Your server must
8 * support PATH_INFO, CGI-based configurations generally don't.
10 require_once( './includes/WebStart.php' );
11 wfProfileIn( 'img_auth.php' );
12 require_once( './includes/StreamFile.php' );
14 if( !isset( $_SERVER['PATH_INFO'] ) ) {
18 # Get filenames/directories
19 $filename = realpath( $wgUploadDirectory . $_SERVER['PATH_INFO'] );
20 $realUploadDirectory = realpath( $wgUploadDirectory );
21 $imageName = $wgContLang->getNsText( NS_IMAGE
) . ":" . basename( $_SERVER['PATH_INFO'] );
23 # Check if the filename is in the correct directory
24 if ( substr( $filename, 0, strlen( $realUploadDirectory ) ) != $realUploadDirectory ) {
28 if ( is_array( $wgWhitelistRead ) && !in_array( $imageName, $wgWhitelistRead ) && !$wgUser->getID() ) {
32 if( !file_exists( $filename ) ) {
35 if( is_dir( $filename ) ) {
40 wfStreamFile( $filename );
43 function wfForbidden() {
44 header( 'HTTP/1.0 403 Forbidden' );
47 <h1>Access denied</h1>
48 <p>You need to log in to access files on this server</p>