From: <var...@us...> - 2014-11-20 15:18:16
|
Revision: 9349 http://sourceforge.net/p/phpwiki/code/9349 Author: vargenau Date: 2014-11-20 15:18:14 +0000 (Thu, 20 Nov 2014) Log Message: ----------- More abstraction Modified Paths: -------------- trunk/lib/BlockParser.php trunk/lib/InlineParser.php trunk/lib/WysiwygEdit.php Modified: trunk/lib/BlockParser.php =================================================================== --- trunk/lib/BlockParser.php 2014-11-20 13:27:16 UTC (rev 9348) +++ trunk/lib/BlockParser.php 2014-11-20 15:18:14 UTC (rev 9349) @@ -19,7 +19,6 @@ * with PhpWiki; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -//require_once('lib/HtmlElement.php'); require_once 'lib/CachedMarkup.php'; require_once 'lib/InlineParser.php'; @@ -143,7 +142,7 @@ $match->postmatch = substr($text, strlen($m[0])); $match->match = $m[1]; $match->regexp_ind = count($m) - 3 + $prevMatch->regexp_ind + 1; - ; + return $match; } } @@ -151,9 +150,8 @@ class BlockParser_Input { - function BlockParser_Input($text) + function __construct($text) { - // Expand leading tabs. // FIXME: do this better. // @@ -345,7 +343,7 @@ class Block_HtmlElement extends HtmlElement { - function Block_HtmlElement($tag /*, ... */) + function __construct($tag /*, ... */) { $this->_init(func_get_args()); } @@ -358,14 +356,14 @@ class ParsedBlock extends Block_HtmlElement { - function ParsedBlock(&$input, $tag = 'div', $attr = array()) + function __construct(&$input, $tag = 'div', $attr = array()) { - $this->Block_HtmlElement($tag, $attr); + parent::__construct($tag, $attr); $this->_initBlockTypes(); $this->_parse($input); } - function _parse(&$input) + private function _parse(&$input) { // php5 failed to advance the block. php5 copies objects by ref. // nextBlock == block, both are the same objects. So we have to clone it. @@ -384,7 +382,7 @@ } // FIXME: hackish. This should only be called once. - function _initBlockTypes() + private function _initBlockTypes() { // better static or global? static $_regexpset, $_block_types; @@ -419,7 +417,7 @@ } } - function _getBlock(&$input) + private function _getBlock(&$input) { $this->_atSpace = $input->skipSpace(); @@ -456,20 +454,20 @@ class WikiText extends ParsedBlock { - function WikiText($text) + function __construct($text) { $input = new BlockParser_Input($text); - $this->ParsedBlock($input); + parent::__construct($input); } } class SubBlock extends ParsedBlock { - function SubBlock(&$input, $indent_re, $initial_indent = false, - $tag = 'div', $attr = array()) + function __construct(&$input, $indent_re, $initial_indent = false, + $tag = 'div', $attr = array()) { $subinput = new BlockParser_InputSubBlock($input, $indent_re, $initial_indent); - $this->ParsedBlock($subinput, $tag, $attr); + parent::__construct($subinput, $tag, $attr); } } @@ -488,7 +486,7 @@ function __construct(&$input, $indent_re, $initial_indent = false, $tag = 'div', $attr = array()) { - $this->SubBlock($input, $indent_re, $initial_indent, $tag, $attr); + parent::__construct($input, $indent_re, $initial_indent, $tag, $attr); // If content is a single paragraph, eliminate the paragraph... if (count($this->_content) == 1) { @@ -691,7 +689,7 @@ $this->_tight_bot = $tight_bot; } - function _addToRow($item) + private function _addToRow($item) { if (empty($this->_accum)) { $this->_accum = HTML::td(); @@ -701,7 +699,7 @@ $this->_accum->pushContent($item); } - function _flushRow($tight_bottom = false) + private function _flushRow($tight_bottom = false) { if (!empty($this->_accum)) { $row = new Block_HtmlElement('tr', false, $this->_accum); @@ -715,7 +713,7 @@ } } - function _addSubtable($table) + private function _addSubtable($table) { if (!($table_rows = $table->getContent())) return; @@ -729,7 +727,7 @@ } } - function _setTerm($th) + private function _setTerm($th) { $first_row = &$this->_content[0]; if (is_a($first_row, 'Block_table_dl_defn')) @@ -738,7 +736,7 @@ $first_row->unshiftContent($th); } - function _ComputeNcols($defn) + private function _ComputeNcols($defn) { $ncols = 2; foreach ($defn as $item) { @@ -750,14 +748,14 @@ return $ncols; } - function _IsASubtable($item) + private function _IsASubtable($item) { return is_a($item, 'HtmlElement') && $item->getTag() == 'table' && $item->getAttr('class') == 'wiki-dl-table'; } - function _FirstDefn($subtable) + private function _FirstDefn($subtable) { $defs = $subtable->getContent(); return $defs[0]; Modified: trunk/lib/InlineParser.php =================================================================== --- trunk/lib/InlineParser.php 2014-11-20 13:27:16 UTC (rev 9348) +++ trunk/lib/InlineParser.php 2014-11-20 15:18:14 UTC (rev 9349) @@ -173,7 +173,8 @@ } // To overcome ANCHORED: // We could sort by longest match and iterate over these. - if (empty($matched)) return false; + if (empty($matched)) + return false; } $match = new RegexpSet_match; @@ -264,16 +265,11 @@ */ abstract class BalancedMarkup { - public $_start_regexp; - /** Get the starting regexp for this rule. * * @return string The starting regexp. */ - function getStartRegexp() - { - return $this->_start_regexp; - } + abstract function getStartRegexp(); /** Get the ending regexp for this rule. * @@ -281,10 +277,7 @@ * * @return string The ending regexp. */ - function getEndRegexp($match) - { - return $this->_end_regexp; - } + abstract function getEndRegexp($match); /** Get expansion for matching input. * @@ -347,8 +340,8 @@ preg_match('/(\#?) \[\s* (?: (.*?) \s* (?<!' . ESCAPE_CHAR . ')(\|) )? \s* (.+?) \s*\]/x', str_replace("\n", " ", $bracketlink), $matches); if (count($matches) < 4) { - trigger_error(_("Invalid [] syntax ignored") . _(": ") . $bracketlink, E_USER_WARNING); - return new Cached_Link; + return HTML::span(array('class' => 'error'), + _("Invalid [] syntax ignored") . _(": ") . $bracketlink); } list (, $hash, $label, $bar, $rawlink) = $matches; @@ -675,7 +668,10 @@ class Markup_wikicreole_italics extends BalancedMarkup { - public $_start_regexp = "\\/\\/"; + function getStartRegexp() + { + return "\\/\\/"; + } function getEndRegexp($match) { @@ -691,7 +687,10 @@ class Markup_wikicreole_bold extends BalancedMarkup { - public $_start_regexp = "\\*\\*"; + function getStartRegexp() + { + return "\\*\\*"; + } function getEndRegexp($match) { @@ -707,7 +706,10 @@ class Markup_wikicreole_monospace extends BalancedMarkup { - public $_start_regexp = "\\#\\#"; + function getStartRegexp() + { + return "\\#\\#"; + } function getEndRegexp($match) { @@ -722,7 +724,10 @@ class Markup_wikicreole_underline extends BalancedMarkup { - public $_start_regexp = "\\_\\_"; + function getStartRegexp() + { + return "\\_\\_"; + } function getEndRegexp($match) { @@ -738,7 +743,10 @@ class Markup_wikicreole_superscript extends BalancedMarkup { - public $_start_regexp = "\\^\\^"; + function getStartRegexp() + { + return "\\^\\^"; + } function getEndRegexp($match) { @@ -754,11 +762,14 @@ class Markup_wikicreole_subscript extends BalancedMarkup { - public $_start_regexp = ",,"; + function getStartRegexp() + { + return ",,"; + } function getEndRegexp($match) { - return $match; + return ",,"; } function markup($match, $body) @@ -770,11 +781,14 @@ class Markup_old_emphasis extends BalancedMarkup { - public $_start_regexp = "''"; + function getStartRegexp() + { + return "''"; + } function getEndRegexp($match) { - return $match; + return "''"; } function markup($match, $body) @@ -846,8 +860,10 @@ class Markup_html_emphasis extends BalancedMarkup { - public $_start_regexp = - "<(?: b|big|i|small|tt|em|strong|cite|code|dfn|kbd|samp|s|strike|del|var|sup|sub )>"; + function getStartRegexp() + { + return "<(?: b|big|i|small|tt|em|strong|cite|code|dfn|kbd|samp|s|strike|del|var|sup|sub )>"; + } function getEndRegexp($match) { @@ -866,9 +882,10 @@ class Markup_html_divspan extends BalancedMarkup { - public $_start_regexp = - "<(?: div|span )(?: \s[^>]*)?>"; - + function getStartRegexp() + { + return "<(?: div|span )(?: \s[^>]*)?>"; + } function getEndRegexp($match) { if (substr($match, 1, 4) == 'span') @@ -898,8 +915,12 @@ { //rurban: abbr|acronym need an optional title tag. //sf.net bug #728595 - public $_start_regexp = "<(?: abbr|acronym )(?: [^>]*)?>"; + function getStartRegexp() + { + return "<(?: abbr|acronym )(?: [^>]*)?>"; + } + function getEndRegexp($match) { if (substr($match, 1, 4) == 'abbr') @@ -933,9 +954,17 @@ class Markup_color extends BalancedMarkup { // %color=blue% blue text %% and back to normal - public $_start_regexp = "%color=(?: [^%]*)%"; - public $_end_regexp = "%%"; + function getStartRegexp() + { + return "%color=(?: [^%]*)%"; + } + + function getEndRegexp($match) + { + return "%%"; + } + function markup($match, $body) { $color = strtolower(substr($match, 7, -1)); @@ -1261,12 +1290,12 @@ public $_regexps = array(); public $_markup = array(); - function __construct($markup_types = false) + function __construct($markup_types = array()) { global $request; // We need to extend the inline parsers by certain actions, like SearchHighlight, // SpellCheck and maybe CreateToc. - if (!$markup_types) { + if (empty($markup_types)) { $non_default = false; $markup_types = array ('escape', 'wikicreolebracketlink', 'bracketlink', 'url', Modified: trunk/lib/WysiwygEdit.php =================================================================== --- trunk/lib/WysiwygEdit.php 2014-11-20 13:27:16 UTC (rev 9348) +++ trunk/lib/WysiwygEdit.php 2014-11-20 15:18:14 UTC (rev 9349) @@ -103,7 +103,10 @@ class Markup_html_p extends BalancedMarkup { - public $_start_regexp = "<(?:p|P)( class=\".*\")?>"; + function getStartRegexp() + { + return "<(?:p|P)( class=\".*\")?>"; + } function getEndRegexp($match) { @@ -119,7 +122,10 @@ //'<span style="font-weight: bold">text</span>' => '*text*' class Markup_html_spanbold extends BalancedMarkup { - public $_start_regexp = "<(?:span|SPAN) style=\"font-weight: bold\">"; + function getStartRegexp() + { + return "<(?:span|SPAN) style=\"font-weight: bold\">"; + } function getEndRegexp($match) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |