summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/parser/action.php55
-rw-r--r--inc/parser/handler.php65
-rw-r--r--inc/parser/renderer.php4
-rw-r--r--inc/parser/xhtml.php18
4 files changed, 91 insertions, 51 deletions
diff --git a/inc/parser/action.php b/inc/parser/action.php
index 34d71d3ae..67864b729 100644
--- a/inc/parser/action.php
+++ b/inc/parser/action.php
@@ -1,4 +1,10 @@
<?php
+/**
+ *
+ * @todo maybe wrap in class
+ * @todo rename to helper
+ */
+
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
function parse_to_instructions($text){
@@ -80,4 +86,53 @@ function render_as_xhtml($instructions){
return $Renderer->doc;
}
+/**
+ * Returns a full page id
+ *
+ */
+function resolve_pageid(&$page,&$exists){
+ global $ID;
+ global $conf;
+ $ns = getNS($ID);
+
+ //if links starts with . add current namespace
+ if($page{0} == '.'){
+ $page = $ns.':'.substr($page,1);
+ }
+
+ //if link contains no namespace. add current namespace (if any)
+ if($ns !== false && strpos($page,':') === false){
+ $page = $ns.':'.$page;
+ }
+
+ //keep hashlink if exists then clean both parts
+ list($page,$hash) = split('#',$page,2);
+ $page = cleanID($page);
+ $hash = cleanID($hash);
+
+ $file = wikiFN($page);
+
+ $exists = false;
+
+ //check alternative plural/nonplural form
+ if(!@file_exists($file)){
+ if( $conf['autoplural'] ){
+ if(substr($page,-1) == 's'){
+ $try = substr($page,0,-1);
+ }else{
+ $try = $page.'s';
+ }
+ if(@file_exists(wikiFN($try))){
+ $page = $try;
+ $exists = true;
+ }
+ }
+ }else{
+ $exists = true;
+ }
+
+ //add hash if any
+ if(!empty($hash)) $page.'#'.$hash;
+}
+
?>
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 78826007e..24f095599 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -341,7 +341,6 @@ class Doku_Handler {
}
/*
- * @TODO What about email?
*/
function internallink($match, $state, $pos) {
// Strip the opening and closing markup
@@ -361,63 +360,47 @@ class Doku_Handler {
$link[1] = $media;
}
}
-
- // Interwiki links
+
+ //decide which kind of link it is
+
if ( preg_match('/^[a-zA-Z]+>{1}[\w()\/\\#~:.?+=&%@!\-;,]+$/u',$link[0]) ) {
+ // Interwiki
$interwiki = preg_split('/>/u',$link[0]);
$this->__addCall(
'interwikilink',
- // UTF8 problem...
array($link[0],$link[1],strtolower($interwiki[0]),$interwiki[1]),
$pos
);
-
- // Link to internal wiki page
- } else if ( preg_match('/^[\w:#]+$/u',$link[0]) ) {
+ }elseif ( preg_match('/\\\\\\\\[\w.:?\-;,]+?\\\\/u',$link[0]) ) {
+ // Windows Share
$this->__addCall(
- 'internallink',
+ 'windowssharelink',
array($link[0],$link[1]),
$pos
);
-
- // Otherwise it's some kind of link to elsewhere
- } else {
-
- // file://
- if ( substr($link[0],0,4) == 'file' ) {
- $this->__addCall(
- 'filelink',
- array($link[0],$link[1]),
- $pos
- );
-
- // Check for Windows shares - potential security issues here?
- // i.e. mode not loaded but still matched here...
- } else if ( preg_match('/\\\\\\\\[\w.:?\-;,]+?\\\\/u',$link[0]) ) {
- $this->__addCall(
- 'windowssharelink',
- array($link[0],$link[1]),
- $pos
+ }elseif ( preg_match('#([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i',$link[0]) ) {
+ // E-Mail
+ $this->__addCall(
+ 'emaillink',
+ array($link[0],$link[1]),
+ $pos
);
-
- // Otherwise it's one of the other valid internal links
- } else {
-
- // Add the scheme as needed...
- $leader = substr($link[0],0,3);
- if ( $leader == 'www' ) {
- $link[0] = 'http://'.$link[0];
- } else if ( $leader == 'ftp' ) {
- $link[0] = 'ftp://'.$link[0];
- }
-
- $this->__addCall(
+ }elseif ( preg_match('#^([a-z0-9]+?)://#i',$link[0]) ) {
+ // external link (accepts all protocols)
+ $this->__addCall(
'externallink',
array($link[0],$link[1]),
$pos
);
- }
+ }else{
+ // internal link
+ $this->__addCall(
+ 'internallink',
+ array($link[0],$link[1]),
+ $pos
+ );
}
+
return TRUE;
}
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index c52ddf6cd..d6072e0a4 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -121,7 +121,7 @@ class Doku_Renderer {
// $link like 'SomePage'
function camelcaselink($link) {}
- // $link like 'wikie:syntax', $title could be an array (media)
+ // $link like 'wiki:syntax', $title could be an array (media)
function internallink($link, $title = NULL) {}
// $link is full URL with scheme, $title could be an array (media)
@@ -163,7 +163,7 @@ class Doku_Renderer {
function tablecell_open($colspan = 1, $align = NULL){}
function tablecell_close(){}
-
+
}
?>
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index db7b4e64e..797b261b0 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -11,10 +11,12 @@ if ( !defined('DOKU_TAB') ) {
define ('DOKU_TAB',"\t");
}
+require_once DOKU_INC . 'inc/parser/renderer.php';
+
/**
* @TODO Probably useful for have constant for linefeed formatting
*/
-class Doku_Renderer_XHTML {
+class Doku_Renderer_XHTML extends Doku_Renderer {
var $doc = '';
@@ -377,7 +379,6 @@ class Doku_Renderer_XHTML {
}
/**
- * @TODO Hook up with page resolver.
* @TODO Support media
* @TODO correct attributes
*/
@@ -387,14 +388,14 @@ class Doku_Renderer_XHTML {
$title = $this->__getLinkTitle($title,$link, $isImage);
+ resolve_pageid($link,$exists);
+
if ( !$isImage ) {
-
- if ( wikiPageExists($link) ) {
+ if ( $exists ) {
echo ' class="wikilink1"';
} else {
echo ' class="wikilink2"';
}
-
} else {
echo ' class="media"';
}
@@ -791,9 +792,10 @@ function interwikiImgExists($name) {
}
/**
-* For determining whether to use CSS class "wikilink1" or "wikilink2"
-* @todo use configinstead of DOKU_DATA
-*/
+ * For determining whether to use CSS class "wikilink1" or "wikilink2"
+ * @todo use configinstead of DOKU_DATA
+ * @deprecated -> resolve_pagename should be used
+ */
function wikiPageExists($name) {
static $pages = array();