+ // Get the local file repository
+ $repo = RepoGroup::singleton()->getRepo( 'local' );
+ $zone = strstr( ltrim( $path, '/' ), '/', true );
+
+ // Get the full file storage path and extract the source file name.
+ // (e.g. 120px-Foo.png => Foo.png or page2-120px-Foo.png => Foo.png).
+ // This only applies to thumbnails/transcoded, and each of them should
+ // be under a folder that has the source file name.
+ if ( $zone === 'thumb' || $zone === 'transcoded' ) {
+ $name = wfBaseName( dirname( $path ) );
+ $filename = $repo->getZonePath( $zone ) . substr( $path, strlen( "/" . $zone ) );
+ // Check to see if the file exists
+ if ( !$repo->fileExists( $filename ) ) {
+ wfForbidden( 'img-auth-accessdenied', 'img-auth-nofile', $filename );
+ return;
+ }
+ } else {
+ $name = wfBaseName( $path ); // file is a source file
+ $filename = $repo->getZonePath( 'public' ) . $path;
+ // Check to see if the file exists and is not deleted
+ $bits = explode( '!', $name, 2 );
+ if ( substr( $path, 0, 9 ) === '/archive/' && count( $bits ) == 2 ) {
+ $file = $repo->newFromArchiveName( $bits[1], $name );
+ } else {
+ $file = $repo->newFile( $name );
+ }
+ if ( !$file->exists() || $file->isDeleted( File::DELETED_FILE ) ) {
+ wfForbidden( 'img-auth-accessdenied', 'img-auth-nofile', $filename );
+ return;
+ }
+ }