1 <?php rcs_id('$Id: savepage.php,v 1.32 2002-01-23 05:10:22 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 // converts spaces to tabs
14 function CookSpaces($pagearray) {
15 return preg_replace("/ {3,8}/", "\t", $pagearray);
18 // FIXME: some links so that it's easy to get back to someplace useful
19 // from these error pages.
21 function ConcurrentUpdates(&$request) {
23 xgettext only knows about c/c++ line-continuation strings
24 it does not know about php's dot operator.
25 We want to translate this entire paragraph as one string, of course.
27 $step = array(_("Use your browser's <b>Back</b> button to go back to the edit page."),
28 _("Copy your changes to the clipboard or to another temporary place (e.g. text editor)."),
29 _("<b>Reload</b> the page. You should now see the most current version of the page. Your changes are no longer there."),
30 _("Make changes to the file again. Paste your additions from the clipboard (or text editor)."),
31 _("Press <b>Save</b> again."));
35 $html[] = HTML::p(_("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 $html[] = HTML::p(_("In order to recover from this situation follow these steps:"));
40 foreach ($steps as $step)
41 $steps->pushContent(HTML::li($step));
44 $html[] = HTML::p(_("Sorry for the inconvenience."));
46 echo GeneratePage('MESSAGE', $html,
47 sprintf(_("Problem while updating %s"), $request->getArg('pagename')));
51 function PageIsLocked (&$request) {
52 $html[] = HTML::p(_("This page has been locked by the administrator so your changes could not be saved."));
53 $html[] = HTML::p(_("Use your browser's <b>Back</b> button to go back to the edit page."),
55 _("Copy your changes to the clipboard. You can try editing a different page or save your text in a text editor."));
56 $html[] = HTML::p(_("Sorry for the inconvenience."));
58 echo GeneratePage('MESSAGE', $html,
59 sprintf (_("Problem while editing %s"), $request->getArg('pagename')));
63 function BadFormVars (&$request) {
64 $html[] = HTML::p(_("Bad form submission"));
65 $html[] = HTML::p(_("Required form variables are missing."));
66 echo GeneratePage('MESSAGE', $html,
67 sprintf(_("Edit aborted: %s"), $request->getArg('pagename')));
71 function savePage (&$request) {
74 if (! $request->isPost())
75 BadFormVars($request);
77 if ($request->getArg('preview') || !$request->getArg('save')) {
78 include_once('lib/editpage.php');
79 return editPage($request, 'do_preview');
82 $pagename = $request->getArg('pagename');
83 $version = $request->getArg('version');
85 $page = $request->getPage();
86 $current = $page->getCurrentRevision();
88 $content = $request->getArg('content');
89 $editversion = $request->getArg('editversion');
91 if ( $content === false || $editversion === false )
92 BadFormVars($request); // noreturn
94 $user = $request->getUser();
95 if ($page->get('locked') && !$user->isAdmin())
96 PageIsLocked($request); // noreturn.
98 $meta['author'] = $user->getId();
99 $meta['author_id'] = $user->getAuthenticatedId();
100 $meta['is_minor_edit'] = (bool) $request->getArg('minor_edit');
101 $meta['summary'] = trim($request->getArg('summary'));
103 $content = preg_replace('/[ \t\r]+\n/', "\n", chop($content));
104 if ($request->getArg('convert'))
105 $content = CookSpaces($content);
107 if ($content == $current->getPackedContent()) {
108 // Save failed. No changes made.
109 include_once('lib/display.php');
110 // force browse of current version:
111 $request->setArg('version', false);
112 return displayPage($request, 'nochanges');
115 ////////////////////////////////////////////////////////////////
117 // From here on, we're actually saving.
119 $newrevision = $page->createRevision($editversion + 1,
121 ExtractWikiPageLinks($content));
124 if (!is_object($newrevision)) {
125 // Save failed. (Concurrent updates).
126 // FIXME: this should return one to the editing form,
127 // (with an explanatory message, and options to
128 // view diffs & merge...)
129 ConcurrentUpdates($request);
131 // New contents successfully saved...
133 // Clean out archived versions of this page.
134 $cleaner = new ArchiveCleaner($GLOBALS['ExpireParams']);
135 $cleaner->cleanPageRevisions($page);
137 $dbi = $request->getDbh();
138 $warnings = $dbi->GenericWarnings();
140 if (empty($warnings) && ! $Theme->getImageURL('signature')) {
141 // Do redirect to browse page if no signature has
142 // been defined. In this case, the user will most
143 // likely not see the rest of the HTML we generate
145 $request->redirect(WikiURL($pagename, false,
149 // Force browse of current page version.
150 $request->setArg('version', false);
152 $wrapper = new WikiTemplate('top');
153 $wrapper->qreplace('TITLE', sprintf(_("Saved: %s"), $pagename));
154 $wrapper->replace('HEADER', fmt("Saved: %s",
155 $Theme->linkExistingWikiWord($pagename)));
156 $wrapper->setPageRevisionTokens($newrevision);
158 $template = new WikiTemplate('savepage');
159 if (!empty($warnings))
160 $template->qreplace('WARNINGS', $warnings);
161 $template->replace('CONTENT', do_transform($newrevision->getContent()));
163 $wrapper->printExpansion($template);
170 // c-hanging-comment-ender-p: nil
171 // indent-tabs-mode: nil