]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/savepage.php
More infiltration of new object-based HTML generation.
[SourceForge/phpwiki.git] / lib / savepage.php
1 <?php rcs_id('$Id: savepage.php,v 1.30 2002-01-21 06:55:47 dairiki Exp $');
2 require_once('lib/Template.php');
3 require_once('lib/transform.php');
4 require_once('lib/ArchiveCleaner.php');
5
6 /*
7    All page saving events take place here.
8    All page info is also taken care of here.
9    This is klugey. But it works. There's probably a slicker way of
10    coding it.
11 */
12
13 // FIXME: some links so that it's easy to get back to someplace useful
14 // from these error pages.
15
16 function ConcurrentUpdates($pagename) {
17    /*
18      xgettext only knows about c/c++ line-continuation strings
19      it does not know about php's dot operator.
20      We want to translate this entire paragraph as one string, of course.
21    */
22     $step = array(_("Use your browser's <b>Back</b> button to go back to the edit page."),
23                   _("Copy your changes to the clipboard or to another temporary place (e.g. text editor)."),
24                   _("<b>Reload</b> the page. You should now see the most current version of the page. Your changes are no longer there."),
25                   _("Make changes to the file again. Paste your additions from the clipboard (or text editor)."),
26                   _("Press <b>Save</b> again."));
27
28     foreach ($steps as $key => $step) {
29         $step[$key] = Element('li', $step);
30     }
31     
32         
33     $html = QElement('p',
34                      _("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."));
35
36     $html .= Element('p',
37                      _("In order to recover from this situation follow these steps:"));
38
39     $html .= Element('ol', join("\n", $steps));
40
41     $html .= QElement('p', _("Sorry for the inconvenience."));
42
43     echo GeneratePage('MESSAGE', $html,
44                       sprintf(_("Problem while updating %s"), $pagename));
45     ExitWiki();
46 }
47
48 function PageIsLocked($pagename) {
49     $html = QElement('p',
50                      _("This page has been locked by the administrator so your changes could not be saved."));
51     $html .= '<p>' ._("Use your browser's <b>Back</b> button to go back to the edit page.");
52     $html .= _("Copy your changes to the clipboard. You can try editing a different page or save your text in a text editor.");
53     $html .= '</p>';
54     $html .= QElement('p',
55                       _("Sorry for the inconvenience."));
56     
57     echo GeneratePage('MESSAGE', $html,
58                       sprintf (_("Problem while editing %s"), $pagename));
59     ExitWiki ("");
60 }
61
62 function BadFormVars($pagename) {
63     $html = QElement('p', _("Bad form submission"));
64     $html .= QElement('p', _("Required form variables are missing."));
65     echo GeneratePage('MESSAGE', $html,
66                       sprintf(_("Edit aborted: %s"), $pagename));
67     ExitWiki ("");
68 }
69
70 function savePage ($dbi, $request) {
71     global $user, $Theme;
72     
73     if ($request->get('REQUEST_METHOD') != 'POST')
74         BadFormVars($request->getArg('pagename'));
75     
76     if ($request->getArg('preview') || !$request->getArg('save')) {
77         include_once('lib/editpage.php');
78         return editPage($dbi, $request, 'do_preview');
79     }
80     
81     $pagename = $request->getArg('pagename');
82     $version = $request->getArg('version');
83     
84     $page = $dbi->getPage($pagename);
85     $current = $page->getCurrentRevision();
86     
87     $content = $request->getArg('content');
88     $editversion = $request->getArg('editversion');
89     
90     if ( $content === false || $editversion === false )
91         BadFormVars($pagename); // noreturn
92
93     if ($page->get('locked') && !$user->isAdmin())
94         PageIsLocked($args->pagename); // noreturn.
95
96     $meta['author'] = $user->getId();
97     $meta['author_id'] = $user->getAuthenticatedId();
98     $meta['is_minor_edit'] = (bool) $request->getArg('minor_edit');
99     $meta['summary'] = trim($request->getArg('summary'));
100
101     $content = preg_replace('/[ \t\r]+\n/', "\n", chop($content));
102     if ($request->getArg('convert'))
103         $content = CookSpaces($content);
104
105     if ($content == $current->getPackedContent()) {
106         // Save failed. No changes made.
107         include_once('lib/display.php');
108         // force browse of current version:
109         $request->setArg('version', false);
110         return displayPage($dbi, $request, 'nochanges');
111     }
112
113     ////////////////////////////////////////////////////////////////
114     //
115     // From here on, we're actually saving.
116     //
117     $newrevision = $page->createRevision($editversion + 1,
118                                          $content, $meta,
119                                          ExtractWikiPageLinks($content));
120         
121         
122     if (!is_object($newrevision)) {
123         // Save failed.  (Concurrent updates).
124         // FIXME: this should return one to the editing form,
125         //        (with an explanatory message, and options to
126         //        view diffs & merge...)
127         ConcurrentUpdates($pagename);
128     }
129     // New contents successfully saved...
130
131     // Clean out archived versions of this page.
132     $cleaner = new ArchiveCleaner($GLOBALS['ExpireParams']);
133     $cleaner->cleanPageRevisions($page);
134     
135     $warnings = $dbi->GenericWarnings();
136
137     if (empty($warnings) && ! $Theme->getImageURL('signature')) {
138         // Do redirect to browse page if no signature has
139         // been defined.  In this case, the user will most
140         // likely not see the rest of the HTML we generate
141         // (below).
142         $request->redirect(WikiURL($pagename, false,
143                                    'absolute_url'));
144     }
145
146     // Force browse of current page version.
147     $request->setArg('version', false);
148     
149     $wrapper = new WikiTemplate('top');
150     $wrapper->qreplace('TITLE', sprintf(_("Saved: %s"), $pagename));
151     $wrapper->replace('HEADER', fmt("Saved: %s",
152                                     $Theme->linkExistingWikiWord($pagename)));
153     $wrapper->setPageRevisionTokens($newrevision);
154
155     $template = new WikiTemplate('savepage');
156     if (!empty($warnings))
157         $template->qreplace('WARNINGS', $warnings);
158     $template->replace('CONTENT', do_transform($newrevision->getContent()));
159
160     $wrapper->printExpansion($template);
161 }
162
163 // Local Variables:
164 // mode: php
165 // tab-width: 8
166 // c-basic-offset: 4
167 // c-hanging-comment-ender-p: nil
168 // indent-tabs-mode: nil
169 // End:   
170 ?>