/** * Get a count or list of revisions * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed */ public function revisions($what = 'list', $filters = array(), $clear = false) { if (!isset($filters['pageid'])) { $filters['pageid'] = $this->get('id'); } if (!isset($filters['approved'])) { $filters['approved'] = array(0, 1); } if (!isset($filters['sortby'])) { $filters['sortby'] = 'version ASC'; } switch (strtolower($what)) { case 'count': if (!is_numeric($this->_revisions_count) || $clear) { $tbl = new Tables\Revision($this->_db); $this->_revisions_count = $tbl->getRecordsCount($filters); } return $this->_revisions_count; break; case 'list': case 'results': default: if (!$this->_revisions instanceof ItemList || $clear) { $results = array(); $tbl = new Tables\Revision($this->_db); if ($results = $tbl->getRecords($filters)) { foreach ($results as $key => $result) { $results[$key] = new Revision($result); } } $this->_revisions = new ItemList($results); } return $this->_revisions; break; } }
/** * 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; } }
/** * Load a wiki with default content * This is largely Help pages * * @param string $option Component name * @return string */ public function scribe($option) { $pages = $this->_defaultPages(); if (count($pages) <= 0) { return Lang::txt('No default pages found'); } $p = Parser::getInstance(); foreach ($pages as $f => $c) { $f = str_replace('_', ':', $f); // Instantiate a new page $page = new Tables\Page($this->_db); $page->pagename = $f; $page->title = $page->getTitle(); $page->access = 0; if ($this->_scope != '__site__') { $page->group_cn = $this->_scope; $page->scope = $this->_scope . '/wiki'; } if ($this->_scope == '__site__' && $page->pagename == 'MainPage') { $page->params = 'mode=static' . "\n"; } else { $page->params = 'mode=wiki' . "\n"; } // Check content if (!$page->check()) { throw new Exception($page->getError(), 500); } // Store content if (!$page->store()) { throw new Exception($page->getError(), 500); } // Ensure we have a page ID if (!$page->id) { $page->id = $this->_db->insertid(); } // Instantiate a new revision $revision = new Tables\Revision($this->_db); $revision->pageid = $page->id; $revision->minor_edit = 0; $revision->version = 1; $revision->pagetext = $c; $revision->approved = 1; $wikiconfig = array('option' => $option, 'scope' => $page->scope, 'pagename' => $page->pagename, 'pageid' => $page->id, 'filepath' => '', 'domain' => $page->group_cn); // Transform the wikitext to HTML if ($page->pagename != 'Help:WikiMath') { $revision->pagehtml = $p->parse($revision->pagetext, $wikiconfig, true, true); } // Check content if (!$revision->check()) { throw new Exception($revision->getError(), 500); } // Store content if (!$revision->store()) { throw new Exception($revision->getError(), 500); } $page->version_id = $revision->id; $page->modified = $revision->created; if (!$page->store()) { // This really shouldn't happen. throw new Exception($page->getError(), 500); } } return null; }