1 <?php rcs_id('$Id: savepage.php,v 1.16 2001-09-18 19:16:23 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.");
28 $html .= gettext ("Copy your changes to the clipboard or to another temporary place (e.g. text editor).");
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.");
32 $html .= gettext ("Make changes to the file again. Paste your additions from the clipboard (or text editor).");
34 $html .= gettext ("Press <b>Save</b> again.");
35 $html .= "</OL>\n<P>";
36 $html .= gettext ("Sorry for the inconvenience.");
39 echo GeneratePage('MESSAGE', $html,
40 sprintf (gettext ("Problem while updating %s"), $pagename));
44 function PageIsLocked($pagename) {
46 gettext("This page has been locked by the administrator and cannot be edited."));
47 $html .= QElement('p',
48 gettext ("Sorry for the inconvenience."));
50 echo GeneratePage('MESSAGE', $html,
51 sprintf (gettext ("Problem while editing %s"), $pagename));
55 function NoChangesMade($pagename) {
56 $html = QElement('p', gettext ("You have not made any changes."));
57 $html .= QElement('p', gettext ("New version not saved."));
58 echo GeneratePage('MESSAGE', $html,
59 sprintf(gettext("Edit aborted: %s"), $pagename));
63 function BadFormVars($pagename) {
64 $html = QElement('p', gettext ("Bad form submission"));
65 $html .= QElement('p', gettext ("Required form variables are missing."));
66 echo GeneratePage('MESSAGE', $html,
67 sprintf(gettext("Edit aborted: %s"), $pagename));
71 function savePreview($dbi, $request) {
72 $pagename = $request->getArg('pagename');
73 $version = $request->getArg('version');
75 $page = $dbi->getPage($pagename);
76 $selected = $page->getRevision($version);
78 // FIXME: sanity checking about posted variables
79 // FIXME: check for simultaneous edits.
80 foreach (array('minor_edit', 'convert') as $key)
81 $formvars[$key] = $request->getArg($key) ? 'checked' : '';
82 foreach (array('content', 'editversion', 'summary', 'pagename', 'version') as $key)
83 @$formvars[$key] = htmlspecialchars($request->getArg($key));
85 $template = new WikiTemplate('EDITPAGE');
86 $template->setPageRevisionTokens($selected);
87 $template->replace('FORMVARS', $formvars);
88 $template->replace('PREVIEW_CONTENT', do_transform($request->getArg('content')));
89 echo $template->getExpansion();
92 function savePage ($dbi, $request) {
95 // FIXME: fail if this check fails?
96 assert($request->get('REQUEST_METHOD') == 'POST');
98 if ($request->getArg('preview'))
99 return savePreview($dbi, $request);
101 $pagename = $request->getArg('pagename');
102 $version = $request->getArg('version');
104 $page = $dbi->getPage($pagename);
105 $current = $page->getCurrentRevision();
107 $content = $request->getArg('content');
108 $editversion = $request->getArg('editversion');
110 if ( $content === false || $editversion === false )
111 BadFormVars($pagename); // noreturn
113 if ($page->get('locked') && !$user->is_admin())
114 PageIsLocked($args->pagename); // noreturn.
116 $meta['author'] = $user->id();
117 $meta['author_id'] = $user->authenticated_id();
118 $meta['is_minor_edit'] = (bool) $request->getArg('minor_edit');
119 $meta['summary'] = trim($request->getArg('summary'));
121 $content = preg_replace('/[ \t\r]+\n/', "\n", chop($content));
122 if ($request->getArg('convert'))
123 $content = CookSpaces($content);
125 if ($content == $current->getPackedContent()) {
126 NoChangesMade($pagename); // noreturn
129 ////////////////////////////////////////////////////////////////
131 // From here on, we're actually saving.
133 $newrevision = $page->createRevision($editversion + 1,
135 ExtractWikiPageLinks($content));
136 if (!is_object($newrevision)) {
138 ConcurrentUpdates($pagename);
141 // Clean out archived versions of this page.
142 $cleaner = new ArchiveCleaner($GLOBALS['ExpireParams']);
143 $cleaner->cleanPageRevisions($page);
145 $warnings = $dbi->GenericWarnings();
146 if (empty($warnings)) {
147 // Do redirect to browse page.
148 // In this case, the user will most likely not see the rest of
149 // the HTML we generate (below).
150 $request->redirect(WikiURL($pagename, false, 'absolute_url'));
153 $html = sprintf(gettext("Thank you for editing %s."),
154 LinkExistingWikiWord($pagename));
156 $html .= gettext ("Your careful attention to detail is much appreciated.");
160 $html .= Element('p', "<b>Warning!</b> "
161 . htmlspecialchars($warnings)
165 global $SignatureImg;
166 if (!empty($SignatureImg))
167 $html .= sprintf("<P><img src=\"%s\"></P>\n", DataURL($SignatureImg));
169 $html .= "<hr noshade>\n";
170 $html .= do_transform($newrevision->getContent());
171 echo GeneratePage('BROWSE', $html, $pagename, $newrevision);
179 // c-hanging-comment-ender-p: nil
180 // indent-tabs-mode: nil