Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
add8678f
Commit
add8678f
authored
12 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
alternative fix for FS#2734
parent
058fd096
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
_test/conf/acl.auth.php
+1
-0
1 addition, 0 deletions
_test/conf/acl.auth.php
_test/tests/inc/media_ispublic.test.php
+18
-0
18 additions, 0 deletions
_test/tests/inc/media_ispublic.test.php
inc/media.php
+14
-0
14 additions, 0 deletions
inc/media.php
lib/exe/fetch.php
+20
-5
20 additions, 5 deletions
lib/exe/fetch.php
with
53 additions
and
5 deletions
_test/conf/acl.auth.php
+
1
−
0
View file @
add8678f
...
...
@@ -19,6 +19,7 @@
#
delete
16
*
@
ALL
8
private:*
@
ALL
0
#
for
testing
wildcards:
users:*
@
ALL
1
...
...
This diff is collapsed.
Click to expand it.
_test/tests/inc/media_ispublic.test.php
0 → 100644
+
18
−
0
View file @
add8678f
<?php
class
media_ispublic_test
extends
DokuWikiTest
{
public
function
test_external
(){
$this
->
assertTrue
(
media_ispublic
(
'http://www.example.com/foo.png'
));
$this
->
assertTrue
(
media_ispublic
(
'https://www.example.com/foo.png'
));
$this
->
assertTrue
(
media_ispublic
(
'hTTp://www.example.com/foo.png'
));
$this
->
assertTrue
(
media_ispublic
(
'hTTps://www.example.com/foo.png'
));
}
public
function
test_internal
(){
$this
->
assertTrue
(
media_ispublic
(
'wiki:logo.png'
));
$this
->
assertFalse
(
media_ispublic
(
'private:logo.png'
));
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
inc/media.php
+
14
−
0
View file @
add8678f
...
...
@@ -82,6 +82,20 @@ function media_metasave($id,$auth,$data){
}
}
/**
* Check if a media item is public (eg, external URL or readable by @ALL)
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $id the media ID or URL
* @return bool
*/
function
media_ispublic
(
$id
){
if
(
preg_match
(
'/^https?:\/\//i'
,
$id
))
return
true
;
$id
=
cleanID
(
$id
);
if
(
auth_aclcheck
(
getNS
(
$id
)
.
':*'
,
''
,
array
())
>=
AUTH_READ
)
return
true
;
return
false
;
}
/**
* Display the form to edit image meta data
*
...
...
This diff is collapsed.
Click to expand it.
lib/exe/fetch.php
+
20
−
5
View file @
add8678f
...
...
@@ -47,6 +47,7 @@ if(!defined('SIMPLE_TEST')) {
'height'
=>
$HEIGHT
,
'status'
=>
$STATUS
,
'statusmessage'
=>
$STATUSMESSAGE
,
'ispublic'
=>
media_ispublic
(
$MEDIA
),
);
// handle the file status
...
...
@@ -81,10 +82,13 @@ if(!defined('SIMPLE_TEST')) {
// finally send the file to the client
$evt
=
new
Doku_Event
(
'MEDIA_SENDFILE'
,
$data
);
if
(
$evt
->
advise_before
())
{
sendFile
(
$data
[
'file'
],
$data
[
'mime'
],
$data
[
'download'
],
$data
[
'cache'
]);
$cache
=
$data
[
'cache'
];
if
(
$cache
!=
0
&&
!
$data
[
'ispublic'
])
$cache
=
0
;
// no cache headers for private files FS#2734
sendFile
(
$data
[
'file'
],
$data
[
'mime'
],
$data
[
'download'
],
$cache
);
}
// Do something after the download finished.
$evt
->
advise_after
();
$evt
->
advise_after
();
// will not be emitted on 304 or x-sendfile
}
// END DO main
...
...
@@ -93,8 +97,18 @@ if(!defined('SIMPLE_TEST')) {
/**
* Set headers and send the file to the client
*
* Unless $cache is set to 0, the data may end up in intermediate proxy servers. Therefor,
* if you're sending (ACL protected) private files, $cache should be 0.
*
* This function will abort the current script when a 304 is sent or file sending is handled
* through x-sendfile
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Ben Coburn <btcoburn@silicodon.net>
* @param string $file local file to send
* @param string $mime mime type of the file
* @param bool $dl set to true to force a browser download
* @param int $cache remaining cache time in seconds (-1 for $conf['cache'], 0 for off)
*/
function
sendFile
(
$file
,
$mime
,
$dl
,
$cache
)
{
global
$conf
;
...
...
@@ -115,9 +129,10 @@ function sendFile($file, $mime, $dl, $cache) {
header
(
'Cache-Control: public, proxy-revalidate, no-transform, max-age='
.
max
(
$fmtime
-
time
()
+
$conf
[
'cachetime'
]
+
10
,
0
));
header
(
'Pragma: public'
);
}
else
if
(
$cache
==
0
)
{
// nocache
header
(
'Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0'
);
header
(
'Pragma: public'
);
// nocache, avoid resending files from intermediate caches without revalidation FS#2734
header
(
'Expires: Thu, 01 Jan 1970 00:00:00 GMT'
);
header
(
'Cache-Control: private, no-transform, max-age=0'
);
header
(
'Pragma: no-cache'
);
}
//send important headers first, script stops here if '304 Not Modified' response
http_conditionalRequest
(
$fmtime
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment