function InsertPage($dbi, $pagename, $pagehash) { global $WikiPageStore; // ugly hack if ($dbi['table'] == $WikiPageStore) { // HACK $linklist = ExtractWikiPageLinks($pagehash['content']); SetWikiPageLinks($dbi, $pagename, $linklist); } $pagehash = MakeDBHash($pagename, $pagehash); $COLUMNS = "author, content, created, flags, " . "lastmodified, pagename, refs, version"; $VALUES = "'{$pagehash['author']}', '{$pagehash['content']}', " . "{$pagehash['created']}, {$pagehash['flags']}, " . "{$pagehash['lastmodified']}, '{$pagehash['pagename']}', " . "'{$pagehash['refs']}', {$pagehash['version']}"; if (!mysql_query("replace into {$dbi['table']} ({$COLUMNS}) values ({$VALUES})", $dbi['dbc'])) { $msg = sprintf(gettext("Error writing page '%s'"), $pagename); $msg .= "<BR>"; $msg .= sprintf(gettext("MySQL error: %s"), mysql_error()); ExitWiki($msg); } }
function InsertPage($dbi, $pagename, $pagehash) { global $WikiPageStore; // ugly hack if ($dbi['table'] == $WikiPageStore) { // HACK $linklist = ExtractWikiPageLinks($pagehash['content']); SetWikiPageLinks($dbi, $pagename, $linklist); } $pagehash = MakeDBHash($pagename, $pagehash); // record the time of modification $pagehash["lastmodified"] = time(); if (IsWikiPage($dbi, $pagename)) { $PAIRS = "author='{$pagehash['author']}'," . "content='{$pagehash['content']}'," . "created={$pagehash['created']}," . "flags={$pagehash['flags']}," . "lastmodified={$pagehash['lastmodified']}," . "pagename='{$pagehash['pagename']}'," . "refs='{$pagehash['refs']}'," . "version={$pagehash['version']}"; $query = "UPDATE {$dbi['table']} SET {$PAIRS} WHERE pagename='{$pagename}'"; } else { // do an insert // build up the column names and values for the query $COLUMNS = "author, content, created, flags, lastmodified, " . "pagename, refs, version"; $VALUES = "'{$pagehash['author']}', '{$pagehash['content']}', " . "{$pagehash['created']}, {$pagehash['flags']}, " . "{$pagehash['lastmodified']}, '{$pagehash['pagename']}', " . "'{$pagehash['refs']}', {$pagehash['version']}"; $query = "INSERT INTO {$dbi['table']} ({$COLUMNS}) VALUES({$VALUES})"; } //echo "<p>Insert/Update Query: $query<p>\n"; $retval = mssql_query($query); if ($retval == false) { printf(gettext("Insert/Update failed: %s <br>\n"), mssql_get_last_message()); } }
function SaveCopyToArchive($dbi, $pagename, $pagehash) { global $ArchivePageStore; $pagehash = MakeDBHash($pagename, $pagehash); // $pagehash["content"] is now an array of strings // of MSQL_MAX_LINE_LENGTH if (IsInArchive($dbi, $pagename)) { $PAIRS = "author='{$pagehash['author']}'," . "created={$pagehash['created']}," . "flags={$pagehash['flags']}," . "lastmodified={$pagehash['lastmodified']}," . "pagename='{$pagehash['pagename']}'," . "refs='{$pagehash['refs']}'," . "version={$pagehash['version']}"; $query = "UPDATE {$ArchivePageStore['table']} SET {$PAIRS} WHERE pagename='{$pagename}'"; } else { // do an insert // build up the column names and values for the query $COLUMNS = "author, created, flags, lastmodified, " . "pagename, refs, version"; $VALUES = "'{$pagehash['author']}', " . "{$pagehash['created']}, {$pagehash['flags']}, " . "{$pagehash['lastmodified']}, '{$pagehash['pagename']}', " . "'{$pagehash['refs']}', {$pagehash['version']}"; $query = "INSERT INTO archive ({$COLUMNS}) VALUES({$VALUES})"; } // echo "<p>Query: $query<p>\n"; // first, insert the metadata $retval = msql_query($query, $dbi['dbc']); if ($retval == false) { printf(gettext("Insert/update into table 'archive' failed: %s"), msql_error()); print "<br>\n"; } // second, insert the page data // remove old data from page_table $query = "delete from {$ArchivePageStore['page_table']} where pagename='{$pagename}'"; // echo "Delete query: $query<br>\n"; $retval = msql_query($query, $dbi['dbc']); if ($retval == false) { printf(gettext("Delete on %s failed: %s"), $ArchivePageStore[page_table], msql_error()); print "<br>\n"; } // insert the new lines reset($pagehash["content"]); for ($x = 0; $x < count($pagehash["content"]); $x++) { $line = addslashes($pagehash["content"][$x]); $query = "INSERT INTO {$ArchivePageStore['page_table']} " . "(pagename, lineno, line) " . "VALUES('{$pagename}', {$x}, '{$line}')"; // echo "Page line insert query: $query<br>\n"; $retval = msql_query($query, $dbi['dbc']); if ($retval == false) { printf(gettext("Insert into %s failed: %s"), $ArchivePageStore[page_table], msql_error()); print "<br>\n"; } } }