-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.php
39 lines (30 loc) · 865 Bytes
/
wrapper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
use MediaWiki\Extension\RestrictImageDownload\ImageFile;
define('MW_ENTRY_POINT', 'restrict_image_download');
require dirname(dirname(__DIR__)).'/includes/WebStart.php';
wfImageWrapperMain();
function wfImageWrapperMain()
{
global $wgServer;
global $wgUploadDirectory;
$file_path = realpath($wgUploadDirectory.($_SERVER['PATH_INFO'] ?? ''));
if (false === $file_path || 0 !== strpos($file_path, $wgUploadDirectory) || !is_file($file_path)) {
error403();
}
$file = new ImageFile($file_path);
if (!$file->validate()) {
error403();
}
// refere check
if (0 !== strpos($_SERVER['HTTP_REFERER'] ?? '', $wgServer)) {
$file->output_protected_image();
} else {
$file->output();
}
}
function error403()
{
header('HTTP/1.1 403 Forbidden');
exit;
}