/** * Delete a revision * * @return void */ public function removeTask() { $pageid = Request::getInt('pageid', 0); $ids = Request::getVar('id', array(0)); $ids = !is_array($ids) ? array($ids) : $ids; if (count($ids) <= 0) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $pageid, false), Lang::txt('COM_WIKI_ERROR_MISSING_ID'), 'warning'); return; } // Incoming $step = Request::getInt('step', 1); $step = !$step ? 1 : $step; // What step are we on? switch ($step) { case 1: Request::setVar('hidemainmenu', 1); $this->view->ids = $ids; $this->view->pageid = $pageid; // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->display(); break; case 2: // Check for request forgeries Request::checkToken(); // Check if they confirmed $confirmed = Request::getInt('confirm', 0); if (!$confirmed) { // Instantiate a new view $this->view->ids = $ids; $this->setMessage(Lang::txt('COM_WIKI_CONFIRM_DELETE'), 'error'); // Output the HTML $this->view->display(); return; } $msg = ''; if (!empty($ids)) { $db = App::get('db'); $tbl = new Tables\Revision($db); foreach ($ids as $id) { // Load the revision $revision = new Revision($id); $pageid = $pageid ? $pageid : $revision->get('pageid'); // Get a count of all approved revisions $tbl->pageid = $pageid; $count = $tbl->getRevisionCount(); // Can't delete - it's the only approved version! if ($count <= 1) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $pageid, false), Lang::txt('COM_WIKI_ERROR_CANNOT_REMOVE_REVISION'), 'error'); return; } // Delete it $revision->delete(); } $msg = Lang::txt('COM_WIKI_PAGES_DELETED', count($ids)); } // Set the redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $pageid, false), $msg); break; } }
/** * Approve a revision * * @return void */ public function approveTask() { // Check if they are logged in if (User::isGuest()) { $url = Request::getVar('REQUEST_URI', '', 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url))); return; } // Incoming $id = Request::getInt('oldid', 0); if (!$id || !$this->page->access('manage')) { App::redirect(Route::url($this->page->link())); return; } // Load the revision, approve it, and save $revision = new Revision($id); $revision->set('approved', 1); if (!$revision->store()) { throw new Exception($revision->getError(), 500); } // Get the most recent revision and compare to the set "current" version $this->page->revisions('list', array(), true)->last(); if ($this->page->revisions()->current()->get('id') == $revision->get('id')) { // The newly approved revision is now the most current // So, we need to update the page's version_id $this->page->set('version_id', $this->page->revisions()->current()->get('id')); $this->page->store(false, 'revision_approved'); } else { $this->page->log('revision_approved'); } App::redirect(Route::url($this->page->link())); }