diff --git a/doku.php b/doku.php index 113c2c7c2762044af6ad8620ab24501c39d7a9e6..0d7fe667a00838f6d6fe6f33460b658a8b27f01a 100644 --- a/doku.php +++ b/doku.php @@ -13,7 +13,6 @@ require_once(DOKU_INC.'inc/common.php'); require_once(DOKU_INC.'inc/pageutils.php'); require_once(DOKU_INC.'inc/html.php'); - require_once(DOKU_INC.'inc/parser.php'); require_once(DOKU_INC.'lang/en/lang.php'); require_once(DOKU_INC.'lang/'.$conf['lang'].'/lang.php'); require_once(DOKU_INC.'inc/auth.php'); diff --git a/inc/common.php b/inc/common.php index 9223b22e44b89f414c3ff306d4163b7f0eb86691..6d0a28ebb21956dd465c8632b560388f7eb97fd9 100644 --- a/inc/common.php +++ b/inc/common.php @@ -11,6 +11,7 @@ require_once(DOKU_INC.'inc/io.php'); require_once(DOKU_INC.'inc/utf8.php'); require_once(DOKU_INC.'inc/mail.php'); + require_once(DOKU_INC.'inc/parserutils.php'); /** * Return info about the current document as associative @@ -46,6 +47,7 @@ function pageinfo(){ $REV = ''; } } + $info['rev'] = $REV; if($info['exists']){ $info['writable'] = (is_writable($info['filepath']) && ($info['perm'] >= AUTH_EDIT)); @@ -358,23 +360,6 @@ function formText($text){ return htmlspecialchars($text); } -/** - * Returns the specified local text in parsed format - * - * @author Andreas Gohr <andi@splitbrain.org> - */ -function parsedLocale($id){ - //disable section editing - global $parser; - $se = $parser['secedit']; - $parser['secedit'] = false; - //fetch parsed locale - $html = io_cacheParse(localeFN($id)); - //reset section editing - $parser['secedit'] = $se; - return $html; -} - /** * Returns the specified local text in raw format * @@ -384,46 +369,6 @@ function rawLocale($id){ return io_readFile(localeFN($id)); } - -/** - * Returns the parsed Wikitext for the given id and revision. - * - * If $excuse is true an explanation is returned if the file - * wasn't found - * - * @author Andreas Gohr <andi@splitbrain.org> - */ -function parsedWiki($id,$rev='',$excuse=true){ - $file = wikiFN($id,$rev); - $ret = ''; - - //ensure $id is in global $ID (needed for parsing) - global $ID; - $ID = $id; - - if($rev){ - if(@file_exists($file)){ - $ret = parse(io_readFile($file)); - }elseif($excuse){ - $ret = parsedLocale('norev'); - } - }else{ - if(@file_exists($file)){ - if(!defined('DOKU_USENEWPARSER')){ - $ret = io_cacheParse($file); - }else{ - msg('using new parser'); - require_once(DOKU_INC.'inc/parser/action.php'); - $ret = render_as_xhtml(parse_to_instructions(io_readFile($file))); - } - }elseif($excuse){ - $ret = parsedLocale('newpage'); - } - } - - return $ret; -} - /** * Returns the raw WikiText * diff --git a/inc/format.php b/inc/format.php index d703d78ad2f9bc7a37dea78ae9111343c6183e57..0a20b566c523d72ef0a37460a8501962dc1fde24 100644 --- a/inc/format.php +++ b/inc/format.php @@ -7,6 +7,8 @@ * @deprecated part of the XHTML renderer */ +trigger_error('deprecated parser.php included'); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); require_once(DOKU_INC.'conf/dokuwiki.php'); require_once(DOKU_INC.'inc/common.php'); diff --git a/inc/html.php b/inc/html.php index 70ebc1f76d47cefd12b25cd625d487b3b8ab4d1f..8cac264b1b5912cd3472c8524d5f0a6d6d019f98 100644 --- a/inc/html.php +++ b/inc/html.php @@ -7,7 +7,6 @@ */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); - require_once(DOKU_INC.'inc/format.php'); /** * Convenience function to quickly build a wikilink @@ -52,7 +51,7 @@ function html_login(){ global $conf; global $ID; - print parsedLocale('login'); + print p_locale_xhtml('login'); ?> <div align="center"> <form action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" method="post"> @@ -144,7 +143,7 @@ function html_secedit_button($section,$p){ */ function html_secedit($text,$show=true){ global $INFO; - if($INFO['writable'] && $show){ + if($INFO['writable'] && $show && !$INFO['rev']){ $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e', "html_secedit_button('\\1',true)", $text); @@ -270,13 +269,13 @@ function html_show($text=''){ if ($text){ //PreviewHeader - print parsedLocale('preview'); + print p_locale_xhtml('preview'); print '<div class="preview">'; print html_secedit(parse($text),false); print '</div>'; }else{ - if ($REV) print parsedLocale('showrev'); - $html = parsedWiki($ID,$REV,true); + if ($REV) print p_locale_xhtml('showrev'); + $html = p_wiki_xhtml($ID,$REV,true); $html = html_secedit($html); print html_hilight($html,$HIGH); } @@ -308,7 +307,7 @@ function html_search(){ global $ID; global $lang; - print parsedLocale('searchpage'); + print p_locale_xhtml('searchpage'); flush(); //show progressbar @@ -372,7 +371,7 @@ function html_locked($ip){ $expire = @date($conf['dformat'], $locktime + $conf['locktime'] ); $min = round(($conf['locktime'] - (time() - $locktime) )/60); - print parsedLocale('locked'); + print p_locale_xhtml('locked'); print '<ul>'; print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>'; print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>'; @@ -392,7 +391,7 @@ function html_revisions(){ $revisions = getRevisions($ID); $date = @date($conf['dformat'],$INFO['lastmod']); - print parsedLocale('revisions'); + print p_locale_xhtml('revisions'); print '<ul>'; if($INFO['exists']){ print '<li>'; @@ -437,7 +436,7 @@ function html_recent(){ global $conf; $recents = getRecents(0,true); - print parsedLocale('recent'); + print p_locale_xhtml('recent'); print '<ul>'; foreach(array_keys($recents) as $id){ $date = date($conf['dformat'],$recents[$id]['date']); @@ -470,7 +469,7 @@ function html_index($ns){ } $ns = utf8_encodeFN(str_replace(':','/',$ns)); - print parsedLocale('index'); + print p_locale_xhtml('index'); $data = array(); search($data,$conf['datadir'],'search_index',array('ns' => $ns)); @@ -599,7 +598,7 @@ function html_backlinks(){ $opts['name'] = $ID; } - print parsedLocale('backlinks'); + print p_locale_xhtml('backlinks'); $data = array(); search($data,$conf['datadir'],'search_backlinks',$opts); @@ -642,7 +641,7 @@ function html_diff($text='',$intro=true){ $lang['current']; } $tdf = new TableDiffFormatter(); - if($intro) print parsedLocale('diff'); + if($intro) print p_locale_xhtml('diff'); ?> <table class="diff" width="100%"> <tr> @@ -667,7 +666,7 @@ function html_conflict($text,$summary){ global $ID; global $lang; - print parsedLocale('conflict'); + print p_locale_xhtml('conflict'); ?> <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>"> <input type="hidden" name="id" value="<?=$ID?>" /> @@ -709,7 +708,7 @@ function html_register(){ global $lang; global $ID; - print parsedLocale('register'); + print p_locale_xhtml('register'); ?> <div align="center"> <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>"> @@ -776,10 +775,10 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed? $wr = $INFO['writable']; if($wr){ - if ($REV) print parsedLocale('editrev'); - print parsedLocale($include); + if ($REV) print p_locale_xhtml('editrev'); + print p_locale_xhtml($include); }else{ - print parsedLocale('read'); + print p_locale_xhtml('read'); $ro='readonly="readonly"'; } if(!$DATE) $DATE = $INFO['lastmod']; @@ -952,7 +951,7 @@ function html_admin(){ global $ID; global $lang; - print parsedLocale('admin'); + print p_locale_xhtml('admin'); ptln('<ul class="admin">'); diff --git a/inc/io.php b/inc/io.php index b0b834f9d7321a44948eb4e0cc9905271e6c48c0..f62dba88b03f114b6dada1f985c1646fa1bf8511 100644 --- a/inc/io.php +++ b/inc/io.php @@ -8,13 +8,13 @@ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); require_once(DOKU_INC.'inc/common.php'); - require_once(DOKU_INC.'inc/parser.php'); /** * Returns the parsed text from the given sourcefile. Uses cache * if exists. Creates it if not. * * @author Andreas Gohr <andi@splitbrain.org> + * @deprecated -> parserutils */ function io_cacheParse($file){ global $conf; diff --git a/inc/parser.php b/inc/parser.php index 4854ac0fbe825d2091bf3cc4b3682ceda445136d..8f4a188b7b419017bc4cbc7a2805e061397c7744 100644 --- a/inc/parser.php +++ b/inc/parser.php @@ -7,6 +7,8 @@ * @deprecated replaced by the new parser */ +trigger_error('deprecated parser.php included'); + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); include_once(DOKU_INC.'inc/common.php'); include_once(DOKU_INC.'inc/html.php'); diff --git a/inc/parser/action.php b/inc/parser/action.php deleted file mode 100644 index 4426c1ac59c278ba6f74f4a20f9669e829b80e9a..0000000000000000000000000000000000000000 --- a/inc/parser/action.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php -/** - * - * @todo maybe wrap in class - * @todo rename to helper - */ - -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); - -require_once(DOKU_INC.'inc/confutils.php'); - -/** - * turns a page into a list of instructions - * - * @author Harry Fuecks <hfuecks@gmail.com> - * @author Andreas Gohr <andi@splitbrain.org> - */ -function parse_to_instructions($text){ - global $conf; - - require_once DOKU_INC . 'inc/parser/parser.php'; - - // Create the parser - $Parser = & new Doku_Parser(); - - // Add the Handler - $Parser->Handler = & new Doku_Handler(); - - // Load all the modes - $Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock()); - $Parser->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); - $Parser->addMode('notoc',new Doku_Parser_Mode_NoToc()); - $Parser->addMode('header',new Doku_Parser_Mode_Header()); - $Parser->addMode('table',new Doku_Parser_Mode_Table()); - - $formats = array ( - 'strong', 'emphasis', 'underline', 'monospace', - 'subscript', 'superscript', 'deleted', - ); - foreach ( $formats as $format ) { - $Parser->addMode($format,new Doku_Parser_Mode_Formatting($format)); - } - - $Parser->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); - $Parser->addMode('footnote',new Doku_Parser_Mode_Footnote()); - $Parser->addMode('hr',new Doku_Parser_Mode_HR()); - - $Parser->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); - $Parser->addMode('php',new Doku_Parser_Mode_PHP()); - $Parser->addMode('html',new Doku_Parser_Mode_HTML()); - $Parser->addMode('code',new Doku_Parser_Mode_Code()); - $Parser->addMode('file',new Doku_Parser_Mode_File()); - $Parser->addMode('quote',new Doku_Parser_Mode_Quote()); - - $Parser->addMode('smiley',new Doku_Parser_Mode_Smiley(array_keys(getSmileys()))); - $Parser->addMode('acronym',new Doku_Parser_Mode_Acronym(array_keys(getAcronyms()))); - #$Parser->addMode('wordblock',new Doku_Parser_Mode_Wordblock(getBadWords())); - $Parser->addMode('entity',new Doku_Parser_Mode_Entity(array_keys(getEntities()))); - - $Parser->addMode('multiplyentity',new Doku_Parser_Mode_MultiplyEntity()); - $Parser->addMode('quotes',new Doku_Parser_Mode_Quotes()); - - if($conf['camelcase']){ - $Parser->addMode('camelcaselink',new Doku_Parser_Mode_CamelCaseLink()); - } - - $Parser->addMode('internallink',new Doku_Parser_Mode_InternalLink()); - $Parser->addMode('rss',new Doku_Parser_Mode_RSS()); - $Parser->addMode('media',new Doku_Parser_Mode_Media()); - $Parser->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); - $Parser->addMode('email',new Doku_Parser_Mode_Email()); - $Parser->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); - //$Parser->addMode('filelink',new Doku_Parser_Mode_FileLink()); //FIXME ??? - $Parser->addMode('eol',new Doku_Parser_Mode_Eol()); - - // Do the parsing - return $Parser->parse($text); -} - -/** - * Renders a list of instruction to XHTML - * - * @author Harry Fuecks <hfuecks@gmail.com> - * @author Andreas Gohr <andi@splitbrain.org> - */ -function render_as_xhtml($instructions){ - -#dbg($instructions); - - // Create the renderer - require_once DOKU_INC . 'inc/parser/xhtml.php'; - $Renderer = & new Doku_Renderer_XHTML(); - - $Renderer->smileys = getSmileys(); - $Renderer->entities = getEntities(); - $Renderer->acronyms = getAcronyms(); - $Renderer->interwiki = getInterwiki(); - #$Renderer->badwords = getBadWords(); - - // Loop through the instructions - foreach ( $instructions as $instruction ) { - // Execute the callback against the Renderer - call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]); - } - // Return the output - return $Renderer->doc; -} - -//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/parserutils.php b/inc/parserutils.php new file mode 100644 index 0000000000000000000000000000000000000000..efda5c85bb6732c5a55b80939269a4f7c52e6947 --- /dev/null +++ b/inc/parserutils.php @@ -0,0 +1,240 @@ +<?php +/** + * Utilities for collecting data from config files + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Harry Fuecks <hfuecks@gmail.com> + * @author Andreas Gohr <andi@splitbrain.org> + */ + + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + + require_once(DOKU_INC.'inc/confutils.php'); + require_once(DOKU_INC.'inc/pageutils.php'); + +/** + * Returns the parsed Wikitext in XHTML for the given id and revision. + * + * If $excuse is true an explanation is returned if the file + * wasn't found + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function p_wiki_xhtml($id, $rev='', $excuse=true){ + $file = wikiFN($id,$rev); + $ret = ''; + + //ensure $id is in global $ID (needed for parsing) + global $ID; + $ID = $id; + + if($rev){ + if(@file_exists($file)){ + $ret = p_render_xhtml(p_get_instructions($file)); //no caching on old revisions + }elseif($excuse){ + $ret = p_locale_xhtml('norev'); + } + }else{ + if(@file_exists($file)){ + $ret = p_cached_xhtml($file); + }elseif($excuse){ + $ret = p_locale_xhtml('newpage'); + } + } + + return $ret; +} + +/** + * Returns the specified local text in parsed format + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function p_locale_xhtml($id){ + //fetch parsed locale + $html = p_cached_xhtml(localeFN($id)); + return $html; +} + +/** + * Returns the given file parsed to XHTML + * + * Uses and creates a cachefile + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function p_cached_xhtml($file){ + global $conf; + $cache = $conf['datadir'].'/_cache/xhtml/'; + $cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT']); + + // check if cache can be used + $cachetime = @filemtime($cache); // 0 if not exists + + if( @file_exists($file) // does the source exist + && $cachetime > @filemtime($file) // cache is fresh + && ((time() - $cachetime) < $conf['cachetime']) // and is cachefile young enough + && !isset($_REQUEST['purge']) // no purge param was set + + && ($cachetime > @filemtime(DOKU_INC.'conf/dokuwiki.php')) // newer than the config file + && ($cachetime > @filemtime(DOKU_INC.'conf/local.php')) // newer than the local config file + && ($cachetime > @filemtime(DOKU_INC.'inc/parser/xhtml.php')) // newer than the renderer + && ($cachetime > @filemtime(DOKU_INC.'inc/parser/parser.php')) // newer than the parser + && ($cachetime > @filemtime(DOKU_INC.'inc/parser/handler.php')))// newer than the handler + { + //well then use the cache + $parsed = io_readfile($cache); + $parsed .= "\n<!-- cachefile $cache used -->\n"; + }else{ + $parsed = p_render_xhtml(p_cached_instructions($file)); //try to use cached instructions + io_saveFile($cache,$parsed); //save cachefile + $parsed .= "\n<!-- no cachefile used, but created -->\n"; + + /* FIXME add nocache directive handling like this: + if($parser['cache']){ + io_saveFile($cache,$parsed); //save cachefile + $parsed .= "\n<!-- no cachefile used, but created -->\n"; + }else{ + @unlink($cache); //try to delete cachefile + $parsed .= "\n<!-- no cachefile used, caching forbidden -->\n"; + } + */ + } + + return $parsed; +} + +/** + * Returns the render instructions for a file + * + * Uses and creates a serialized cache file + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function p_cached_instructions($file){ + global $conf; + $cache = $conf['datadir'].'/_cache/instructions/'; + $cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT']); + + // check if cache can be used + $cachetime = @filemtime($cache); // 0 if not exists + + if( @file_exists($file) // does the source exist + && $cachetime > @filemtime($file) // cache is fresh + && !isset($_REQUEST['purge']) // no purge param was set + && ($cachetime > @filemtime(DOKU_INC.'conf/dokuwiki.php')) // newer than the config file + && ($cachetime > @filemtime(DOKU_INC.'conf/local.php')) // newer than the local config file + && ($cachetime > @filemtime(DOKU_INC.'inc/parser/parser.php')) // newer than the parser + && ($cachetime > @filemtime(DOKU_INC.'inc/parser/handler.php')))// newer than the handler + { + //well then use the cache + return unserialize(io_readfile($cache)); + }elseif(@file_exists($file)){ + // no cache - do some work + $ins = p_get_instructions($file); + io_savefile($cache,serialize($ins)); + return $ins; + } + + return NULL; +} + +/** + * turns a page into a list of instructions + * + * @author Harry Fuecks <hfuecks@gmail.com> + * @author Andreas Gohr <andi@splitbrain.org> + */ +function p_get_instructions($file){ + global $conf; + + $text = io_readfile($file); + + require_once DOKU_INC . 'inc/parser/parser.php'; + + // Create the parser + $Parser = & new Doku_Parser(); + + // Add the Handler + $Parser->Handler = & new Doku_Handler(); + + // Load all the modes + $Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock()); + $Parser->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); + $Parser->addMode('notoc',new Doku_Parser_Mode_NoToc()); + $Parser->addMode('header',new Doku_Parser_Mode_Header()); + $Parser->addMode('table',new Doku_Parser_Mode_Table()); + + $formats = array ( + 'strong', 'emphasis', 'underline', 'monospace', + 'subscript', 'superscript', 'deleted', + ); + foreach ( $formats as $format ) { + $Parser->addMode($format,new Doku_Parser_Mode_Formatting($format)); + } + + $Parser->addMode('linebreak',new Doku_Parser_Mode_Linebreak()); + $Parser->addMode('footnote',new Doku_Parser_Mode_Footnote()); + $Parser->addMode('hr',new Doku_Parser_Mode_HR()); + + $Parser->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); + $Parser->addMode('php',new Doku_Parser_Mode_PHP()); + $Parser->addMode('html',new Doku_Parser_Mode_HTML()); + $Parser->addMode('code',new Doku_Parser_Mode_Code()); + $Parser->addMode('file',new Doku_Parser_Mode_File()); + $Parser->addMode('quote',new Doku_Parser_Mode_Quote()); + + $Parser->addMode('smiley',new Doku_Parser_Mode_Smiley(array_keys(getSmileys()))); + $Parser->addMode('acronym',new Doku_Parser_Mode_Acronym(array_keys(getAcronyms()))); + #$Parser->addMode('wordblock',new Doku_Parser_Mode_Wordblock(getBadWords())); + $Parser->addMode('entity',new Doku_Parser_Mode_Entity(array_keys(getEntities()))); + + $Parser->addMode('multiplyentity',new Doku_Parser_Mode_MultiplyEntity()); + $Parser->addMode('quotes',new Doku_Parser_Mode_Quotes()); + + if($conf['camelcase']){ + $Parser->addMode('camelcaselink',new Doku_Parser_Mode_CamelCaseLink()); + } + + $Parser->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $Parser->addMode('rss',new Doku_Parser_Mode_RSS()); + $Parser->addMode('media',new Doku_Parser_Mode_Media()); + $Parser->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); + $Parser->addMode('email',new Doku_Parser_Mode_Email()); + $Parser->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); + //$Parser->addMode('filelink',new Doku_Parser_Mode_FileLink()); //FIXME ??? + $Parser->addMode('eol',new Doku_Parser_Mode_Eol()); + + // Do the parsing + return $Parser->parse($text); +} + +/** + * Renders a list of instruction to XHTML + * + * @author Harry Fuecks <hfuecks@gmail.com> + * @author Andreas Gohr <andi@splitbrain.org> + */ +function p_render_xhtml($instructions){ + if(is_null($instructions)) return ''; + + // Create the renderer + require_once DOKU_INC . 'inc/parser/xhtml.php'; + $Renderer = & new Doku_Renderer_XHTML(); + + $Renderer->smileys = getSmileys(); + $Renderer->entities = getEntities(); + $Renderer->acronyms = getAcronyms(); + $Renderer->interwiki = getInterwiki(); + #$Renderer->badwords = getBadWords(); + + // Loop through the instructions + foreach ( $instructions as $instruction ) { + // Execute the callback against the Renderer + call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]); + } + // Return the output + return $Renderer->doc; +} + +//Setup VIM: ex: et ts=2 enc=utf-8 :