コード例 #1
0
 protected function initializeAdditional()
 {
     $sInitLog = "";
     //-----------------------------
     // create default home page
     //-----------------------------
     $oContentClass = AnwContentClasses::getContentClass('page');
     $sPageName = AnwComponent::globalCfgHomePage();
     $sPageLang = AnwComponent::globalCfgLangDefault();
     $sChangeComment = "Installation assistant";
     $oContent = new AnwContentPage($oContentClass);
     $sHomeTitle = $this->t_("local_homepage_title", array(), $sPageLang);
     $sHomeHead = $this->tpl()->homePageHead($sPageLang);
     $sHomeBody = $this->tpl()->homePageBody($sPageLang, ANWIKI_WEBSITE);
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_TITLE, array($sHomeTitle));
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_HEAD, array($sHomeHead));
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_BODY, array($sHomeBody));
     $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, $sChangeComment, $oContent);
     $sInitLog .= $this->t_("initlog_pagecreated", array('pagename' => $sPageName)) . '<br/>';
     //-----------------------------
     // create default menu
     //-----------------------------
     $oContentClass = AnwContentClasses::getContentClass('menu');
     $sPageName = 'en/_include/menu';
     //TODO
     $sPageLang = Anwi18n::langExists('en') ? 'en' : AnwComponent::globalCfgLangDefault();
     //TODO
     $sChangeComment = "Installation assistant";
     $oContent = new AnwContentPage($oContentClass);
     //menu title
     $sMenuTitle = $this->t_("local_menu_title", array(), $sPageLang);
     $oContent->setContentFieldValues(AnwIContentClassPageDefault_menu::FIELD_TITLE, array($sMenuTitle));
     //items
     $oContentFieldItems = $oContentClass->getContentField(AnwIContentClassPageDefault_menu::FIELD_ITEMS);
     $oSubContentItem = new AnwContentPage($oContentFieldItems);
     //main link
     $oContentFieldMainLink = $oContentFieldItems->getContentField(AnwIContentFieldPage_menu_menuItem::FIELD_MAINLINK);
     $oSubContentMainLink = new AnwContentPage($oContentFieldMainLink);
     $sMainLinkTitle = $this->t_("local_menu_mainlink_title", array(), $sPageLang);
     $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_TITLE, array($sMainLinkTitle));
     $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_URL, array(AnwComponent::globalCfgHomePage()));
     $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_TARGET, array(AnwIPage_link::TARGET_SELF));
     $oSubContentItem->setSubContents(AnwIContentFieldPage_menu_menuItem::FIELD_MAINLINK, array($oSubContentMainLink));
     $oContent->setSubContents(AnwIContentClassPageDefault_menu::FIELD_ITEMS, array($oSubContentItem));
     $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, $sChangeComment, $oContent);
     $sInitLog .= $this->t_("initlog_pagecreated", array('pagename' => $sPageName)) . '<br/>';
     return $sInitLog;
 }
コード例 #2
0
 /**
  * If we come from action "history", returns the page requested.
  */
 protected function getPageForHistory()
 {
     static $oPageForHistory = null, $bInitialized = false;
     // only initialize first time for performances saving
     if (!$bInitialized) {
         // only look for page if no pagegroup was requested - important for checkActionAllowed()
         if (!$this->getPageGroupForHistory()) {
             $nPageId = (int) AnwEnv::_GET("page");
             if ($nPageId > 0) {
                 try {
                     $oPageTmp = AnwPage::getLastPageRevision($nPageId);
                 } catch (AnwPageNotFoundException $e) {
                     throw new AnwBadCallException();
                 }
                 $oPageTmp->setSkipLoadingContent(true);
                 if ($oPageTmp->exists()) {
                     $oPageForHistory = $oPageTmp;
                 }
             }
         }
         $bInitialized = true;
     }
     return $oPageForHistory;
 }
