1 <?php rcs_id('$Id: savepage.php,v 1.7.2.2 2001-09-21 19:59:13 dairiki Exp $');
4 All page saving events take place here.
5 All page info is also taken care of here.
6 This is klugey. But it works. There's probably a slicker way of
10 function UpdateRecentChanges($dbi, $pagename, $isnewpage)
12 global $remoteuser; // this is set in the config
14 global $WikiPageStore;
16 $recentchanges = RetrievePage($dbi, gettext ("RecentChanges"), $WikiPageStore);
18 // this shouldn't be necessary, since PhpWiki loads
19 // default pages if this is a new baby Wiki
20 if ($recentchanges == -1) {
21 $recentchanges = array();
25 $today = date($dateformat, $now);
27 if (date($dateformat, $recentchanges['lastmodified']) != $today) {
29 $recentchanges['lastmodified'] = $now;
34 $numlines = sizeof($recentchanges['content']);
38 // scroll through the page to the first date and break
39 // dates are marked with "____" at the beginning of the line
40 for ($i = 0; $i < $numlines; $i++) {
41 if (preg_match("/^____/",
42 $recentchanges['content'][$i])) {
45 $newpage[$k++] = $recentchanges['content'][$i];
49 // if it's a new date, insert it
50 $newpage[$k++] = $isNewDay ? "____$today\r"
51 : $recentchanges['content'][$i++];
53 // add the updated page's name to the array
55 $newpage[$k++] = "* [$pagename] (new) ..... $remoteuser\r";
57 $diffurl = "phpwiki:?diff=" . rawurlencode($pagename);
58 $newpage[$k++] = "* [$pagename] ([diff|$diffurl]) ..... $remoteuser\r";
61 $newpage[$k++] = "\r";
63 // copy the rest of the page into the new array
64 // and skip previous entry for $pagename
65 $pagename = preg_quote($pagename);
66 for (; $i < $numlines; $i++) {
67 if (!preg_match("|\[$pagename\]|", $recentchanges['content'][$i])) {
68 $newpage[$k++] = $recentchanges['content'][$i];
72 // copy the new page back into recentchanges, skipping empty days
73 $numlines = sizeof($newpage);
74 $recentchanges['content'] = array();
76 for ($i = 0; $i < $numlines; $i++) {
77 if ($i != $numlines-1 &&
78 preg_match("/^____/", $newpage[$i]) &&
79 preg_match("/^[\r\n]*$/", $newpage[$i+1])) {
82 $recentchanges['content'][$k++] = $newpage[$i];
86 InsertPage($dbi, gettext ("RecentChanges"), $recentchanges);
90 function ConcurrentUpdates($pagename)
92 /* xgettext only knows about c/c++ line-continuation strings
93 is does not know about php's dot operator.
94 We want to translate this entire paragraph as one string, of course.
97 $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.");
99 $html .= gettext ("In order to recover from this situation follow these steps:");
100 $html .= "\n<OL><LI>";
101 $html .= gettext ("Use your browser's <b>Back</b> button to go back to the edit page.");
103 $html .= gettext ("Copy your changes to the clipboard or to another temporary place (e.g. text editor).");
105 $html .= gettext ("<b>Reload</b> the page. You should now see the most current version of the page. Your changes are no longer there.");
107 $html .= gettext ("Make changes to the file again. Paste your additions from the clipboard (or text editor).");
109 $html .= gettext ("Press <b>Save</b> again.");
110 $html .= "</OL>\n<P>";
111 $html .= gettext ("Sorry for the inconvenience.");
114 GeneratePage('MESSAGE', $html,
115 sprintf (gettext ("Problem while updating %s"), $pagename), 0);
121 $pagename = rawurldecode($post);
122 $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore);
124 // if this page doesn't exist yet, now's the time!
125 if (! is_array($pagehash)) {
127 $pagehash['version'] = 0;
128 $pagehash['created'] = time();
129 $pagehash['flags'] = 0;
132 if (($pagehash['flags'] & FLAG_PAGE_LOCKED) && !defined('WIKI_ADMIN')) {
133 $html = "<p>" . gettext ("This page has been locked by the administrator and cannot be edited.");
134 $html .= "\n<p>" . gettext ("Sorry for the inconvenience.");
135 GeneratePage('MESSAGE', $html, sprintf (gettext ("Problem while editing %s"), $pagename), 0);
139 if(isset($editversion) && ($editversion != $pagehash['version'])) {
140 ConcurrentUpdates($pagename);
143 // archive it if it's a new author
144 if ($pagehash['author'] != $remoteuser) {
145 SaveCopyToArchive($dbi, $pagename, $pagehash);
151 $pagehash['lastmodified'] = time();
152 $pagehash['version']++;
153 $pagehash['author'] = $remoteuser;
155 // create page header
156 $enc_url = rawurlencode($pagename);
157 $enc_name = htmlspecialchars($pagename);
158 $html = sprintf(gettext("Thank you for editing %s."),
159 "<a href=\"$ScriptUrl?$enc_url\">$enc_name</a>");
162 if (! empty($content)) {
163 // patch from Grant Morgan <grant@ryuuguu.com> for magic_quotes_gpc
164 if (get_magic_quotes_gpc())
165 $content = stripslashes($content);
167 $pagehash['content'] = preg_split('/[ \t\r]*\n/', chop($content));
169 // convert spaces to tabs at user request
170 if (isset($convert)) {
171 $pagehash['content'] = CookSpaces($pagehash['content']);
175 for ($i = 1; $i <= NUM_LINKS; $i++) {
176 if (! empty(${'r'.$i})) {
177 if (preg_match("#^($AllowedProtocols):#", ${'r'.$i}))
178 $pagehash['refs'][$i] = ${'r'.$i};
180 $html .= "<P>Link [$i]: <B>unknown protocol</B>" .
181 " - use one of $AllowedProtocols - link discarded.</P>\n";
185 InsertPage($dbi, $pagename, $pagehash);
186 UpdateRecentChanges($dbi, $pagename, $newpage);
188 $html .= gettext ("Your careful attention to detail is much appreciated.");
191 // fixme: no test for flat file db system
192 if (isset($DBMdir) && preg_match('@^/tmp\b@', $DBMdir)) {
193 $html .= "<P><B>Warning: the Wiki DB files still live in the " .
194 "/tmp directory. Please read the INSTALL file and move " .
195 "the DBM file to a permanent location or risk losing " .
196 "all the pages!</B>\n";
199 if (!empty($SignatureImg))
200 $html .= "<P><img src=\"$SignatureImg\"></P>\n";
202 $html .= "<hr noshade><P>";
203 include('lib/transform.php');
205 GeneratePage('BROWSE', $html, $pagename, $pagehash);