diff options
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/handler.php | 28 | ||||
-rw-r--r-- | inc/parser/lexer.php | 25 | ||||
-rw-r--r-- | inc/parser/metadata.php | 19 | ||||
-rw-r--r-- | inc/parser/renderer.php | 13 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 141 |
5 files changed, 160 insertions, 66 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php index a1040d12e..d96a01a60 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -71,6 +71,7 @@ class Doku_Handler { */ function plugin($match, $state, $pos, $pluginname){ $data = array($match); + /** @var DokuWiki_Syntax_Plugin $plugin */ $plugin = plugin_load('syntax',$pluginname); if($plugin != null){ $data = $plugin->handle($match, $state, $pos, $this); @@ -711,6 +712,9 @@ class Doku_Handler_CallWriter { var $Handler; + /** + * @param Doku_Handler $Handler + */ function Doku_Handler_CallWriter(& $Handler) { $this->Handler = & $Handler; } @@ -747,7 +751,7 @@ class Doku_Handler_Nest { /** * constructor * - * @param object $CallWriter the renderers current call writer + * @param Doku_Handler_CallWriter $CallWriter the renderers current call writer * @param string $close closing instruction name, this is required to properly terminate the * syntax mode if the document ends without a closing pattern */ @@ -805,6 +809,8 @@ class Doku_Handler_List { var $listCalls = array(); var $listStack = array(); + const NODE = 1; + function Doku_Handler_List(& $CallWriter) { $this->CallWriter = & $CallWriter; } @@ -856,7 +862,8 @@ class Doku_Handler_List { $depth = $this->interpretSyntax($call[1][0], $listType); $this->initialDepth = $depth; - $this->listStack[] = array($listType, $depth); + // array(list type, current depth, index of current listitem_open) + $this->listStack[] = array($listType, $depth, 1); $this->listCalls[] = array('list'.$listType.'_open',array(),$call[2]); $this->listCalls[] = array('listitem_open',array(1),$call[2]); @@ -881,6 +888,7 @@ class Doku_Handler_List { function listOpen($call) { $depth = $this->interpretSyntax($call[1][0], $listType); $end = end($this->listStack); + $key = key($this->listStack); // Not allowed to be shallower than initialDepth if ( $depth < $this->initialDepth ) { @@ -897,6 +905,9 @@ class Doku_Handler_List { $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]); $this->listCalls[] = array('listcontent_open',array(),$call[2]); + // new list item, update list stack's index into current listitem_open + $this->listStack[$key][2] = count($this->listCalls) - 2; + // Switched list type... } else { @@ -908,7 +919,7 @@ class Doku_Handler_List { $this->listCalls[] = array('listcontent_open',array(),$call[2]); array_pop($this->listStack); - $this->listStack[] = array($listType, $depth); + $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2); } //------------------------------------------------------------------------ @@ -920,7 +931,10 @@ class Doku_Handler_List { $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]); $this->listCalls[] = array('listcontent_open',array(),$call[2]); - $this->listStack[] = array($listType, $depth); + // set the node/leaf state of this item's parent listitem_open to NODE + $this->listCalls[$this->listStack[$key][2]][1][1] = self::NODE; + + $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2); //------------------------------------------------------------------------ // Getting shallower ( $depth < $end[1] ) @@ -934,6 +948,7 @@ class Doku_Handler_List { while (1) { $end = end($this->listStack); + $key = key($this->listStack); if ( $end[1] <= $depth ) { @@ -946,6 +961,9 @@ class Doku_Handler_List { $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]); $this->listCalls[] = array('listcontent_open',array(),$call[2]); + // new list item, update list stack's index into current listitem_open + $this->listStack[$key][2] = count($this->listCalls) - 2; + } else { // Switching list type... $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]); @@ -954,7 +972,7 @@ class Doku_Handler_List { $this->listCalls[] = array('listcontent_open',array(),$call[2]); array_pop($this->listStack); - $this->listStack[] = array($listType, $depth); + $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2); } break; diff --git a/inc/parser/lexer.php b/inc/parser/lexer.php index 2e84eca7c..b46a5f505 100644 --- a/inc/parser/lexer.php +++ b/inc/parser/lexer.php @@ -56,12 +56,12 @@ class Doku_LexerParallelRegex { /** * Adds a pattern with an optional label. * - * @param mixed $pattern Perl style regex. Must be UTF-8 + * @param mixed $pattern Perl style regex. Must be UTF-8 * encoded. If its a string, the (, ) * lose their meaning unless they * form part of a lookahead or * lookbehind assertation. - * @param string $label Label of regex to be returned + * @param bool|string $label Label of regex to be returned * on a match. Label must be ASCII * @access public */ @@ -151,7 +151,8 @@ class Doku_LexerParallelRegex { * "or" operator. Caches the regex. * Will automatically escape (, ) and / tokens. * - * @param array $patterns List of patterns in order. + * @internal array $_patterns List of patterns in order. + * @return null|string * @access private */ function _getCompoundedRegex() { @@ -297,6 +298,7 @@ class Doku_Lexer { */ function Doku_Lexer(&$parser, $start = "accept", $case = false) { $this->_case = $case; + /** @var Doku_LexerParallelRegex[] _regexes */ $this->_regexes = array(); $this->_parser = &$parser; $this->_mode = new Doku_LexerStateStack($start); @@ -425,11 +427,13 @@ class Doku_Lexer { * Sends the matched token and any leading unmatched * text to the parser changing the lexer to a new * mode if one is listed. - * @param string $unmatched Unmatched leading portion. - * @param string $matched Actual token match. - * @param string $mode Mode after match. A boolean + * @param string $unmatched Unmatched leading portion. + * @param string $matched Actual token match. + * @param bool|string $mode Mode after match. A boolean * false mode causes no change. - * @param int $pos Current byte index location in raw doc + * @param int $initialPos + * @param int $matchPos + * Current byte index location in raw doc * thats being parsed * @return boolean False if there was any error * from the parser. @@ -498,11 +502,12 @@ class Doku_Lexer { * Calls the parser method named after the current * mode. Empty content will be ignored. The lexer * has a parser handler for each mode in the lexer. - * @param string $content Text parsed. - * @param boolean $is_match Token is recognised rather + * @param string $content Text parsed. + * @param boolean $is_match Token is recognised rather * than unparsed data. - * @param int $pos Current byte index location in raw doc + * @param int $pos Current byte index location in raw doc * thats being parsed + * @return bool * @access private */ function _invokeParser($content, $is_match, $pos) { diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 25bf3fe3d..ac8fd2130 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -165,7 +165,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { if(!isset($this->meta['title'])) $this->meta['title'] = $text; // add the header to the TOC - $hid = $this->_headerToLink($text, 'true'); + $hid = $this->_headerToLink($text, true); $this->toc_additem($hid, $text, $level); // add to summary @@ -251,8 +251,9 @@ class Doku_Renderer_metadata extends Doku_Renderer { * Open a list item * * @param int $level the nesting level + * @param bool $node true when a node; false when a leaf */ - function listitem_open($level) { + function listitem_open($level,$node=false) { $this->cdata(str_repeat(DOKU_TAB, $level).'* '); } @@ -421,8 +422,8 @@ class Doku_Renderer_metadata extends Doku_Renderer { /** * keep track of internal links in $this->meta['relation']['references'] * - * @param string $id page ID to link to. eg. 'wiki:syntax' - * @param string|array $name name for the link, array for media file + * @param string $id page ID to link to. eg. 'wiki:syntax' + * @param string|array|null $name name for the link, array for media file */ function internallink($id, $name = null) { global $ID; @@ -458,8 +459,8 @@ class Doku_Renderer_metadata 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|null $name name for the link, array for media file */ function externallink($url, $name = null) { if(is_array($name)) { @@ -628,9 +629,9 @@ class Doku_Renderer_metadata extends Doku_Renderer { * Construct a title and handle images in titles * * @author Harry Fuecks <hfuecks@gmail.com> - * @param string|array $title either string title or media array - * @param string $default default title if nothing else is found - * @param null|string $id linked page id (used to extract title from first heading) + * @param string|array|null $title either string title or media array + * @param string $default default title if nothing else is found + * @param null|string $id linked page id (used to extract title from first heading) * @return string title text */ function _getLinkTitle($title, $default, $id = null) { diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 09294539e..e1d28267a 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -190,7 +190,7 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * Render plain text data * - * @param $text + * @param string $text */ function cdata($text) { } @@ -343,8 +343,9 @@ class Doku_Renderer extends DokuWiki_Plugin { * Open a list item * * @param int $level the nesting level + * @param bool $node true when a node; false when a leaf */ - function listitem_open($level) { + function listitem_open($level,$node=false) { } /** @@ -759,6 +760,9 @@ class Doku_Renderer extends DokuWiki_Plugin { * casing and special chars * * @author Andreas Gohr <andi@splitbrain.org> + * + * @param string $name + * @return string */ function _simpleTitle($name) { global $conf; @@ -778,6 +782,11 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * Resolve an interwikilink + * + * @param string $shortcut identifier for the interwiki link + * @param string $reference fragment that refers the content + * @param null|bool $exists reference which returns if an internal page exists + * @return string interwikilink */ function _resolveInterWiki(&$shortcut, $reference, &$exists = null) { //get interwiki URL diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 5c0353688..f1703111e 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -28,6 +28,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /** @var array A stack of section edit data */ protected $sectionedits = array(); + var $date_at = ''; // link pages and media against this revision /** @var int last section edit id, used by startSectionEdit */ protected $lastsecid = 0; @@ -58,10 +59,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /** * Register a new edit section range * - * @param $type string The section type identifier - * @param $title string The section title - * @param $start int The byte position for the edit start - * @return string A marker class for the starting HTML element + * @param string $type The section type identifier + * @param string $title The section title + * @param int $start The byte position for the edit start + * @return string A marker class for the starting HTML element + * * @author Adrian Lang <lang@cosmocode.de> */ public function startSectionEdit($start, $type, $title = null) { @@ -72,8 +74,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /** * Finish an edit section range * - * @param $end int The byte position for the edit end; null for the rest of - * the page + * @param int $end The byte position for the edit end; null for the rest of the page + * * @author Adrian Lang <lang@cosmocode.de> */ public function finishSectionEdit($end = null) { @@ -455,9 +457,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * Open a list item * * @param int $level the nesting level + * @param bool $node true when a node; false when a leaf */ - function listitem_open($level) { - $this->doc .= '<li class="level'.$level.'">'; + function listitem_open($level, $node=false) { + $branching = $node ? ' node' : ''; + $this->doc .= '<li class="level'.$level.$branching.'">'; } /** @@ -818,8 +822,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $default = $this->_simpleTitle($id); // now first resolve and clean up the $id - resolve_pageid(getNS($ID), $id, $exists); + resolve_pageid(getNS($ID), $id, $exists, $this->date_at, true); + $link = array(); $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); if(!$isImage) { if($exists) { @@ -846,11 +851,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['pre'] = '<span class="curid">'; $link['suf'] = '</span>'; } - $link['more'] = ''; - $link['class'] = $class; - $link['url'] = wl($id, $params); - $link['name'] = $name; - $link['title'] = $id; + $link['more'] = ''; + $link['class'] = $class; + if($this->date_at) { + $params['at'] = $this->date_at; + } + $link['url'] = wl($id, $params); + $link['name'] = $name; + $link['title'] = $id; //add search string if($search) { ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&'; @@ -904,6 +912,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } //prepare for formating + $link = array(); $link['target'] = $conf['target']['extern']; $link['style'] = ''; $link['pre'] = ''; @@ -981,6 +990,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { global $conf; //simple setup + $link = array(); $link['target'] = $conf['target']['windows']; $link['pre'] = ''; $link['suf'] = ''; @@ -995,6 +1005,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['title'] = $this->_xmlEntities($url); $url = str_replace('\\', '/', $url); + $url = ltrim($url,'/'); $url = 'file:///'.$url; $link['url'] = $url; @@ -1062,7 +1073,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $height = null, $cache = null, $linking = null, $return = false) { global $ID; list($src, $hash) = explode('#', $src, 2); - resolve_mediaid(getNS($ID), $src, $exists); + resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true); $noLink = false; $render = ($linking == 'linkonly') ? false : true; @@ -1070,7 +1081,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext, $mime) = mimetype($src, false); if(substr($mime, 0, 5) == 'image' && $render) { - $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), ($linking == 'direct')); + $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct')); } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { // don't link movies $noLink = true; @@ -1078,7 +1089,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // add file icons $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); $link['class'] .= ' mediafile mf_'.$class; - $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true); + $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), true); if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')'; } @@ -1109,9 +1120,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @param int $height height of media in pixel * @param string $cache cache|recache|nocache * @param string $linking linkonly|detail|nolink + * @param bool $return return HTML instead of adding to $doc */ function externalmedia($src, $title = null, $align = null, $width = null, - $height = null, $cache = null, $linking = null) { + $height = null, $cache = null, $linking = null, $return = false) { list($src, $hash) = explode('#', $src, 2); $noLink = false; $render = ($linking == 'linkonly') ? false : true; @@ -1135,8 +1147,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if($hash) $link['url'] .= '#'.$hash; //output formatted - if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; - else $this->doc .= $this->_formatLink($link); + if($return) { + if($linking == 'nolink' || $noLink) return $link['name']; + else return $this->_formatLink($link); + } else { + if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; + else $this->doc .= $this->_formatLink($link); + } } /** @@ -1430,7 +1447,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $title; } //add image tag - $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache)).'"'; + $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src))).'"'; $ret .= ' class="media'.$align.'"'; if($title) { @@ -1565,7 +1582,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * Returns HTML code for images used in link titles * * @author Andreas Gohr <andi@splitbrain.org> - * @param string $img + * @param array $img * @return string HTML img tag or similar */ function _imageTitle($img) { @@ -1575,7 +1592,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // see internalmedia() and externalmedia() list($img['src']) = explode('#', $img['src'], 2); if($img['type'] == 'internalmedia') { - resolve_mediaid(getNS($ID), $img['src'], $exists); + resolve_mediaid(getNS($ID), $img['src'], $exists ,$this->date_at, true); } return $this->_media( @@ -1638,13 +1655,22 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(!$atts['width']) $atts['width'] = 320; if(!$atts['height']) $atts['height'] = 240; - // prepare alternative formats - $extensions = array('webm', 'ogv', 'mp4'); - $alternatives = media_alternativefiles($src, $extensions); - $poster = media_alternativefiles($src, array('jpg', 'png'), true); - $posterUrl = ''; - if(!empty($poster)) { - $posterUrl = ml(reset($poster), '', true, '&'); + $posterUrl = ''; + $files = array(); + $isExternal = media_isexternal($src); + + if ($isExternal) { + // take direct source for external files + list(/*ext*/, $srcMime) = mimetype($src); + $files[$srcMime] = $src; + } else { + // prepare alternative formats + $extensions = array('webm', 'ogv', 'mp4'); + $files = media_alternativefiles($src, $extensions); + $poster = media_alternativefiles($src, array('jpg', 'png')); + if(!empty($poster)) { + $posterUrl = ml(reset($poster), '', true, '&'); + } } $out = ''; @@ -1655,13 +1681,19 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $fallback = ''; // output source for each alternative video format - foreach($alternatives as $mime => $file) { - $url = ml($file, '', true, '&'); + foreach($files as $mime => $file) { + if ($isExternal) { + $url = $file; + $linkType = 'externalmedia'; + } else { + $url = ml($file, '', true, '&'); + $linkType = 'internalmedia'; + } $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) - $fallback .= $this->internalmedia($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); + $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); } // finish @@ -1679,11 +1711,19 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @param array $atts - additional attributes for the <audio> tag * @return string */ - function _audio($src, $atts = null) { + function _audio($src, $atts = array()) { + $files = array(); + $isExternal = media_isexternal($src); - // prepare alternative formats - $extensions = array('ogg', 'mp3', 'wav'); - $alternatives = media_alternativefiles($src, $extensions); + if ($isExternal) { + // take direct source for external files + list(/*ext*/, $srcMime) = mimetype($src); + $files[$srcMime] = $src; + } else { + // prepare alternative formats + $extensions = array('ogg', 'mp3', 'wav'); + $files = media_alternativefiles($src, $extensions); + } $out = ''; // open audio tag @@ -1691,13 +1731,19 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $fallback = ''; // output source for each alternative audio format - foreach($alternatives as $mime => $file) { - $url = ml($file, '', true, '&'); + foreach($files as $mime => $file) { + if ($isExternal) { + $url = $file; + $linkType = 'externalmedia'; + } else { + $url = ml($file, '', true, '&'); + $linkType = 'internalmedia'; + } $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; // alternative content (just a link to the file) - $fallback .= $this->internalmedia($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); + $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); } // finish @@ -1705,6 +1751,21 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $out .= '</audio>'.NL; return $out; } + + /** + * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media() + * which returns an existing media revision less or equal to rev or date_at + * + * @author lisps + * @param string $media_id + * @access protected + * @return string revision ('' for current) + */ + function _getLastMediaRevisionAt($media_id){ + if(!$this->date_at || media_isexternal($media_id)) return ''; + $pagelog = new MediaChangeLog($media_id); + return $pagelog->getLastRevisionAt($this->date_at); + } #endregion } |