1 <?php rcs_id('$Id: savepage.php,v 1.17 2001-11-14 21:05:38 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 from these
16 function ConcurrentUpdates($pagename) {
17 /* xgettext only knows about c/c++ line-continuation strings
18 is does not know about php's dot operator.
19 We want to translate this entire paragraph as one string, of course.
22 $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.");
24 $html .= gettext ("In order to recover from this situation follow these steps:");
25 $html .= "\n<ol><li>";
26 $html .= gettext ("Use your browser's <b>Back</b> button to go back to the edit page.");
27 $html .= "</li>\n<li>";
28 $html .= gettext ("Copy your changes to the clipboard or to another temporary place (e.g. text editor).");
29 $html .= "</li>\n<li>";
30 $html .= gettext ("<b>Reload</b> the page. You should now see the most current version of the page. Your changes are no longer there.");
31 $html .= "</li>\n<li>";
32 $html .= gettext ("Make changes to the file again. Paste your additions from the clipboard (or text editor).");
33 $html .= "</li>\n<li>";
34 $html .= gettext ("Press <b>Save</b> again.");
35 $html .= "</li></ol></p>\n";
36 $html .= QElement('p', gettext ("Sorry for the inconvenience."));
38 echo GeneratePage('MESSAGE', $html,
39 sprintf (gettext ("Problem while updating %s"), $pagename));
43 function PageIsLocked($pagename) {
45 gettext("This page has been locked by the administrator and cannot be edited."));
46 $html .= QElement('p',
47 gettext ("Sorry for the inconvenience."));
49 echo GeneratePage('MESSAGE', $html,
50 sprintf (gettext ("Problem while editing %s"), $pagename));
54 function NoChangesMade($pagename) {
55 $html = QElement('p', gettext ("You have not made any changes."));
56 $html .= QElement('p', gettext ("New version not saved."));
57 echo GeneratePage('MESSAGE', $html,
58 sprintf(gettext("Edit aborted: %s"), $pagename));
62 function BadFormVars($pagename) {
63 $html = QElement('p', gettext ("Bad form submission"));
64 $html .= QElement('p', gettext ("Required form variables are missing."));
65 echo GeneratePage('MESSAGE', $html,
66 sprintf(gettext("Edit aborted: %s"), $pagename));
70 function savePreview($dbi, $request) {
71 $pagename = $request->getArg('pagename');
72 $version = $request->getArg('version');
74 $page = $dbi->getPage($pagename);
75 $selected = $page->getRevision($version);
77 // FIXME: sanity checking about posted variables
78 // FIXME: check for simultaneous edits.
79 foreach (array('minor_edit', 'convert') as $key)
80 $formvars[$key] = $request->getArg($key) ? 'checked' : '';
81 foreach (array('content', 'editversion', 'summary', 'pagename', 'version') as $key)
82 @$formvars[$key] = htmlspecialchars($request->getArg($key));
84 $template = new WikiTemplate('EDITPAGE');
85 $template->setPageRevisionTokens($selected);
86 $template->replace('FORMVARS', $formvars);
87 $template->replace('PREVIEW_CONTENT', do_transform($request->getArg('content')));
88 echo $template->getExpansion();
91 function savePage ($dbi, $request) {
94 // FIXME: fail if this check fails?
95 assert($request->get('REQUEST_METHOD') == 'POST');
97 if ($request->getArg('preview'))
98 return savePreview($dbi, $request);
100 $pagename = $request->getArg('pagename');
101 $version = $request->getArg('version');
103 $page = $dbi->getPage($pagename);
104 $current = $page->getCurrentRevision();
106 $content = $request->getArg('content');
107 $editversion = $request->getArg('editversion');
109 if ( $content === false || $editversion === false )
110 BadFormVars($pagename); // noreturn
112 if ($page->get('locked') && !$user->is_admin())
113 PageIsLocked($args->pagename); // noreturn.
115 $meta['author'] = $user->id();
116 $meta['author_id'] = $user->authenticated_id();
117 $meta['is_minor_edit'] = (bool) $request->getArg('minor_edit');
118 $meta['summary'] = trim($request->getArg('summary'));
120 $content = preg_replace('/[ \t\r]+\n/', "\n", chop($content));
121 if ($request->getArg('convert'))
122 $content = CookSpaces($content);
124 if ($content == $current->getPackedContent()) {
125 NoChangesMade($pagename); // noreturn
128 ////////////////////////////////////////////////////////////////
130 // From here on, we're actually saving.
132 $newrevision = $page->createRevision($editversion + 1,
134 ExtractWikiPageLinks($content));
135 if (!is_object($newrevision)) {
137 ConcurrentUpdates($pagename);
140 // Clean out archived versions of this page.
141 $cleaner = new ArchiveCleaner($GLOBALS['ExpireParams']);
142 $cleaner->cleanPageRevisions($page);
144 $warnings = $dbi->GenericWarnings();
145 if (empty($warnings)) {
146 // Do redirect to browse page.
147 // In this case, the user will most likely not see the rest of
148 // the HTML we generate (below).
149 $request->redirect(WikiURL($pagename, false, 'absolute_url'));
152 $html = sprintf(gettext("Thank you for editing %s."),
153 LinkExistingWikiWord($pagename));
155 $html .= gettext ("Your careful attention to detail is much appreciated.");
159 $html .= Element('p', "<b>Warning!</b> "
160 . htmlspecialchars($warnings)
164 global $SignatureImg;
165 if (!empty($SignatureImg))
166 $html .= sprintf("<P><img src=\"%s\"></P>\n", DataURL($SignatureImg));
168 $html .= "<hr noshade>\n";
169 $html .= do_transform($newrevision->getContent());
170 echo GeneratePage('BROWSE', $html, $pagename, $newrevision);
178 // c-hanging-comment-ender-p: nil
179 // indent-tabs-mode: nil