1 <?php rcs_id('$Id: savepage.php,v 1.7.2.3 2001-11-07 18:52:14 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);
120 if (get_magic_quotes_gpc()) {
121 $post = stripslashes($post);
123 $pagename = rawurldecode($post);
124 $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore);
126 // if this page doesn't exist yet, now's the time!
127 if (! is_array($pagehash)) {
129 $pagehash['version'] = 0;
130 $pagehash['created'] = time();
131 $pagehash['flags'] = 0;
134 if (($pagehash['flags'] & FLAG_PAGE_LOCKED) && !defined('WIKI_ADMIN')) {
135 $html = "<p>" . gettext ("This page has been locked by the administrator and cannot be edited.");
136 $html .= "\n<p>" . gettext ("Sorry for the inconvenience.");
137 GeneratePage('MESSAGE', $html, sprintf (gettext ("Problem while editing %s"), $pagename), 0);
141 if(isset($editversion) && ($editversion != $pagehash['version'])) {
142 ConcurrentUpdates($pagename);
145 // archive it if it's a new author
146 if ($pagehash['author'] != $remoteuser) {
147 SaveCopyToArchive($dbi, $pagename, $pagehash);
153 $pagehash['lastmodified'] = time();
154 $pagehash['version']++;
155 $pagehash['author'] = $remoteuser;
157 // create page header
158 $enc_url = rawurlencode($pagename);
159 $enc_name = htmlspecialchars($pagename);
160 $html = sprintf(gettext("Thank you for editing %s."),
161 "<a href=\"$ScriptUrl?$enc_url\">$enc_name</a>");
164 if (! empty($content)) {
165 // patch from Grant Morgan <grant@ryuuguu.com> for magic_quotes_gpc
166 if (get_magic_quotes_gpc())
167 $content = stripslashes($content);
169 $pagehash['content'] = preg_split('/[ \t\r]*\n/', chop($content));
171 // convert spaces to tabs at user request
172 if (isset($convert)) {
173 $pagehash['content'] = CookSpaces($pagehash['content']);
177 for ($i = 1; $i <= NUM_LINKS; $i++) {
178 if (! empty(${'r'.$i})) {
179 if (preg_match("#^($AllowedProtocols):#", ${'r'.$i}))
180 $pagehash['refs'][$i] = ${'r'.$i};
182 $html .= "<P>Link [$i]: <B>unknown protocol</B>" .
183 " - use one of $AllowedProtocols - link discarded.</P>\n";
187 InsertPage($dbi, $pagename, $pagehash);
188 UpdateRecentChanges($dbi, $pagename, $newpage);
190 $html .= gettext ("Your careful attention to detail is much appreciated.");
193 // fixme: no test for flat file db system
194 if (isset($DBMdir) && preg_match('@^/tmp\b@', $DBMdir)) {
195 $html .= "<P><B>Warning: the Wiki DB files still live in the " .
196 "/tmp directory. Please read the INSTALL file and move " .
197 "the DBM file to a permanent location or risk losing " .
198 "all the pages!</B>\n";
201 if (!empty($SignatureImg))
202 $html .= "<P><img src=\"$SignatureImg\"></P>\n";
204 $html .= "<hr noshade><P>";
205 include('lib/transform.php');
207 GeneratePage('BROWSE', $html, $pagename, $pagehash);