]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/savepage.php
log
[SourceForge/phpwiki.git] / lib / savepage.php
1 <?php rcs_id('$Id: savepage.php,v 1.13 2001-02-14 05:22:49 dairiki Exp $');
2
3 /*
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
7    coding it.
8 */
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       echo GeneratePage('MESSAGE', $html,
36                         sprintf (gettext ("Problem while updating %s"), $pagename), 0);
37       ExitWiki();
38    }
39
40
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) && ! $user->is_admin()) {
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          echo GeneratePage('MESSAGE', $html,
55                            sprintf (gettext ("Problem while editing %s"), $pagename), 0);
56          ExitWiki ("");
57       }
58
59       if(isset($editversion) && ($editversion != $pagehash['version'])) {
60          ConcurrentUpdates($pagename);
61       }
62
63       if ($user->id() != $pagehash['author'] && ! $user->is_admin())
64          unset($minor_edit);      // Force archive
65       
66       if (empty($minor_edit))
67          SaveCopyToArchive($dbi, $pagename, $pagehash);
68
69       $newpage = 0;
70    }
71
72    // set new pageinfo
73    $pagehash['lastmodified'] = time();
74    $pagehash['version']++;
75    $pagehash['author'] = $user->id();
76
77    // create page header
78    $html = sprintf(gettext("Thank you for editing %s."),
79                    LinkExistingWikiWord($pagename));
80    $html .= "<br>\n";
81
82    if (! empty($content)) {
83       // patch from Grant Morgan <grant@ryuuguu.com> for magic_quotes_gpc
84       fix_magic_quotes_gpc($content);
85
86       $pagehash['content'] = preg_split('/[ \t\r]*\n/', chop($content));
87
88       // convert spaces to tabs at user request
89       if (isset($convert)) {
90          $pagehash['content'] = CookSpaces($pagehash['content']);
91       }
92    }
93
94    InsertPage($dbi, $pagename, $pagehash);
95    UpdateRecentChanges($dbi, $pagename, $newpage);
96
97    $html .= gettext ("Your careful attention to detail is much appreciated.");
98    $html .= "\n";
99
100    // fixme: no test for flat file db system
101    if (!empty($DBWarning)) {
102       $html .= "<P><B>Warning: $DBWarning" .
103                 "Please read the INSTALL file and move " .
104                 "the DB file to a permanent location or risk losing " .
105                 "all the pages!</B>\n";
106    }
107
108    if (!empty($SignatureImg))
109       $html .= sprintf("<P><img src=\"%s\"></P>\n", DataURL($SignatureImg));
110       
111    $html .= "<hr noshade><P>";
112    include('lib/transform.php');
113
114    echo GeneratePage('BROWSE', $html, $pagename, $pagehash);
115 ?>