function runAndOutput() { try { AnwDebug::startbench("action runAndOutput", true); //captcha request? if (AnwEnv::_GET(self::GET_CAPTCHA)) { $this->doCaptcha(); exit; } //make sure this action is enabled in configuration if (!in_array($this->getName(), AnwComponent::getEnabledComponents(AnwComponent::TYPE_ACTION))) { throw new AnwAclException("Trying to execute an action which is not enabled"); } //is it an admin action? if ($this instanceof AnwAdminAction) { if (!AnwCurrentSession::getUser()->isAdminAllowed()) { throw new AnwAclException("Admin is not allowed"); } } //does action require https if available? if (self::isHttpsAction($this->getName())) { //do we need to redirect to https? if (self::globalCfgHttpsEnabled() && !AnwEnv::isHttps()) { //redirect to https self::debug("Redirecting to https..."); AnwUtils::httpPostToSession(); $asParams = $_GET; $sLink = AnwUtils::alink($this->getName(), $asParams); AnwUtils::redirect($sLink); //should automatically use https } } if (AnwCurrentSession::needsReauth()) { //reauth processing if (AnwEnv::_POST("reauth")) { self::debug("Processing reauth request..."); try { //check password and reset reauth $this->doReauth(AnwEnv::_POST("reauth")); self::debug("Reauth request success!"); } catch (AnwException $e) { //reauth failed, show reauth form again self::debug("Reauth success failed."); $this->doReauthForm(); //post data is already in session exit; } } //must the user reauth for this action? - do this after reauth processing if ($this instanceof AnwHarmlessAction) { //ok, user is authorized to run action without reauthenticating } else { //user needs to reauthenticate $this->checkReauth(); } } //restore POST if any in session AnwUtils::restoreHttpPostFromSession(); $this->initializeAction(); //run the action $this->init(); $this->run(); AnwDebug::stopbench("action runAndOutput"); $this->output(); } catch (AnwLockException $e) { $aoLocks = $e->getLocks(); $asLockInfos = array(); foreach ($aoLocks as $oLock) { $nLockType = $oLock->getLockType(); switch ($nLockType) { case AnwLock::TYPE_PAGEONLY: $sTranslation = "err_ex_lock_details_pageonly"; break; case AnwLock::TYPE_PAGEGROUP: $sTranslation = "err_ex_lock_details_pagegroup"; break; default: throw new AnwUnexpectedException("lock type unknown"); break; } $asLockInfos[] = self::g_($sTranslation, array("user" => '<b>' . AnwUtils::xText($oLock->getLockUser()->getDisplayName()) . '</b>', "pagename" => '<i>' . AnwUtils::xText($oLock->getLockPage()->getName()) . '</i>', "timestart" => Anwi18n::dateTime($oLock->getLockTime()), "timeseen" => Anwi18n::dateTime($oLock->getLockTimeLast()), "timeexpire" => Anwi18n::dateTime($oLock->getLockTimeLast() + self::globalCfgLocksExpiry()))); } $this->headJs($this->tpl()->errorLock_js()); $this->out = $this->tpl()->errorLock($asLockInfos); $this->output(); } catch (AnwException $e) { $nErrorNumber = false; if ($e instanceof AnwAclPhpEditionException) { $sTitle = self::g_("err_ex_acl_t"); $sExplain = self::g_("err_ex_acl_php_p"); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwAclJsEditionException) { $sTitle = self::g_("err_ex_acl_t"); $sExplain = self::g_("err_ex_acl_js_p"); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwAclMinTranslatedPercentException) { $sTitle = self::g_("err_ex_acl_t"); $sExplain = self::g_("err_ex_acl_mintranslatedpercent_p", array('percent' => $e->getTranslatedPercent())); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwAclException) { $sTitle = self::g_("err_ex_acl_t"); if (AnwCurrentSession::isLoggedIn()) { $sExplain = self::g_("err_ex_acl_loggedin_p"); } else { $sExplain = self::g_("err_ex_acl_loggedout_p"); } $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwBadCallException) { $sTitle = self::g_("err_ex_badcall_t"); $sExplain = self::g_("err_ex_badcall_p"); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwDbConnectException) { $sTitle = self::g_("err_ex_dbconnect_t"); $sExplain = self::g_("err_ex_dbconnect_p"); $sImageSrc = AnwUtils::pathImg("error.gif"); $nErrorNumber = AnwDebug::reportError($e); } else { $sTitle = self::g_("err_ex_unexpected_t"); $sExplain = self::g_("err_ex_unexpected_p"); $sImageSrc = AnwUtils::pathImg("error.gif"); $nErrorNumber = AnwDebug::reportError($e); } } } } } } $this->out = $this->tpl()->errorException($sTitle, $sExplain, $sImageSrc, $nErrorNumber); //self::output(); //not use $this to avoid potential errors if it's an ActionPage $this->output(); } }
private function showFormRevert($oPageGroup, $aaRevertPlan, $nRevToChangeId) { $aoChanges = array(); $aoChangesUnfiltered = AnwStorage::getLastChanges(false, 0, null, null, null, null, $oPageGroup); foreach ($aoChangesUnfiltered as $oChange) { // only keep "revertable" changes if ($oChange->isRevertAvailable()) { $aoChanges[] = $oChange; } } $sHistoryPageGroupLink = false; if (AnwCurrentSession::isActionGlobalAllowed("lastchanges")) { $sHistoryPageGroupLink = AnwUtils::aLink("lastchanges", array("pagegroup" => $oPageGroup->getId())); } $this->out .= $this->tpl()->formRevert($this->linkMe(array("pagegroup" => $oPageGroup->getId())), $aoChanges, $nRevToChangeId, $sHistoryPageGroupLink); foreach ($aaRevertPlan['DELETE'] as $oPageForDelete) { $this->out .= $this->tpl()->simulateDelete($oPageForDelete->getLang(), $oPageForDelete->getName()); } foreach ($aaRevertPlan['REVERT'] as $aoRevertPages) { $oPageCurrent = $aoRevertPages[0]; $oPageForRevert = $aoRevertPages[1]; if ($oPageCurrent->isGlobalAndViewActionAllowed('diff')) { $sImgDiff = AnwUtils::xQuote(AnwUtils::pathImg("diff.gif")); $sAltDiff = AnwUtils::xQuote(self::g_("change_diff_link")); $sLnkDiff = AnwUtils::xQuote(AnwUtils::link($oPageCurrent, "diff", array("page" => $oPageCurrent->getId(), "revfrom" => $oPageCurrent->getChangeId(), "revto" => $oPageForRevert->getChangeId()))); $sLnkDiff = <<<EOF <a href="{$sLnkDiff}" title="{$sAltDiff}" target="_blank"><img src="{$sImgDiff}" alt="{$sAltDiff}"/></a> EOF; } else { $sLnkDiff = ''; } $this->out .= $this->tpl()->simulateRevert($oPageCurrent->getLang(), $oPageCurrent->getName(), $oPageForRevert, $sLnkDiff); } foreach ($aaRevertPlan['RESTORE'] as $oPageForRestore) { $this->out .= $this->tpl()->simulateCreate($oPageForRestore); } foreach ($aaRevertPlan['KEEP'] as $oPageForKeep) { $this->out .= $this->tpl()->simulateKeep($oPageForKeep->getLang(), $oPageForKeep->getName()); } $this->out .= $this->tpl()->end(); }
static function srcFlag($sLang) { return AnwUtils::pathImg("flags/" . strtolower($sLang) . ".png"); }
function showHtml($aoChanges, $amAllChangeTypes, $amDisplayChangeTypes, $asAllLangs, $asDisplayLangs, $asAllClasses, $asDisplayClasses, $nStartPrev, $nStartNext, $sTitle, $bGrouped, $oPage, $oPageGroup) { $this->out .= $this->tpl()->lastchangesHeader($sTitle); $sUrl = AnwEnv::_SERVER('REQUEST_URI'); $sUrl = preg_replace("/&s=([0-9]*)/", "", $sUrl); //rss link $sRssLink = $sUrl; $sRssLink .= '&feed=rss2'; //without start $this->head($this->tpl()->headRss($sRssLink)); $this->out .= $this->tpl()->filterBefore($this->linkMe()); $nPageId = $oPage ? $oPage->getId() : null; $nPageGroupId = $oPageGroup ? $oPageGroup->getId() : null; $bShowHistoryColumn = $oPage ? false : true; //disable filters if a page is selected if (!$nPageId) { //filter lang $this->out .= $this->tpl()->filterLangs($asAllLangs, $asDisplayLangs); } if (!$nPageId && !$nPageGroupId) { //filter contentclass $this->out .= $this->tpl()->filterClass($asAllClasses, $asDisplayClasses); } //filter changes types $this->out .= $this->tpl()->filterChangeTypes($amAllChangeTypes, $amDisplayChangeTypes); //display mode $sHistoryPageGroupLink = false; if ($oPage && AnwCurrentSession::isActionGlobalAllowed($this->getName())) { $sHistoryPageGroupLink = AnwEnv::_SERVER('REQUEST_URI'); $sHistoryPageGroupLink = preg_replace("\$&page=([0-9]*)\$", "", $sHistoryPageGroupLink); $sHistoryPageGroupLink = preg_replace("\$&pagegroup=([0-9]*)\$", "", $sHistoryPageGroupLink); $sHistoryPageGroupLink .= '&pagegroup=' . $oPage->getPageGroup()->getId(); } $this->out .= $this->tpl()->filterAfter($bGrouped, $nPageId, $nPageGroupId, $sRssLink, $sHistoryPageGroupLink); //nav $sLatestLink = ""; $sPrevLink = ""; if ($nStartPrev >= 0) { $sPrevLink = $sUrl . '&s=' . $nStartPrev; if ($nStartPrev > 0) { $sLatestLink = $sUrl . '&s=0'; } } $sNextLink = $sUrl . '&s=' . $nStartNext; $this->out .= $this->tpl()->nav($sLatestLink, $sPrevLink, $sNextLink, $bShowHistoryColumn); foreach ($aoChanges as $i => $oChange) { $sType = AnwChange::changeTypei18n($oChange->getType()); //links $sLnkPage = '<span class="pageid">#' . $oChange->getPageId() . '</span>'; $sLnkDiff = '-'; if ($oChange->activePageExists()) { $sLnkPage = $oChange->getActivePage()->link(); //active link, if it exists } //diffs link if ($oChange->isGlobalAndViewActionAllowed('diff')) { if ($oChange->isDiffAvailable()) { $sImgDiff = AnwUtils::xQuote(AnwUtils::pathImg("diff.gif")); $sAltDiff = AnwUtils::xQuote(self::g_("change_diff_link")); $sLnkDiff = AnwUtils::xQuote(AnwUtils::alink("diff", array("page" => $oChange->getPageId(), "revto" => $oChange->getChangeId()))); $sLnkDiff = <<<EOF <a href="{$sLnkDiff}" title="{$sAltDiff}"><img src="{$sImgDiff}" alt="{$sAltDiff}"/></a> EOF; } } //history link $sLnkHistory = false; if ($bShowHistoryColumn) { $sLnkHistory = " - "; if ($oChange->isActionAllowed('history')) { $sImgHistory = AnwUtils::xQuote(AnwUtils::pathImg("history.gif")); $sAltHistory = AnwUtils::xQuote($this->t_("change_history_link")); $sLnkHistory = AnwUtils::xQuote(AnwUtils::alink("lastchanges", array("page" => $oChange->getPageId()))); $sLnkHistory = <<<EOF <a href="{$sLnkHistory}" title="{$sAltHistory}"><img src="{$sImgHistory}" alt="{$sAltHistory}"/></a> EOF; } } //revert link $sLnkRevert = " - "; if ($oChange->isGlobalAndViewActionAllowed('revert')) { if ($oChange->isRevertAvailable()) { $sImgRevert = AnwUtils::xQuote(AnwUtils::pathImg("revert.gif")); $sAltRevert = AnwUtils::xQuote(self::t_("change_revert_link")); $sLnkRevert = AnwUtils::xQuote(AnwUtils::alink("revert", array("page" => $oChange->getPageId(), "revto" => $oChange->getChangeId()))); //we pass pageid instead of pagegroupid for better performances... $sLnkRevert = <<<EOF <a href="{$sLnkRevert}" title="{$sAltRevert}"><img src="{$sImgRevert}" alt="{$sAltRevert}"/></a> EOF; } } //output $this->out .= $this->tpl()->lastchangesLine(Anwi18n::dateTime($oChange->getTime()), $sType, $oChange->getComment(), $oChange->getInfo(), $oChange->getUser()->getDisplayName(), $sLnkPage, $sLnkDiff, $sLnkHistory, $sLnkRevert, $oChange->getPageName(), $oChange->getPageLang()); } $this->out .= $this->tpl()->lastchangesFooter(); }
function reauthForm($sFormAction, $sDisplayName) { $sImgSrc = AnwUtils::pathImg("warning.gif"); $sSubmitLabel = self::g_("in_submit"); $HTML = <<<EOF <div class="reauthinfo"> \t<h1>{$this->g_('reauth_t')}</h1> \t<img src="{$this->xQuote($sImgSrc)}" alt=""/> \t<form action="{$sFormAction}" method="post"> \t<p>{$this->g_('reauth_explain')}</p> \t<label for="reauth">{$this->g_('reauth_password', array('displayname' => $this->xText($sDisplayName)))}</label> \t<input type="password" name="reauth" class="intext" id="reauth"/> \t<input type="submit" value="{$this->xQuote($sSubmitLabel)}"/> \t</form> \t<div class="break"></div> </div> EOF; return $HTML; }