From 76d9b26bf9f75b108040af35d0408222c9f27065 Mon Sep 17 00:00:00 2001 From: dairiki Date: Fri, 8 Feb 2002 03:01:12 +0000 Subject: [PATCH] Transform API cleanup. Change from revision meta-data markup=new to markup=2.0 to indicate new markup. (For future growing room.) git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@1910 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/BlockParser.php | 32 ++++++--------- lib/InlineParser.php | 41 +++++++++++++++---- lib/display.php | 8 ++-- lib/editpage.php | 24 ++++------- lib/plugin/IncludePage.php | 13 ++---- lib/plugin/RecentChanges.php | 4 +- lib/stdlib.php | 79 +++++++++++++++++++++--------------- pgsrc/NewMarkupTestPage | 4 +- 8 files changed, 113 insertions(+), 92 deletions(-) diff --git a/lib/BlockParser.php b/lib/BlockParser.php index 7d939507b..70d0f4c99 100644 --- a/lib/BlockParser.php +++ b/lib/BlockParser.php @@ -1,4 +1,4 @@ - * * This file is part of PhpWiki. @@ -20,8 +20,6 @@ require_once('lib/HtmlElement.php'); require_once('lib/InlineParser.php'); -require_once('lib/transform.php'); - //////////////////////////////////////////////////////////////// // // @@ -916,11 +914,18 @@ class Block_p extends BlockMarkup +function TransformText ($text, $markup = 2.0) { + if (isa($text, 'WikiDB_PageRevision')) { + $rev = $text; + $text = $rev->getPackedContent(); + $markup = $rev->get('markup'); + } -// FIXME: This is temporary, too... -function NewTransform ($text) { - - //set_time_limit(5); + if (empty($markup) || $markup < 2.0) { + include_once("lib/transform.php"); + return do_transform($text); + //$text = ConvertOldMarkup($text); + } // Expand leading tabs. // FIXME: do this better. also move it... @@ -931,18 +936,7 @@ function NewTransform ($text) { return $output; } - -// FIXME: bad name -function TransformRevision ($revision) { - if ($revision->get('markup') == 'new') { - return NewTransform($revision->getPackedContent()); - } - else { - return do_transform($revision->getContent()); - } -} - - + // (c-file-style: "gnu") // Local Variables: // mode: php diff --git a/lib/InlineParser.php b/lib/InlineParser.php index 27d2d1be0..291c01f34 100644 --- a/lib/InlineParser.php +++ b/lib/InlineParser.php @@ -1,4 +1,4 @@ - * * This file is part of PhpWiki. @@ -349,11 +349,14 @@ class InlineTransformer var $_regexps = array(); var $_markup = array(); - function InlineTransformer () { - foreach (array('escape', 'bracketlink', 'url', - 'interwiki', 'wikiword', 'linebreak', - 'old_emphasis', 'nestled_emphasis', - 'html_emphasis') as $mtype) { + function InlineTransformer ($markup_types = false) { + if (!$markup_types) + $markup_types = array('escape', 'bracketlink', 'url', + 'interwiki', 'wikiword', 'linebreak', + 'old_emphasis', 'nestled_emphasis', + 'html_emphasis'); + + foreach ($markup_types as $mtype) { $class = "Markup_$mtype"; $this->_addMarkup(new $class); } @@ -431,10 +434,34 @@ class InlineTransformer } } +class LinkTransformer extends InlineTransformer +{ + function LinkTransformer () { + $this->InlineTransformer(array('escape', 'bracketlink', 'url', + 'interwiki', 'wikiword')); + } +} + function TransformInline($text) { static $trfm; - if (empty($trfm)) + + if (empty($trfm)) { $trfm = new InlineTransformer; + } + + return $trfm->parse($text); +} + +function TransformLinks($text, $markup = 2.0) { + static $trfm; + + if (empty($trfm)) { + $trfm = new LinkTransformer; + } + + if ($markup < 2.0) + $text = ConvertOldMarkup($text, 'links'); + return $trfm->parse($text); } diff --git a/lib/display.php b/lib/display.php index 62d68f876..dc3e0948e 100644 --- a/lib/display.php +++ b/lib/display.php @@ -1,10 +1,8 @@ getName(), ": ", $Theme->linkExistingWikiWord($pagename, false, $version)); - $template = Template('browse', array('CONTENT' => TransformRevision($actionrev))); + $template = Template('browse', array('CONTENT' => TransformText($actionrev))); GeneratePage($template, $pagetitle, $revision); flush(); @@ -88,7 +86,7 @@ function displayPage(&$request, $tmpl = 'browse') { $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); include_once('lib/BlockParser.php'); - $template = Template($tmpl, array('CONTENT' => TransformRevision($revision))); + $template = Template($tmpl, array('CONTENT' => TransformText($revision))); GeneratePage($template, $pagetitle, $revision, array('ROBOTS_META' => 'index,follow', diff --git a/lib/editpage.php b/lib/editpage.php index 7a650b4c0..6442c8153 100644 --- a/lib/editpage.php +++ b/lib/editpage.php @@ -1,5 +1,5 @@ setArg('version', false); include_once('lib/BlockParser.php'); $template = Template('savepage', - array('CONTENT' => TransformRevision($newrevision))); + array('CONTENT' => TransformText($newrevision))); if (!empty($warnings)) $template->replace('WARNINGS', $warnings); @@ -195,15 +195,8 @@ class PageEditor } function getPreview () { - if ($this->meta['markup'] == 'new') { - include_once('lib/BlockParser.php'); - $trfm = 'NewTransform'; - } - else { - include_once('lib/transform.php'); - $trfm = 'do_transform'; - } - return $trfm($this->_content); + include_once('lib/BlockParser.php'); + return TransformText($this->_content, $this->meta['markup']); } function getLockedMessage () { @@ -282,7 +275,7 @@ class PageEditor = HTML::input(array('type' => 'checkbox', 'name' => 'edit[markup]', 'value' => 'new', - 'checked' => $this->meta['markup'] == 'new')); + 'checked' => $this->meta['markup'] >= 2.0)); $el['LOCKED_CB'] = HTML::input(array('type' => 'checkbox', @@ -323,7 +316,7 @@ class PageEditor return false; // FIXME: some kind of warning? $is_new_markup = !empty($posted['markup']) && $posted['markup'] == 'new'; - $meta['markup'] = $is_new_markup ? 'new' : false; + $meta['markup'] = $is_new_markup ? 2.0: false; $meta['summary'] = trim(substr($posted['summary'], 0, 256)); $meta['locked'] = !empty($posted['locked']); $meta['is_minor_edit'] = !empty($posted['minor_edit']); @@ -363,10 +356,11 @@ class PageEditor // Default for new pages is new-style markup. if ($selected->hasDefaultContents()) - $this->meta['markup'] = 'new'; + $is_new_markup = true; else - $this->meta['markup'] = $selected->get('markup'); + $is_new_markup = $selected->get('markup') >= 2.0; + $this->meta['markup'] = $is_new_markup ? 2.0: false; $this->editaction = 'edit'; } } diff --git a/lib/plugin/IncludePage.php b/lib/plugin/IncludePage.php index 3c79aa660..e012a0bbe 100644 --- a/lib/plugin/IncludePage.php +++ b/lib/plugin/IncludePage.php @@ -1,13 +1,11 @@ * author: Joe Edelman */ -require_once('lib/transform.php'); - class WikiPlugin_IncludePage extends WikiPlugin { @@ -109,13 +107,8 @@ extends WikiPlugin array_push($included_pages, $page); - if ($r->get('markup') == 'new') { - include_once('lib/BlockParser.php'); - $content = NewTransform(implode("\n", $c)); - } - else { - $content = do_transform($c); - } + include_once('lib/BlockParser.php'); + $content = TransformText(implode("\n", $c), $r->get('markup')); array_pop($included_pages); diff --git a/lib/plugin/RecentChanges.php b/lib/plugin/RecentChanges.php index 544118ad9..4ea5b1b11 100644 --- a/lib/plugin/RecentChanges.php +++ b/lib/plugin/RecentChanges.php @@ -1,5 +1,5 @@ 'wiki-summary'), "[", - do_transform($summary, 'LinkTransform'), + TransformLinks($summary, $rev->get('markup')), "]"); } diff --git a/lib/stdlib.php b/lib/stdlib.php index 82a7b90c4..32942c42f 100644 --- a/lib/stdlib.php +++ b/lib/stdlib.php @@ -1,4 +1,4 @@ -\[\]\"'()]*[^\s<>\[\]\"'(),.?]"; - $bang_esc[] = $map->getRegexp() . ":[^\\s.,;?()]+"; // FIXME: is this really needed? - $bang_esc[] = $WikiNameRegexp; - $orig[] = '/!((?:' . join(')|(', $bang_esc) . '))/'; - $repl[] = '~\\1'; + if (empty($orig)) { + /***************************************************************** + * Conversions for inline markup: + */ - - /***************************************************************** - * Conversions for block markup - */ - // convert indented blocks to
.
-    $orig[] = '/^[ \t]+\S.*\n(?:(?:\s*\n)?^[ \t]+\S.*\n)*/m';
-    $repl[] = "
\n\\0
\n"; + // escape tilde's + $orig[] = '/~/'; + $repl[] = '~~'; + + // escape escaped brackets + $orig[] = '/\[\[/'; + $repl[] = '~['; - // convert lists - $orig[] = '/^([#*;]*)([*#]|;.*?:) */me'; - $repl[] = "_ConvertOldListMarkup('\\1', '\\2')"; + // change ! escapes to ~'s. + global $AllowedProtocols, $WikiNameRegexp, $request; + include_once('lib/interwiki.php'); + $map = InterWikiMap::GetMap($request); + $bang_esc[] = "(?:$AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]"; + $bang_esc[] = $map->getRegexp() . ":[^\\s.,;?()]+"; // FIXME: is this really needed? + $bang_esc[] = $WikiNameRegexp; + $orig[] = '/!((?:' . join(')|(', $bang_esc) . '))/'; + $repl[] = '~\\1'; + + + $link_orig = $orig; + $link_repl = $repl; + + /***************************************************************** + * Conversions for block markup + */ + // convert indented blocks to
.
+        $orig[] = '/^[ \t]+\S.*\n(?:(?:\s*\n)?^[ \t]+\S.*\n)*/m';
+        $repl[] = "
\n\\0
\n"; + + // convert lists + $orig[] = '/^([#*;]*)([*#]|;.*?:) */me'; + $repl[] = "_ConvertOldListMarkup('\\1', '\\2')"; + } - return preg_replace($orig, $repl, $text); + + if ($just_links) + return preg_replace($link_orig, $link_repl, $text); + else + return preg_replace($orig, $repl, $text); } diff --git a/pgsrc/NewMarkupTestPage b/pgsrc/NewMarkupTestPage index 78c184432..c8f9a0c9f 100644 --- a/pgsrc/NewMarkupTestPage +++ b/pgsrc/NewMarkupTestPage @@ -1,6 +1,6 @@ Date: Sun, 27 Jan 2002 17:28:55 -0500 Mime-Version: 1.0 (Produced by PhpWiki 1.3.2-jeffs-hacks) -X-Rcs-Id: $Id: NewMarkupTestPage,v 1.2 2002-01-28 00:57:14 carstenklapp Exp $ +X-Rcs-Id: $Id: NewMarkupTestPage,v 1.3 2002-02-08 03:01:12 dairiki Exp $ Content-Type: application/x-phpwiki; pagename=NewMarkupTestPage; author=JeffDairiki; @@ -8,7 +8,7 @@ Content-Type: application/x-phpwiki; flags=""; charset=iso-8859-1; author_id=JeffDairiki; - markup=new + markup=2.0 Content-Transfer-Encoding: binary New lists: asterisks, hash marks, and ";text:def" (wrong...) -- 2.45.0