示例#1
0
 /**
  * Save a revision
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $revision = Request::getVar('revision', array(), 'post', 'none', 2);
     $revision = array_map('trim', $revision);
     // Initiate extended database class
     $row = new Revision($revision['id']);
     $before = $row->get('approved');
     if (!$row->bind($revision)) {
         $this->setMessage($row->getError(), 'error');
         $this->editTask($row);
         return;
     }
     if (!$row->exists()) {
         $row->set('created', Date::toSql());
     }
     $page = new Page(intval($row->get('pageid')));
     // Parse text
     $wikiconfig = array('option' => $this->_option, 'scope' => $page->get('scope'), 'pagename' => $page->get('pagename'), 'pageid' => $page->get('id'), 'filepath' => '', 'domain' => $this->_group);
     $p = Parser::getInstance();
     $row->set('pagehtml', $p->parse($row->get('pagetext'), $wikiconfig));
     // Store new content
     if (!$row->store()) {
         $this->setMessage($row->getError(), 'error');
         $this->editTask($row);
         return;
     }
     // Get the most recent revision and compare to the set "current" version
     if ($before != 1 && $row->get('approved') == 1) {
         $page->revisions('list', array(), true)->last();
         if ($page->revisions()->current()->get('id') == $row->get('id')) {
             // The newly approved revision is now the most current
             // So, we need to update the page's version_id
             $page->set('version_id', $page->revisions()->current()->get('id'));
             $page->store(false, 'revision_approved');
         } else {
             $page->log('revision_approved');
         }
     }
     // Set the redirect
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $row->get('pageid'), false), Lang::txt('COM_WIKI_REVISION_SAVED'));
 }