Compare commits

..

No commits in common. "9b35e43161c8467fc4e1f81b7e3bf2363614542a" and "ba06d04a08d5196d8448e2e3d5f38b428a853d6d" have entirely different histories.

18 changed files with 16 additions and 163 deletions

View File

@ -85,7 +85,6 @@ Config::Config(const std::map<std::string, std::string> &map)
this->urls.linkindex = required("linkindex"); this->urls.linkindex = required("linkindex");
this->urls.linklogout = required("linklogout"); this->urls.linklogout = required("linklogout");
this->urls.linkpage = required("linkpage"); this->urls.linkpage = required("linkpage");
this->urls.linkpagebytitle = required("linkpagebytitle");
this->urls.linkrecent = required("linkrecent"); this->urls.linkrecent = required("linkrecent");
this->urls.linkrevision = required("linkrevision"); this->urls.linkrevision = required("linkrevision");
this->urls.linksettings = required("linksettings"); this->urls.linksettings = required("linksettings");

View File

@ -26,7 +26,6 @@ struct ConfigUrls
std::string linkallcats; std::string linkallcats;
std::string linkshere; std::string linkshere;
std::string linkpage; std::string linkpage;
std::string linkpagebytitle;
std::string linkrevision; std::string linkrevision;
std::string linkhistory; std::string linkhistory;
std::string linkedit; std::string linkedit;

View File

@ -13,7 +13,6 @@ class PageDao
virtual bool exists(std::string page) const = 0; virtual bool exists(std::string page) const = 0;
virtual bool exists(unsigned int id) const = 0; virtual bool exists(unsigned int id) const = 0;
virtual std::optional<Page> find(std::string name) = 0; virtual std::optional<Page> find(std::string name) = 0;
virtual std::optional<Page> findByTitle(std::string title) = 0;
virtual std::optional<Page> find(unsigned int id) = 0; virtual std::optional<Page> find(unsigned int id) = 0;
virtual std::vector<std::string> getPageList(QueryOption option) = 0; virtual std::vector<std::string> getPageList(QueryOption option) = 0;
virtual std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) = 0; virtual std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) = 0;

View File

@ -52,26 +52,6 @@ std::optional<Page> PageDaoSqlite::find(std::string name)
} }
} }
std::optional<Page> PageDaoSqlite::findByTitle(std::string title)
{
Page result;
try
{
auto ps = *db << "SELECT id, name, title, lastrevision, visible FROM page WHERE title = ?";
ps << title >> std::tie(result.pageid, result.name, result.title, result.current_revision, result.listed);
}
catch(const sqlite::errors::no_rows &e)
{
return {};
}
catch(sqlite::sqlite_exception &e)
{
throwFrom(e);
}
return result;
}
std::optional<Page> PageDaoSqlite::find(unsigned int id) std::optional<Page> PageDaoSqlite::find(unsigned int id)
{ {
Page result; Page result;

View File

@ -20,7 +20,6 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
bool exists(std::string name) const override; bool exists(std::string name) const override;
void save(const Page &page) override; void save(const Page &page) override;
std::optional<Page> find(std::string name) override; std::optional<Page> find(std::string name) override;
std::optional<Page> findByTitle(std::string title) override;
std::optional<Page> find(unsigned int id) override; std::optional<Page> find(unsigned int id) override;
std::vector<std::string> getPageList(QueryOption option) override; std::vector<std::string> getPageList(QueryOption option) override;
std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) override; std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) override;

View File

@ -1,11 +0,0 @@
#include "dynamiccontentgetvar.h"
std::string DynamicContentGetVar::render()
{
return (*this->map)[this->argument];
}
void DynamicContentGetVar::setMap(std::map<std::string, std::string> &map)
{
this->map = &map;
}

View File

