/** * Returns a publish article * * @param $a_id * @param $row * * @return TBGWikiArticle */ static function articleName($article_name, $row = null) { if (!isset(self::$_article_names[$article_name])) { try { $article = TBGWikiArticle::getByName($article_name); if ($article instanceof TBGWikiArticle) { self::$_articles[$article->getID()] = $article; self::$_article_names[$article_name] = $article->getID(); } else { throw new Exception('No such article'); } } catch (Exception $e) { throw $e; } } return self::$_articles[self::$_article_names[$article_name]]; }
public function listen_createNewProject(TBGEvent $event) { if (!TBGWikiArticle::getByName(ucfirst($event->getSubject()->getKey()) . ':MainPage') instanceof TBGWikiArticle) { $project_key = $event->getSubject()->getKey(); $article = TBGWikiArticle::createNew("{$project_key}:MainPage", "This is the wiki frontpage for {$event->getSubject()->getName()} \n\n[[Category:{$project_key}:About]]", true); $this->loadArticles($project_key); } }
public function runDetachFile(TBGrequest $request) { try { switch ($request['mode']) { case 'issue': $issue = TBGContext::factory()->TBGIssue($request['issue_id']); if ($issue->canRemoveAttachments() && (int) $request->getParameter('file_id', 0)) { \b2db\Core::getTable('TBGIssueFilesTable')->removeByIssueIDAndFileID($issue->getID(), (int) $request['file_id']); return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($issue->getFiles()) + count($issue->getLinks()), 'message' => TBGContext::getI18n()->__('The attachment has been removed'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue'))); break; case 'article': $article = TBGWikiArticle::getByName($request['article_name']); if ($article instanceof TBGWikiArticle && $article->canEdit() && (int) $request->getParameter('file_id', 0)) { $article->removeFile(TBGContext::factory()->TBGFile((int) $request['file_id'])); return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($article->getFiles()), 'message' => TBGContext::getI18n()->__('The attachment has been removed'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue'))); break; } } catch (Exception $e) { throw $e; } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Invalid mode'))); }
public function componentAttachedfile() { if ($this->mode == 'issue' && !isset($this->issue)) { $this->issue = TBGContext::factory()->TBGIssue($this->issue_id); } elseif ($this->mode == 'article' && !isset($this->article)) { $this->article = TBGWikiArticle::getByName($this->article_name); } $this->file_id = $this->file->getID(); }
/** * Show an article * * @param TBGRequest $request */ public function runEditArticle(TBGRequest $request) { $article_name = $this->article instanceof TBGWikiArticle ? $this->article->getName() : $request->getParameter('article_name'); if (!TBGContext::getModule('publish')->canUserEditArticle($article_name)) { TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article_name))); } if ($request->isMethod(TBGRequest::POST)) { if ($request->hasParameter('new_article_name') && $request->getParameter('new_article_name') != '') { if ($request->hasParameter('change_reason') && trim($request->getParameter('change_reason')) != '') { try { if ($request->getParameter('article_id')) { if (($article = PublishFactory::article($request->getParameter('article_id'))) && $article instanceof TBGWikiArticle) { if ($article->getLastUpdatedDate() != $request->getParameter('last_modified')) { $this->error = TBGContext::getI18n()->__('The file has been modified since you last opened it'); } else { try { $article->setName($request->getParameter('new_article_name')); $article->setContent($request->getRawParameter('new_article_content')); if ($request->getParameter('preview')) { $this->article = $article; } else { $article->doSave(array(), $request->getParameter('change_reason')); TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $article->getName()))); } } catch (Exception $e) { $this->error = $e->getMessage(); } } } } } catch (Exception $e) { } if (($article = TBGWikiArticle::getByName($request->getParameter('new_article_name'))) && $article instanceof TBGWikiArticle && $article->getID() != $request->getParameter('article_id')) { $this->error = TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name'); } elseif (!$article instanceof TBGWikiArticle) { if ($request->getParameter('preview')) { $article = new TBGWikiArticle(); $article->setContent($request->getRawParameter('new_article_content')); $article->setName($request->getParameter('new_article_name')); $this->article = $article; } else { $article_id = TBGWikiArticle::createNew($request->getParameter('new_article_name'), $request->getRawParameter('new_article_content', ''), true); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $request->getParameter('new_article_name')))); } } } else { $this->error = TBGContext::getI18n()->__('You have to provide a reason for the changes'); } } else { $this->error = TBGContext::getI18n()->__('You need to specify the article name'); } } $this->preview = (bool) $request->getParameter('preview'); $this->article_title = null; $this->article_content = null; $this->article_intro = null; $this->change_reason = null; if ($this->article instanceof TBGWikiArticle) { $this->article_title = $this->article->getTitle(); $this->article_content = $this->article->getContent(); if ($request->isMethod(TBGRequest::POST)) { if ($request->hasParameter('new_article_name')) { $this->article_title = $request->getParameter('new_article_name'); } if ($request->hasParameter('new_article_content')) { $this->article_content = $request->getRawParameter('new_article_content'); } if ($request->hasParameter('change_reason')) { $this->change_reason = $request->getParameter('change_reason'); } } } else { if ($request->hasParameter('new_article_content')) { $this->article_content = $request->getRawParameter('new_article_content'); } TBGContext::loadLibrary('publish'); $this->article_title = str_replace(array(':', '_'), array(' ', ' '), get_spaced_name($this->article_name)); } }
/** * Show an article * * @param TBGRequest $request */ public function runEditArticle(TBGRequest $request) { if (!$this->article->canEdit()) { TBGContext::setMessage('publish_article_error', TBGContext::getI18n()->__('You do not have permission to edit this article')); $this->forward(TBGContext::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(TBGArticlesTable::getTable()->getArticleByName($request['parent_article_name'])); $this->article->setManualName($request['manual_name']); if ($this->article->getArticleType() == TBGWikiArticle::TYPE_MANUAL && !$this->article->getName()) { $article_name_prefix = $this->article->getParentArticle() instanceof TBGWikiArticle ? $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(TBGContext::getI18n()->__('You need to specify a valid article name')); } if ($request['article_type'] == TBGWikiArticle::TYPE_MANUAL && (!$this->article->getManualName() || trim($this->article->getManualName()) == '' || !preg_match('/[\\w:]+/i', $this->article->getManualName()))) { throw new Exception(TBGContext::getI18n()->__('You need to specify a valid article name')); } if (TBGPublish::getModule()->getSetting('require_change_reason') == 1 && (!$this->change_reason || trim($this->change_reason) == '')) { throw new Exception(TBGContext::getI18n()->__('You have to provide a reason for the changes')); } if ($this->article->getLastUpdatedDate() != $request['last_modified']) { throw new Exception(TBGContext::getI18n()->__('The file has been modified since you last opened it')); } if (($article = TBGWikiArticle::getByName($request['new_new_article_name'])) && $article instanceof TBGWikiArticle && $article->getID() != $request['article_id']) { throw new Exception(TBGContext::getI18n()->__('An article with that name already exists. Please choose a different article name')); } if (!$this->preview) { $this->article->doSave(array(), $request['change_reason']); TBGContext::setMessage('publish_article_message', TBGContext::getI18n()->__('The article was saved')); $this->forward(TBGContext::getRouting()->generate('publish_article', array('article_name' => $this->article->getName()))); } } catch (Exception $e) { $this->error = $e->getMessage(); } } }