コード例 #3
0
ファイル: action_diff.php プロジェクト: MenZil-Team/anwiki
 function run()
 {
     try {
         $nPageId = (int) AnwEnv::_GET("page");
         if ($nPageId <= 0) {
             throw new AnwBadCallException();
         }
         //find TO revision
         $nRevToChangeId = (int) AnwEnv::_GET("revto");
         if ($nRevToChangeId <= 0) {
             throw new AnwBadCallException();
         } else {
             $oPageRevTo = AnwPage::getPageByChangeId($nPageId, $nRevToChangeId);
         }
         //find FROM revision
         $nRevFromChangeId = (int) AnwEnv::_GET("revfrom");
         if ($nRevFromChangeId <= 0) {
             try {
                 $oPageRevFrom = $oPageRevTo->getPreviousArchive();
             } catch (AnwArchiveNotFoundException $e) {
                 //if TO revision is already the last...
                 $oPageRevFrom = $oPageRevTo;
             }
         } else {
             $oPageRevFrom = AnwPage::getPageByChangeId($nPageId, $nRevFromChangeId);
         }
         if (!$oPageRevTo) {
             throw new AnwBadCallException("page revision TO not found :" . $nRevToChangeId);
         }
         if (!$oPageRevTo->getContent() instanceof AnwContentPage) {
             throw new AnwUnexpectedException("error getcontent for page revision TO :" . $nRevToChangeId);
         }
         if (!$oPageRevFrom) {
             throw new AnwBadCallException("page revision FROM not found :" . $nRevFromChangeId);
         }
         if (!$oPageRevFrom->getContent() instanceof AnwContentPage) {
             throw new AnwUnexpectedException("error getcontent for page revision FROM :" . $nRevFromChangeId);
         }
         // check permissions
         $oPageRevFrom->checkGlobalAndViewActionAllowed($this->getName());
         $oPageRevTo->checkGlobalAndViewActionAllowed($this->getName());
         $oContentXmlFrom = $oPageRevFrom->getContent()->toXml();
         $oContentXmlTo = $oPageRevTo->getContent()->toXml();
     } catch (AnwBadPageNameException $e) {
         $this->error($this->g_("err_badcall"));
     } catch (AnwBadCallException $e) {
         $this->error($this->g_("err_badcall"));
     } catch (AnwPageNotFoundException $e) {
         $this->error($this->g_("err_badcall"));
     } catch (AnwArchiveNotFoundException $e) {
         $this->error($this->g_("err_badcall"));
     }
     $this->setTitle($this->t_("title", array("pagename" => $oPageRevTo->getName())));
     $oDiffs = new AnwDiffs($oContentXmlFrom, $oContentXmlTo);
     if (!AnwCurrentSession::getUser()->isPhpEditionAllowed()) {
         $oDiffs->hidePhpCode();
     } else {
         $oDiffs->showPhpCode();
     }
     $this->out .= $this->tpl()->beforeDiffs($this->linkMe(), $oPageRevFrom, $oPageRevTo, $oPageRevTo->getActivePage());
     if ($oPageRevFrom->getChangeId() == $oPageRevTo->getChangeId()) {
         $this->out .= $this->tpl()->drawNotice($this->t_("notice_same"));
     }
     if ($oPageRevFrom->getChangeId() > $oPageRevTo->getChangeId()) {
         $this->out .= $this->tpl()->drawNotice($this->t_("notice_reverse"));
     }
     $this->renderDiffs($oDiffs);
 }