@ -1,19 +0,0 @@
#ifndef DYNAMICCONTENTGETVAR_H
#define DYNAMICCONTENTGETVAR_H
#include "dynamiccontent.h"
class DynamicContentGetVar : public DynamicContent
{
private:
std::map<std::string, std::string> *map;
public:
using DynamicContent::DynamicContent;
// DynamicContent interface
public:
std::string render();
void setMap(std::map<std::string, std::string> &map);
};
#endif // DYNAMICCONTENTGETVAR_H

View File

@ -6,7 +6,9 @@ std::string DynamicContentIncludePage::render()
auto rev = revisionDao->getCurrentForPage(this->argument); auto rev = revisionDao->getCurrentForPage(this->argument);
if(rev) if(rev)
{ {
return rev->content; Parser parser;
auto result = parser.parse(*this->database->createPageDao(), *this->urlProvider, rev->content);
return result;
} }
return {}; return {};
} }

View File

@ -25,13 +25,12 @@ std::string DynamicContentPostList::render()
stream << postListBegin; stream << postListBegin;
for(auto &pair : pageList) for(auto &pair : pageList)
{ {
std::string title = pageDao->find(pair.first)->title; std::string link = this->urlProvider->page(pair.first);
std::string link = this->urlProvider->pageByTitle(title);
std::string date = utils::toISODate(pair.second); std::string date = utils::toISODate(pair.second);
Varreplacer replacer{"{"}; Varreplacer replacer{"{"};
replacer.addKeyValue("url", link); replacer.addKeyValue("url", link);
replacer.addKeyValue("date", date); replacer.addKeyValue("date", date);
replacer.addKeyValue("title", title); replacer.addKeyValue("title", pageDao->find(pair.first)->title);
stream << replacer.parse(postLink); stream << replacer.parse(postLink);
} }

View File

@ -1,21 +0,0 @@
#include "dynamiccontentsetvar.h"
std::string DynamicContentSetVar::render()
{
auto result = utils::split(this->argument, '=');
if(result.size() == 2)
{
this->map->emplace(std::make_pair(result[0], result[1]));
}
return {};
}
void DynamicContentSetVar::setArgument(std::string argument)
{
this->argument = argument;
}
void DynamicContentSetVar::setMap(std::map<std::string, std::string> &map)
{
this->map = &map;
}

View File

@ -1,17 +0,0 @@
#ifndef DYNAMCCONTENTPUSHVAR_H
#define DYNAMCCONTENTPUSHVAR_H
#include "dynamiccontent.h"
class DynamicContentSetVar : public DynamicContent
{
private:
std::map<std::string, std::string> *map;
public:
using DynamicContent::DynamicContent;
std::string render();
void setArgument(std::string argument);
void setMap(std::map<std::string, std::string> &map);
};
#endif // DYNAMCCONTENTPUSHVAR_H

View File

