From: Geoffrey T. D. <da...@us...> - 2001-02-14 05:22:11
|
Update of /cvsroot/phpwiki/phpwiki/lib In directory usw-pr-cvs1:/tmp/cvs-serv4186/lib Modified Files: editpage.php interwiki.php loadsave.php prepend.php savepage.php stdlib.php transform.php Log Message: log Index: editpage.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/editpage.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** editpage.php 2001/02/13 05:54:38 1.12 --- editpage.php 2001/02/14 05:22:49 1.13 *************** *** 68,72 **** 'name' => 'minor_edit', 'value' => 'yes', ! 'checked' => ($do_archive == 'probably'))); } --- 68,72 ---- 'name' => 'minor_edit', 'value' => 'yes', ! 'checked' => ($do_archive == 'maybe'))); } Index: interwiki.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/interwiki.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** interwiki.php 2001/02/12 01:43:10 1.2 --- interwiki.php 2001/02/14 05:22:49 1.3 *************** *** 26,57 **** list( $wiki, $page ) = split( ":", $link ); ! $url = $interwikimap[$wiki] . urlencode($page); ! return LinkURL($url, $linktext ? $linktext : $link); } // Link InterWiki links // These can be protected by a '!' like Wiki words. ! function wtt_interwikilinks($line, &$trfrm) { global $InterWikiLinkRegexp, $WikiNameRegexp; - - $n = $ntok = $trfrm->tokencounter; - - // FIXME: perhaps WikiNameRegexp is a bit too restrictive? - $line = wt_tokenize($line, "!?(?<![A-Za-z0-9])$InterWikiLinkRegexp:$WikiNameRegexp", - $trfrm->replacements, $ntok); - while ($n < $ntok) { - $old = $trfrm->replacements[$n]; - if ($old[0] == '!') { - $trfrm->replacements[$n] = substr($old,1); - } else { - $trfrm->replacements[$n] = LinkInterWikiLink($old); - } - $n++; - } ! $trfrm->tokencounter = $ntok; ! return $line; } --- 26,53 ---- list( $wiki, $page ) = split( ":", $link ); ! $url = $interwikimap[$wiki] . urlencode($page); ! ! if ($linktext) ! $linktext = htmlspecialchars($linktext); ! else ! $linktext = Element('span', array('class' => 'interwiki'), ! htmlspecialchars("$wiki:") . ! QElement('span', array('class' => 'wikiword'), $page)); ! ! return Element('a', array('href' => $url, ! 'class' => 'interwikilink'), ! $linktext); } // Link InterWiki links // These can be protected by a '!' like Wiki words. ! function wtt_interwikilinks($match, &$trfrm) { global $InterWikiLinkRegexp, $WikiNameRegexp; ! if ($match[0] == "!") ! return htmlspecialchars(substr($match,1)); ! return LinkInterWikiLink($match); } Index: loadsave.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/loadsave.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** loadsave.php 2001/02/13 05:54:38 1.2 --- loadsave.php 2001/02/14 05:22:49 1.3 *************** *** 373,379 **** echo "<dl>\n"; ! LoadAny($dbi, SearchPath(WIKI_PGSRC)); if ($LANG != "C") ! LoadAny($dbi, SearchPath(DEFAULT_WIKI_PGSRC), $GenericPages); echo "</dl>\n"; --- 373,381 ---- echo "<dl>\n"; ! $ignore = array(gettext('RecentChanges')); ! ! LoadAny($dbi, SearchPath(WIKI_PGSRC), false, $ignore); if ($LANG != "C") ! LoadAny($dbi, SearchPath(DEFAULT_WIKI_PGSRC), $GenericPages, $ignore); echo "</dl>\n"; Index: prepend.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/prepend.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** prepend.php 2001/02/13 05:54:38 1.1 --- prepend.php 2001/02/14 05:22:49 1.2 *************** *** 2,6 **** /* lib/prepend.php * ! * Things which must be done before all else. */ $RCS_IDS = ''; --- 2,6 ---- /* lib/prepend.php * ! * Things which must be done and defined before anything else. */ $RCS_IDS = ''; *************** *** 113,116 **** --- 113,135 ---- PostponeErrorMessages(E_ALL); + + + function SearchPath ($file, $missing_ok = false, $path = false) + { + if (ereg('^/', $file)) + return $file; // absolute path. + + if (!$path) + $path = $GLOBALS['DataPath']; + + while (list($i, $dir) = each($path)) + { + if (file_exists("$dir/$file")) + return "$dir/$file"; + } + if ($missing_ok) + return false; + ExitWiki("$file: file not found"); + } // For emacs users Index: savepage.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/savepage.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** savepage.php 2001/02/13 05:54:38 1.12 --- savepage.php 2001/02/14 05:22:49 1.13 *************** *** 77,81 **** // create page header $html = sprintf(gettext("Thank you for editing %s."), ! WikiURL($pagename)); $html .= "<br>\n"; --- 77,81 ---- // create page header $html = sprintf(gettext("Thank you for editing %s."), ! LinkExistingWikiWord($pagename)); $html .= "<br>\n"; Index: stdlib.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/stdlib.php,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -r1.29 -r1.30 *** stdlib.php 2001/02/13 05:54:38 1.29 --- stdlib.php 2001/02/14 05:22:49 1.30 *************** *** 42,62 **** } - function SearchPath ($file, $missing_ok = false, $path = false) - { - if (ereg('^/', $file)) - return $file; // absolute path. - - if (!$path) - $path = $GLOBALS['DataPath']; - - while (list($i, $dir) = each($path)) - { - if (file_exists("$dir/$file")) - return "$dir/$file"; - } - if ($missing_ok) - return false; - ExitWiki("$file: file not found"); - } function arrays_equal ($a, $b) --- 42,45 ---- *************** *** 70,76 **** } - - - function DataURL($url) { --- 53,56 ---- *************** *** 106,109 **** --- 86,106 ---- } + function StartTag($tag, $args = '') + { + $s = ''; + if (is_array($args)) + { + while (list($key, $val) = each($args)) + { + if (is_string($val) || is_numeric($val)) + $s .= sprintf(' %s="%s"', $key, htmlspecialchars($val)); + else if ($val) + $s .= " $key"; + } + } + return "<$tag $s>"; + } + + define('NO_END_TAG_PAT', '/^' . join('|', array('area', 'base', 'basefont', *************** *** 112,137 **** 'isindex', 'link', 'meta', 'param')) . '$/i'); ! function Element($tag, $args = '', $content = '') { $html = "<$tag"; ! if (is_array($args)) { - while (list($key, $val) = each($args)) - { - if (is_string($val) || is_numeric($val)) - $html .= sprintf(' %s="%s"', $key, htmlspecialchars($val)); - else if ($val) - $html .= " $key"; - } - } - else $content = $args; ! ! $html .= '>'; if (!preg_match(NO_END_TAG_PAT, $tag)) { $html .= $content; ! $html .= "</$tag>\n";//FIXME: newline might not always be desired. } return $html; --- 109,126 ---- 'isindex', 'link', 'meta', 'param')) . '$/i'); ! function Element($tag, $args = '', $content = '') { $html = "<$tag"; ! if (!is_array($args)) { $content = $args; ! $args = false; ! } ! $html = StartTag($tag, $args); if (!preg_match(NO_END_TAG_PAT, $tag)) { $html .= $content; ! $html .= "</$tag>";//FIXME: newline might not always be desired. } return $html; *************** *** 154,175 **** return "<b><u>BAD URL -- remove all of <, >, "</u></b>"; } ! return QElement('a', array('href' => $url), ($linktext ? $linktext : $url)); } ! function LinkExistingWikiWord($wikiword, $linktext='', $class = 'wikiword') { return Element('a', array('href' => WikiURL($wikiword), ! 'class' => $class), ! $linktext ? $linktext : $wikiword); } ! function LinkUnknownWikiWord($wikiword, $linktext='', $class = 'unknownwikiword') { if (empty($linktext)) ! $linktext = $wikiword; ! return Element('span', array('class' => 'unknownwikiword'), ! QElement('u', array('class' => 'unknownwikiword'), $linktext) . QElement('a', array('href' => WikiURL($wikiword, array('action' => 'edit')), ! 'class' => 'unknownwikiword'), '?')); } --- 143,180 ---- return "<b><u>BAD URL -- remove all of <, >, "</u></b>"; } ! ! ! if (empty($linktext)) ! $linktext = QElement('span', array('class' => 'rawurl'), $url); ! else ! $linktext = htmlspecialchars($linktext); ! ! return Element('a', ! array('href' => $url, 'class' => 'linkurl'), ! $linktext); } ! function LinkExistingWikiWord($wikiword, $linktext='') { ! if (empty($linktext)) ! $linktext = QElement('span', array('class' => 'wikiword'), $wikiword); ! else ! $linktext = htmlspecialchars($linktext); ! return Element('a', array('href' => WikiURL($wikiword), ! 'class' => 'wikilink'), ! $linktext); } ! function LinkUnknownWikiWord($wikiword, $linktext='') { if (empty($linktext)) ! $linktext = QElement('span', array('class' => 'wikiword'), $wikiword); ! else ! $linktext = htmlspecialchars($linktext); ! return Element('span', array('class' => 'wikiunknown'), ! Element('u', $linktext) . QElement('a', array('href' => WikiURL($wikiword, array('action' => 'edit')), ! 'class' => 'wikiunknown'), '?')); } *************** *** 225,232 **** ! function MakeWikiForm ($pagename, $args, $button_text = '') { $formargs['action'] = USE_PATH_INFO ? WikiURL($pagename) : SCRIPT_NAME; $formargs['method'] = 'post'; $contents = ''; $input_seen = 0; --- 230,239 ---- ! function MakeWikiForm ($pagename, $args, $class, $button_text = '') { $formargs['action'] = USE_PATH_INFO ? WikiURL($pagename) : SCRIPT_NAME; $formargs['method'] = 'post'; + $formargs['class'] = $class; + $contents = ''; $input_seen = 0; *************** *** 264,268 **** return Element('form', $formargs, ! Element('table', Element('tr', $row))); } --- 271,275 ---- return Element('form', $formargs, ! Element('table', array('cellspacing' => 0, 'cellpadding' => 2, 'border' => 0), Element('tr', $row))); } *************** *** 301,320 **** } ! // FIXME: ug, don't like this ! ! if (!empty($args['action']) && !IsSafeAction($args['action'])) { // Don't allow administrative links on unlocked pages. global $pagehash; if (($pagehash['flags'] & FLAG_PAGE_LOCKED) == 0) ! return QElement('u', gettext('Lock page to enable link')); } // FIXME: ug, don't like this if (preg_match('/=\d*\(/', $qargs)) ! return MakeWikiForm($page, $args, $text); else ! return LinkURL(WikiURL($page, $args), $text ? $text : $url); } --- 308,344 ---- } + if ($args['action'] == 'browse') + unset($args['action']); ! if (empty($args['action'])) ! $class = 'wikilink'; ! else if (IsSafeAction($args['action'])) ! $class = 'wikiaction'; ! else { // Don't allow administrative links on unlocked pages. + // FIXME: Ugh: don't like this... global $pagehash; if (($pagehash['flags'] & FLAG_PAGE_LOCKED) == 0) ! return QElement('u', array('class' => 'wikiunsafe'), ! gettext('Lock page to enable link')); ! ! $class = 'wikiadmin'; } // FIXME: ug, don't like this if (preg_match('/=\d*\(/', $qargs)) ! return MakeWikiForm($page, $args, $class, $text); else ! { ! if ($text) ! $text = htmlspecialchars($text); ! else ! $text = QElement('span', array('class' => 'rawurl'), $url); ! ! return Element('a', array('href' => WikiURL($page, $args), ! 'class' => $class), ! $text); ! } } *************** *** 520,523 **** --- 544,548 ---- _dotoken('PAGE', htmlspecialchars($name), $page); _dotoken('LOGO', htmlspecialchars(DataURL($logo)), $page); + _dotoken('CSS_URL', htmlspecialchars(DataURL(CSS_URL)), $page); _dotoken('RCS_IDS', $GLOBALS['RCS_IDS'], $page); *************** *** 572,585 **** // this shouldn't be necessary, since PhpWiki loads // default pages if this is a new baby Wiki - if ($recentchanges == -1) { - $recentchanges = array(); - } - $now = time(); $today = date($dateformat, $now); if (date($dateformat, $recentchanges['lastmodified']) != $today) { $isNewDay = TRUE; - $recentchanges['lastmodified'] = $now; } else { $isNewDay = FALSE; --- 597,622 ---- // this shouldn't be necessary, since PhpWiki loads // default pages if this is a new baby Wiki $now = time(); $today = date($dateformat, $now); + if (!is_array($recentchanges)) { + $recentchanges = array('version' => 1, + 'created' => $now, + 'lastmodified' => $now - 48 * 4600, // force $isNewDay + 'flags' => FLAG_PAGE_LOCKED, + 'author' => $GLOBALS['user']->id()); + $recentchanges['content'] + = array(gettext("The most recently changed pages are listed below."), + '', + "____$today " . gettext("(first day for this Wiki)"), + '', + gettext("Quick title search:"), + '[phpwiki:?action=search&searchterm=()]', + '----'); + } + $recentchanges['lastmodified'] = $now; + if (date($dateformat, $recentchanges['lastmodified']) != $today) { $isNewDay = TRUE; } else { $isNewDay = FALSE; Index: transform.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/transform.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** transform.php 2001/02/12 01:43:10 1.15 --- transform.php 2001/02/14 05:22:49 1.16 *************** *** 1,7 **** <?php rcs_id('$Id$'); define('WT_TOKENIZER', 1); ! define('WT_SIMPLE_MARKUP', 2); ! define('WT_MODE_MARKUP', 3); define("ZERO_LEVEL", 0); --- 1,7 ---- <?php rcs_id('$Id$'); + define('WT_SIMPLE_MARKUP', 0); define('WT_TOKENIZER', 1); ! define('WT_MODE_MARKUP', 2); define("ZERO_LEVEL", 0); *************** *** 13,27 **** function WikiTransform() -- init ! function register($type, $function) Registers transformer functions This should be done *before* calling do_transform ! $type ... one of WT_TOKENIZER, WT_SIMPLE_MARKUP, WT_MODE_MARKUP ! Currently on WT_MODE_MARKUP has a special meaning. ! If one WT_MODE_MARKUP really sets the html mode, then all successive WT_MODE_MARKUP functions are skipped ! ! $function ... function name ! function SetHTMLMode($tag, $tagtype, $level) Wiki HTML output can, at any given time, be in only one mode. --- 13,35 ---- function WikiTransform() -- init ! function register($type, $function, [$regexp]) Registers transformer functions This should be done *before* calling do_transform ! $type: ! WT_MODE_MARKUP ! If one WT_MODE_MARKUP really sets the html mode, then all successive WT_MODE_MARKUP functions are skipped ! WT_TOKENIZER ! The transformer function is called once for each match ! of the $regexp in the line. The matched values are tokenized ! to protect them from further transformation. ! ! $function: function name ! ! $regexp: Required for WT_TOKENIZER functions. Optional for others. ! If given, the transformer function will only be called if the ! line matches the $regexp. ! function SetHTMLMode($tag, $tagtype, $level) Wiki HTML output can, at any given time, be in only one mode. *************** *** 32,35 **** --- 40,45 ---- $tag ... HTML tag to insert + If $tag is an array, first element give tag, second element + is a hash containing arguments for the tag. $tagtype ... ZERO_LEVEL - close all open tags before inserting $tag NESTED_LEVEL - close tags until depths match *************** *** 48,53 **** var $linenumber; // current linenumber var $replacements; // storage for tokenized strings of current line ! var $tokencounter; // counter of $replacements array ! // private variables var $content; // wiki markup, array of lines --- 58,64 ---- var $linenumber; // current linenumber var $replacements; // storage for tokenized strings of current line ! var $user_data; // can be used by the transformer functions ! // to store miscellaneous data. ! // private variables var $content; // wiki markup, array of lines *************** *** 64,70 **** // register transformation functions ! function register($type, $function) { ! $this->trfrm_func[] = array ($type, $function); } --- 75,81 ---- // register transformation functions ! function register($type, $function, $regexp = false) { ! $this->trfrm_func[] = array ($type, $function, $regexp); } *************** *** 73,80 **** function SetHTMLMode($tag, $tagtype, $level) { $this->mode_set = 1; // in order to prevent other mode markup // to be executed $retvar = ''; ! if ($tagtype == ZERO_LEVEL) { // empty the stack until $level == 0; --- 84,99 ---- function SetHTMLMode($tag, $tagtype, $level) { + if (is_array($tag)) { + $args = $tag[1]; + $tag = $tag[0]; + } + else { + $args = array(); + } + $this->mode_set = 1; // in order to prevent other mode markup // to be executed $retvar = ''; ! if ($tagtype == ZERO_LEVEL) { // empty the stack until $level == 0; *************** *** 88,92 **** if ($tag) { ! $retvar .= "<$tag>\n"; $this->stack->push($tag); } --- 107,111 ---- if ($tag) { ! $retvar .= StartTag($tag, $args) . "\n"; $this->stack->push($tag); } *************** *** 110,114 **** if ($tag != $this->stack->top()) { $closetag = $this->stack->pop(); ! $retvar .= "</$closetag><$tag>\n"; $this->stack->push($tag); } --- 129,133 ---- if ($tag != $this->stack->top()) { $closetag = $this->stack->pop(); ! $retvar .= "</$closetag>" . StartTag($tag, $args) . "\n"; $this->stack->push($tag); } *************** *** 118,122 **** // stack might be zero while ($this->stack->cnt() < $level) { ! $retvar .= "<$tag>\n"; $this->stack->push($tag); if ($this->stack->cnt() > 10) { --- 137,141 ---- // stack might be zero while ($this->stack->cnt() < $level) { ! $retvar .= StartTag($tag, $args) . "\n"; $this->stack->push($tag); if ($this->stack->cnt() > 10) { *************** *** 131,135 **** } ! return $retvar; } // end SetHTMLMode --- 150,154 ---- } ! return $this->token($retvar); } // end SetHTMLMode *************** *** 143,153 **** $this->content = $content; ! // Loop over all lines of the page and apply transformation rules $numlines = count($this->content); for ($lnum = 0; $lnum < $numlines; $lnum++) { ! $this->tokencounter = 0; ! $this->replacements = array(); $this->linenumber = $lnum; $line = $this->content[$lnum]; --- 162,173 ---- $this->content = $content; ! $this->replacements = array(); ! $this->user_data = array(); ! // Loop over all lines of the page and apply transformation rules $numlines = count($this->content); for ($lnum = 0; $lnum < $numlines; $lnum++) { ! $this->linenumber = $lnum; $line = $this->content[$lnum]; *************** *** 164,181 **** // tokenizers, markup, html mode, ... // functions are executed in order of registering ! for ($func = 0; $func < count($this->trfrm_func); $func++) { // if HTMLmode is already set then skip all following // WT_MODE_MARKUP functions ! if ($this->mode_set && ! ($this->trfrm_func[$func][0] == WT_MODE_MARKUP)) { continue; - } - // call registered function - $line = $this->trfrm_func[$func][1]($line, $this); - } ! // Replace tokens ($replacements was filled by wtt_* functions) ! for ($i = 0; $i < $this->tokencounter; $i++) { ! $line = str_replace($FieldSeparator.$FieldSeparator.$i.$FieldSeparator, $this->replacements[$i], $line); } --- 184,204 ---- // tokenizers, markup, html mode, ... // functions are executed in order of registering ! for (reset($this->trfrm_func); ! list($flags, $func, $regexp) = current($this->trfrm_func); ! next($this->trfrm_func)) { ! // if HTMLmode is already set then skip all following // WT_MODE_MARKUP functions ! if ($this->mode_set && ($flags & WT_MODE_MARKUP) != 0) continue; ! if (!empty($regexp) && !preg_match("/$regexp/", $line)) ! continue; ! ! // call registered function ! if (($flags & WT_TOKENIZER) != 0) ! $line = $this->tokenize($line, $regexp, $func); ! else ! $line = $func($line, $this); } *************** *** 185,210 **** $html .= $this->SetHTMLMode('', ZERO_LEVEL, 0); ! return $html; } // end do_transfrom() } // end class WikiTransform ! ////////////////////////////////////////////////////////// ! $transform = new WikiTransform; ! // register functions ! // functions are applied in order of registering ! $transform->register(WT_TOKENIZER, 'wtt_bracketlinks'); ! $transform->register(WT_TOKENIZER, 'wtt_urls'); ! if (function_exists('wtt_interwikilinks')) { ! $transform->register(WT_TOKENIZER, 'wtt_interwikilinks'); ! } ! $transform->register(WT_TOKENIZER, 'wtt_bumpylinks'); $transform->register(WT_SIMPLE_MARKUP, 'wtm_htmlchars'); $transform->register(WT_SIMPLE_MARKUP, 'wtm_linebreak'); --- 208,275 ---- $html .= $this->SetHTMLMode('', ZERO_LEVEL, 0); ! return $this->untokenize($html); } // end do_transfrom() + // Register a new token. + function token($repl) { + global $FieldSeparator; + $tok = $FieldSeparator . sizeof($this->replacements) . $FieldSeparator; + $this->replacements[] = $repl; + return $tok; + } + + // helper function which does actual tokenizing + function tokenize($str, $pattern, $func) { + // Find any strings in $str that match $pattern and + // store them in $orig, replacing them with tokens + // starting at number $ntokens - returns tokenized string + $new = ''; + while (preg_match("/^(.*?)($pattern)/", $str, $matches)) { + $str = substr($str, strlen($matches[0])); + $new .= $matches[1] . $this->token($func($matches[2], $this)); + } + return $new . $str; + } + + function untokenize($line) { + global $FieldSeparator; + + $chunks = explode ($FieldSeparator, "$line "); + $line = $chunks[0]; + for ($i = 1; $i < count($chunks); $i += 2) + { + $tok = $chunks[$i]; + $line .= $this->replacements[$tok] . $chunks[$i + 1]; + } + return $line; + } } // end class WikiTransform ! ////////////////////////////////////////////////////////// ! $transform = new WikiTransform; ! // register functions ! // functions are applied in order of registering ! $transform->register(WT_TOKENIZER, 'wtt_doublebrackets', '\[\['); ! $transform->register(WT_TOKENIZER, 'wtt_footnotes', '^\[\d+\]'); ! $transform->register(WT_TOKENIZER, 'wtt_footnoterefs', '\[\d+\]'); ! $transform->register(WT_TOKENIZER, 'wtt_bracketlinks', '\[.+?\]'); ! $transform->register(WT_TOKENIZER, 'wtt_urls', ! "!?\b($AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]"); ! ! if (function_exists('wtt_interwikilinks')) { ! $transform->register(WT_TOKENIZER, 'wtt_interwikilinks', ! "!?(?<![A-Za-z0-9])$InterWikiLinkRegexp:$WikiNameRegexp"); ! } ! $transform->register(WT_TOKENIZER, 'wtt_bumpylinks', "!?$WikiNameRegexp"); + if (function_exists('wtm_table')) { + $transform->register(WT_MODE_MARKUP, 'wtm_table', '^\|'); + } $transform->register(WT_SIMPLE_MARKUP, 'wtm_htmlchars'); $transform->register(WT_SIMPLE_MARKUP, 'wtm_linebreak'); *************** *** 224,228 **** $html = $transform->do_transform($html, $pagehash['content']); - /* Requirements for functions registered to WikiTransform: --- 289,292 ---- *************** *** 249,357 **** // Tokenizer functions - // helper function which does actual tokenizing and is - // called by other wtt_* functions - function wt_tokenize($str, $pattern, &$orig, &$ntokens) { - global $FieldSeparator; - // Find any strings in $str that match $pattern and - // store them in $orig, replacing them with tokens - // starting at number $ntokens - returns tokenized string - $new = ''; - while (preg_match("/^(.*?)($pattern)/", $str, $matches)) { - $linktoken = $FieldSeparator . $FieldSeparator . ($ntokens++) . $FieldSeparator; - $new .= $matches[1] . $linktoken; - $orig[] = $matches[2]; - $str = substr($str, strlen($matches[0])); - } - $new .= $str; - return $new; - } - ! // New linking scheme: links are in brackets. This will ! // emulate typical HTML linking as well as Wiki linking. ! function wtt_bracketlinks($line, &$trfrm) ! { ! static $footnotes = array(); ! // protecting [[ ! $n = $ntok = $trfrm->tokencounter; ! $line = wt_tokenize($line, '\[\[', $trfrm->replacements, $ntok); ! while ($n < $ntok) { ! $trfrm->replacements[$n++] = '['; ! } ! ! // match anything else between brackets ! $line = wt_tokenize($line, '\[.+?\]', $trfrm->replacements, $ntok); ! while ($n < $ntok) { ! $link = ParseAndLink($trfrm->replacements[$n]); ! if (strpos($link['type'], 'footnote') === false) { ! $trfrm->replacements[$n] = $link['link']; ! } else { ! $ftnt = $link['link']; ! if (isset($footnotes[$ftnt])) { ! $trfrm->replacements[$n] = "<A NAME=\"footnote-$ftnt\"></A><A HREF=\"#footnote-rev-$ftnt\">[$ftnt]</A>"; ! } else { // first encounter of [x] ! $trfrm->replacements[$n] = "<A NAME=\"footnote-rev-$ftnt\"></A><SUP><A HREF=\"#footnote-$ftnt\">[$ftnt]</A></SUP>"; ! $footnotes[$ftnt] = 1; ! } ! } ! $n++; ! } ! $trfrm->tokencounter = $ntok; ! return $line; } ! // replace all URL's with tokens, so we don't confuse them ! // with Wiki words later. Wiki words in URL's break things. ! // URLs preceeded by a '!' are not linked ! function wtt_urls($line, &$trfrm) ! { ! global $AllowedProtocols; ! $n = $ntok = $trfrm->tokencounter; ! $line = wt_tokenize($line, "!?\b($AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]", $trfrm->replacements, $ntok); ! while ($n < $ntok) { ! if($trfrm->replacements[$n][0] == '!') ! $trfrm->replacements[$n] = substr($trfrm->replacements[$n], 1); ! else ! $trfrm->replacements[$n] = LinkURL($trfrm->replacements[$n]); ! $n++; ! } ! $trfrm->tokencounter = $ntok; ! return $line; } ! - // Link Wiki words (BumpyText) - // Wikiwords preceeded by a '!' are not linked - function wtt_bumpylinks($line, &$trfrm) - { - global $WikiNameRegexp, $dbi; ! $n = $ntok = $trfrm->tokencounter; ! $line = wt_tokenize($line, "!?$WikiNameRegexp", $trfrm->replacements, $ntok); ! while ($n < $ntok) { ! $old = $trfrm->replacements[$n]; ! if ($old[0] == '!') { ! $trfrm->replacements[$n] = substr($old,1); ! } elseif (IsWikiPage($dbi, $old)) { ! $trfrm->replacements[$n] = LinkExistingWikiWord($old); ! } else { ! $trfrm->replacements[$n] = LinkUnknownWikiWord($old); ! } ! $n++; ! } ! $trfrm->tokencounter = $ntok; ! return $line; ! } ! // end of tokenizer functions ! ////////////////////////////////////////////////////////// --- 313,405 ---- // Tokenizer functions ! function wtt_doublebrackets($match, &$trfrm) ! { ! return '['; ! } ! function wtt_footnotes($match, &$trfrm) ! { ! // FIXME: should this set HTML mode? ! $ftnt = trim(substr($match,1,-1)) + 0; ! $fntext = "[$ftnt]"; ! $html = "<br>"; ! ! $fnlist = $trfrm->user_data['footnotes'][$ftnt]; ! if (!is_array($fnlist)) ! return $html . $fntext; ! ! $trfrm->user_data['footnotes'][$ftnt] = 'footnote_seen'; ! while (list($k, $anchor) = each($fnlist)) ! { ! $html .= Element("a", array("name" => "footnote-$ftnt", ! "href" => "#$anchor", ! "class" => "footnote-rev"), ! $fntext); ! $fntext = '+'; } + return $html; + } + function wtt_footnoterefs($match, &$trfrm) + { + $ftnt = trim(substr($match,1,-1)) + 0; ! $footnote_definition_seen = false; ! if (empty($trfrm->user_data['footnotes'])) ! $trfrm->user_data['footnotes'] = array(); ! if (empty($trfrm->user_data['footnotes'][$ftnt])) ! $trfrm->user_data['footnotes'][$ftnt] = array(); ! else if (!is_array($trfrm->user_data['footnotes'][$ftnt])) ! $footnote_definition_seen = true; ! ! $args['href'] = "#footnote-$ftnt"; ! if (!$footnote_definition_seen) ! { ! $args['name'] = "footrev-$ftnt-" . ! count($trfrm->user_data['footnotes'][$ftnt]); ! $trfrm->user_data['footnotes'][$ftnt][] = $args['name']; } ! ! return Element('sup', array('class' => 'footnote'), ! QElement("a", $args, "[$ftnt]")); ! } + function wtt_bracketlinks($match, &$trfrm) + { + $link = ParseAndLink($match); + return $link["link"]; + } ! // replace all URL's with tokens, so we don't confuse them ! // with Wiki words later. Wiki words in URL's break things. ! // URLs preceeded by a '!' are not linked ! function wtt_urls($match, &$trfrm) ! { ! if ($match[0] == "!") ! return htmlspecialchars(substr($match,1)); ! return LinkURL($match); ! } ! // Link Wiki words (BumpyText) ! // Wikiwords preceeded by a '!' are not linked ! function wtt_bumpylinks($match, &$trfrm) ! { ! global $dbi; ! if ($match[0] == "!") ! return htmlspecialchars(substr($match,1)); ! // FIXME: make a LinkWikiWord() function? ! if (IsWikiPage($dbi, $match)) ! return LinkExistingWikiWord($match); ! return LinkUnknownWikiWord($match); ! } ! // end of tokenizer functions ! ////////////////////////////////////////////////////////// *************** *** 491,494 **** --- 539,579 ---- return $line; } + + // markup for tables + function wtm_table($line, &$trfrm) + { + $row = ''; + while (preg_match('/^(\|+)(v*)([<>^]?)([^|]*)/', $line, $m)) + { + $line = substr($line, strlen($m[0])); + $td = array(); + + if (strlen($m[1]) > 1) + $td['colspan'] = strlen($m[1]); + if (strlen($m[2]) > 0) + $td['rowspan'] = strlen($m[2]) + 1; + + if ($m[3] == '<') + $td['align'] = 'left'; + else if ($m[3] == '>') + $td['align'] = 'right'; + else + $td['align'] = 'center'; + + $row .= $trfrm->token(StartTag('td', $td) . " "); + $row .= trim($m[4]); + $row .= $trfrm->token(" </td>"); + } + assert(empty($line)); + $row = $trfrm->token("<tr>") . $row . $trfrm->token("</tr>"); + + return $trfrm->SetHTMLMode(array('table', + array('align' => 'center', + 'cellpadding' => 1, + 'cellspacing' => 1, + 'border' => 1)), + ZERO_LEVEL, 0) . + $row; + } // four or more dashes to <hr> |