function SavePage($dbi, $page, $source) { global $WikiPageStore; $pagename = $page['pagename']; $version = $page['version']; if (is_array($current = RetrievePage($dbi, $pagename, $WikiPageStore))) { if ($version <= $current['version']) { $page['version'] = $current['version'] + 1; $version = $page['version'] . " [was {$version}]"; } SaveCopyToArchive($dbi, $pagename, $current); } printf(gettext("Inserting page %s, version %s from %s"), "<b>" . htmlspecialchars($pagename) . "</b>", $version, $source); print "<br>\n"; flush(); InsertPage($dbi, $pagename, $page); }
function port1_0RenderHash($dbi, $dbmh, $pagename) { $pagehash = unserialize(dbmfetch($dbmh, $pagename)); // array fields for pagehash 1.0 // 'version', 'date' as string, 'author', 'text' echo "{$pagename}<br>\n"; $newhash['version'] = isset($pagehash['version']) ? $pagehash['version'] : 1; $newhash['author'] = isset($pagehash['author']) ? $pagehash['author'] : '1.0 wiki setup page'; $newhash['created'] = time(); $newhash['lastmodified'] = time(); $newhash['flags'] = 0; $newhash['pagename'] = $pagename; $newhash['refs'] = array(); for ($i = 1; $i <= 4; $i++) { if (isset($pagehash['r$i'])) { $newhash['refs'][$i] = $pagehash['r$i']; } } $content = implode("\n", $pagehash['text']); $content = str_replace("[", "[[", $content); $newhash['content'] = explode("\n", $content); InsertPage($dbi, $pagename, $newhash); }
<!-- $Id: lockpage.php,v 1.1 2004/09/28 21:48:44 gcasse Exp $ --> <?php if (isset($lock)) { $page = $lock; } elseif (isset($unlock)) { $page = $unlock; } $argv[0] = $page; // necessary for displaying the page afterwards $pagename = rawurldecode($page); $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore); if (!is_array($pagehash)) { ExitWiki("Unknown page '" . htmlspecialchars($pagename) . "'\n"); } if (isset($lock)) { $pagehash['flags'] |= FLAG_PAGE_LOCKED; InsertPage($dbi, $pagename, $pagehash); // echo htmlspecialchars($page) . " locked\n"; } elseif (isset($unlock)) { $pagehash['flags'] &= ~FLAG_PAGE_LOCKED; InsertPage($dbi, $pagename, $pagehash); // echo htmlspecialchars($page) . " unlocked\n"; }
function SetWikiPageLinks($dbi, $pagename, $linklist) { $cache = array(); // Phase 1: fetch the relevant pairs from 'wikilinks' into $cache // --------------------------------------------------------------- // first the info for $pagename $linkinfo = RetrievePage($dbi, $pagename, 'wikilinks'); if (is_array($linkinfo)) { // page exists? $cache[$pagename] = $linkinfo; } else { // create info for page $cache[$pagename] = array('fromlinks' => array(), 'tolinks' => array()); // look up pages that link to $pagename $pname = dbmfirstkey($dbi['wikilinks']); while ($pname) { $linkinfo = RetrievePage($dbi, $pname, 'wikilinks'); if ($linkinfo['tolinks'][$pagename]) { $cache[$pagename]['fromlinks'][$pname] = 1; } $pname = dbmnextkey($dbi['wikilinks'], $pname); } } // then the info for the pages that $pagename used to point to $oldTolinks = $cache[$pagename]['tolinks']; reset($oldTolinks); while (list($link, $dummy) = each($oldTolinks)) { $linkinfo = RetrievePage($dbi, $link, 'wikilinks'); if (is_array($linkinfo)) { $cache[$link] = $linkinfo; } } // finally the info for the pages that $pagename will point to reset($linklist); while (list($link, $dummy) = each($linklist)) { $linkinfo = RetrievePage($dbi, $link, 'wikilinks'); if (is_array($linkinfo)) { $cache[$link] = $linkinfo; } } // Phase 2: delete the old links // --------------------------------------------------------------- // delete the old tolinks for $pagename // $cache[$pagename]['tolinks'] = array(); // (overwritten anyway in Phase 3) // remove $pagename from the fromlinks of pages in $oldTolinks reset($oldTolinks); while (list($oldTolink, $dummy) = each($oldTolinks)) { if ($cache[$oldTolink]) { // links to existing page? $oldFromlinks = $cache[$oldTolink]['fromlinks']; $cache[$oldTolink]['fromlinks'] = array(); // erase fromlinks reset($oldFromlinks); // comp. new fr.links while (list($fromlink, $dummy) = each($oldFromlinks)) { if ($fromlink != $pagename) { $cache[$oldTolink]['fromlinks'][$fromlink] = 1; } } } } // Phase 3: add the new links // --------------------------------------------------------------- // set the new tolinks for $pagename $cache[$pagename]['tolinks'] = $linklist; // add $pagename to the fromlinks of pages in $linklist reset($linklist); while (list($link, $dummy) = each($linklist)) { if ($cache[$link]) { // existing page? $cache[$link]['fromlinks'][$pagename] = 1; } } // Phase 4: write $cache back to 'wikilinks' // --------------------------------------------------------------- reset($cache); while (list($link, $fromAndTolinks) = each($cache)) { InsertPage($dbi, $link, $fromAndTolinks, 'wikilinks'); } }
function SaveCopyToArchive($dbi, $pagename, $pagehash) { global $ArchivePageStore; $adbi = OpenDataBase($ArchivePageStore); InsertPage($adbi, $pagename, $pagehash); }
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 $newpage[$k++] = $isNewDay ? "____{$today}" : $recentchanges['content'][$i++]; // add the updated page's name to the array if ($isnewpage) { $newpage[$k++] = "\n \n* [{$pagename}] (new) ..... {$remoteuser}"; } else { $diffurl = "phpwiki:?diff=" . rawurlencode($pagename); $newpage[$k++] = "\n \n* [{$pagename}] ([diff|{$diffurl}]) ..... {$remoteuser}"; } if ($isNewDay) { $newpage[$k++] = "\r"; } // copy the rest of the page into the new array // and skip previous entry for $pagename $pagename = preg_quote($pagename); for (; $i < $numlines; $i++) { if (!preg_match("|\\[{$pagename}\\]|", $recentchanges['content'][$i])) { $newpage[$k++] = $recentchanges['content'][$i]; } } // copy the new page back into recentchanges, skipping empty days $numlines = sizeof($newpage); $recentchanges['content'] = array(); $k = 0; for ($i = 0; $i < $numlines; $i++) { if ($i != $numlines - 1 && preg_match("/^____/", $newpage[$i]) && preg_match("/^[\r\n]*\$/", $newpage[$i + 1])) { $i++; } else { $recentchanges['content'][$k++] = $newpage[$i]; } } InsertPage($dbi, gettext("RecentChanges"), $recentchanges); }