summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorAndreas Gohr <gohr@cosmocode.de>2007-01-24 12:14:38 +0100
committerAndreas Gohr <gohr@cosmocode.de>2007-01-24 12:14:38 +0100
commit1f82fabe74da331707281178e4a9c1df1107e46d (patch)
tree5745eca979b9a592326dff460b1bef2df0e17cc7 /inc/parser
parentda9f31c579b1d16d9a1a27ff627fa4e68a70531f (diff)
downloadrpg-1f82fabe74da331707281178e4a9c1df1107e46d.tar.gz
rpg-1f82fabe74da331707281178e4a9c1df1107e46d.tar.bz2
moved interwiki resolve logic to base renderer class
darcs-hash:20070124111438-6e07b-7d3e534aa7eff56821bf94232fea7711c5881719.gz
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/renderer.php41
-rw-r--r--inc/parser/xhtml.php40
2 files changed, 43 insertions, 38 deletions
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index 21d784276..2b6957692 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -22,6 +22,12 @@ class Doku_Renderer extends DokuWiki_Plugin {
'toc' => true, // render the TOC?
);
+ // keep some config options
+ var $acronyms = array();
+ var $smileys = array();
+ var $badwords = array();
+ var $entities = array();
+ var $interwiki = array();
function nocache() {
$this->info['cache'] = false;
@@ -251,7 +257,42 @@ class Doku_Renderer extends DokuWiki_Plugin {
return $name;
}
+ /**
+ * Resolve an interwikilink
+ */
+ function _resolveInterWiki(&$shortcut,$reference){
+ //get interwiki URL
+ if ( isset($this->interwiki[$shortcut]) ) {
+ $url = $this->interwiki[$shortcut];
+ } else {
+ // Default to Google I'm feeling lucky
+ $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
+ $shortcut = 'go';
+ }
+ //split into hash and url part
+ list($wikiUri,$hash) = explode('#',$wikiUri,2);
+
+ //replace placeholder
+ if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
+ //use placeholders
+ $url = str_replace('{URL}',rawurlencode($reference),$url);
+ $url = str_replace('{NAME}',$reference,$url);
+ $parsed = parse_url($reference);
+ if(!$parsed['port']) $parsed['port'] = 80;
+ $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
+ $url = str_replace('{HOST}',$parsed['host'],$url);
+ $url = str_replace('{PORT}',$parsed['port'],$url);
+ $url = str_replace('{PATH}',$parsed['path'],$url);
+ $url = str_replace('{QUERY}',$parsed['query'],$url);
+ }else{
+ //default
+ $url = $url.rawurlencode($reference);
+ }
+ if($hash) $url .= '#'.rawurlencode($hash);
+
+ return $url;
+ }
}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 97b99d824..5e3a12849 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -32,17 +32,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
var $headers = array();
-
var $footnotes = array();
-
- var $acronyms = array();
- var $smileys = array();
- var $badwords = array();
- var $entities = array();
- var $interwiki = array();
-
var $lastsec = 0;
-
var $store = '';
function document_start() {
@@ -577,13 +568,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage);
//get interwiki URL
- if ( isset($this->interwiki[$wikiName]) ) {
- $url = $this->interwiki[$wikiName];
- } else {
- // Default to Google I'm feeling lucky
- $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
- $wikiName = 'go';
- }
+ $url = $this-> _resolveInterWiki($wikiName,$wikiUri);
if ( !$isImage ) {
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
@@ -597,28 +582,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['target'] = $conf['target']['wiki'];
}
- //split into hash and url part
- list($wikiUri,$hash) = explode('#',$wikiUri,2);
-
- //replace placeholder
- if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
- //use placeholders
- $url = str_replace('{URL}',rawurlencode($wikiUri),$url);
- $url = str_replace('{NAME}',$wikiUri,$url);
- $parsed = parse_url($wikiUri);
- if(!$parsed['port']) $parsed['port'] = 80;
- $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
- $url = str_replace('{HOST}',$parsed['host'],$url);
- $url = str_replace('{PORT}',$parsed['port'],$url);
- $url = str_replace('{PATH}',$parsed['path'],$url);
- $url = str_replace('{QUERY}',$parsed['query'],$url);
- $link['url'] = $url;
- }else{
- //default
- $link['url'] = $url.rawurlencode($wikiUri);
- }
- if($hash) $link['url'] .= '#'.rawurlencode($hash);
-
+ $link['url'] = $url;
$link['title'] = htmlspecialchars($link['url']);
//output formatted