User:Robchurch/CGI-supporting image authorisation/img auth.php patch

From MediaWiki.org
Jump to navigation Jump to search

This needs to be applied against img_auth.php.

Index: img_auth.php
===================================================================
--- img_auth.php	(revision 22127)
+++ img_auth.php	(working copy)
@@ -1,27 +1,26 @@
 <?php
+
 /**
- * Image download authorisation script
- *
- * To use, in LocalSettings.php set $wgUploadDirectory to point to a non-public
- * directory, and $wgUploadPath to point to this file. Also set $wgWhitelistRead
- * to an array of pages you want everyone to be able to access. Your server must
- * support PATH_INFO, CGI-based configurations generally don't.
+ * Version of img_auth.php that's been hacked up to work in CGI-based configurations.
+ * Requires mod_rewrite and some minor configuration tweaking; see
+ * http://www.mediawiki.org/wiki/User:Robchurch/CGI-supporting_image_authorisation
  */
 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
 require_once( './includes/WebStart.php' );
 wfProfileIn( 'img_auth.php' );
 require_once( './includes/StreamFile.php' );
 
-if( !isset( $_SERVER['PATH_INFO'] ) ) {
-	wfDebugLog( 'img_auth', "missing PATH_INFO" );
+if( !isset( $_REQUEST['path'] ) ) {
+	wfDebugLog( 'img_auth', "missing \$path" );
 	wfForbidden();
 }
+$path = $_REQUEST['path'];
 
 # Get filenames/directories
-wfDebugLog( 'img_auth', "PATH_INFO is: " . $_SERVER['PATH_INFO'] );
-$filename = realpath( $wgUploadDirectory . $_SERVER['PATH_INFO'] );
+wfDebugLog( 'img_auth', "\$path is {$path}" );
+$filename = realpath( $wgUploadDirectory . $path );
 $realUploadDirectory = realpath( $wgUploadDirectory );
-$imageName = $wgContLang->getNsText( NS_IMAGE ) . ":" . wfBaseName( $_SERVER['PATH_INFO'] );
+$imageName = $wgContLang->getNsText( NS_IMAGE ) . ":" . wfBaseName( $path );
 
 # Check if the filename is in the correct directory
 if ( substr( $filename, 0, strlen( $realUploadDirectory ) ) != $realUploadDirectory ) {