コード例 #4
0
ファイル: action_revert.php プロジェクト: MenZil-Team/anwiki
 private function doRevert($oPageGroup, $aaRevertPlan)
 {
     $nTime = time();
     // simulation
     $aoAllFutureContents = array();
     foreach ($aaRevertPlan['REVERT'] as $aoRevertPages) {
         $oPageCurrent = $aoRevertPages[0];
         $oPageForRevert = $aoRevertPages[1];
         if (isset($aoAllFutureContents[$oPageForRevert->getLang()])) {
             throw new AnwUnexpectedException("already have a content for this lang");
         }
         $aoAllFutureContents[$oPageForRevert->getLang()] = $oPageForRevert->getContent();
     }
     foreach ($aaRevertPlan['RESTORE'] as $oPageForRestore) {
         if (isset($aoAllFutureContents[$oPageForRestore->getLang()])) {
             throw new AnwUnexpectedException("already have a content for this lang");
         }
         $aoAllFutureContents[$oPageForRestore->getLang()] = $oPageForRestore->getContent();
     }
     foreach ($aaRevertPlan['KEEP'] as $oPageKept) {
         if (isset($aoAllFutureContents[$oPageKept->getLang()])) {
             throw new AnwUnexpectedException("already have a content for this lang");
         }
         $aoAllFutureContents[$oPageKept->getLang()] = $oPageKept->getContent();
     }
     // make sure that everything is in order... (or throws an exception)
     AnwPage::checkSimilarContents($aoAllFutureContents);
     // now, apply changes
     AnwStorage::transactionStart();
     try {
         //important, firstly delete pages which needs it, to avoid conflicts when reverting or creating pages
         foreach ($aaRevertPlan['DELETE'] as $oPageForDelete) {
             $sChangeComment = "delete for revert";
             $oPageForDelete->delete($nTime, $sChangeComment);
         }
         foreach ($aaRevertPlan['REVERT'] as $aoRevertPages) {
             $oPageCurrent = $aoRevertPages[0];
             $oPageForRevert = $aoRevertPages[1];
             $sChangeComment = "revert to old revision";
             $oPageCurrent->revertToRevision($oPageForRevert, $nTime, $sChangeComment);
         }
         foreach ($aaRevertPlan['RESTORE'] as $oPageForRestore) {
             $sChangeComment = "restore for revert";
             $oPageForRestore->restoreArchive($nTime, $sChangeComment);
         }
         AnwStorage::transactionCommit();
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
     // redirect to reverted page if possible
     $oPageGroup->refresh();
     if (count($oPageGroup->getPages()) > 0) {
         $oPageRedirect = $oPageGroup->getPreferedPage();
         AnwUtils::redirect(AnwUtils::link($oPageRedirect));
     } else {
         // no page available, go home
         AnwUtils::redirect();
     }
 }
コード例 #5
0
ファイル: class_output.php プロジェクト: MenZil-Team/anwiki
 private function doBindLinksToPreferedLang($sContentHtmlAndPhp)
 {
     $aoOutgoingLinks = AnwPage::getOutgoingLinksFromContent($sContentHtmlAndPhp);
     foreach ($aoOutgoingLinks as $sOutgoingLink => $oPageTarget) {
         //get target page in the lang we want
         $sPreferedLang = $this->oPage->getLang();
         $oPageTarget = $oPageTarget->getPageGroup()->getPreferedPage($sPreferedLang);
         //update the link in content
         $sLinkTarget = AnwUtils::link($oPageTarget->getName());
         $sLinkLang = $oPageTarget->getLang();
         $sContentHtmlAndPhp = AnwPage::updateOutgoingLinkInContent($sOutgoingLink, $sLinkTarget, $sContentHtmlAndPhp, $sLinkLang);
     }
     return $sContentHtmlAndPhp;
 }
コード例 #6
0
ファイル: action_create.php プロジェクト: MenZil-Team/anwiki
 private function createPageProcess($sLang, $sContentClass)
 {
     $sPageName = $this->getPageName();
     if (!AnwCurrentSession::isActionAllowed($sPageName, 'create', $sLang)) {
         throw new AnwAclException("permission create denied");
     }
     $oContentClass = AnwContentClasses::getContentClass($sContentClass);
     AnwStorage::transactionStart();
     try {
         //create page
         $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sLang);
         //should we create translations for this new page?
         $asAvailableLangs = $oPage->getPageGroup()->getAvailableLangs();
         //check permissions : translate
         foreach ($asAvailableLangs as $sLang) {
             if (AnwEnv::_POST($this->getChkName($sLang))) {
                 $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), "");
                 if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sLang)) {
                     throw new AnwAclException("permission translate denied");
                 }
             }
         }
         foreach ($asAvailableLangs as $sLang) {
             if (AnwEnv::_POST($this->getChkName($sLang))) {
                 $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), "");
                 //create translation
                 $oPageTranslation = $oPage->createNewTranslation($sTranslationName, $sLang);
             }
         }
         AnwStorage::transactionCommit();
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
     AnwUtils::redirect(AnwUtils::link($oPage, "edit"));
 }
