qswiki/urlprovider.cpp

122 wiersze
3.6 KiB
C++
Czysty Zwykły widok Historia

2018-11-03 17:12:20 +01:00
/* Copyright (c) 2018 Albert S.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "urlprovider.h"
std::string replaceSingleVar(std::string where, std::string varname, std::string replacement)
{
// TODO: Varreplacer is a bit of an overkill, isn't it?
Varreplacer replacer("{");
replacer.addKeyValue(varname, replacement);
return replacer.parse(where);
}
std::string UrlProvider::replaceOnlyPage(std::string templatepart, std::string page)
{
return replaceSingleVar(templatepart, "page", page);
}
std::string UrlProvider::index()
{
return config->linkindex;
}
std::string UrlProvider::recentSorted(unsigned int limit, unsigned int offset, unsigned int sort)
{
Varreplacer replace("{");
replace.addKeyValue("limit", std::to_string(limit));
replace.addKeyValue("offset", std::to_string(offset));
replace.addKeyValue("sort", std::to_string(sort));
return replace.parse(config->linkrecentsort);
}
std::string UrlProvider::allPages()
{
return config->linkallpages;
}
std::string UrlProvider::allCats()
{
return config->linkallcats;
}
std::string UrlProvider::page(std::string pagename)
{
return replaceOnlyPage(config->linkpage, pagename);
}
std::string UrlProvider::linksHere(std::string pagename)
{
return replaceOnlyPage(config->linkshere, pagename);
}
std::string UrlProvider::pageHistory(std::string pagename)
{
return replaceOnlyPage(config->linkhistory, pagename);
}
std::string UrlProvider::pageHistorySort(std::string pagename, unsigned int limit, unsigned int offset,
unsigned int sort)
{
Varreplacer replace("{");
replace.addKeyValue("page", pagename);
replace.addKeyValue("limit", std::to_string(limit));
replace.addKeyValue("offset", std::to_string(offset));
replace.addKeyValue("sort", std::to_string(sort));
return replace.parse(config->linkhistorysort);
}
std::string UrlProvider::pageRevision(std::string pagename, unsigned int revision)
{
Varreplacer replace("{");
replace.addKeyValue("page", pagename);
replace.addKeyValue("revisionid", std::to_string(revision));
return replace.parse(config->linkrevision);
}
std::string UrlProvider::editPage(std::string pagename)
{
return replaceOnlyPage(config->linkedit, pagename);
}
std::string UrlProvider::pageSettings(std::string pagename)
{
return replaceOnlyPage(config->linksettings, pagename);
}
std::string UrlProvider::pageDelete(std::string pagename)
{
return replaceOnlyPage(config->linkdelete, pagename);
}
std::string UrlProvider::userSettings()
{
return config->usersettingsurl;
}
2018-11-03 17:12:20 +01:00
std::string UrlProvider::category(std::string catname)
{
return replaceSingleVar(config->linkcategory, "category", catname);
}
std::string UrlProvider::login(std::string page)
{
return replaceOnlyPage(config->loginurl, page);
}