@ -26,20 +26,9 @@ Response HandlerPage::handle(const Request &r)
std::string pagename = r.get("page"); std::string pagename = r.get("page");
auto pageDao = this->database->createPageDao(); auto pageDao = this->database->createPageDao();
if(pagename.empty()) if(pagename.empty())
{
std::string title = r.get("title");
if(title.empty())
{ {
return errorResponse("No page given", "No page given to request"); return errorResponse("No page given", "No page given to request");
} }
title = utils::strreplace(title, "-", " ");
auto page = pageDao->findByTitle(title);
if(!page)
{
return errorResponse("No page by such title", "No page with such title exists");
}
pagename = page->name;
}
if(pageMustExist() && !pageDao->exists(pagename)) if(pageMustExist() && !pageDao->exists(pagename))
{ {

View File

@ -25,9 +25,6 @@ SOFTWARE.
#include "../htmllink.h" #include "../htmllink.h"
#include "../dynamic/dynamiccontentpostlist.h" #include "../dynamic/dynamiccontentpostlist.h"
#include "../dynamic/dynamiccontentincludepage.h" #include "../dynamic/dynamiccontentincludepage.h"
#include "../dynamic/dynamiccontentsetvar.h"
#include "../dynamic/dynamiccontentgetvar.h"
bool HandlerPageView::canAccess(std::string page) bool HandlerPageView::canAccess(std::string page)
{ {
return effectivePermissions(page).canRead(); return effectivePermissions(page).canRead();
@ -140,7 +137,6 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
std::string indexcontent; std::string indexcontent;
std::string parsedcontent; std::string parsedcontent;
std::map<std::string, std::string> dynamicVarsMap;
std::function<std::string(std::string_view, std::string_view)> dynamicParseCallback = std::function<std::string(std::string_view, std::string_view)> dynamicParseCallback =
[&](std::string_view key, std::string_view value) -> std::string [&](std::string_view key, std::string_view value) -> std::string
{ {
@ -151,35 +147,17 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
return postlist->render(); return postlist->render();
} }
if(key == "dynamic:includepage") if(key == "dynamic:includepage")
{
if((effectivePermissions(std::string(value)).canRead()))
{ {
std::shared_ptr<DynamicContentIncludePage> includePage = createDynamic<DynamicContentIncludePage>(); std::shared_ptr<DynamicContentIncludePage> includePage = createDynamic<DynamicContentIncludePage>();
includePage->setArgument(std::string(value)); includePage->setArgument(std::string(value));
return parser.parseDynamics(includePage->render(), dynamicParseCallback); return includePage->render();
}
}
if(key == "dynamic:setvar")
{
std::shared_ptr<DynamicContentSetVar> setVar = createDynamic<DynamicContentSetVar>();
setVar->setMap(dynamicVarsMap);
setVar->setArgument(std::string(value));
return setVar->render();
}
if(key == "dynamic:getvar")
{
std::shared_ptr<DynamicContentGetVar> getVar = createDynamic<DynamicContentGetVar>();
getVar->setMap(dynamicVarsMap);
getVar->setArgument(std::string(value));
return getVar->render();
} }
return std::string{}; return std::string{};
}; };
std::string resolvedContent = parser.parseDynamics(revision->content, dynamicParseCallback);
if(revisionid > 0) if(revisionid > 0)
{ {
indexcontent = createIndexContent(parser, resolvedContent); indexcontent = createIndexContent(parser, revision->content);
parsedcontent = parser.parse(pageDao, *this->urlProvider, resolvedContent); parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback);
} }
else else
{ {
@ -193,7 +171,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
} }
else else
{ {
indexcontent = createIndexContent(parser, resolvedContent); indexcontent = createIndexContent(parser, revision->content);
this->cache->put(cachekeyindexcontent, indexcontent); this->cache->put(cachekeyindexcontent, indexcontent);
} }
if(cachedparsedcontent) if(cachedparsedcontent)
@ -202,7 +180,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
} }
else else
{ {
parsedcontent = parser.parse(pageDao, *this->urlProvider, resolvedContent); parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback);
this->cache->put(cachekeyparsedcontent, parsedcontent); this->cache->put(cachekeyparsedcontent, parsedcontent);
} }
} }

View File

@ -23,10 +23,6 @@ class IParser
} }
virtual std::string parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content, virtual std::string parse(const PageDao &pagedao, UrlProvider &provider, const std::string &content,
const std::function<std::string(std::string_view, std::string_view)> &callback) const = 0; const std::function<std::string(std::string_view, std::string_view)> &callback) const = 0;
virtual std::string parseDynamics(
const std::string &content,
const std::function<std::string(std::string_view, std::string_view)> &callback) const = 0;
virtual std::vector<std::string> extractCategories(const std::string &content) const = 0; virtual std::vector<std::string> extractCategories(const std::string &content) const = 0;
virtual ~IParser(){}; virtual ~IParser(){};

View File

