public static function createNew($name, $content, $published, $scope = null, $options = array())
 {
     $user_id = TBGContext::getUser() instanceof TBGUser ? TBGContext::getUser()->getID() : 0;
     $article = new TBGWikiArticle();
     $article->setName($name);
     $article->setContent($content);
     $article->setIsPublished($published);
     if (!isset($options['noauthor'])) {
         $article->setAuthor($user_id);
     } else {
         $article->setAuthor(0);
     }
     if ($scope !== null) {
         $article->setScope($scope);
     }
     $article->doSave($options);
     return $article->getID();
 }
Пример #2
0
 /**
  * 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));
     }
 }