From d9de46354ee1df4b444a24e33e83b2b201bd2b24 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 29 Sep 2019 21:34:53 +0200 Subject: [PATCH] Handlers: set page title --- handlers/handler.cpp | 6 ++++++ handlers/handler.h | 1 + handlers/handlerallcategories.cpp | 1 + handlers/handlerallpages.cpp | 1 + handlers/handlercategory.cpp | 1 + handlers/handlerhistory.cpp | 5 ++++- handlers/handlerlogin.cpp | 1 + handlers/handlerpage.cpp | 1 + handlers/handlerpagedelete.cpp | 1 + handlers/handlerpageedit.cpp | 2 ++ handlers/handlersearch.cpp | 1 + 11 files changed, 20 insertions(+), 1 deletion(-) diff --git a/handlers/handler.cpp b/handlers/handler.cpp index 2111f48..89ce269 100644 --- a/handlers/handler.cpp +++ b/handlers/handler.cpp @@ -35,6 +35,7 @@ void Handler::setGeneralVars(TemplatePage &page) Response Handler::errorResponse(std::string errortitle, std::string errormessage, int status) { TemplatePage &error = this->templ->getPage("error"); + error.setVar("title", createPageTitle(errortitle)); error.setVar("errortitle", errortitle); error.setVar("errormessage", errormessage); // TODO: log? @@ -42,6 +43,11 @@ Response Handler::errorResponse(std::string errortitle, std::string errormessage return {status, error.render()}; } +std::string Handler::createPageTitle(std::string append) +{ + return this->handlersConfig->wikiname + " - " + append; // TODO: we might wanna make the format configurable +} + QueryOption Handler::queryOption(const Request &r) const { QueryOption result; diff --git a/handlers/handler.h b/handlers/handler.h index 58adf05..2b3185e 100644 --- a/handlers/handler.h +++ b/handlers/handler.h @@ -54,6 +54,7 @@ class Handler { } Response errorResponse(std::string errortitle, std::string errormessage, int status = 200); + std::string createPageTitle(std::string append); }; #endif // HANDLER_H diff --git a/handlers/handlerallcategories.cpp b/handlers/handlerallcategories.cpp index b00a0d4..26a6313 100644 --- a/handlers/handlerallcategories.cpp +++ b/handlers/handlerallcategories.cpp @@ -36,6 +36,7 @@ Response HandlerAllCategories::handleRequest(const Request &r) std::string body = this->templ->renderSearch(resultList, [&](std::string str) { return this->urlProvider->category(str); }); searchPage.setVar("categorylist", body); + searchPage.setVar("title", createPageTitle("All categories")); setGeneralVars(searchPage); Response response; diff --git a/handlers/handlerallpages.cpp b/handlers/handlerallpages.cpp index 2ac6373..d9e1a4a 100644 --- a/handlers/handlerallpages.cpp +++ b/handlers/handlerallpages.cpp @@ -35,6 +35,7 @@ Response HandlerAllPages::handleRequest(const Request &r) TemplatePage &searchPage = this->templ->getPage("allpages"); std::string body = this->templ->renderSearch(resultList); searchPage.setVar("pagelist", body); + searchPage.setVar("title", createPageTitle("All pages")); setGeneralVars(searchPage); response.setBody(searchPage.render()); response.setStatus(200); diff --git a/handlers/handlercategory.cpp b/handlers/handlercategory.cpp index 99844dc..3e52ea9 100644 --- a/handlers/handlercategory.cpp +++ b/handlers/handlercategory.cpp @@ -38,6 +38,7 @@ Response HandlerCategory::handleRequest(const Request &r) searchPage.setVar("pagelist", body); searchPage.setVar("categoryname", categoryname); setGeneralVars(searchPage); + searchPage.setVar("title", createPageTitle("Category: " + categoryname)); response.setBody(searchPage.render()); response.setStatus(200); return response; diff --git a/handlers/handlerhistory.cpp b/handlers/handlerhistory.cpp index 703a6d1..584b646 100644 --- a/handlers/handlerhistory.cpp +++ b/handlers/handlerhistory.cpp @@ -27,13 +27,14 @@ Response HandlerHistory::handleRequest(const Request &r) { QueryOption qo = queryOption(r); std::string page = r.get("page"); - + std::string title; if(page.empty()) { if(!this->userSession->user.permissions.canSeeGlobalHistory()) { return errorResponse("Permission denied", "You can't see the changes history on this wiki", 403); } + title = "History"; } else { @@ -42,6 +43,7 @@ Response HandlerHistory::handleRequest(const Request &r) { return errorResponse("Permission denied", "You cannot see the changes history of this page", 403); } + title = "History: " + page; } unsigned int count = 0; @@ -113,6 +115,7 @@ Response HandlerHistory::handleRequest(const Request &r) unsigned int neworder = (qo.order == DESCENDING) ? ASCENDING : DESCENDING; historyPage.setVar("linkrecentsort", makeSortedLink(qo.limit, qo.offset, neworder)); historyPage.setVar("revisionlist", this->templ->renderRevisionList(resultList, page.empty())); + historyPage.setVar("title", createPageTitle(title)); Response response; response.setBody(historyPage.render()); response.setStatus(200); diff --git a/handlers/handlerlogin.cpp b/handlers/handlerlogin.cpp index 20ca360..e2dc8f2 100644 --- a/handlers/handlerlogin.cpp +++ b/handlers/handlerlogin.cpp @@ -119,6 +119,7 @@ Response HandlerLogin::handleRequest(const Request &r) TemplatePage &loginTemplatePage = this->templ->getPage("login"); setGeneralVars(loginTemplatePage); loginTemplatePage.setVar("loginurl", urlProvider->login(page)); + loginTemplatePage.setVar("title", createPageTitle("Login")); Response result; result.setStatus(200); result.setBody(loginTemplatePage.render()); diff --git a/handlers/handlerpage.cpp b/handlers/handlerpage.cpp index 2eead55..bf3ea53 100644 --- a/handlers/handlerpage.cpp +++ b/handlers/handlerpage.cpp @@ -87,5 +87,6 @@ void HandlerPage::setPageVars(TemplatePage &page, std::string pagename) page.setVar("headerlinks", headerlinks); page.setVar("page", pagename); + page.setVar("title", createPageTitle(pagename)); } } diff --git a/handlers/handlerpagedelete.cpp b/handlers/handlerpagedelete.cpp index 2498f0e..3d56364 100644 --- a/handlers/handlerpagedelete.cpp +++ b/handlers/handlerpagedelete.cpp @@ -50,6 +50,7 @@ Response HandlerPageDelete::handleRequest(PageDao &pageDao, std::string pagename TemplatePage delPage = this->templ->getPage("page_deletion"); delPage.setVar("deletionurl", this->urlProvider->pageDelete(pagename)); setPageVars(delPage, pagename); + delPage.setVar("title", createPageTitle("Delete:" + pagename)); Response r; r.setBody(delPage.render()); return r; diff --git a/handlers/handlerpageedit.cpp b/handlers/handlerpageedit.cpp index af65783..8231bc1 100644 --- a/handlers/handlerpageedit.cpp +++ b/handlers/handlerpageedit.cpp @@ -113,6 +113,7 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, templatePage.setVar("preview_content", parser.parse(pageDao, *this->urlProvider, newContent)); templatePage.setVar("content", newContent); setPageVars(templatePage, pagename); + templatePage.setVar("title", createPageTitle("Preview: " + pagename)); Response response; response.setBody(templatePage.render()); @@ -124,6 +125,7 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, templatePage.setVar("actionurl", urlProvider->editPage(pagename)); templatePage.setVar("content", body); setPageVars(templatePage, pagename); + templatePage.setVar("title", createPageTitle("Edit: " + pagename)); Response response; response.setBody(templatePage.render()); return response; diff --git a/handlers/handlersearch.cpp b/handlers/handlersearch.cpp index 4dbcc4d..5327644 100644 --- a/handlers/handlersearch.cpp +++ b/handlers/handlersearch.cpp @@ -51,6 +51,7 @@ Response HandlerSearch::handleRequest(const Request &r) searchPage.setVar("pagelist", body); searchPage.setVar("searchterm", q); setGeneralVars(searchPage); + searchPage.setVar("title", createPageTitle("Search")); response.setBody(searchPage.render()); response.setStatus(200); return response;