示例#1
0
 /**
  * Updates wiki-links of a page
  *
  * @param WikiPage $page
  * @param bool $justCreated if page was just created
  * @return bool
  */
 private function updateWikiLinks(WikiPage $page, $justCreated = false)
 {
     if ($justCreated) {
         $criteria = new CDbCriteria();
         $criteria->compare('wiki_uid', $page->getWikiUid());
         WikiLink::model()->updateAll(array('page_to_id' => $page->id), $criteria);
     }
     WikiLink::model()->deleteAllByAttributes(array('page_from_id' => $page->id));
     $links = $this->getWikiLinks($page->content);
     foreach ($links as $link) {
         $wikiLink = new WikiLink();
         $wikiLink->page_from_id = $page->id;
         $wikiLink->wiki_uid = $link['wiki_uid'];
         $wikiLink->title = $link['title'];
         $linkedPage = WikiPage::model()->findByWikiUid($link['wiki_uid']);
         if ($linkedPage) {
             $wikiLink->page_to_id = $linkedPage->id;
         }
         if (!$wikiLink->save()) {
             return false;
         }
     }
     return true;
 }
示例#2
0
 /**
  * Title field validator
  * 
  * @param type $attribute
  * @param type $params
  */
 public function validateTitle($attribute, $params)
 {
     if (strpos($this->title, "/") !== false || strpos($this->title, ")") !== false || strpos($this->title, "(") !== false) {
         $this->addError('title', Yii::t('WikiModule.base', 'Invalid character in page title!'));
     }
     $criteria = new CDbCriteria();
     if (!$this->isNewRecord) {
         $criteria->condition = 't.id != :selfId';
         $criteria->params = array(':selfId' => $this->id);
     }
     $page = WikiPage::model()->contentContainer($this->content->container)->findByAttributes(array('title' => $this->title), $criteria);
     if ($page !== null) {
         $this->addError('title', Yii::t('WikiModule.base', 'Page title already in use!'));
     }
 }
 public function actionRevert()
 {
     $this->forcePostRequest();
     $id = (int) Yii::app()->request->getQuery('id');
     $toRevision = (int) Yii::app()->request->getQuery('toRevision');
     $page = WikiPage::model()->contentContainer($this->contentContainer)->findByPk($id);
     if ($page === null) {
         throw new CHttpException(404, 'Page not found!');
     }
     if ($page->admin_only && !$page->canAdminister()) {
         throw new CHttpException(403, 'Page not editable!');
     }
     $revision = WikiPageRevision::model()->findByAttributes(array('revision' => $toRevision, 'wiki_page_id' => $page->id));
     if ($revision->is_latest) {
         throw new CHttpException(404, 'Already latest revision!');
     }
     $revertedRevision = $page->createRevision();
     $revertedRevision->content = $revision->content;
     $revertedRevision->save();
     $this->redirect($this->createContainerUrl('view', array('title' => $page->title)));
 }
示例#4
0
 public function disableUserModule(User $user)
 {
     foreach (WikiPage::model()->contentContainer($user)->findAll() as $page) {
         $page->delete();
     }
 }