]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - wiki_savepage.php3
fixed sloppy coding: had omitted an "
[SourceForge/phpwiki.git] / wiki_savepage.php3
1 <!-- $Id: wiki_savepage.php3,v 1.12 2000-07-05 13:52:28 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 $pagename", 0);
29       exit;
30    }
31
32    $pagename = rawurldecode($post);
33    $pagehash = RetrievePage($dbi, $pagename);
34
35    // if this page doesn't exist yet, now's the time!
36    if (! is_array($pagehash)) {
37       $pagehash = array();
38       $pagehash["version"] = 0;
39       $pagehash["created"] = time();
40       $pagehash["flags"] = 0;
41       $newpage = 1;
42    } else {
43       if(isset($editversion) && ($editversion != $pagehash["version"])) {
44          ConcurrentUpdates($pagename);
45       }
46       // archive it if it's a new author
47       if ($pagehash["author"] != $remoteuser) {
48          SaveCopyToArchive($pagename, $pagehash);
49       }
50       $newpage = 0;
51    }
52
53    $pagehash["lastmodified"] = time();
54    $pagehash["version"]++;
55    $pagehash["author"] = $remoteuser;
56
57    // create page header
58    $enc_url = rawurlencode($pagename);
59    $enc_name = htmlspecialchars($pagename);
60    $html = "Thank you for editing " .
61         "<a href=\"$ScriptUrl?$enc_url\">$enc_name</a><br>\n";
62
63    if (! empty($content)) {
64       // patch from Grant Morgan <grant@ryuuguu.com> for magic_quotes_gpc
65       if (get_magic_quotes_gpc())
66          $content = stripslashes($content);
67
68       $pagehash["content"] = explode("\n", $content);
69
70       // convert spaces to tabs at user request
71       if ($convert) {
72          $pagehash["content"] = CookSpaces($pagehash["content"]);      
73       }
74    }
75
76    for ($i = 1; $i <= NUM_LINKS; $i++) {
77         if (! empty(${'r'.$i})) {
78            if (preg_match("#^($AllowedProtocols):#", ${'r'.$i}))
79               $pagehash['refs'][$i] = ${'r'.$i};
80            else
81               $html .= "<P>Link [$i]: <B>unknown protocol</B>" .
82                    " - use one of $AllowedProtocols - link discarded.</P>\n";
83         }
84    }
85
86    InsertPage($dbi, $pagename, $pagehash);
87    UpdateRecentChanges($dbi, $pagename, $newpage);
88
89    $html .= "Your careful attention to detail is much appreciated.\n";
90
91    if ($WikiDataBase == "/tmp/wikidb") {
92       $html .= "<P><B>Warning: the Wiki DBM file still lives in the " .
93                 "/tmp directory. Please read the INSTALL file and move " .
94                 "the DBM file to a permanent location or risk losing " .
95                 "all the pages!</B>\n";
96    }
97
98    $html .= "<P><img src=\"$SignatureImg\"></P><hr noshade><P>";
99    include("wiki_transform.php3");
100
101    GeneratePage('BROWSE', $html, $pagename, $pagehash);
102 ?>