lang $this->setupLocale(); } /** * * Return the message properties from a query string * * An internal HTTP redirect pass them via query string */ private static function getMessageQueryStringProperties(): array { $returnValues = array(); global $INPUT; $origin = $INPUT->str(self::ORIGIN_PAGE, null); if ($origin != null) { $returnValues = array( $origin, $INPUT->str(self::ORIGIN_TYPE, null) ); } return $returnValues; } function register(Doku_Event_Handler $controller) { /* This will call the function _displayRedirectMessage */ $controller->register_hook( 'TPL_ACT_RENDER', 'BEFORE', $this, '_displayRedirectMessage', array() ); } /** * Main function; dispatches the visual comment actions * @param $event Doku_Event */ function _displayRedirectMessage(&$event, $param) { $pageIdOrigin = null; $redirectSource = null; $messageQueryStringProperties = self::getMessageQueryStringProperties(); if (!empty($messageQueryStringProperties)) { list($pageIdOrigin, $redirectSource) = $messageQueryStringProperties; } if ($pageIdOrigin) { switch ($redirectSource) { case action_plugin_combo_router::TARGET_ORIGIN_PAGE_RULES: if (!$this->showMessageIfPublicAndPlanned()) { return; } $message = Message::createInfoMessage() ->addHtmlContent("
" . sprintf($this->getLang('message_redirected_by_redirect'), hsc($pageIdOrigin)) . "
"); break; case action_plugin_combo_router::TARGET_ORIGIN_START_PAGE: $message = Message::createWarningMessage() ->addHtmlContent("" . sprintf($this->lang['message_redirected_to_startpage'], hsc($pageIdOrigin)) . "
"); break; case action_plugin_combo_router::TARGET_ORIGIN_BEST_PAGE_NAME: $message = Message::createWarningMessage() ->addHtmlContent("" . sprintf($this->lang['message_redirected_to_bestpagename'], hsc($pageIdOrigin)) . "
"); break; case action_plugin_combo_router::TARGET_ORIGIN_BEST_END_PAGE_NAME: $message = Message::createWarningMessage() ->addHtmlContent("" . sprintf($this->lang['message_redirected_to_bestendpagename'], hsc($pageIdOrigin)) . "
"); break; case action_plugin_combo_router::TARGET_ORIGIN_BEST_NAMESPACE: $message = Message::createWarningMessage() ->addHtmlContent("" . sprintf($this->lang['message_redirected_to_bestnamespace'], hsc($pageIdOrigin)) . "
"); break; case action_plugin_combo_router::TARGET_ORIGIN_SEARCH_ENGINE: $message = Message::createWarningMessage() ->addHtmlContent("" . sprintf($this->lang['message_redirected_to_searchengine'], hsc($pageIdOrigin)) . "
"); break; case action_plugin_combo_router::GO_TO_EDIT_MODE: $message = Message::createInfoMessage() ->addHtmlContent("" . $this->lang['message_redirected_to_edit_mode'] . "
"); break; case action_plugin_combo_router::TARGET_ORIGIN_PERMALINK_EXTENDED: case action_plugin_combo_router::TARGET_ORIGIN_PERMALINK: $message = Message::createInfoMessage() ->addHtmlContent("" . $this->lang['message_redirected_from_permalink'] . "
"); break; case action_plugin_combo_router::TARGET_ORIGIN_CANONICAL: if (!$this->showMessageIfPublicAndPlanned()) { return; } $message = Message::createInfoMessage() ->addHtmlContent("" . $this->lang['message_redirected_from_canonical'] . "
"); break; default: LogUtility::msg("The redirection source ($redirectSource) is unknown. It was not expected", LogUtility::LVL_MSG_ERROR, action_plugin_combo_router::CANONICAL); return; } // Add a list of page with the same name to the message // if the redirections is not planned if ($redirectSource != action_plugin_combo_router::TARGET_ORIGIN_PAGE_RULES) { $pageOrigin = MarkupPath::createMarkupFromId($pageIdOrigin); $this->addToMessagePagesWithSameName($message, $pageOrigin); } if ($event->data === 'show' || $event->data === 'edit' || $event->data === 'search') { $html = $message ->setPlugin($this) ->setClass(action_plugin_combo_routermessage::REDIRECT_MANAGER_BOX_CLASS) ->setCanonical(action_plugin_combo_router::CANONICAL) ->setSignatureName(action_plugin_combo_router::URL_MANAGER_NAME) ->toHtmlBox(); LogUtility::infoToPublic($html, action_plugin_combo_router::CANONICAL); } } } /** * Add the page with the same page name but in an other location * @param Message $message * @param MarkupPath $pageOrigin */ function addToMessagePagesWithSameName(Message $message, MarkupPath $pageOrigin) { if (!$this->getConf(self::CONF_SHOW_PAGE_NAME_IS_NOT_UNIQUE) == 1) { return; } global $ID; // The page name $pageName = $pageOrigin->getNameOrDefault(); $pagesWithSameName = Index::getOrCreate()->getPagesWithSameLastName($pageOrigin); if (count($pagesWithSameName) === 1) { $page = $pagesWithSameName[0]; if ($page->getWikiId() === $ID) { // the page itself return; } } if (count($pagesWithSameName) > 0) { $message->setType(Message::TYPE_WARNING); // Assign the value to a variable to be able to use the construct .= if ($message->getPlainTextContent() <> '') { $message->addHtmlContent('