private function doRename($sNewName, $sComment, $bUpdateLinks) { $nTime = time(); try { if (!AnwCurrentSession::isActionAllowed($sNewName, 'create', $this->getoPage()->getLang())) { throw new AnwAclException("permission create denied"); } $oPageTest = new AnwPageByName($sNewName); $oPageTest->setSkipLoadingContent(true); if ($oPageTest->exists()) { throw new AnwPageAlreadyExistsException(); } $sOldName = $this->getoPage()->getName(); //rename page $this->getoPage()->rename($sNewName, $bUpdateLinks); //unlock $this->unlockPageForEdition(); //redirect AnwUtils::redirect(AnwUtils::link($sNewName)); } catch (AnwBadPageNameException $e) { $sError = $this->g_("err_badpagename"); $this->renameForm($sNewName, $sComment, $sError); } catch (AnwBadCommentException $e) { $sError = $this->g_("err_badcomment"); $this->renameForm($sNewName, $sComment, $sError); } catch (AnwPageAlreadyExistsException $e) { $sError = $this->g_("err_pagealreadyexists"); $this->renameForm($sNewName, $sComment, $sError); } catch (AnwAclException $e) { $sError = $this->g_("err_nopermission"); $this->renameForm($sNewName, $sComment, $sError); } }
static function isCurrentPage($sPageName) { try { $sCurrentPage = AnwActionPage::getCurrentPageName(); if ($sPageName == $sCurrentPage) { AnwDebug::log("isCurrentPage (" . $sPageName . ") : YES (currently " . $sCurrentPage . ")"); return true; } //check translations if page exists $oPage = new AnwPageByName($sCurrentPage); if ($oPage->exists()) { $aoPages = $oPage->getPageGroup()->getPages(); foreach ($aoPages as $oPageTranslation) { if ($oPageTranslation->getName() == $sPageName) { AnwDebug::log("isCurrentPage (" . $sPageName . ") : YES (currently " . $sCurrentPage . ")"); return true; } } } } catch (AnwException $e) { } AnwDebug::log("isCurrentPage (" . $sPageName . ") : NO (currently " . $sCurrentPage . ")"); return false; }
protected static function getCurrentPageNames() { $asCurrentPageNames = array(); $sCurrentPageName = AnwActionPage::getCurrentPageName(); if (!$sCurrentPageName) { // FS#144 - avoids AnwBadPageNameException return $asCurrentPageNames; } //allow currentPageNames even if it doesn't exist (useful for action_output) $asCurrentPageNames[] = $sCurrentPageName; try { $oCurrentPage = new AnwPageByName($sCurrentPageName); $oCurrentPage->setSkipLoadingTranslationsContent(true); $aoCurrentPageTranslations = $oCurrentPage->getPageGroup()->getPages($oCurrentPage); foreach ($aoCurrentPageTranslations as $oTranslation) { $asCurrentPageNames[] = $oTranslation->getName(); } } catch (AnwPageNotFoundException $e) { } return $asCurrentPageNames; }
static function getByNameOrSecondChance($sPageName) { //try to find page by name $oPageTest = new AnwPageByName($sPageName); if ($oPageTest->exists()) { return $oPageTest; } //if name not found, try second chance $oPageTest = $oPageTest->getSecondChance(); if ($oPageTest) { return $oPageTest; } //page not found return false; }
private function saveTranslation($nRevChangeId) { $bPageWasEditedDuringTranslation = $this->getoPage()->getChangeId() > $nRevChangeId ? true : false; if ($bPageWasEditedDuringTranslation) { //someone has edited the page since user was translating it, let's get the old revision from which we started the translation AnwDebug::log("Someone edited the page since we were translating it"); $oPageRev = new AnwPageByName($this->getoPage()->getName(), $nRevChangeId); $oContentBeforeEdit = $oPageRev->getContent(); $oContentAfterEdit = $this->getoPage()->getContent(); } else { $oPageRev = $this->getoPage(); } $oContent = clone $oPageRev->getContent(); //preload original lang $fOnValue = "preloadOriginalLang_onContentFieldValue"; AnwUtils::runCallbacksOnTranslatableField($this, $oPageRev->getContent(), $fOnValue); //update content from post $fOnValue = "saveTranslation_cbkOnValue"; //$fBeforeContentField $fBeforeContentField = "saveTranslation_cbkBeforeField"; $fAfterContentField = "saveTranslation_cbkAfterField"; AnwUtils::runCallbacksOnTranslatableField($this, $oContent, $fOnValue, $fBeforeContentField, $fAfterContentField); //if needed, apply again the edit which was done since the translation if ($bPageWasEditedDuringTranslation) { AnwDebug::log("Someone edited the page since we were translating it --> reapplying changes"); $oContent = AnwAutoSync::propagateContentEdition($oContentBeforeEdit, $oContentAfterEdit, $oContent); } //save changes to the current page $this->debug("Updating current page..."); $this->getoPage()->saveTranslation($oContent); //unlock $this->unlockPageForEdition(); //redirect AnwUtils::redirect(AnwUtils::link($this->getPageName())); }