From dbefbd322c115ef94f061ed93ccfa8e6ba24e8f5 Mon Sep 17 00:00:00 2001 From: carstenklapp Date: Fri, 3 Jan 2003 02:43:26 +0000 Subject: [PATCH] New class LoadFileConflictPageEditor, for merging / comparing a loaded pgsrc file with an existing page. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@2477 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/editpage.php | 81 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/lib/editpage.php b/lib/editpage.php index 0cf4ac2d1..adffdd7e6 100644 --- a/lib/editpage.php +++ b/lib/editpage.php @@ -1,5 +1,5 @@ canEdit()) { + if ($this->isInitialEdit()) + return $this->viewSource(); + $tokens['PAGE_LOCKED_MESSAGE'] = $this->getLockedMessage(); + } + elseif ($this->editaction == 'save') { + if ($this->savePage()) + return true; // Page saved. + $saveFailed = true; + } + + if ($saveFailed || $this->isConcurrentUpdate()) + { + // Get the text of the original page, and the two conflicting edits + // The diff class takes arrays as input. So retrieve content as + // an array, or convert it as necesary. + $orig = $this->page->getRevision($this->_currentVersion); + $this_content = explode("\n", $this->_content); + $other_content = $this->current->getContent(); + include_once("lib/diff.php"); + $diff2 = new Diff($other_content, $this_content); + $context_lines = max(4, count($other_content) + 1, + count($this_content) + 1); + $fmt = new BlockDiffFormatter($context_lines); + $this->_content = $fmt->format($diff2); + $this->_currentVersion = $this->current->getVersion(); + $this->version = $this->_currentVersion; + $tokens['CONCURRENT_UPDATE_MESSAGE'] = $this->getConflictMessage(); + } + + if ($this->editaction == 'preview') + $tokens['PREVIEW_CONTENT'] = $this->getPreview(); // FIXME: convert to _MESSAGE? + + // FIXME: NOT_CURRENT_MESSAGE? + + $tokens = array_merge($tokens, $this->getFormElements()); + + return $this->output('editpage', _("Merge and Edit: %s"), $tokens); // FIXME: this doesn't display + } + + function output ($template, $title_fs, $tokens) { + $selected = &$this->selected; + $current = &$this->current; + + if ($selected && $selected->getVersion() != $current->getVersion()) { + $rev = $selected; + $pagelink = WikiLink($selected); + } + else { + $rev = $current; + $pagelink = WikiLink($this->page); + } + + $title = new FormattedText ($title_fs, $pagelink); + $template = Template($template, $tokens); + + //GeneratePage($template, $title, $rev); + PrintXML($template); + return true; + } + function getConflictMessage () { + $message = HTML(HTML::p(fmt("Some of the changes could not automatically be combined. Please look for sections beginning with '%s', and ending with '%s'. You will need to edit those sections by hand before you click Save.", + "<<<<<<<", + "======="), + HTML::p(_("Please check it through before saving.")))); + return $message; + } +} + +/** + $Log: not supported by cvs2svn $ + */ + // Local Variables: // mode: php // tab-width: 8 -- 2.45.0