/** * Show an article * * @param \thebuggenie\core\framework\Request $request */ public function runEditArticle(framework\Request $request) { if (!$this->article->canEdit()) { framework\Context::setMessage('publish_article_error', framework\Context::getI18n()->__('You do not have permission to edit this article')); $this->forward(framework\Context::getRouting()->generate('publish_article', array('article_name' => $this->article_name))); } $this->article_route = $this->article->getID() ? 'publish_article_edit' : 'publish_article_new'; $this->article_route_params = $this->article->getID() ? array('article_name' => $this->article_name) : array(); if ($request->isPost()) { $this->preview = (bool) $request['preview']; $this->change_reason = $request['change_reason']; try { $this->article->setArticleType($request['article_type']); $this->article->setName($request['new_article_name']); $this->article->setParentArticle(Articles::getTable()->getArticleByName($request['parent_article_name'])); $this->article->setManualName($request['manual_name']); if ($this->article->getArticleType() == Article::TYPE_MANUAL && !$this->article->getName()) { $article_name_prefix = $this->article->getParentArticle() instanceof Article ? $this->article->getParentArticle()->getName() . ':' : $request['parent_article_name']; $this->article->setName(str_replace(' ', '', $article_name_prefix . $this->article->getManualName())); } $this->article->setContentSyntax($request['article_content_syntax']); $this->article->setContent($request->getRawParameter('article_content')); if (!$this->article->getName() || trim($this->article->getName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getName())) { throw new \Exception(framework\Context::getI18n()->__('You need to specify a valid article name')); } if ($request['article_type'] == Article::TYPE_MANUAL && (!$this->article->getManualName() || trim($this->article->getManualName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getManualName()))) { throw new \Exception(framework\Context::getI18n()->__('You need to specify a valid article name')); } if (!$this->preview && framework\Context::getModule('publish')->getSetting('require_change_reason') == 1 && (!$this->change_reason || trim($this->change_reason) == '')) { throw new \Exception(framework\Context::getI18n()->__('You have to provide a reason for the changes')); } if ($this->article->getLastUpdatedDate() != $request['last_modified']) { throw new \Exception(framework\Context::getI18n()->__('The file has been modified since you last opened it')); } if (($article = Article::getByName($request['new_new_article_name'])) && $article instanceof Article && $article->getID() != $request['article_id']) { throw new \Exception(framework\Context::getI18n()->__('An article with that name already exists. Please choose a different article name')); } if (!$this->preview) { $this->article->doSave(array(), $request['change_reason']); framework\Context::setMessage('publish_article_message', framework\Context::getI18n()->__('The article was saved')); $this->forward(framework\Context::getRouting()->generate('publish_article', array('article_name' => $this->article->getName()))); } } catch (\Exception $e) { $this->error = $e->getMessage(); } } }
public function componentAttachedfile() { if ($this->mode == 'issue' && !isset($this->issue)) { $this->issue = entities\Issue::getB2DBTable()->selectById($this->issue_id); } elseif ($this->mode == 'article' && !isset($this->article)) { $this->article = \thebuggenie\modules\publish\entities\Article::getByName($this->article_name); } $this->file_id = $this->file->getID(); }
public function runGetUploadStatus(framework\Request $request) { $id = $request->getParameter('upload_id', 0); framework\Logging::log('requesting status for upload with id ' . $id); $status = framework\Context::getRequest()->getUploadStatus($id); framework\Logging::log('status was: ' . (int) $status['finished'] . ', pct: ' . (int) $status['percent']); if (array_key_exists('file_id', $status) && $request['mode'] == 'issue') { $file = entities\File::getB2DBTable()->selectById($status['file_id']); $status['content_uploader'] = $this->getComponentHTML('main/attachedfile', array('base_id' => 'uploaded_files', 'mode' => 'issue', 'issue_id' => $request['issue_id'], 'file' => $file)); $status['content_inline'] = $this->getComponentHTML('main/attachedfile', array('base_id' => 'viewissue_files', 'mode' => 'issue', 'issue_id' => $request['issue_id'], 'file' => $file)); $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']); $status['attachmentcount'] = count($issue->getFiles()) + count($issue->getLinks()); } elseif (array_key_exists('file_id', $status) && $request['mode'] == 'article') { $file = entities\File::getB2DBTable()->selectById($status['file_id']); $status['content_uploader'] = $this->getComponentHTML('main/attachedfile', array('base_id' => 'article_' . $request['article_id'] . '_files', 'mode' => 'article', 'article_id' => $request['article_id'], 'file' => $file)); $status['content_inline'] = $this->getComponentHTML('main/attachedfile', array('base_id' => 'article_' . $request['article_id'] . '_files', 'mode' => 'article', 'article_id' => $request['article_id'], 'file' => $file)); $article = \thebuggenie\modules\publish\entities\Article::getByName($request['article_id']); $status['attachmentcount'] = count($article->getFiles()); } return $this->renderJSON($status); }
public function listen_createNewProject(framework\Event $event) { if (!Article::getByName(ucfirst($event->getSubject()->getKey()) . ':MainPage') instanceof Article) { $project_key = $event->getSubject()->getKey(); $article = Article::createNew("{$project_key}:MainPage", "This is the wiki frontpage for {$event->getSubject()->getName()} \n\n[[Category:{$project_key}:About]]"); $this->loadArticles($project_key); } }
public function runDetachFile(framework\Request $request) { try { $file = entities\File::getB2DBTable()->selectById((int) $request['file_id']); switch ($request['mode']) { case 'issue': $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']); if ($issue instanceof entities\Issue && $issue->canRemoveAttachments() && (int) $request->getParameter('file_id', 0)) { $issue->detachFile($file); return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($issue->getFiles()) + count($issue->getLinks()), 'message' => framework\Context::getI18n()->__('The attachment has been removed'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You can not remove items from this issue'))); case 'article': $article = \thebuggenie\modules\publish\entities\Article::getByName($request['article_name']); if ($article instanceof \thebuggenie\modules\publish\entities\Article && $article->canEdit() && (int) $request->getParameter('file_id', 0)) { $article->detachFile($file); return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($article->getFiles()), 'message' => framework\Context::getI18n()->__('The attachment has been removed'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You can not remove items from this issue'))); } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $this->getI18n()->__('An error occurred when removing the file'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Invalid mode'))); }