]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/savepage.php
fixed E_NOTICE warnings
[SourceForge/phpwiki.git] / lib / savepage.php
1 <!-- $Id: savepage.php,v 1.5 2000-11-01 11:31:41 ahollosi Exp $ -->
2 <?php
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       /* xgettext only knows about c/c++ line-continuation strings
14         is does not know about php's dot operator.
15         We want to translate this entire paragraph as one string, of course.
16       */
17       $html = "<P>";
18       $html .= gettext ("PhpWiki is unable to save your changes, because another user edited and saved the page while you were editing the page too. If saving proceeded now changes from the previous author would be lost.");
19       $html .= "</P>\n<P>";
20       $html .= gettext ("In order to recover from this situation follow these steps:");
21       $html .= "\n<OL><LI>";
22       $html .= gettext ("Use your browser's <b>Back</b> button to go back to the edit page.");
23       $html .= "\n<LI>";
24       $html .= gettext ("Copy your changes to the clipboard or to another temporary place (e.g. text editor).");
25       $html .= "\n<LI>";
26       $html .= gettext ("<b>Reload</b> the page. You should now see the most current version of the page. Your changes are no longer there.");
27       $html .= "\n<LI>";
28       $html .= gettext ("Make changes to the file again. Paste your additions from the clipboard (or text editor).");
29       $html .= "\n<LI>";
30       $html .= gettext ("Press <b>Save</b> again.");
31       $html .= "</OL>\n<P>";
32       $html .= gettext ("Sorry for the inconvenience.");
33       $html .= "</P>";
34
35       GeneratePage('MESSAGE', $html,
36         sprintf (gettext ("Problem while updating %s"), $pagename), 0);
37       exit;
38    }
39
40    $pagename = rawurldecode($post);
41    $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore);
42
43    // if this page doesn't exist yet, now's the time!
44    if (! is_array($pagehash)) {
45       $pagehash = array();
46       $pagehash["version"] = 0;
47       $pagehash["created"] = time();
48       $pagehash["flags"] = 0;
49       $newpage = 1;
50    } else {
51       if (($pagehash['flags'] & FLAG_PAGE_LOCKED) && !$admin_edit) {
52          $html = "<p>" . gettext ("This page has been locked by the administrator and cannot be edited.");
53          $html .= "\n<p>" . gettext ("Sorry for the inconvenience.");
54          GeneratePage('MESSAGE', $html, sprintf (gettext ("Problem while editing %s"), $pagename), 0);
55          ExitWiki ("");
56       }
57
58       if(isset($editversion) && ($editversion != $pagehash["version"])) {
59          ConcurrentUpdates($pagename);
60       }
61
62       // archive it if it's a new author
63       if ($pagehash["author"] != $remoteuser) {
64          SaveCopyToArchive($dbi, $pagename, $pagehash);
65       }
66       $newpage = 0;
67    }
68
69    $pagehash["lastmodified"] = time();
70    $pagehash["version"]++;
71    $pagehash["author"] = $remoteuser;
72
73    // create page header
74    $enc_url = rawurlencode($pagename);
75    $enc_name = htmlspecialchars($pagename);
76    $html = sprintf(gettext("Thank you for editing %s."),
77                    "<a href=\"$ScriptUrl?$enc_url\">$enc_name</a>");
78    $html .= "<br>\n";
79
80    if (! empty($content)) {
81       // patch from Grant Morgan <grant@ryuuguu.com> for magic_quotes_gpc
82       if (get_magic_quotes_gpc())
83          $content = stripslashes($content);
84
85       $pagehash["content"] = preg_split('/[ \t\r]*\n/', chop($content));
86
87       // convert spaces to tabs at user request
88       if (isset($convert)) {
89          $pagehash["content"] = CookSpaces($pagehash["content"]);      
90       }
91    }
92
93    for ($i = 1; $i <= NUM_LINKS; $i++) {
94         if (! empty(${'r'.$i})) {
95            if (preg_match("#^($AllowedProtocols):#", ${'r'.$i}))
96               $pagehash['refs'][$i] = ${'r'.$i};
97            else
98               $html .= "<P>Link [$i]: <B>unknown protocol</B>" .
99                    " - use one of $AllowedProtocols - link discarded.</P>\n";
100         }
101    }
102
103    InsertPage($dbi, $pagename, $pagehash);
104    UpdateRecentChanges($dbi, $pagename, $newpage);
105
106    $html .= gettext ("Your careful attention to detail is much appreciated.");
107    $html .= "\n";
108
109    if ($WikiPageStore == "/tmp/wikidb") {
110       $html .= "<P><B>Warning: the Wiki DBM file still lives in the " .
111                 "/tmp directory. Please read the INSTALL file and move " .
112                 "the DBM file to a permanent location or risk losing " .
113                 "all the pages!</B>\n";
114    }
115
116    $html .= "<P><img src=\"$SignatureImg\"></P><hr noshade><P>";
117    include("lib/transform.php");
118
119    GeneratePage('BROWSE', $html, $pagename, $pagehash);
120 ?>