summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/handler.php48
-rw-r--r--inc/parser/lexer.php8
-rw-r--r--inc/parser/parser.php32
-rw-r--r--inc/parser/renderer.php14
-rw-r--r--inc/parser/xhtml.php93
5 files changed, 123 insertions, 72 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index b8e2de82a..815ac39c5 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -17,7 +17,7 @@ class Doku_Handler {
var $rewriteBlocks = true;
- function Doku_Handler() {
+ function __construct() {
$this->CallWriter = new Doku_Handler_CallWriter($this);
}
@@ -295,7 +295,7 @@ class Doku_Handler {
switch ( $state ) {
case DOKU_LEXER_ENTER:
$ReWriter = new Doku_Handler_Preformatted($this->CallWriter);
- $this->CallWriter = & $ReWriter;
+ $this->CallWriter = $ReWriter;
$this->_addCall('preformatted_start',array(), $pos);
break;
case DOKU_LEXER_EXIT:
@@ -715,15 +715,21 @@ function Doku_Handler_Parse_Media($match) {
}
//------------------------------------------------------------------------
-class Doku_Handler_CallWriter {
+interface Doku_Handler_CallWriter_Interface {
+ public function writeCall($call);
+ public function writeCalls($calls);
+ public function finalise();
+}
+
+class Doku_Handler_CallWriter implements Doku_Handler_CallWriter_Interface {
var $Handler;
/**
* @param Doku_Handler $Handler
*/
- function Doku_Handler_CallWriter(& $Handler) {
- $this->Handler = & $Handler;
+ function __construct(Doku_Handler $Handler) {
+ $this->Handler = $Handler;
}
function writeCall($call) {
@@ -748,7 +754,7 @@ class Doku_Handler_CallWriter {
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
-class Doku_Handler_Nest {
+class Doku_Handler_Nest implements Doku_Handler_CallWriter_Interface {
var $CallWriter;
var $calls = array();
@@ -762,8 +768,8 @@ class Doku_Handler_Nest {
* @param string $close closing instruction name, this is required to properly terminate the
* syntax mode if the document ends without a closing pattern
*/
- function Doku_Handler_Nest(& $CallWriter, $close="nest_close") {
- $this->CallWriter = & $CallWriter;
+ function __construct(Doku_Handler_CallWriter_Interface $CallWriter, $close="nest_close") {
+ $this->CallWriter = $CallWriter;
$this->closingInstruction = $close;
}
@@ -808,7 +814,7 @@ class Doku_Handler_Nest {
}
}
-class Doku_Handler_List {
+class Doku_Handler_List implements Doku_Handler_CallWriter_Interface {
var $CallWriter;
@@ -818,8 +824,8 @@ class Doku_Handler_List {
const NODE = 1;
- function Doku_Handler_List(& $CallWriter) {
- $this->CallWriter = & $CallWriter;
+ function __construct(Doku_Handler_CallWriter_Interface $CallWriter) {
+ $this->CallWriter = $CallWriter;
}
function writeCall($call) {
@@ -1018,7 +1024,7 @@ class Doku_Handler_List {
}
//------------------------------------------------------------------------
-class Doku_Handler_Preformatted {
+class Doku_Handler_Preformatted implements Doku_Handler_CallWriter_Interface {
var $CallWriter;
@@ -1028,8 +1034,8 @@ class Doku_Handler_Preformatted {
- function Doku_Handler_Preformatted(& $CallWriter) {
- $this->CallWriter = & $CallWriter;
+ function __construct(Doku_Handler_CallWriter_Interface $CallWriter) {
+ $this->CallWriter = $CallWriter;
}
function writeCall($call) {
@@ -1078,7 +1084,7 @@ class Doku_Handler_Preformatted {
}
//------------------------------------------------------------------------
-class Doku_Handler_Quote {
+class Doku_Handler_Quote implements Doku_Handler_CallWriter_Interface {
var $CallWriter;
@@ -1086,8 +1092,8 @@ class Doku_Handler_Quote {
var $quoteCalls = array();
- function Doku_Handler_Quote(& $CallWriter) {
- $this->CallWriter = & $CallWriter;
+ function __construct(Doku_Handler_CallWriter_Interface $CallWriter) {
+ $this->CallWriter = $CallWriter;
}
function writeCall($call) {
@@ -1170,7 +1176,7 @@ class Doku_Handler_Quote {
}
//------------------------------------------------------------------------
-class Doku_Handler_Table {
+class Doku_Handler_Table implements Doku_Handler_CallWriter_Interface {
var $CallWriter;
@@ -1185,8 +1191,8 @@ class Doku_Handler_Table {
var $currentRow = array('tableheader' => 0, 'tablecell' => 0);
var $countTableHeadRows = 0;
- function Doku_Handler_Table(& $CallWriter) {
- $this->CallWriter = & $CallWriter;
+ function __construct(Doku_Handler_CallWriter_Interface $CallWriter) {
+ $this->CallWriter = $CallWriter;
}
function writeCall($call) {
@@ -1551,7 +1557,7 @@ class Doku_Handler_Block {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- function Doku_Handler_Block(){
+ function __construct(){
global $DOKU_PLUGINS;
//check if syntax plugins were loaded
if(empty($DOKU_PLUGINS['syntax'])) return;
diff --git a/inc/parser/lexer.php b/inc/parser/lexer.php
index b46a5f505..17aa6c170 100644
--- a/inc/parser/lexer.php
+++ b/inc/parser/lexer.php
@@ -46,7 +46,7 @@ class Doku_LexerParallelRegex {
* for insensitive.
* @access public
*/
- function Doku_LexerParallelRegex($case) {
+ function __construct($case) {
$this->_case = $case;
$this->_patterns = array();
$this->_labels = array();
@@ -232,7 +232,7 @@ class Doku_LexerStateStack {
* @param string $start Starting state name.
* @access public
*/
- function Doku_LexerStateStack($start) {
+ function __construct($start) {
$this->_stack = array($start);
}
@@ -296,11 +296,11 @@ class Doku_Lexer {
* @param boolean $case True for case sensitive.
* @access public
*/
- function Doku_Lexer(&$parser, $start = "accept", $case = false) {
+ function __construct($parser, $start = "accept", $case = false) {
$this->_case = $case;
/** @var Doku_LexerParallelRegex[] _regexes */
$this->_regexes = array();
- $this->_parser = &$parser;
+ $this->_parser = $parser;
$this->_mode = new Doku_LexerStateStack($start);
$this->_mode_handlers = array();
}
diff --git a/inc/parser/parser.php b/inc/parser/parser.php
index 5f86cf5c4..7814e94f6 100644
--- a/inc/parser/parser.php
+++ b/inc/parser/parser.php
@@ -64,24 +64,24 @@ class Doku_Parser {
/**
* @param Doku_Parser_Mode_base $BaseMode
*/
- function addBaseMode(& $BaseMode) {
- $this->modes['base'] =& $BaseMode;
+ function addBaseMode($BaseMode) {
+ $this->modes['base'] = $BaseMode;
if ( !$this->Lexer ) {
$this->Lexer = new Doku_Lexer($this->Handler,'base', true);
}
- $this->modes['base']->Lexer =& $this->Lexer;
+ $this->modes['base']->Lexer = $this->Lexer;
}
/**
* PHP preserves order of associative elements
* Mode sequence is important
*/
- function addMode($name, & $Mode) {
+ function addMode($name, Doku_Parser_Mode_Interface $Mode) {
if ( !isset($this->modes['base']) ) {
$this->addBaseMode(new Doku_Parser_Mode_base());
}
- $Mode->Lexer = & $this->Lexer;
- $this->modes[$name] =& $Mode;
+ $Mode->Lexer = $this->Lexer;
+ $this->modes[$name] = $Mode;
}
function connectModes() {
@@ -226,7 +226,7 @@ class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mod
//-------------------------------------------------------------------
class Doku_Parser_Mode_base extends Doku_Parser_Mode {
- function Doku_Parser_Mode_base() {
+ function __construct() {
global $PARSER_MODES;
$this->allowedModes = array_merge (
@@ -248,7 +248,7 @@ class Doku_Parser_Mode_base extends Doku_Parser_Mode {
//-------------------------------------------------------------------
class Doku_Parser_Mode_footnote extends Doku_Parser_Mode {
- function Doku_Parser_Mode_footnote() {
+ function __construct() {
global $PARSER_MODES;
$this->allowedModes = array_merge (
@@ -416,7 +416,7 @@ class Doku_Parser_Mode_formatting extends Doku_Parser_Mode {
/**
* @param string $type
*/
- function Doku_Parser_Mode_formatting($type) {
+ function __construct($type) {
global $PARSER_MODES;
if ( !array_key_exists($type, $this->formatting) ) {
@@ -470,7 +470,7 @@ class Doku_Parser_Mode_formatting extends Doku_Parser_Mode {
//-------------------------------------------------------------------
class Doku_Parser_Mode_listblock extends Doku_Parser_Mode {
- function Doku_Parser_Mode_listblock() {
+ function __construct() {
global $PARSER_MODES;
$this->allowedModes = array_merge (
@@ -504,7 +504,7 @@ class Doku_Parser_Mode_listblock extends Doku_Parser_Mode {
//-------------------------------------------------------------------
class Doku_Parser_Mode_table extends Doku_Parser_Mode {
- function Doku_Parser_Mode_table() {
+ function __construct() {
global $PARSER_MODES;
$this->allowedModes = array_merge (
@@ -648,7 +648,7 @@ class Doku_Parser_Mode_file extends Doku_Parser_Mode {
//-------------------------------------------------------------------
class Doku_Parser_Mode_quote extends Doku_Parser_Mode {
- function Doku_Parser_Mode_quote() {
+ function __construct() {
global $PARSER_MODES;
$this->allowedModes = array_merge (
@@ -682,7 +682,7 @@ class Doku_Parser_Mode_acronym extends Doku_Parser_Mode {
var $acronyms = array();
var $pattern = '';
- function Doku_Parser_Mode_acronym($acronyms) {
+ function __construct($acronyms) {
usort($acronyms,array($this,'_compare'));
$this->acronyms = $acronyms;
}
@@ -729,7 +729,7 @@ class Doku_Parser_Mode_smiley extends Doku_Parser_Mode {
var $smileys = array();
var $pattern = '';
- function Doku_Parser_Mode_smiley($smileys) {
+ function __construct($smileys) {
$this->smileys = $smileys;
}
@@ -762,7 +762,7 @@ class Doku_Parser_Mode_wordblock extends Doku_Parser_Mode {
var $badwords = array();
var $pattern = '';
- function Doku_Parser_Mode_wordblock($badwords) {
+ function __construct($badwords) {
$this->badwords = $badwords;
}
@@ -797,7 +797,7 @@ class Doku_Parser_Mode_entity extends Doku_Parser_Mode {
var $entities = array();
var $pattern = '';
- function Doku_Parser_Mode_entity($entities) {
+ function __construct($entities) {
$this->entities = $entities;
}
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index 35bdd0e3f..d7a3faef8 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -806,18 +806,26 @@ class Doku_Renderer extends DokuWiki_Plugin {
$url = $this->interwiki[$shortcut];
} else {
// Default to Google I'm feeling lucky
- $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
+ $url = 'https://www.google.com/search?q={URL}&amp;btnI=lucky';
$shortcut = 'go';
}
//split into hash and url part
- @list($reference, $hash) = explode('#', $reference, 2);
+ $hash = strrchr($reference, '#');
+ if($hash) {
+ $reference = substr($reference, 0, -strlen($hash));
+ $hash = substr($hash, 1);
+ }
//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);
+ //wiki names will be cleaned next, otherwise urlencode unsafe chars
+ $url = str_replace('{NAME}', ($url{0} === ':') ? $reference :
+ preg_replace_callback('/[[\\\\\]^`{|}#%]/', function($match) {
+ return rawurlencode($match[0]);
+ }, $reference), $url);
$parsed = parse_url($reference);
if(!$parsed['port']) $parsed['port'] = 80;
$url = str_replace('{SCHEME}', $parsed['scheme'], $url);
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index d1bf91a02..c92892a35 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -761,27 +761,40 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
/**
* Render a CamelCase link
*
- * @param string $link The link name
+ * @param string $link The link name
+ * @param bool $returnonly whether to return html or write to doc attribute
* @see http://en.wikipedia.org/wiki/CamelCase
*/
- function camelcaselink($link) {
- $this->internallink($link, $link);
+ function camelcaselink($link, $returnonly = false) {
+ if($returnonly) {
+ return $this->internallink($link, $link, null, true);
+ } else {
+ $this->internallink($link, $link);
+ }
}
/**
* Render a page local link
*
- * @param string $hash hash link identifier
- * @param string $name name for the link
+ * @param string $hash hash link identifier
+ * @param string $name name for the link
+ * @param bool $returnonly whether to return html or write to doc attribute
*/
- function locallink($hash, $name = null) {
+ function locallink($hash, $name = null, $returnonly = false) {
global $ID;
$name = $this->_getLinkTitle($name, $hash, $isImage);
$hash = $this->_headerToLink($hash);
$title = $ID.' ↵';
- $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
- $this->doc .= $name;
- $this->doc .= '</a>';
+
+ $doc = '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
+ $doc .= $name;
+ $doc .= '</a>';
+
+ if($returnonly) {
+ return $doc;
+ } else {
+ $this->doc .= $doc;
+ }
}
/**
@@ -884,10 +897,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
/**
* Render an external link
*
- * @param string $url full URL with scheme
- * @param string|array $name name for the link, array for media file
+ * @param string $url full URL with scheme
+ * @param string|array $name name for the link, array for media file
+ * @param bool $returnonly whether to return html or write to doc attribute
*/
- function externallink($url, $name = null) {
+ function externallink($url, $name = null, $returnonly = false) {
global $conf;
$name = $this->_getLinkTitle($name, $url, $isImage);
@@ -900,7 +914,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
// is there still an URL?
if(!$url) {
- $this->doc .= $name;
+ if($returnonly) {
+ return $name;
+ } else {
+ $this->doc .= $name;
+ }
return;
}
@@ -926,7 +944,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
//output formatted
- $this->doc .= $this->_formatLink($link);
+ if($returnonly) {
+ return $this->_formatLink($link);
+ } else {
+ $this->doc .= $this->_formatLink($link);
+ }
}
/**
@@ -934,12 +956,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
*
* You may want to use $this->_resolveInterWiki() here
*
- * @param string $match original link - probably not much use
- * @param string|array $name name for the link, array for media file
- * @param string $wikiName indentifier (shortcut) for the remote wiki
- * @param string $wikiUri the fragment parsed from the original link
+ * @param string $match original link - probably not much use
+ * @param string|array $name name for the link, array for media file
+ * @param string $wikiName indentifier (shortcut) for the remote wiki
+ * @param string $wikiUri the fragment parsed from the original link
+ * @param bool $returnonly whether to return html or write to doc attribute
*/
- function interwikilink($match, $name = null, $wikiName, $wikiUri) {
+ function interwikilink($match, $name = null, $wikiName, $wikiUri, $returnonly = false) {
global $conf;
$link = array();
@@ -977,16 +1000,21 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['title'] = htmlspecialchars($link['url']);
//output formatted
- $this->doc .= $this->_formatLink($link);
+ if($returnonly) {
+ return $this->_formatLink($link);
+ } else {
+ $this->doc .= $this->_formatLink($link);
+ }
}
/**
* Link to windows share
*
- * @param string $url the link
- * @param string|array $name name for the link, array for media file
+ * @param string $url the link
+ * @param string|array $name name for the link, array for media file
+ * @param bool $returnonly whether to return html or write to doc attribute
*/
- function windowssharelink($url, $name = null) {
+ function windowssharelink($url, $name = null, $returnonly = false) {
global $conf;
//simple setup
@@ -1010,7 +1038,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['url'] = $url;
//output formatted
- $this->doc .= $this->_formatLink($link);
+ if($returnonly) {
+ return $this->_formatLink($link);
+ } else {
+ $this->doc .= $this->_formatLink($link);
+ }
}
/**
@@ -1018,10 +1050,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
*
* Honors $conf['mailguard'] setting
*
- * @param string $address Email-Address
- * @param string|array $name name for the link, array for media file
+ * @param string $address Email-Address
+ * @param string|array $name name for the link, array for media file
+ * @param bool $returnonly whether to return html or write to doc attribute
*/
- function emaillink($address, $name = null) {
+ function emaillink($address, $name = null, $returnonly = false) {
global $conf;
//simple setup
$link = array();
@@ -1053,7 +1086,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['title'] = $title;
//output formatted
- $this->doc .= $this->_formatLink($link);
+ if($returnonly) {
+ return $this->_formatLink($link);
+ } else {
+ $this->doc .= $this->_formatLink($link);
+ }
}
/**