From: Arno H. <aho...@us...> - 2001-01-04 18:32:23
|
Update of /cvsroot/phpwiki/phpwiki/lib In directory usw-pr-cvs1:/tmp/cvs-serv8258 Modified Files: stdlib.php Log Message: moved UpdateRecentChanges() to savepage.php ZERO/SINGLE_DEPTH renamed into ZERO/NESTED_LEVEL added and corrected some comments, some code cleanup Index: stdlib.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/stdlib.php,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -r1.18 -r1.19 *** stdlib.php 2001/01/01 23:34:57 1.18 --- stdlib.php 2001/01/04 18:32:25 1.19 *************** *** 1,22 **** ! <?php ! rcs_id('$Id$'); /* Standard functions for Wiki functionality ! LinkRelatedPages($dbi, $pagename) ! GeneratePage($template, $content, $name, $hash) LinkExistingWikiWord($wikiword) LinkUnknownWikiWord($wikiword) ! LinkURL($url) ! LinkImage($url) ! RenderQuickSearch() ! RenderFullSearch() RenderMostPopular() CookSpaces($pagearray) ! class Stack SetHTMLOutputMode($newmode, $depth) UpdateRecentChanges($dbi, $pagename, $isnewpage) ParseAndLink($bracketlink) ExtractWikiPageLinks($content) ! ExitWiki($errormsg) */ --- 1,22 ---- ! <?php rcs_id('$Id$'); ! /* Standard functions for Wiki functionality ! ExitWiki($errormsg) LinkExistingWikiWord($wikiword) LinkUnknownWikiWord($wikiword) ! LinkURL($url, $linktext) ! LinkImage($url, $alt) ! RenderQuickSearch($value) ! RenderFullSearch($value) RenderMostPopular() CookSpaces($pagearray) ! class Stack (push(), pop(), cnt(), top()) SetHTMLOutputMode($newmode, $depth) UpdateRecentChanges($dbi, $pagename, $isnewpage) ParseAndLink($bracketlink) ExtractWikiPageLinks($content) ! LinkRelatedPages($dbi, $pagename) ! GeneratePage($template, $content, $name, $hash) */ *************** *** 42,171 **** - function LinkRelatedPages($dbi, $pagename) - { - // currently not supported everywhere - if(!function_exists('GetWikiPageLinks')) - return ''; - - $links = GetWikiPageLinks($dbi, $pagename); - - $txt = "<b>"; - $txt .= sprintf (gettext ("%d best incoming links:"), NUM_RELATED_PAGES); - $txt .= "</b>\n"; - for($i = 0; $i < NUM_RELATED_PAGES; $i++) { - if(isset($links['in'][$i])) { - list($name, $score) = $links['in'][$i]; - $txt .= LinkExistingWikiWord($name) . " ($score), "; - } - } - - $txt .= "\n<br><b>"; - $txt .= sprintf (gettext ("%d best outgoing links:"), NUM_RELATED_PAGES); - $txt .= "</b>\n"; - for($i = 0; $i < NUM_RELATED_PAGES; $i++) { - if(isset($links['out'][$i])) { - list($name, $score) = $links['out'][$i]; - if(IsWikiPage($dbi, $name)) - $txt .= LinkExistingWikiWord($name) . " ($score), "; - } - } - - $txt .= "\n<br><b>"; - $txt .= sprintf (gettext ("%d most popular nearby:"), NUM_RELATED_PAGES); - $txt .= "</b>\n"; - for($i = 0; $i < NUM_RELATED_PAGES; $i++) { - if(isset($links['popular'][$i])) { - list($name, $score) = $links['popular'][$i]; - $txt .= LinkExistingWikiWord($name) . " ($score), "; - } - } - - return $txt; - } - - - function GeneratePage($template, $content, $name, $hash) - { - global $ScriptUrl, $AllowedProtocols, $templates; - global $datetimeformat, $dbi, $logo, $FieldSeparator; - - if (!is_array($hash)) - unset($hash); - - function _dotoken ($id, $val, &$page) { - global $FieldSeparator; - $page = str_replace("$FieldSeparator#$id$FieldSeparator#", - $val, $page); - } - - function _iftoken ($id, $condition, &$page) { - global $FieldSeparator; - - // line based IF directive - $lineyes = "$FieldSeparator#IF $id$FieldSeparator#"; - $lineno = "$FieldSeparator#IF !$id$FieldSeparator#"; - // block based IF directive - $blockyes = "$FieldSeparator#IF:$id$FieldSeparator#"; - $blockyesend = "$FieldSeparator#ENDIF:$id$FieldSeparator#"; - $blockno = "$FieldSeparator#IF:!$id$FieldSeparator#"; - $blocknoend = "$FieldSeparator#ENDIF:!$id$FieldSeparator#"; - - if ($condition) { - $page = str_replace($lineyes, '', $page); - $page = str_replace($blockyes, '', $page); - $page = str_replace($blockyesend, '', $page); - $page = preg_replace("/$blockno(.*?)$blocknoend/s", '', $page); - $page = ereg_replace("${lineno}[^\n]*\n", '', $page); - } else { - $page = str_replace($lineno, '', $page); - $page = str_replace($blockno, '', $page); - $page = str_replace($blocknoend, '', $page); - $page = preg_replace("/$blockyes(.*?)$blockyesend/s", '', $page); - $page = ereg_replace("${lineyes}[^\n]*\n", '', $page); - } - } - - $page = join('', file($templates[$template])); - $page = str_replace('###', "$FieldSeparator#", $page); - - // valid for all pagetypes - _iftoken('COPY', isset($hash['copy']), $page); - _iftoken('LOCK', (isset($hash['flags']) && - ($hash['flags'] & FLAG_PAGE_LOCKED)), $page); - _iftoken('ADMIN', defined('WIKI_ADMIN'), $page); - - _dotoken('SCRIPTURL', $ScriptUrl, $page); - _dotoken('PAGE', htmlspecialchars($name), $page); - _dotoken('ALLOWEDPROTOCOLS', $AllowedProtocols, $page); - _dotoken('LOGO', $logo, $page); - - // invalid for messages (search results, error messages) - if ($template != 'MESSAGE') { - _dotoken('PAGEURL', rawurlencode($name), $page); - _dotoken('LASTMODIFIED', - date($datetimeformat, $hash['lastmodified']), $page); - _dotoken('LASTAUTHOR', $hash['author'], $page); - _dotoken('VERSION', $hash['version'], $page); - if (strstr($page, "$FieldSeparator#HITS$FieldSeparator#")) { - _dotoken('HITS', GetHitCount($dbi, $name), $page); - } - if (strstr($page, "$FieldSeparator#RELATEDPAGES$FieldSeparator#")) { - _dotoken('RELATEDPAGES', LinkRelatedPages($dbi, $name), $page); - } - } - - // valid only for EditLinks - if ($template == 'EDITLINKS') { - for ($i = 1; $i <= NUM_LINKS; $i++) { - $ref = isset($hash['refs'][$i]) ? $hash['refs'][$i] : ''; - _dotoken("R$i", $ref, $page); - } - } - - _dotoken('CONTENT', $content, $page); - print $page; - } - - function LinkExistingWikiWord($wikiword, $linktext='') { global $ScriptUrl; --- 42,45 ---- *************** *** 189,193 **** return "<b><u>BAD URL -- remove all of <, >, "</u></b>"; } - if(empty($linktext)) $linktext = htmlspecialchars($url); --- 63,66 ---- *************** *** 195,202 **** } ! ! function LinkImage($url, $alt="[External Image]") { global $ScriptUrl; ! if(ereg("[<>\"]", $url)) { return "<b><u>BAD URL -- remove all of <, >, "</u></b>"; } --- 68,74 ---- } ! function LinkImage($url, $alt='[External Image]') { global $ScriptUrl; ! if(ereg('[<>"]', $url)) { return "<b><u>BAD URL -- remove all of <, >, "</u></b>"; } *************** *** 205,209 **** ! function RenderQuickSearch($value = "") { global $ScriptUrl; return "<form action=\"$ScriptUrl\">\n" . --- 77,81 ---- ! function RenderQuickSearch($value = '') { global $ScriptUrl; return "<form action=\"$ScriptUrl\">\n" . *************** *** 213,217 **** } ! function RenderFullSearch($value = "") { global $ScriptUrl; return "<form action=\"$ScriptUrl\">\n" . --- 85,89 ---- } ! function RenderFullSearch($value = '') { global $ScriptUrl; return "<form action=\"$ScriptUrl\">\n" . *************** *** 234,242 **** } function ParseAdminTokens($line) { global $ScriptUrl; while (preg_match("/%%ADMIN-INPUT-(.*?)-(\w+)%%/", $line, $matches)) { ! $head = str_replace("_", " ", $matches[2]); $form = "<FORM ACTION=\"$ScriptUrl\" METHOD=POST>" ."$head: <INPUT NAME=$matches[1] SIZE=20> " --- 106,115 ---- } + function ParseAdminTokens($line) { global $ScriptUrl; while (preg_match("/%%ADMIN-INPUT-(.*?)-(\w+)%%/", $line, $matches)) { ! $head = str_replace('_', ' ', $matches[2]); $form = "<FORM ACTION=\"$ScriptUrl\" METHOD=POST>" ."$head: <INPUT NAME=$matches[1] SIZE=20> " *************** *** 287,292 **** ! // I couldn't move this to lib/config.php because it ! // wasn't declared yet. $stack = new Stack; --- 160,164 ---- ! // I couldn't move this to lib/config.php because it wasn't declared yet. $stack = new Stack; *************** *** 296,310 **** plain text etc. When we change modes we have to issue close tags for one mode and start tags for another. */ ! function SetHTMLOutputMode($tag, $tagdepth, $tabcount) { global $stack; ! $retvar = ""; ! if ($tagdepth == SINGLE_DEPTH) { ! if ($tabcount < $stack->cnt()) { ! // there are fewer tabs than stack, // reduce stack to that tab count ! while ($stack->cnt() > $tabcount) { $closetag = $stack->pop(); if ($closetag == false) { --- 168,205 ---- plain text etc. When we change modes we have to issue close tags for one mode and start tags for another. + + $tag ... HTML tag to insert + $tagtype ... ZERO_LEVEL - close all open tags before inserting $tag + NESTED_LEVEL - close tags until depths match + $level ... nesting level (depth) of $tag + nesting is arbitrary limited to 10 levels */ ! function SetHTMLOutputMode($tag, $tagtype, $level) ! { global $stack; ! $retvar = ''; ! ! if ($tagtype == ZERO_LEVEL) { ! // empty the stack until $level == 0; ! if ($tag == $stack->top()) { ! return; // same tag? -> nothing to do ! } ! while ($stack->cnt() > 0) { ! $closetag = $stack->pop(); ! $retvar .= "</$closetag>\n"; ! } ! if ($tag) { ! $retvar .= "<$tag>\n"; ! $stack->push($tag); ! } ! ! ! } elseif ($tagtype == NESTED_LEVEL) { ! if ($level < $stack->cnt()) { ! // $tag has fewer nestings (old: tabs) than stack, // reduce stack to that tab count ! while ($stack->cnt() > $level) { $closetag = $stack->pop(); if ($closetag == false) { *************** *** 323,331 **** } ! } elseif ($tabcount > $stack->cnt()) { // we add the diff to the stack // stack might be zero ! while ($stack->cnt() < $tabcount) { ! #echo "<$tag>\n"; $retvar .= "<$tag>\n"; $stack->push($tag); --- 218,225 ---- } ! } elseif ($level > $stack->cnt()) { // we add the diff to the stack // stack might be zero ! while ($stack->cnt() < $level) { $retvar .= "<$tag>\n"; $stack->push($tag); *************** *** 336,377 **** } ! } else { if ($tag == $stack->top()) { ! return; } else { $closetag = $stack->pop(); - #echo "</$closetag>\n"; - #echo "<$tag>\n"; $retvar .= "</$closetag>\n"; $retvar .= "<$tag>\n"; $stack->push($tag); } - } - - } elseif ($tagdepth == ZERO_DEPTH) { - // empty the stack for $depth == 0; - // what if the stack is empty? - if ($tag == $stack->top()) { - return; } ! while ($stack->cnt() > 0) { ! $closetag = $stack->pop(); ! #echo "</$closetag>\n"; ! $retvar .= "</$closetag>\n"; ! } ! ! if ($tag) { ! #echo "<$tag>\n"; ! $retvar .= "<$tag>\n"; ! $stack->push($tag); ! } ! } else { ! // error ! ExitWiki ("Passed bad tag depth value in SetHTMLOutputMode"); } return $retvar; - } // end SetHTMLOutputMode --- 230,251 ---- } ! } else { // $level == $stack->cnt() if ($tag == $stack->top()) { ! return; // same tag? -> nothing to do } else { + // different tag - close old one, add new one $closetag = $stack->pop(); $retvar .= "</$closetag>\n"; $retvar .= "<$tag>\n"; $stack->push($tag); } } ! ! } else { // unknown $tagtype ! ExitWiki ("Passed bad tag type value in SetHTMLOutputMode"); } return $retvar; } // end SetHTMLOutputMode *************** *** 379,455 **** - // The Recent Changes file is solely handled here - function UpdateRecentChanges($dbi, $pagename, $isnewpage) { - - global $remoteuser; // this is set in the config - global $dateformat; - global $WikiPageStore; - - $recentchanges = RetrievePage($dbi, gettext ("RecentChanges"), - $WikiPageStore); - - // 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; - } - - $numlines = sizeof($recentchanges["content"]); - $newpage = array(); - $k = 0; - - // scroll through the page to the first date and break - // dates are marked with "____" at the beginning of the line - for ($i = 0; $i < $numlines; $i++) { - if (preg_match("/^____/", - $recentchanges["content"][$i])) { - break; - } else { - $newpage[$k++] = $recentchanges["content"][$i]; - } - } - - // if it's a new date, insert it, else add the updated page's - // name to the array - - $newpage[$k++] = $isNewDay ? "____$today\r" - : $recentchanges["content"][$i++]; - if($isnewpage) { - $newpage[$k++] = "* [$pagename] (new) ..... $remoteuser\r"; - } else { - $diffurl = "phpwiki:?diff=" . rawurlencode($pagename); - $newpage[$k++] = "* [$pagename] ([diff|$diffurl]) ..... $remoteuser\r"; - } - if ($isNewDay) - $newpage[$k++] = "\r"; - - // copy the rest of the page into the new array - $pagename = preg_quote($pagename); - for (; $i < $numlines; $i++) { - // skip previous entry for $pagename - if (preg_match("|\[$pagename\]|", $recentchanges["content"][$i])) { - continue; - } else { - $newpage[$k++] = $recentchanges["content"][$i]; - } - } - - $recentchanges["content"] = $newpage; - - InsertPage($dbi, gettext ("RecentChanges"), $recentchanges); - } - - - function ParseAndLink($bracketlink) { global $dbi, $ScriptUrl, $AllowedProtocols, $InlineImages; --- 253,256 ---- *************** *** 509,513 **** for($l = 0; $l < $numlines; $l++) { ! $line = str_replace('[[', ' ', $content[$l]); // remove escaped '[' $numBracketLinks = preg_match_all("/\[\s*([^\]|]+\|)?\s*(.+?)\s*\]/", $line, $brktlinks); for ($i = 0; $i < $numBracketLinks; $i++) { --- 310,317 ---- for($l = 0; $l < $numlines; $l++) { ! // remove escaped '[' ! $line = str_replace('[[', ' ', $content[$l]); ! ! // bracket links (only type wiki-* is of interest) $numBracketLinks = preg_match_all("/\[\s*([^\]|]+\|)?\s*(.+?)\s*\]/", $line, $brktlinks); for ($i = 0; $i < $numBracketLinks; $i++) { *************** *** 520,523 **** --- 324,328 ---- } + // BumpyText old-style wiki links if (preg_match_all("/!?$WikiNameRegexp/", $line, $link)) { for ($i = 0; isset($link[0][$i]); $i++) { *************** *** 529,531 **** --- 334,462 ---- return $wikilinks; } + + + function LinkRelatedPages($dbi, $pagename) + { + // currently not supported everywhere + if(!function_exists('GetWikiPageLinks')) + return ''; + + $links = GetWikiPageLinks($dbi, $pagename); + + $txt = "<b>"; + $txt .= sprintf (gettext ("%d best incoming links:"), NUM_RELATED_PAGES); + $txt .= "</b>\n"; + for($i = 0; $i < NUM_RELATED_PAGES; $i++) { + if(isset($links['in'][$i])) { + list($name, $score) = $links['in'][$i]; + $txt .= LinkExistingWikiWord($name) . " ($score), "; + } + } + + $txt .= "\n<br><b>"; + $txt .= sprintf (gettext ("%d best outgoing links:"), NUM_RELATED_PAGES); + $txt .= "</b>\n"; + for($i = 0; $i < NUM_RELATED_PAGES; $i++) { + if(isset($links['out'][$i])) { + list($name, $score) = $links['out'][$i]; + if(IsWikiPage($dbi, $name)) + $txt .= LinkExistingWikiWord($name) . " ($score), "; + } + } + + $txt .= "\n<br><b>"; + $txt .= sprintf (gettext ("%d most popular nearby:"), NUM_RELATED_PAGES); + $txt .= "</b>\n"; + for($i = 0; $i < NUM_RELATED_PAGES; $i++) { + if(isset($links['popular'][$i])) { + list($name, $score) = $links['popular'][$i]; + $txt .= LinkExistingWikiWord($name) . " ($score), "; + } + } + + return $txt; + } + + + function GeneratePage($template, $content, $name, $hash) + { + global $ScriptUrl, $AllowedProtocols, $templates; + global $datetimeformat, $dbi, $logo, $FieldSeparator; + + if (!is_array($hash)) + unset($hash); + + function _dotoken ($id, $val, &$page) { + global $FieldSeparator; + $page = str_replace("$FieldSeparator#$id$FieldSeparator#", + $val, $page); + } + + function _iftoken ($id, $condition, &$page) { + global $FieldSeparator; + + // line based IF directive + $lineyes = "$FieldSeparator#IF $id$FieldSeparator#"; + $lineno = "$FieldSeparator#IF !$id$FieldSeparator#"; + // block based IF directive + $blockyes = "$FieldSeparator#IF:$id$FieldSeparator#"; + $blockyesend = "$FieldSeparator#ENDIF:$id$FieldSeparator#"; + $blockno = "$FieldSeparator#IF:!$id$FieldSeparator#"; + $blocknoend = "$FieldSeparator#ENDIF:!$id$FieldSeparator#"; + + if ($condition) { + $page = str_replace($lineyes, '', $page); + $page = str_replace($blockyes, '', $page); + $page = str_replace($blockyesend, '', $page); + $page = preg_replace("/$blockno(.*?)$blocknoend/s", '', $page); + $page = ereg_replace("${lineno}[^\n]*\n", '', $page); + } else { + $page = str_replace($lineno, '', $page); + $page = str_replace($blockno, '', $page); + $page = str_replace($blocknoend, '', $page); + $page = preg_replace("/$blockyes(.*?)$blockyesend/s", '', $page); + $page = ereg_replace("${lineyes}[^\n]*\n", '', $page); + } + } + + $page = join('', file($templates[$template])); + $page = str_replace('###', "$FieldSeparator#", $page); + + // valid for all pagetypes + _iftoken('COPY', isset($hash['copy']), $page); + _iftoken('LOCK', (isset($hash['flags']) && + ($hash['flags'] & FLAG_PAGE_LOCKED)), $page); + _iftoken('ADMIN', defined('WIKI_ADMIN'), $page); + + _dotoken('SCRIPTURL', $ScriptUrl, $page); + _dotoken('PAGE', htmlspecialchars($name), $page); + _dotoken('ALLOWEDPROTOCOLS', $AllowedProtocols, $page); + _dotoken('LOGO', $logo, $page); + + // invalid for messages (search results, error messages) + if ($template != 'MESSAGE') { + _dotoken('PAGEURL', rawurlencode($name), $page); + _dotoken('LASTMODIFIED', + date($datetimeformat, $hash['lastmodified']), $page); + _dotoken('LASTAUTHOR', $hash['author'], $page); + _dotoken('VERSION', $hash['version'], $page); + if (strstr($page, "$FieldSeparator#HITS$FieldSeparator#")) { + _dotoken('HITS', GetHitCount($dbi, $name), $page); + } + if (strstr($page, "$FieldSeparator#RELATEDPAGES$FieldSeparator#")) { + _dotoken('RELATEDPAGES', LinkRelatedPages($dbi, $name), $page); + } + } + + // valid only for EditLinks + if ($template == 'EDITLINKS') { + for ($i = 1; $i <= NUM_LINKS; $i++) { + $ref = isset($hash['refs'][$i]) ? $hash['refs'][$i] : ''; + _dotoken("R$i", $ref, $page); + } + } + + _dotoken('CONTENT', $content, $page); + print $page; + } ?> |