Skip to content
Snippets Groups Projects
Commit 42905504 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

some fixes for getID and the detail page

darcs-hash:20051021212304-7ad00-f01b3954b6b71ecc9e0cf899ed62bfb33e0c437e.gz
parent bc228f15
No related branches found
No related tags found
No related merge requests found
......@@ -12,16 +12,38 @@ class init_getID_test extends UnitTestCase {
function test1(){
global $conf;
$conf['basedir'] = '//';
$conf['urlrewrite'] = 2;
$conf['userewrite'] = 2;
$conf['deaccent'] = 0; // the default (1) gives me strange exceptions
$_SERVER['SCRIPT_FILENAME'] = '/lib/exe/fetch.php';
$_SERVER['REQUEST_URI'] = '/lib/exe/fetch.php/myhdl-0.5dev1.tar.gz?id=snapshots&cache=cache';
$this->assertEqual(getID($param='not_id'), 'myhdl-0.5dev1.tar.gz');
$this->assertEqual(getID('media'), 'myhdl-0.5dev1.tar.gz');
}
}
/**
* getID with internal mediafile, urlrewrite=2, no basedir set, apache, mod_php
*/
function test2(){
global $conf;
$conf['basedir'] = '';
$conf['userewrite'] = '2';
$conf['baseurl'] = '';
$conf['useslash'] = '1';
$_SERVER['DOCUMENT_ROOT'] = '/var/www/';
$_SERVER['HTTP_HOST'] = 'xerxes.my.home';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/lib/exe/detail.php';
$_SERVER['PHP_SELF'] = '/dokuwiki/lib/exe/detail.php/wiki/discussion/button-dw.png';
$_SERVER['REQUEST_URI'] = '/dokuwiki/lib/exe/detail.php/wiki/discussion/button-dw.png?id=test&debug=1';
$_SERVER['SCRIPT_NAME'] = '/dokuwiki/lib/exe/detail.php';
$_SERVER['PATH_INFO'] = '/wiki/discussion/button-dw.png';
$_SERVER['PATH_TRANSLATED'] = '/var/www/wiki/discussion/button-dw.png';
$this->assertEqual(getID('media',true), 'wiki:discussion:button-dw.png');
$this->assertEqual(getID('media',false), 'wiki/discussion/button-dw.png');
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
......@@ -310,7 +310,7 @@ function auth_aclcheck($id,$user,$groups){
}
//check exact match first
$matches = preg_grep('/^'.$id.'\s+('.$regexp.')\s+/',$AUTH_ACL);
$matches = preg_grep('/^'.preg_quote($id,'/').'\s+('.$regexp.')\s+/',$AUTH_ACL);
if(count($matches)){
foreach($matches as $match){
$match = preg_replace('/#.*$/','',$match); //ignore comments
......
......@@ -13,19 +13,16 @@
* Uses either standard $_REQUEST variable or extracts it from
* the full request URI when userewrite is set to 2
*
* For $param='id' $conf['start'] is returned if no id was found
* and the returned ID will be cleaned. For other params the
* cleaning has to be done outside this function
* For $param='id' $conf['start'] is returned if no id was found.
* If the second parameter is true (default) the ID is cleaned.
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getID($param='id'){
function getID($param='id',$clean=true){
global $conf;
$id = $_REQUEST[$param];
if($param == 'id') $id = cleanID($id);
//construct page id from request URI
if(empty($id) && $conf['userewrite'] == 2){
//get the script URL
......@@ -52,10 +49,12 @@ function getID($param='id'){
$id = preg_replace ('/\?.*/','',$match[1]);
}
$id = urldecode($id);
$id = cleanID($id);
//strip leading slashes
$id = preg_replace('!^/+!','',$id);
}
if(empty($id) && $param=='id') $id = cleanID($conf['start']);
if(empty($id) && $param=='id') $id = $conf['start'];
if($clean) $id = cleanID($id);
return $id;
}
......
......@@ -14,6 +14,21 @@
$IMG = getID('media');
$ID = cleanID($_REQUEST['id']);
//FIXME remove me later
if($_REQUEST['debug']){
print '<pre>';
foreach(explode(' ','basedir userewrite baseurl useslash') as $x){
print '$'."conf['$x'] = '".$conf[$x]."';\n";
}
foreach(explode(' ','DOCUMENT_ROOT HTTP_HOST SCRIPT_FILENAME PHP_SELF '.
'REQUEST_URI SCRIPT_NAME PATH_INFO PATH_TRANSLATED') as $x){
print '$'."_SERVER['$x'] = '".$_SERVER[$x]."';\n";
}
print "getID('media'): ".getID('media')."\n";
print "getID('media',false): ".getID('media',false)."\n";
print '</pre>';
}
$ERROR = false;
// check image permissions
$AUTH = auth_quickaclcheck($IMG);
......
......@@ -18,7 +18,7 @@
$mimetypes = getMimeTypes();
//get input
$MEDIA = getID('media');
$MEDIA = getID('media',false); // no cleaning - maybe external
$CACHE = calc_cache($_REQUEST['cache']);
$WIDTH = $_REQUEST['w'];
$HEIGHT = $_REQUEST['h'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment