1 <?php rcs_id('$Id: savepage.php,v 1.11 2001-02-12 01:43:10 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)
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 $userid = $user->id();
55 // add the updated page's name to the array
57 $newpage[$k++] = "* [$pagename] (new) ..... $userid\r";
59 $diffurl = "phpwiki:" . rawurlencode($pagename) . "?action=diff";
60 $newpage[$k++] = "* [$pagename] ([diff|$diffurl]) ..... $userid\r";
63 $newpage[$k++] = "\r";
65 // copy the rest of the page into the new array
66 // and skip previous entry for $pagename
67 $pagename = preg_quote($pagename);
68 for (; $i < $numlines; $i++) {
69 if (!preg_match("|\[$pagename\]|", $recentchanges['content'][$i])) {
70 $newpage[$k++] = $recentchanges['content'][$i];
74 $recentchanges['content'] = $newpage;
76 InsertPage($dbi, gettext ("RecentChanges"), $recentchanges);
80 function ConcurrentUpdates($pagename)
82 /* xgettext only knows about c/c++ line-continuation strings
83 is does not know about php's dot operator.
84 We want to translate this entire paragraph as one string, of course.
87 $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.");
89 $html .= gettext ("In order to recover from this situation follow these steps:");
90 $html .= "\n<OL><LI>";
91 $html .= gettext ("Use your browser's <b>Back</b> button to go back to the edit page.");
93 $html .= gettext ("Copy your changes to the clipboard or to another temporary place (e.g. text editor).");
95 $html .= gettext ("<b>Reload</b> the page. You should now see the most current version of the page. Your changes are no longer there.");
97 $html .= gettext ("Make changes to the file again. Paste your additions from the clipboard (or text editor).");
99 $html .= gettext ("Press <b>Save</b> again.");
100 $html .= "</OL>\n<P>";
101 $html .= gettext ("Sorry for the inconvenience.");
104 echo GeneratePage('MESSAGE', $html,
105 sprintf (gettext ("Problem while updating %s"), $pagename), 0);
110 $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore);
112 // if this page doesn't exist yet, now's the time!
113 if (! is_array($pagehash)) {
115 $pagehash['version'] = 0;
116 $pagehash['created'] = time();
117 $pagehash['flags'] = 0;
120 if (($pagehash['flags'] & FLAG_PAGE_LOCKED) && ! $user->is_admin()) {
121 $html = "<p>" . gettext ("This page has been locked by the administrator and cannot be edited.");
122 $html .= "\n<p>" . gettext ("Sorry for the inconvenience.");
123 echo GeneratePage('MESSAGE', $html,
124 sprintf (gettext ("Problem while editing %s"), $pagename), 0);
128 if(isset($editversion) && ($editversion != $pagehash['version'])) {
129 ConcurrentUpdates($pagename);
132 if ($user->id() != $pagehash['author'] && ! $user->is_admin())
133 unset($minor_edit); // Force archive
135 if (empty($minor_edit))
136 SaveCopyToArchive($dbi, $pagename, $pagehash);
142 $pagehash['lastmodified'] = time();
143 $pagehash['version']++;
144 $pagehash['author'] = $user->id();
146 // create page header
147 $html = sprintf(gettext("Thank you for editing %s."),
151 if (! empty($content)) {
152 // patch from Grant Morgan <grant@ryuuguu.com> for magic_quotes_gpc
153 fix_magic_quotes_gpc($content);
155 $pagehash['content'] = preg_split('/[ \t\r]*\n/', chop($content));
157 // convert spaces to tabs at user request
158 if (isset($convert)) {
159 $pagehash['content'] = CookSpaces($pagehash['content']);
163 InsertPage($dbi, $pagename, $pagehash);
164 UpdateRecentChanges($dbi, $pagename, $newpage);
166 $html .= gettext ("Your careful attention to detail is much appreciated.");
169 // fixme: no test for flat file db system
170 if (!empty($DBWarning)) {
171 $html .= "<P><B>Warning: $DBWarning" .
172 "Please read the INSTALL file and move " .
173 "the DB file to a permanent location or risk losing " .
174 "all the pages!</B>\n";
177 if (!empty($SignatureImg))
178 $html .= sprintf("<P><img src=\"%s\"></P>\n", DataURL($SignatureImg));
180 $html .= "<hr noshade><P>";
181 include('lib/transform.php');
183 echo GeneratePage('BROWSE', $html, $pagename, $pagehash);