]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - wiki_savepage.php3
Knocked off about 4-5 items.
[SourceForge/phpwiki.git] / wiki_savepage.php3
1 <!-- $Id: wiki_savepage.php3,v 1.9 2000-06-21 22:57:17 ahollosi Exp $ -->
2 <?
3
4 /*
5    All page saving events take place here.
6    All page info is also taken care of here.
7    This is klugey. But it works. There's probably a slicker way of
8    coding it.
9 */
10
11    function ConcurrentUpdates($pagename)
12    {
13       $html = "<P>PhpWiki is unable to save your changes, because\n" .
14            "another user edited and saved the page while you\n" .
15            "were editing the page too. If saving proceeded now\n" .
16            "changes from the previous author would be lost.</P>\n" .
17            "<P>In order to recover from this situation follow these steps:\n" .
18            "<OL><LI>Use your browsers <B>Back</B> button to go back " .
19            "to the edit page.\n" .
20            "<LI>Copy your changes to the clipboard or to another temporary " .
21            "place (e.g. text editor).\n" .
22            "<LI><B>Reload</B> the page. You should now see the most current" .
23            " version of the page. Your changes are no longer there.\n" .
24            "<LI>Make changes to the file again. Paste your additions from " .
25            "the clipboard (or text editor).\n" .
26            "<LI>Press <B>Save</B> again.</OL>\n" .
27            "<P>Sorry for the inconvinience.</P>";
28       GeneratePage('MESSAGE', $html, "Problem while updating " .
29                    htmlspecialchars($pagename), 0);
30       exit;
31    }
32
33    $pagename = rawurldecode($post);
34    $pagehash = RetrievePage($dbi, $pagename);
35
36    // if this page doesn't exist yet, now's the time!
37    if (! is_array($pagehash)) {
38       $pagehash = array();
39       $pagehash["version"] = 0;
40       $newpage = 1;
41    } else {
42       if(isset($editversion) && ($editversion != $pagehash["version"])) {
43          ConcurrentUpdates($pagename);
44       }
45       // archive it if it's a new author
46       if ($pagehash["author"] != $remoteuser) {
47          SaveCopyToArchive($pagename, $pagehash);
48       }
49       $newpage = 0;
50    }
51
52    $pagehash["lastmodified"] = time();
53    $pagehash["version"]++;
54    $pagehash["author"] = $remoteuser;
55
56    // create page header
57    $enc_url = rawurlencode($pagename);
58    $enc_name = htmlspecialchars($pagename);
59    $html = "Thank you for editing " .
60         "<a href=\"$ScriptUrl?$enc_url\">$enc_name</a><br>\n";
61
62    if (! empty($content)) {
63       // patch from Grant Morgan <grant@ryuuguu.com> for magic_quotes_gpc
64       if (get_magic_quotes_gpc())
65          $content = stripslashes($content);
66
67       $pagehash["content"] = explode("\n", $content);
68
69       // convert spaces to tabs at user request
70       if ($convert) {
71          $pagehash["content"] = CookSpaces($pagehash["content"]);      
72       }
73    }
74
75    for ($i = 1; $i <= NUM_LINKS; $i++) {
76         if (! empty(${'r'.$i})) {
77            if (preg_match("#^($AllowedProtocols):#", ${'r'.$i}))
78               $pagehash['refs'][$i] = ${'r'.$i};
79            else
80               $html .= "<P>Link [$i]: <B>unknown protocol</B>" .
81                    " - use one of $AllowedProtocols - link discarded.</P>\n";
82         }
83    }
84
85    InsertPage($dbi, $pagename, $pagehash);
86    UpdateRecentChanges($dbi, $pagename, $newpage);
87
88    $html .= "Your careful attention to detail is much appreciated.\n";
89
90    if ($WikiDataBase == "/tmp/wikidb") {
91       $html .= "<P><B>Warning: the Wiki DBM file still lives in the " .
92                 "/tmp directory. Please read the INSTALL file and move " .
93                 "the DBM file to a permanent location or risk losing " .
94                 "all the pages!</B>\n";
95    }
96
97    $html .= "<P><img src=\"$SignatureImg\"></P><hr noshade><P>";
98    include("wiki_transform.php3");
99
100    GeneratePage('BROWSE', $html, $pagename, $pagehash);
101 ?>