コード例 #7
0
ファイル: action_import.php プロジェクト: MenZil-Team/anwiki
 private function checkPermissions($sPageName, $sPageLang, $sPageContent)
 {
     $asNotices = array();
     //check that page don't exist
     if (!AnwPage::isAvailablePageName($sPageName)) {
         $asNotices[] = $this->t_("notice_exists");
     }
     //check PHP permission
     if (AnwUtils::contentHasPhpCode($sPageContent) && !AnwCurrentSession::getUser()->isPhpEditionAllowed()) {
         $asNotices[] = $this->t_("notice_php");
     }
     //check JS permission
     if (AnwUtils::contentHasJsCode($sPageContent) && !AnwCurrentSession::getUser()->isJsEditionAllowed()) {
         $asNotices[] = $this->t_("notice_js");
     }
     //check ACL permission : create and edit
     if (!AnwCurrentSession::isActionAllowed($sPageName, "create", $sPageLang) || !AnwCurrentSession::isActionAllowed($sPageName, "edit", $sPageLang)) {
         $asNotices[] = $this->t_("notice_acl");
     }
     return $asNotices;
 }
コード例 #8
0
 protected function getoPage()
 {
     if (!self::$oPage) {
         if (AnwEnv::_GET(self::GET_PAGENAME)) {
             //read pagename from env
             $sPageName = self::getCurrentPageName();
             if (AnwPage::isValidPageName(self::getCurrentPageName())) {
                 self::$oPage = new AnwPageByName($sPageName);
             } else {
                 //warning, doing error404() here may lead to infinite recursion in some very special cases... that's why $oPage is set to the homepage here, to prevent loop.
                 self::$oPage = new AnwPageByName(self::globalCfgHomePage());
                 self::error404();
             }
         } else {
             //load homepage
             $sPageName = self::globalCfgHomePage();
             self::$oPage = new AnwPageByName($sPageName);
             //make sure to load homepage in the session language, if available
             try {
                 $sWantedLang = AnwCurrentSession::getLang();
                 if (self::$oPage->exists() && self::$oPage->getLang() != $sWantedLang) {
                     $aoPages = self::$oPage->getPageGroup()->getPages();
                     if (isset($aoPages[$sWantedLang])) {
                         self::$oPage = $aoPages[$sWantedLang];
                         self::debug("Homepage found in current session lang");
                     } else {
                         self::debug("Homepage NOT found in current session lang");
                     }
                 }
             } catch (AnwException $e) {
             }
         }
     }
     return self::$oPage;
 }
コード例 #9
0
 private static function getPageFromData($oDataPage, $bArchive = false, $bActiveExists = -1)
 {
     $sContentClass = $oDataPage->PageGroupContentClass;
     $oPageGroup = new AnwPageGroup($oDataPage->PageGroup, $sContentClass);
     $nPageId = $oDataPage->PageId;
     $sPageName = $oDataPage->PageName;
     $sPageLang = $oDataPage->PageLang;
     $nPageTime = $oDataPage->PageTime;
     $nPageChangeId = $oDataPage->PageChange;
     $sPageContent = $oDataPage->PageContent;
     //may be null if performances+memory boost
     $bPageTranslated = (bool) $oDataPage->PageTranslated;
     $nPageTranslatedPercent = $oDataPage->PageTranslatedPercent;
     $nPageCreationTime = $oDataPage->PageCreationTime;
     if (!$bArchive) {
         $bActiveExists = true;
     }
     $oPage = AnwPage::rebuildPage($nPageId, $sPageName, $oPageGroup, $sPageLang, $nPageTime, $nPageChangeId, $sPageContent, $bPageTranslated, $nPageTranslatedPercent, $nPageCreationTime, $bArchive, $bActiveExists);
     return $oPage;
 }
コード例 #10
0
ファイル: class_page.php プロジェクト: MenZil-Team/anwiki
 function loadInfo()
 {
     if ($this->bInfoLoaded) {
         return;
     }
     try {
         $this->debug("Loading page info..." . ($this->bSkipLoadingTranslationsContent ? "(boost)" : "") . ($this->bSkipLoadingContent ? "(superboost)" : ""));
         if (!$this->isArchive()) {
             $oPage = AnwStorage::getPageByName($this->sName, $this->bSkipLoadingTranslationsContent, $this->bSkipLoadingContent);
         } else {
             $oPage = AnwStorage::getPageArchiveByName($this->sName, $this->nChangeId, $this->bSkipLoadingTranslationsContent, $this->bSkipLoadingContent);
         }
         $this->nId = $oPage->getId();
         parent::doLoadInfo($oPage);
     } catch (AnwPageNotFoundException $e) {
         //page doesn't exist
         $this->bExists = false;
     }
     $this->bInfoLoaded = true;
 }