Handlers: set page title

This commit is contained in:
Albert S. 2019-09-29 21:34:53 +02:00
parent ec10c764d5
commit d9de46354e
11 changed files with 20 additions and 1 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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());

View File

@ -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));
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;