/** * Create an item entry for a wiki page * * @param integer $id Optional ID to use * @return boolean */ public function make($id = null) { if ($this->exists()) { return true; } include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'book.php'; $page = null; if (!$id) { $group = Request::getVar('cn', ''); $book = new Book($group ? $group : '__site__'); $page = $book->page(); $id = $page->get('id'); } $this->_tbl->loadType($id, $this->_type); if ($this->exists()) { return true; } if (!$page) { $page = new Page($id); } if (!$page->exists()) { $this->setError(Lang::txt('Wiki page not found.')); return false; } $this->set('type', $this->_type)->set('object_id', $page->get('id'))->set('created', $page->get('created'))->set('created_by', $page->get('created_by'))->set('title', $page->get('title'))->set('description', $page->revision()->content('clean', 300))->set('url', Route::url($page->link())); if (!$this->store()) { return false; } return true; }
/** * 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')); }
/** * Update a page * * @apiParameter { * "name": "id", * "description": "Entry identifier", * "type": "integer", * "required": true, * "default": null * } * @apiParameter { * "name": "title", * "description": "Entry title", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "pagename", * "description": "Page name", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "pagetext", * "description": "Page content", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "created", * "description": "Created timestamp (YYYY-MM-DD HH:mm:ss)", * "type": "string", * "required": false, * "default": "now" * } * @apiParameter { * "name": "created_by", * "description": "User ID of entry creator", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "state", * "description": "Published state (0 = unpublished, 1 = published)", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "access", * "description": "Access level (0 = public, 1 = registered users, 4 = private)", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "scope", * "description": "Page scope", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "group_cn", * "description": "Group name the wiki page belongs to", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "params", * "description": "Page options", * "type": "array", * "required": false, * "default": null * } * @apiParameter { * "name": "summary", * "description": "Summary of changes made", * "type": "string", * "required": false, * "default": null * } * @return void */ public function updateTask() { $this->requiresAuthentication(); $fields = array('title' => Request::getVar('title', null, '', 'none', 2), 'pagename' => Request::getVar('pagename', null), 'scope' => Request::getVar('scope', null), 'created' => Request::getVar('created', null), 'created_by' => Request::getInt('created_by', null), 'state' => Request::getInt('state', null), 'access' => Request::getInt('access', null), 'group_cn' => Request::getVar('group_cn', null)); if (!$id) { throw new Exception(Lang::txt('COM_TAGS_ERROR_MISSING_DATA'), 422); } $page = new Page($id); if (!$page->exists()) { throw new Exception(Lang::txt('Specified page not found.'), 404); } $revision = $page->revision('current'); if (!$revision->bind($rev)) { throw new Exception($revision->getError(), 500); } $params = new \Hubzero\Config\Registry($page->get('params', '')); $params->merge(Request::getVar('params', array(), 'post')); $page->set('params', $params->toString()); foreach ($fields as $key => $value) { if (!is_null($value)) { $page->set($key, $value); } } $page->set('modified', Date::toSql()); if (!$page->store(true)) { throw new Exception($page->getError(), 500); } if (!$page->updateAuthors(Request::getVar('authors', '', 'post'))) { throw new Exception($page->getError(), 500); } $revision->set('pagetext', Request::getVar('pagetext', '', '', 'none', 2)); $revision->set('summary', Request::getVar('summary', null)); if ($revision->get('pagetext') == '') { $revision->set('id', 0); $revision->set('pageid', $page->get('id')); $revision->set('pagename', $page->get('pagename')); $revision->set('scope', $page->get('scope')); $revision->set('group_cn', $page->get('group_cn')); $revision->set('version', $revision->get('version') + 1); if ($page->param('mode', 'wiki') == 'knol') { // Set revisions to NOT approved $revision->set('approved', 0); // If an author or the original page creator, set to approved if ($page->get('created_by') == User::get('id') || $page->isAuthor(User::get('id'))) { $revision->set('approved', 1); } } else { // Wiki mode, approve revision $revision->set('approved', 1); } $revision->set('pagehtml', $revision->content('parsed')); if ($page->access('manage') || $page->access('edit')) { $revision->set('approved', 1); } // Store content if (!$revision->store(true)) { throw new Exception(Lang::txt('COM_WIKI_ERROR_SAVING_REVISION'), 500); } $page->set('version_id', $revision->get('id')); if (!$page->store(true)) { throw new Exception($page->getError(), 500); } } $page->tag(Request::getVar('tags', '')); $this->send($page->toObject()); }