summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.htaccess.dist2
-rw-r--r--inc/common.php68
-rw-r--r--inc/pageutils.php13
-rw-r--r--inc/parser/xhtml.php16
-rw-r--r--inc/template.php17
-rw-r--r--lib/exe/detail.php4
-rw-r--r--lib/exe/fetch.php2
7 files changed, 91 insertions, 31 deletions
diff --git a/.htaccess.dist b/.htaccess.dist
index c77ee05f0..45747c1ca 100644
--- a/.htaccess.dist
+++ b/.htaccess.dist
@@ -12,6 +12,8 @@ Options -Indexes
## Comment these rules in if you want to have nice URLs
#RewriteEngine on
+#RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
+#RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
#RewriteRule ^$ doku.php [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
diff --git a/inc/common.php b/inc/common.php
index b0d7c4c10..891601357 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -238,7 +238,11 @@ function idfilter($id,$ue=true){
*/
function wl($id='',$more='',$abs=false){
global $conf;
- $more = str_replace(',','&',$more);
+ if(is_array($more)){
+ $more = buildURLparams($more);
+ }else{
+ $more = str_replace(',','&',$more);
+ }
$id = idfilter($id);
if($abs){
@@ -262,6 +266,68 @@ function wl($id='',$more='',$abs=false){
}
/**
+ * Build a link to a media file
+ *
+ * Will return a link to the detail page if $direct is false
+ */
+function ml($id='',$more='',$direct=true){
+ global $conf;
+ if(is_array($more)){
+ $more = buildURLparams($more);
+ }else{
+ $more = str_replace(',','&',$more);
+ }
+
+ $xlink = DOKU_BASE;
+
+ // external URLs are always direct without rewriting
+ if(preg_match('#^(https?|ftp)://#i',$id)){
+ $xlink .= 'lib/exe/fetch.php';
+ if($more){
+ $xlink .= '?'.$more;
+ $xlink .= '&media='.$id;
+ }else{
+ $xlink .= '?media='.$id;
+ }
+ return $xlink;
+ }
+
+ $id = idfilter($id);
+
+ // decide on scriptname
+ if($direct){
+ if($conf['userewrite'] == 1){
+ $script = '_media';
+ }else{
+ $script = 'lib/exe/fetch.php';
+ }
+ }else{
+ if($conf['userewrite'] == 1){
+ $script = '_detail';
+ }else{
+ $script = 'lib/exe/detail.php';
+ }
+ }
+
+ // build URL based on rewrite mode
+ if($conf['userewrite']){
+ $xlink .= $script.'/'.$id;
+ if($more) $xlink .= '?'.$more;
+ }else{
+ if($more){
+ $xlink .= '?'.$more;
+ $xlink .= '&media='.$id;
+ }else{
+ $xlink .= '?media='.$id;
+ }
+ }
+
+ return $xlink;
+}
+
+
+
+/**
* Just builds a link to a script
*
* @todo maybe obsolete
diff --git a/inc/pageutils.php b/inc/pageutils.php
index 1e0792b7d..d81d22a58 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -8,25 +8,25 @@
*/
/**
- * Fetch the pageid
+ * Fetch the an ID from request
*
* Uses either standard $_REQUEST variable or extracts it from
* the full request URI when userewrite is set to 2
*
- * Returns $conf['start'] if no id was found.
+ * Returns $conf['start'] if no id was found and $param is 'id'
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function getID(){
+function getID($param='id'){
global $conf;
- $id = cleanID($_REQUEST['id']);
+ $id = cleanID($_REQUEST[$param]);
//construct page id from request URI
if(empty($id) && $conf['userewrite'] == 2){
//get the script URL
if($conf['basedir']){
- $script = $conf['basedir'].DOKU_SCRIPT;
+ $script = $conf['basedir'].basedir($_SERVER['SCRIPT_FILENAME']);
}elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
$script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
$_SERVER['SCRIPT_FILENAME']);
@@ -43,9 +43,10 @@ function getID(){
if(preg_match('/^'.preg_quote($script,'/').'(.*)/',$request, $match)){
$id = preg_replace ('/\?.*/','',$match[1]);
}
+ $id = urldecode($id);
$id = cleanID($id);
}
- if(empty($id)) $id = $conf['start'];
+ if(empty($id) && $param='id') $id = $conf['start'];
return $id;
}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 181562b2a..f6e9b7add 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -734,10 +734,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['title'] = $this->_xmlEntities($src);
list($ext,$mime) = mimetype($src);
- if(substr($mime,0,5) == 'image' && !preg_match('#^(https?|ftp)://#i',$src)){
- $link['url']= DOKU_BASE.'lib/exe/detail.php?id='.$ID.'&amp;cache='.$cache.'&amp;media='.urlencode($src);
+ if(substr($mime,0,5)){
+ $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),false);
}else{
- $link['url']= DOKU_BASE.'lib/exe/fetch.php?cache='.$cache.'&amp;media='.urlencode($src);
+ $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
}
$link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache);
@@ -762,7 +762,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['target'] = $conf['target']['media'];
$link['title'] = $this->_xmlEntities($src);
- $link['url'] = DOKU_BASE.'lib/exe/fetch.php?cache='.$cache.'&amp;media='.urlencode($src);
+ $link['url'] = ml($src,array('cache'=>$cache));
$link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache);
@@ -917,9 +917,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
list($ext,$mime) = mimetype($src);
if(substr($mime,0,5) == 'image'){
//add image tag
- $ret .= '<img src="'.DOKU_BASE.'lib/exe/fetch.php?w='.$width.'&amp;h='.$height.
- '&amp;cache='.$cache.'&amp;media='.urlencode($src).'"';
-
+ $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
$ret .= ' class="media'.$align.'"';
if (!is_null($title)) {
@@ -952,9 +950,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
$ret .= '>'.DOKU_LF;
- $ret .= '<param name="movie" value="'.DOKU_BASE.'lib/exe/fetch.php?media='.urlencode($src).'" />'.DOKU_LF;
+ $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF;
$ret .= '<param name="quality" value="high" />'.DOKU_LF;
- $ret .= '<embed src="'.DOKU_BASE.'lib/exe/fetch.php?media='.urlencode($src).'"'.
+ $ret .= '<embed src="'.ml($src).'"'.
' quality="high"';
if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
diff --git a/inc/template.php b/inc/template.php
index 34fdfb009..9f39b6b79 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -674,11 +674,7 @@ function tpl_mediafilelist(){
$h = floor($h * $ratio);
}
- $p = array();
- $p['w'] = $w;
- $p['h'] = $h;
- $p['media'] = $item['id'];
- $src = DOKU_BASE.'lib/exe/fetch.php?'.buildURLParams($p);
+ $src = ml($item['id'],array('w'=>$w,'h'=>$h));
$p = array();
$p['width'] = $w;
@@ -854,12 +850,9 @@ function tpl_img($maxwidth=900,$maxheight=700){
$h = floor($ratio*$h);
}
- //prepare URL
- $p = array();
- $p['cache'] = $_REQUEST['cache'];
- $p['media'] = $IMG;
- $p = buildURLparams($p);
- $url=DOKU_BASE.'lib/exe/fetch.php?'.$p;
+ //prepare URLs
+ $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
+ $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
//prepare attributes
$alt=tpl_img_getTag('Simple.Title');
@@ -876,7 +869,7 @@ function tpl_img($maxwidth=900,$maxheight=700){
$p = buildAttributes($p);
print '<a href="'.$url.'">';
- print '<img src="'.$url.'&amp;w='.$w.'&amp;h='.$w.'" '.$p.'/>';
+ print '<img src="'.$src.'" '.$p.'/>';
print '</a>';
}
diff --git a/lib/exe/detail.php b/lib/exe/detail.php
index 6e2ae96c6..21a34d721 100644
--- a/lib/exe/detail.php
+++ b/lib/exe/detail.php
@@ -11,8 +11,8 @@
//close session
session_write_close();
- $IMG = cleanID($_REQUEST['media']);
- $ID = getID();
+ $IMG = getID('media');
+ $ID = cleanID($_REQUEST['id']);
$ERROR = false;
// check image permissions
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 812850267..e647ea384 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -18,7 +18,7 @@
$mimetypes = getMimeTypes();
//get input
- $MEDIA = $_REQUEST['media'];
+ $MEDIA = getID('media');
$CACHE = calc_cache($_REQUEST['cache']);
$WIDTH = $_REQUEST['w'];
$HEIGHT = $_REQUEST['h'];