From: Steve W. <sw...@pa...> - 2001-12-06 22:35:04
|
Can I do: <code> <script language="Javascript"> alert("hello sailor!); </script> </code> If so, this is a security breach... ~swain On Thu, 6 Dec 2001, Lawrence Akka wrote: > I have patched lib/transform.php (cvs as of today) to enable a new > formatting rule. > > A line beginning <code> will switch wiki formatting off, until a line > beginning </code> > > It is now easier to cut and paste large chunks of code into a wiki, without > all the ['s creating automatic links. > > In other words: > > test > <code> > This is a __wiki test__. $array['index'] > </code> > test > > will display as > > test > > This is a __wiki test__. $array['index'] > > test > > I would appreciate feedback on this: > > * Is it useful? > * Does it work? > * Should <code></code> be something else? > * Should it go into the cvs? > > At the moment I am aware of one problem - an extra blank line seems to be > inserted after the end of the code > > Thanks > > Lawrence Akka > > > Context diff follows: > > > *** transform.old.php Thu Dec 6 14:21:31 2001 > --- transform.php Thu Dec 6 14:29:43 2001 > *************** > *** 1,10 **** > ! <?php rcs_id('$Id: transform.php,v 1.27 2001/11/16 22:59:02 dairiki Exp $'); > require_once('lib/WikiPlugin.php'); > > define('WT_SIMPLE_MARKUP', 0); > define('WT_TOKENIZER', 1); > define('WT_MODE_MARKUP', 2); > ! > define("ZERO_LEVEL", 0); > define("NESTED_LEVEL", 1); > > --- 1,10 ---- > ! <?php rcs_id('$Id: transform.php,v 1.4 2001/11/27 10:44:32 lakka Exp $'); > require_once('lib/WikiPlugin.php'); > > define('WT_SIMPLE_MARKUP', 0); > define('WT_TOKENIZER', 1); > define('WT_MODE_MARKUP', 2); > ! define('WT_NO_MARKUP', 4); > define("ZERO_LEVEL", 0); > define("NESTED_LEVEL", 1); > > *************** > *** 15,20 **** > --- 15,21 ---- > var $replacements; // storage for tokenized strings of current line > var $user_data; // can be used by the transformer functions > // to store miscellaneous data. > + var $MarkupEnabled; // flag to determine whether markup shoud be > transformed. added by LA > > // private variables > var $content; // wiki markup, array of lines > *************** > *** 27,32 **** > --- 28,34 ---- > { > $this->trfrm_func = array(); > $this->stack = new Stack; > + $this->MarkupEnabled = 1; // Added by LA > } > > /** > *************** > *** 241,246 **** > --- 243,256 ---- > list($flags, $func, $regexp) = current($this->trfrm_func); > next($this->trfrm_func)) { > > + // if MarkupEnabled is not set then ignore all further markup, > + // except WT_NO_MARKUP functions (or we couldn't turn markup > + // back on again (!), and wtm_specialchars (to remove html) > + // Added by LA > + > + if (!$this->MarkupEnabled && !($flags & WT_NO_MARKUP) && $func != > 'wtm_htmlchars') > + continue; > + > // if HTMLmode is already set then skip all following > // WT_MODE_MARKUP functions > if ($this->mode_set && ($flags & WT_MODE_MARKUP) != 0) > *************** > *** 316,321 **** > --- 326,332 ---- > // register functions > // functions are applied in order of registering > > + $transform->register(WT_NO_MARKUP, 'wtm_no_markup', '^<code>|^<\/code>'); > //Added by LA > $transform->register(WT_SIMPLE_MARKUP, 'wtm_plugin_link'); > $transform->register(WT_MODE_MARKUP, 'wtm_plugin'); > > *************** > *** 643,648 **** > --- 654,673 ---- > function wtm_paragraph($line, &$trfrm) { > $line = $trfrm->SetHTMLMode('p') . $line; > return $line; > + } > + > + // No markup between <code>, </code>. Added by LA > + function wtm_no_markup($line, &$trfrm) { > + if (preg_match('/^<code>(.*)/', $line, $m)) { > + $trfrm->MarkupEnabled = 0; > + $line = $trfrm->SetHTMLMode('pre').$m[1]; > + echo 'on'; > + } elseif (preg_match('/^<\/code>(.*)/', $line, $m)) { > + $trfrm->MarkupEnabled = 1; > + $line = $trfrm->SetHTMLMode('',0).$m[1]; > + echo 'off'; > + } > + return $line; > } > > // (c-file-style: "gnu") > > > _______________________________________________ > Phpwiki-talk mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpwiki-talk > --- http://www.panix.com/~swain/ "Without music to decorate it, time is just a bunch of boring production deadlines or dates by which bills must be paid." -- Frank Zappa |