@ -30,8 +30,7 @@ SOFTWARE.
std::vector<Headline> Parser::extractHeadlines(const std::string &content) const std::vector<Headline> Parser::extractHeadlines(const std::string &content) const
{ {
std::vector<Headline> result; std::vector<Headline> result;
std::string reg = R"(\[h(1|2|3)\](.*?)\[/h\1\])";
std::string reg = R"(\[h(1|2|3)\](\[.*?\])*(.*?)\[.*?\]*\[\/h\1\])";
std::regex headerfinder(reg); std::regex headerfinder(reg);
auto begin = std::sregex_iterator(content.begin(), content.end(), headerfinder); auto begin = std::sregex_iterator(content.begin(), content.end(), headerfinder);
auto end = std::sregex_iterator(); auto end = std::sregex_iterator();
@ -41,7 +40,7 @@ std::vector<Headline> Parser::extractHeadlines(const std::string &content) const
auto smatch = *it; auto smatch = *it;
Headline h; Headline h;
h.level = utils::toUInt(smatch.str(1)); h.level = utils::toUInt(smatch.str(1));
h.title = smatch.str(3); h.title = smatch.str(2);
result.push_back(h); result.push_back(h);
} }
return result; return result;
@ -123,7 +122,7 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
std::string result; std::string result;
// we don't care about commands, but we nevertheless replace them with empty strings // we don't care about commands, but we nevertheless replace them with empty strings
std::regex tagfinder( std::regex tagfinder(
R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect|cmd:pagetitle|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1])"); R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect|cmd:pagetitle|category|dynamic:postlist|dynamic:includepage)*?\]((\s|\S)*?)\[/\1])");
result = utils::regex_callback_replacer( result = utils::regex_callback_replacer(
tagfinder, content, tagfinder, content,
[&](std::smatch &match) [&](std::smatch &match)
@ -151,11 +150,3 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
result = utils::strreplace(result, "\r\n", "<br>"); result = utils::strreplace(result, "\r\n", "<br>");
return result; return result;
} }
std::string Parser::parseDynamics(const std::string &content,
const std::function<std::string(std::string_view, std::string_view)> &callback) const
{
std::regex tagfinder(R"(\[(dynamic:\w+)*?\]((\s|\S)*?)\[/\1])");
return utils::regex_callback_replacer(tagfinder, content,
[&](std::smatch &match) { return callback(match.str(1), match.str(2)); });
}

View File

@ -15,9 +15,6 @@ class Parser : public IParser
virtual std::string parse( virtual std::string parse(
const PageDao &pagedao, UrlProvider &provider, const std::string &content, const PageDao &pagedao, UrlProvider &provider, const std::string &content,
const std::function<std::string(std::string_view, std::string_view)> &callback) const override; const std::function<std::string(std::string_view, std::string_view)> &callback) const override;
std::string parseDynamics(
const std::string &content,
const std::function<std::string(std::string_view, std::string_view)> &callback) const override;
using IParser::IParser; using IParser::IParser;
}; };

View File

@ -63,11 +63,6 @@ std::string UrlProvider::page(std::string pagename)
return replaceOnlyPage(config->linkpage, pagename); return replaceOnlyPage(config->linkpage, pagename);
} }
std::string UrlProvider::pageByTitle(std::string title)
{
return replaceSingleVar(config->linkpagebytitle, "title", utils::strreplace(title, " ", "-"));
}
std::string UrlProvider::linksHere(std::string pagename) std::string UrlProvider::linksHere(std::string pagename)
{ {
return replaceOnlyPage(config->linkshere, pagename); return replaceOnlyPage(config->linkshere, pagename);

View File

@ -27,8 +27,6 @@ class UrlProvider
std::string page(std::string pagename); std::string page(std::string pagename);
std::string pageByTitle(std::string title);
std::string linksHere(std::string pagename); std::string linksHere(std::string pagename);
std::string pageHistory(std::string pagename); std::string pageHistory(std::string pagename);