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');
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
13 // FIXME: some links so that it's easy to get back to someplace useful
14 // from these error pages.
16 function ConcurrentUpdates($pagename) {
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.
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."));
28 foreach ($steps as $key => $step) {
29 $step[$key] = Element('li', $step);
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."));
37 _("In order to recover from this situation follow these steps:"));
39 $html .= Element('ol', join("\n", $steps));
41 $html .= QElement('p', _("Sorry for the inconvenience."));
43 echo GeneratePage('MESSAGE', $html,
44 sprintf(_("Problem while updating %s"), $pagename));
48 function PageIsLocked($pagename) {
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.");
54 $html .= QElement('p',
55 _("Sorry for the inconvenience."));
57 echo GeneratePage('MESSAGE', $html,
58 sprintf (_("Problem while editing %s"), $pagename));
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));
70 function savePage ($dbi, $request) {
73 if ($request->get('REQUEST_METHOD') != 'POST')
74 BadFormVars($request->getArg('pagename'));
76 if ($request->getArg('preview') || !$request->getArg('save')) {
77 include_once('lib/editpage.php');
78 return editPage($dbi, $request, 'do_preview');
81 $pagename = $request->getArg('pagename');
82 $version = $request->getArg('version');
84 $page = $dbi->getPage($pagename);
85 $current = $page->getCurrentRevision();
87 $content = $request->getArg('content');
88 $editversion = $request->getArg('editversion');
90 if ( $content === false || $editversion === false )
91 BadFormVars($pagename); // noreturn
93 if ($page->get('locked') && !$user->isAdmin())
94 PageIsLocked($args->pagename); // noreturn.
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'));
101 $content = preg_replace('/[ \t\r]+\n/', "\n", chop($content));
102 if ($request->getArg('convert'))
103 $content = CookSpaces($content);
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');
113 ////////////////////////////////////////////////////////////////
115 // From here on, we're actually saving.
117 $newrevision = $page->createRevision($editversion + 1,
119 ExtractWikiPageLinks($content));
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);
129 // New contents successfully saved...
131 // Clean out archived versions of this page.
132 $cleaner = new ArchiveCleaner($GLOBALS['ExpireParams']);
133 $cleaner->cleanPageRevisions($page);
135 $warnings = $dbi->GenericWarnings();
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
142 $request->redirect(WikiURL($pagename, false,
146 // Force browse of current page version.
147 $request->setArg('version', false);
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);
155 $template = new WikiTemplate('savepage');
156 if (!empty($warnings))
157 $template->qreplace('WARNINGS', $warnings);
158 $template->replace('CONTENT', do_transform($newrevision->getContent()));
160 $wrapper->printExpansion($template);
167 // c-hanging-comment-ender-p: nil
168 // indent-tabs-mode: nil