From 27bbdb8909764cf7cdd4be5ca8bd32b5ffae0a3b Mon Sep 17 00:00:00 2001 From: rurban Date: Sat, 20 Jan 2007 11:25:07 +0000 Subject: [PATCH] add SpellCheck support git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@5519 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/CachedMarkup.php | 21 ++++++++++++++++++++- lib/InlineParser.php | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/lib/CachedMarkup.php b/lib/CachedMarkup.php index 04aecf3ed..e61a52fee 100644 --- a/lib/CachedMarkup.php +++ b/lib/CachedMarkup.php @@ -1,5 +1,5 @@ * Copyright (C) 2004,2005,2006,2007 $ThePhpWikiProgrammingTeam * @@ -367,6 +367,22 @@ class Cached_WikiLinkIfKnown extends Cached_WikiLink return WikiLink($this->_page, 'if_known'); } } + +class Cached_SpellCheck extends Cached_WikiLink +{ + function Cached_SpellCheck ($word, $suggs) { + $this->_page = $word; + $this->suggestions = $suggs; + } + + function expand($basepage, &$markup) { + $link = HTML::a(array('class' => 'spell-wrong', + 'title' => 'SpellCheck: '.join(', ', $this->suggestions), + 'name' => $this->_page), + $this->_page); + return $link; + } +} class Cached_PhpwikiURL extends Cached_DynamicContent { @@ -711,6 +727,9 @@ class Cached_PluginInvocation extends Cached_DynamicContent { } // $Log: not supported by cvs2svn $ +// Revision 1.50 2007/01/07 18:41:51 rurban +// Fix fallback ZipReader syntax error. Use label=false. Add parsed plugin names to the stored tree. +// // Revision 1.49 2007/01/04 16:40:35 rurban // Remove units object from CachedMarkup links, Store parsed linkinfo only: basevalue, baseunit. // diff --git a/lib/InlineParser.php b/lib/InlineParser.php index c8831e29b..b68f292ef 100644 --- a/lib/InlineParser.php +++ b/lib/InlineParser.php @@ -1,5 +1,5 @@ * Copyright (C) 2004,2005,2006 Reini Urban * @@ -453,6 +453,25 @@ class Markup_bracketlink extends SimpleMarkup } } +class Markup_spellcheck extends SimpleMarkup +{ + function Markup_spellcheck () { + $this->suggestions = $GLOBALS['request']->getArg('suggestions'); + } + function getMatchRegexp () { + if (empty($this->suggestions)) + return "(?# false )"; + $words = array_keys($this->suggestions); + return "(?<= \W ) (?:" . join('|', $words) . ") (?= \W )"; + } + + function markup ($match) { + if (empty($this->suggestions) or empty($this->suggestions[$match])) + return $match; + return new Cached_SpellCheck(UnWikiEscape($match), $this->suggestions[$match]); + } +} + class Markup_url extends SimpleMarkup { function getMatchRegexp () { @@ -822,6 +841,8 @@ class InlineTransformer var $_markup = array(); function InlineTransformer ($markup_types = false) { + // We need to extend the inline parsers by certain actions, like SearchHighlight, + // SpellCheck and maybe CreateToc. if (!$markup_types) { $non_default = false; $markup_types = array @@ -833,6 +854,12 @@ class InlineTransformer ); if (DISABLE_MARKUP_WIKIWORD) $markup_types = array_remove($markup_types, 'wikiword'); + + $action = $GLOBALS['request']->getArg('action'); + if ($action == 'SpellCheck' and $GLOBALS['request']->getArg('suggestions')) + { // insert it after url + array_splice($markup_types, 2, 1, array('url','spellcheck')); + } } else { $non_default = true; } @@ -840,8 +867,7 @@ class InlineTransformer $class = "Markup_$mtype"; $this->_addMarkup(new $class); } - // This does not work yet - if (0 and ENABLE_MARKUP_DIVSPAN and !$non_default) + if (ENABLE_MARKUP_DIVSPAN and !$non_default) $this->_addMarkup(new Markup_html_divspan); if (ENABLE_MARKUP_COLOR and !$non_default) $this->_addMarkup(new Markup_color); @@ -964,8 +990,8 @@ class NowikiTransformer extends InlineTransformer function TransformInline($text, $markup = 2.0, $basepage=false) { static $trfm; - - if (empty($trfm)) { + $action = $GLOBALS['request']->getArg('action'); + if (empty($trfm) or $action == 'SpellCheck') { $trfm = new InlineTransformer; } @@ -1013,6 +1039,9 @@ function TransformInlineNowiki($text, $markup = 2.0, $basepage=false) { // $Log: not supported by cvs2svn $ +// Revision 1.85 2007/01/07 18:42:49 rurban +// Add support for non-bracket semantic relation parsing. Assert empty regex (interwikimap?) earlier. Change {{Template||}} vars handling to new style. Stricter interwikimap matching not to find semantic links +// // Revision 1.84 2007/01/02 13:18:07 rurban // fix semantic attributes syntax :=, not :-, disable DIVSPAN and PLUGIN_MARKUP_MAP // -- 2.45.0