diff options
-rw-r--r-- | conf/dokuwiki.php | 2 | ||||
-rw-r--r-- | doku.php | 6 | ||||
-rw-r--r-- | inc/common.php | 14 | ||||
-rw-r--r-- | inc/html.php | 12 | ||||
-rw-r--r-- | inc/pageutils.php | 39 |
5 files changed, 60 insertions, 13 deletions
diff --git a/conf/dokuwiki.php b/conf/dokuwiki.php index f5aabd189..d22dbe94b 100644 --- a/conf/dokuwiki.php +++ b/conf/dokuwiki.php @@ -56,7 +56,7 @@ $conf['defaultgroup']= 'user'; //Default groups new Users are added to $conf['superuser'] = 'superman'; //The admin can be user or @group /* Advanced Options */ -$conf['userewrite'] = 0; //this makes nice URLs but you need to enable it in .htaccess first 0|1 +$conf['userewrite'] = 0; //this makes nice URLs: 0: off 1: .htaccess 2: internal $conf['useslash'] = 0; //use slash instead of colon? only when rewrite is on $conf['canonical'] = 0; //Should all URLs use full canonical http://... style? $conf['autoplural'] = 0; //try (non)plural form of nonexisting files? @@ -20,7 +20,8 @@ //import variables $QUERY = trim($_REQUEST['id']); - $ID = cleanID($_REQUEST['id']); +# $ID = cleanID($_REQUEST['id']); + $ID = getID(); $REV = $_REQUEST['rev']; $ACT = $_REQUEST['do']; $IDX = $_REQUEST['idx']; @@ -43,8 +44,7 @@ } if(!empty($IDX)) $ACT='index'; - //set defaults - if(empty($ID)) $ID = $conf['start']; + //set default #FIXME not needed here? done in actions? if(empty($ACT)) $ACT = 'show'; diff --git a/inc/common.php b/inc/common.php index 8cfe4eea8..84c6bded4 100644 --- a/inc/common.php +++ b/inc/common.php @@ -183,6 +183,9 @@ function idfilter($id,$ue=true){ /** * This builds a link to a wikipage * + * It handles URL rewriting and adds additional parameter if + * given in $more + * * @author Andreas Gohr <andi@splitbrain.org> */ function wl($id='',$more='',$abs=false){ @@ -196,12 +199,15 @@ function wl($id='',$more='',$abs=false){ $xlink = DOKU_BASE; } - if(!$conf['userewrite']){ - $xlink .= DOKU_SCRIPT.'?id='.$id; - if($more) $xlink .= '&'.$more; - }else{ + if($conf['userewrite'] == 2){ + $xlink .= DOKU_SCRIPT.'/'.$id; + if($more) $xlink .= '?'.$more; + }elseif($conf['userewrite']){ $xlink .= $id; if($more) $xlink .= '?'.$more; + }else{ + $xlink .= DOKU_SCRIPT.'?id='.$id; + if($more) $xlink .= '&'.$more; } return $xlink; diff --git a/inc/html.php b/inc/html.php index 7e60cad34..3f6306dc1 100644 --- a/inc/html.php +++ b/inc/html.php @@ -186,14 +186,16 @@ function html_btn($name,$id,$akey,$params,$method='get'){ //filter id (without urlencoding) $id = idfilter($id,false); - //make nice URLs even for buttons - if(!$conf['userewrite']){ + //make nice URLs even for buttons + if($conf['userewrite'] == 2){ + $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; + }elseif($conf['userewrite']){ + $script = DOKU_BASE.$id; + }else{ $script = DOKU_BASE.DOKU_SCRIPT; $params['id'] = $id; - }else{ - $script = DOKU_BASE.$id; } - + $ret .= '<form class="button" method="'.$method.'" action="'.$script.'" onsubmit="return svchk()">'; reset($params); diff --git a/inc/pageutils.php b/inc/pageutils.php index 9a255ec2e..724514982 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -6,6 +6,45 @@ * @author Andreas Gohr <andi@splitbrain.org> */ +/** + * Fetch the pageid + * + * 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. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function getID(){ + global $conf; + + $id = cleanID($_REQUEST['id']); + + //construct page id from request URI + if(empty($id) && $conf['userewrite'] == 2){ + //get the script URL + if($conf['basedir']){ + $script = $conf['basedir'].DOKU_SCRIPT; + }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){ + $script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', + $_SERVER['SCRIPT_FILENAME']); + $script = '/'.$script; + }else{ + $script = $_SERVER['SCRIPT_NAME']; + } + + //remove script URL and Querystring to gain the id + if(preg_match('/^'.preg_quote($script,'/').'(.*)/', + $_SERVER['REQUEST_URI'], $match)){ + $id = preg_replace ('/\?.*/','',$match[1]); + } + $id = cleanID($id); + } + if(empty($id)) $id = $conf['start']; + + return $id; +} /** * Remove unwanted chars from ID |