summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-04-29 22:53:20 +0200
committerandi <andi@splitbrain.org>2005-04-29 22:53:20 +0200
commit6c7843b5addbca9ae2dc1d9d19be8d67663eb8e5 (patch)
treea9a3f0f481e32f2ce5cb3b256b25b5f482b0b777
parent093ec9e4fcc037744441b83e6ab1a7193c258f96 (diff)
downloadrpg-6c7843b5addbca9ae2dc1d9d19be8d67663eb8e5.tar.gz
rpg-6c7843b5addbca9ae2dc1d9d19be8d67663eb8e5.tar.bz2
added internal rewriting
darcs-hash:20050429205320-9977f-6bf54f3b022104a0a9aefa882dfba09a98bc9c2a.gz
-rw-r--r--conf/dokuwiki.php2
-rw-r--r--doku.php6
-rw-r--r--inc/common.php14
-rw-r--r--inc/html.php12
-rw-r--r--inc/pageutils.php39
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?
diff --git a/doku.php b/doku.php
index 6f4ce89b2..dc1553591 100644
--- a/doku.php
+++ b/doku.php
@@ -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 .= '&amp;'.$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 .= '&amp;'.$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