Handlers: set page title

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

View File

@ -36,6 +36,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?
@ -43,6 +44,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

@ -48,6 +48,7 @@ public:
void setGeneralVars(TemplatePage &page);
virtual ~Handler() { }
Response errorResponse(std::string errortitle, std::string errormessage, int status = 200);
std::string createPageTitle(std::string append);
};
#endif // HANDLER_H

View File

@ -35,6 +35,7 @@ Response HandlerAllCategories::handleRequest(const Request &r)
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

@ -39,6 +39,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;
}
@ -116,6 +118,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

@ -124,6 +124,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,6 +87,7 @@ void HandlerPage::setPageVars(TemplatePage &page, std::string pagename)
page.setVar("headerlinks", headerlinks);
page.setVar("page", pagename);
page.setVar("title", createPageTitle(pagename));
}

View File

@ -52,6 +52,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

@ -117,6 +117,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());
@ -129,6 +130,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

@ -49,6 +49,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;