pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new RescuePage(rescueTemplate, this), "Rescue"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(SonePlugin.getYear()), new PluginHomepage(SonePlugin.getHomepage())), "About"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", emptyImageTitleTemplate, "Page.EmptyImageTitle.Title", this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title", this)));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", this, noPermissionTemplate, "Page.NoPermission.Title")));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", this, emptyImageTitleTemplate, "Page.EmptyImageTitle.Title")));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", this, emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title")));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", invalidTemplate, "Page.Invalid.Title", this)));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", this, invalidTemplate, "Page.Invalid.Title")));
pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("css/", "/static/css/", "text/css")));
pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("javascript/", "/static/javascript/", "text/javascript")));
pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("images/", "/static/images/", "image/png")));
class AboutPage(template: Template, webInterface: WebInterface,
private val pluginVersion: PluginVersion,
private val pluginYear: PluginYear,
- private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", template, "Page.About.Title", webInterface, false) {
+ private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, template, "Page.About.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
templateContext["version"] = pluginVersion.version
* Page that lets the user bookmark a post.
*/
class BookmarkPage(template: Template, webInterface: WebInterface)
- : SoneTemplatePage("bookmark.html", template, "Page.Bookmark.Title", webInterface) {
+ : SoneTemplatePage("bookmark.html", webInterface, template, "Page.Bookmark.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
/**
* Page that lets the user browse all his bookmarked posts.
*/
-class BookmarksPage(template: Template, webInterface: WebInterface): SoneTemplatePage("bookmarks.html", template, "Page.Bookmarks.Title", webInterface) {
+class BookmarksPage(template: Template, webInterface: WebInterface) :
+ SoneTemplatePage("bookmarks.html", webInterface, template, "Page.Bookmarks.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
webInterface.core.bookmarkedPosts.let { posts ->
* The “create Sone” page lets the user create a new Sone.
*/
class CreateSonePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("createSone.html", template, "Page.CreateSone.Title", webInterface, false) {
+ SoneTemplatePage("createSone.html", webInterface, template, "Page.CreateSone.Title") {
private val logger = Logger.getLogger(CreateSonePage::class.java.name)
* Page that lets the user dismiss a notification.
*/
class DismissNotificationPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("dismissNotification.html", template, "Page.DismissNotification.Title", webInterface) {
+ SoneTemplatePage("dismissNotification.html", webInterface, template, "Page.DismissNotification.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
* This page shows all known Sones.
*/
class KnownSonesPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("knownSones.html", template, "Page.KnownSones.Title", webInterface, false) {
+ SoneTemplatePage("knownSones.html", webInterface, template, "Page.KnownSones.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
* This page lets the user lock a [net.pterodactylus.sone.data.Sone] to prevent it from being inserted.
*/
class LockSonePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("lockSone.html", template, "Page.LockSone.Title", webInterface, false) {
+ SoneTemplatePage("lockSone.html", webInterface, template, "Page.LockSone.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
freenetRequest.parameters["returnPage", 256]!!.let { returnPage ->
* Base class for [SoneTemplatePage] implementations that require a logged in user.
*/
abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface) :
- SoneTemplatePage(path, template, pageTitleKey, webInterface, true) {
+ SoneTemplatePage(path, webInterface, template, pageTitleKey, true) {
final override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
handleRequest(freenetRequest, getCurrentSone(freenetRequest.toadletContext, false)!!, templateContext)
* The login page lets the user log in.
*/
class LoginPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("login.html", template, "Page.Login.Title", webInterface) {
+ SoneTemplatePage("login.html", webInterface, template, "Page.Login.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
* [Replie][net.pterodactylus.sone.data.Reply]s as known.
*/
class MarkAsKnownPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("markAsKnown.html", template, "Page.MarkAsKnown.Title", webInterface, false) {
+ SoneTemplatePage("markAsKnown.html", webInterface, template, "Page.MarkAsKnown.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
val ids = freenetRequest.parameters["id", 65536]!!.split(" ")
* [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time.
*/
class NewPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("new.html", template, "Page.New.Title", webInterface, false) {
+ SoneTemplatePage("new.html", webInterface, template, "Page.New.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) =
getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
* This page lets the user edit the options of the Sone plugin.
*/
class OptionsPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("options.html", template, "Page.Options.Title", webInterface, false) {
+ SoneTemplatePage("options.html", webInterface, template, "Page.Options.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
* words.
*/
class SearchPage @JvmOverloads constructor(template: Template, webInterface: WebInterface, ticker: Ticker = Ticker.systemTicker()):
- SoneTemplatePage("search.html", template, "Page.Search.Title", webInterface, false) {
+ SoneTemplatePage("search.html", webInterface, template, "Page.Search.Title") {
private val cache: Cache<Iterable<Phrase>, Pagination<Post>> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build()
/**
* Base page for the Sone web interface.
*/
-open class SoneTemplatePage(
+open class SoneTemplatePage @JvmOverloads constructor(
path: String,
protected val webInterface: WebInterface,
template: Template,
private val pageTitleKey: String? = null,
- private val requiresLogin: Boolean = true
+ private val requiresLogin: Boolean = false,
+ private val pageTitle: (FreenetRequest) -> String = { pageTitleKey?.let(webInterface.l10n::getString) ?: "" }
) : FreenetTemplatePage(path, webInterface.templateContextFactory, template, "noPermission.html") {
- @JvmOverloads
- constructor(path: String, template: Template, pageTitleKey: String?, webInterface: WebInterface, requireLogin: Boolean = false) :
- this(path, webInterface, template, pageTitleKey, requireLogin)
-
- constructor(path: String, template: Template, webInterface: WebInterface, requireLogin: Boolean = true) :
- this(path, webInterface, template, null, requireLogin)
-
private val core = webInterface.core
protected val sessionProvider: SessionProvider = webInterface
fun requiresLogin() = requiresLogin
- override public fun getPageTitle(freenetRequest: FreenetRequest) =
- pageTitleKey?.let(webInterface.l10n::getString) ?: ""
+ override public fun getPageTitle(freenetRequest: FreenetRequest) = pageTitle(freenetRequest)
override public fun getStyleSheets() =
listOf("css/sone.css")
* Page that lets the user unbookmark a post.
*/
class UnbookmarkPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("unbookmark.html", template, "Page.Unbookmark.Title", webInterface, false) {
+ SoneTemplatePage("unbookmark.html", webInterface, template, "Page.Unbookmark.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
when {
* This page lets the user unlock a [net.pterodactylus.sone.data.Sone] to allow its insertion.
*/
class UnlockSonePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("unlockSone.html", template, "Page.UnlockSone.Title", webInterface, false) {
+ SoneTemplatePage("unlockSone.html", webInterface, template, "Page.UnlockSone.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
if (freenetRequest.isPOST) {
* This page lets the user view a post and all its replies.
*/
class ViewPostPage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("viewPost.html", template, "Page.ViewPost.Title", webInterface, false) {
+ SoneTemplatePage("viewPost.html", webInterface, template, "Page.ViewPost.Title") {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
templateContext["post"] = freenetRequest.parameters["post"]?.let(webInterface.core::getPost)
* Lets the user browser another Sone.
*/
class ViewSonePage(template: Template, webInterface: WebInterface):
- SoneTemplatePage("viewSone.html", template, webInterface, false) {
+ SoneTemplatePage("viewSone.html", webInterface, template) {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
templateContext["soneId"] = freenetRequest.parameters["sone"]
/**
* Unit test for [SoneTemplatePage].
*/
-class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : SoneTemplatePage("path.html", template, webInterface, true) {} }) {
+class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : SoneTemplatePage("path.html", webInterface, template, requiresLogin = true) {} }) {
@Test
fun `page title is empty string if no page title key was given`() {
- SoneTemplatePage("path.html", template, null, webInterface).let { page ->
+ SoneTemplatePage("path.html", webInterface, template, requiresLogin = false).let { page ->
assertThat(page.getPageTitle(freenetRequest), equalTo(""))
}
}
@Test
fun `page title is retrieved from l10n if page title key is given`() {
- SoneTemplatePage("path.html", template, "page.title", webInterface).let { page ->
+ SoneTemplatePage("path.html", webInterface, template, "page.title", false).let { page ->
whenever(l10n.getString("page.title")).thenReturn("Page Title")
assertThat(page.getPageTitle(freenetRequest), equalTo("Page Title"))
}
@Test
fun `handleRequest method is called`() {
var called = false
- val page = object : SoneTemplatePage("path.html", template, webInterface, true) {
+ val page = object : SoneTemplatePage("path.html", webInterface, template, requiresLogin = true) {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
called = true
}
@Test
fun `redirect does not happen if login is not required`() {
- val page = SoneTemplatePage("page.html", template, webInterface, false)
+ val page = SoneTemplatePage("page.html", webInterface, template, requiresLogin = false)
assertThat(page.getRedirectTarget(freenetRequest), nullValue())
}
@Test
fun `page is enabled if no full access is required and login is not required`() {
- SoneTemplatePage("path.html", template, webInterface, false).let { page ->
+ SoneTemplatePage("path.html", webInterface, template, requiresLogin = false).let { page ->
assertThat(page.isEnabled(toadletContext), equalTo(true))
}
}