示例#1
0
 function showForm(&$request, $args, $template = 'blogform')
 {
     // Show blog-entry form.
     $args = array('PAGENAME' => $args['pagename'], 'HIDDEN_INPUTS' => HiddenInputs($request->getArgs()));
     if (ENABLE_EDIT_TOOLBAR and !ENABLE_WYSIWYG and $template != 'addcomment') {
         include_once "lib/EditToolbar.php";
         $toolbar = new EditToolbar();
         $args = array_merge($args, $toolbar->getTokens());
     }
     return new Template($template, $request, $args);
 }
示例#2
0
 function editPage()
 {
     global $WikiTheme;
     $saveFailed = false;
     $tokens =& $this->tokens;
     $tokens['PAGE_LOCKED_MESSAGE'] = '';
     $tokens['CONCURRENT_UPDATE_MESSAGE'] = '';
     $r =& $this->request;
     if (isset($r->args['pref']['editWidth']) and $r->getPref('editWidth') != $r->args['pref']['editWidth']) {
         $r->_prefs->set('editWidth', $r->args['pref']['editWidth']);
     }
     if (isset($r->args['pref']['editHeight']) and $r->getPref('editHeight') != $r->args['pref']['editHeight']) {
         $r->_prefs->set('editHeight', $r->args['pref']['editHeight']);
     }
     if (!$this->canEdit()) {
         if ($this->isInitialEdit()) {
             return $this->viewSource();
         }
         $tokens['PAGE_LOCKED_MESSAGE'] = $this->getLockedMessage();
     } elseif ($r->getArg('save_and_redirect_to') != "") {
         if (ENABLE_CAPTCHA && $this->Captcha->Failed()) {
             $this->tokens['PAGE_LOCKED_MESSAGE'] = HTML::p(HTML::h1($this->Captcha->failed_msg));
         } elseif ($this->savePage()) {
             // noreturn
             $r->redirect(WikiURL($r->getArg('save_and_redirect_to')));
             return true;
             // Page saved.
         }
         $saveFailed = true;
     } elseif ($this->editaction == 'save') {
         if (ENABLE_CAPTCHA && $this->Captcha->Failed()) {
             $this->tokens['PAGE_LOCKED_MESSAGE'] = HTML::p(HTML::h1($this->Captcha->failed_msg));
         } elseif ($this->savePage()) {
             return true;
             // Page saved.
         } else {
             $saveFailed = true;
         }
     }
     if ($saveFailed and $this->isConcurrentUpdate()) {
         // Get the text of the original page, and the two conflicting edits
         // The diff3 class takes arrays as input.  So retrieve content as
         // an array, or convert it as necesary.
         $orig = $this->page->getRevision($this->_currentVersion);
         // FIXME: what if _currentVersion has be deleted?
         $orig_content = $orig->getContent();
         $this_content = explode("\n", $this->_content);
         $other_content = $this->current->getContent();
         include_once "lib/diff3.php";
         $diff = new diff3($orig_content, $this_content, $other_content);
         $output = $diff->merged_output(_("Your version"), _("Other version"));
         // Set the content of the textarea to the merged diff
         // output, and update the version
         $this->_content = implode("\n", $output);
         $this->_currentVersion = $this->current->getVersion();
         $this->version = $this->_currentVersion;
         $unresolved = $diff->ConflictingBlocks;
         $tokens['CONCURRENT_UPDATE_MESSAGE'] = $this->getConflictMessage($unresolved);
     } elseif ($saveFailed && !$this->_isSpam) {
         $tokens['CONCURRENT_UPDATE_MESSAGE'] = HTML(HTML::h2(_("Some internal editing error")), HTML::p(_("Your are probably trying to edit/create an invalid version of this page.")), HTML::p(HTML::em(_("&version=-1 might help."))));
     }
     if ($this->editaction == 'edit_convert') {
         $tokens['PREVIEW_CONTENT'] = $this->getConvertedPreview();
     }
     if ($this->editaction == 'preview') {
         $tokens['PREVIEW_CONTENT'] = $this->getPreview();
     }
     // FIXME: convert to _MESSAGE?
     // FIXME: NOT_CURRENT_MESSAGE?
     $tokens = array_merge($tokens, $this->getFormElements());
     if (ENABLE_EDIT_TOOLBAR) {
         include_once "lib/EditToolbar.php";
         $toolbar = new EditToolbar();
         $tokens = array_merge($tokens, $toolbar->getTokens());
     }
     return $this->output('editpage', _("Edit: %s"));
 }
示例#3
0
 function editPage($saveFailed = true)
 {
     $tokens =& $this->tokens;
     if (!$this->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();
         require_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);
         // FIXME: integrate this into class BlockDiffFormatter
         $this->_content = str_replace(">>>>>>>\n<<<<<<<\n", "=======\n", $this->_content);
         $this->_content = str_replace("<<<<<<<\n>>>>>>>\n", "=======\n", $this->_content);
         $this->_currentVersion = $this->current->getVersion();
         $this->version = $this->_currentVersion;
         $tokens['CONCURRENT_UPDATE_MESSAGE'] = $this->getConflictMessage();
     }
     if ($this->editaction == 'edit_convert') {
         $tokens['PREVIEW_CONTENT'] = $this->getConvertedPreview();
     }
     if ($this->editaction == 'preview') {
         $tokens['PREVIEW_CONTENT'] = $this->getPreview();
     }
     // FIXME: convert to _MESSAGE?
     // FIXME: NOT_CURRENT_MESSAGE?
     $tokens = array_merge($tokens, $this->getFormElements());
     // we need all GET params for loadfile overwrite
     if ($this->request->getArg('action') == 'loadfile') {
         $this->tokens['HIDDEN_INPUTS'] = HTML(HiddenInputs(array('source' => $this->request->getArg('source'), 'merge' => 1)), $this->tokens['HIDDEN_INPUTS']);
         // add two conflict resolution buttons before preview and save.
         $tokens['PREVIEW_B'] = HTML(Button('submit:edit[keep_old]', _("Keep old"), 'wikiaction'), $tokens['SEP'], Button('submit:edit[overwrite]', _("Overwrite with new"), 'wikiaction'), $tokens['SEP'], $tokens['PREVIEW_B']);
     }
     if (ENABLE_EDIT_TOOLBAR and !ENABLE_WYSIWYG) {
         include_once "lib/EditToolbar.php";
         $toolbar = new EditToolbar();
         $tokens = array_merge($tokens, $toolbar->getTokens());
     }
     return $this->output('editpage', _("Merge and Edit: %s"));
 }