From: David ‘Bombe’ Roden Date: Fri, 17 May 2019 14:42:01 +0000 (+0200) Subject: 🚧 Add Loaders to all template-using pages X-Git-Tag: v79^2~31 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6a3f1fede0cda5cd6ed56204aa1dd37a19813cb9;p=Sone.git 🚧 Add Loaders to all template-using pages --- diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 836145e..d4f3f55 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -635,51 +635,51 @@ public class WebInterface implements SessionProvider { Template openSearchTemplate = loaders.loadTemplate("/templates/xml/OpenSearch.xml"); pageToadletRegistry.addPage(new RedirectPage("", "index.html")); - pageToadletRegistry.addPage(new IndexPage(indexTemplate, this, postVisibilityFilter)); - pageToadletRegistry.addPage(new NewPage(newTemplate, this)); - pageToadletRegistry.addPage(new CreateSonePage(createSoneTemplate, this)); - pageToadletRegistry.addPage(new KnownSonesPage(knownSonesTemplate, this)); - pageToadletRegistry.addPage(new EditProfilePage(editProfileTemplate, this)); - pageToadletRegistry.addPage(new EditProfileFieldPage(editProfileFieldTemplate, this)); - pageToadletRegistry.addPage(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this)); - pageToadletRegistry.addPage(new CreatePostPage(createPostTemplate, this)); - pageToadletRegistry.addPage(new CreateReplyPage(createReplyTemplate, this)); - pageToadletRegistry.addPage(new ViewSonePage(viewSoneTemplate, this)); - pageToadletRegistry.addPage(new ViewPostPage(viewPostTemplate, this)); - pageToadletRegistry.addPage(new LikePage(emptyTemplate, this)); - pageToadletRegistry.addPage(new UnlikePage(emptyTemplate, this)); - pageToadletRegistry.addPage(new DeletePostPage(deletePostTemplate, this)); - pageToadletRegistry.addPage(new DeleteReplyPage(deleteReplyTemplate, this)); - pageToadletRegistry.addPage(new LockSonePage(emptyTemplate, this)); - pageToadletRegistry.addPage(new UnlockSonePage(emptyTemplate, this)); - pageToadletRegistry.addPage(new FollowSonePage(emptyTemplate, this)); - pageToadletRegistry.addPage(new UnfollowSonePage(emptyTemplate, this)); - pageToadletRegistry.addPage(new ImageBrowserPage(imageBrowserTemplate, this)); - pageToadletRegistry.addPage(new CreateAlbumPage(createAlbumTemplate, this)); - pageToadletRegistry.addPage(new EditAlbumPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new DeleteAlbumPage(deleteAlbumTemplate, this)); - pageToadletRegistry.addPage(new UploadImagePage(invalidTemplate, this)); - pageToadletRegistry.addPage(new EditImagePage(emptyTemplate, this)); - pageToadletRegistry.addPage(new DeleteImagePage(deleteImageTemplate, this)); - pageToadletRegistry.addPage(new TrustPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new DistrustPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new UntrustPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new MarkAsKnownPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new BookmarkPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new UnbookmarkPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new BookmarksPage(bookmarksTemplate, this)); - pageToadletRegistry.addPage(new SearchPage(searchTemplate, this)); - pageToadletRegistry.addPage(new DeleteSonePage(deleteSoneTemplate, this)); - pageToadletRegistry.addPage(new LoginPage(loginTemplate, this)); - pageToadletRegistry.addPage(new LogoutPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new OptionsPage(optionsTemplate, this)); - pageToadletRegistry.addPage(new RescuePage(rescueTemplate, this)); - pageToadletRegistry.addPage(new AboutPage(aboutTemplate, this, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(sonePlugin.getHomepage()))); - pageToadletRegistry.addPage(new SoneTemplatePage("noPermission.html", this, noPermissionTemplate, "Page.NoPermission.Title")); - pageToadletRegistry.addPage(new SoneTemplatePage("emptyImageTitle.html", this, emptyImageTitleTemplate, "Page.EmptyImageTitle.Title")); - pageToadletRegistry.addPage(new SoneTemplatePage("emptyAlbumTitle.html", this, emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title")); - pageToadletRegistry.addPage(new DismissNotificationPage(emptyTemplate, this)); - pageToadletRegistry.addPage(new SoneTemplatePage("invalid.html", this, invalidTemplate, "Page.Invalid.Title")); + pageToadletRegistry.addPage(new IndexPage(indexTemplate, this, loaders, postVisibilityFilter)); + pageToadletRegistry.addPage(new NewPage(newTemplate, this, loaders)); + pageToadletRegistry.addPage(new CreateSonePage(createSoneTemplate, this, loaders)); + pageToadletRegistry.addPage(new KnownSonesPage(knownSonesTemplate, this, loaders)); + pageToadletRegistry.addPage(new EditProfilePage(editProfileTemplate, this, loaders)); + pageToadletRegistry.addPage(new EditProfileFieldPage(editProfileFieldTemplate, this, loaders)); + pageToadletRegistry.addPage(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this, loaders)); + pageToadletRegistry.addPage(new CreatePostPage(createPostTemplate, this, loaders)); + pageToadletRegistry.addPage(new CreateReplyPage(createReplyTemplate, this, loaders)); + pageToadletRegistry.addPage(new ViewSonePage(viewSoneTemplate, this, loaders)); + pageToadletRegistry.addPage(new ViewPostPage(viewPostTemplate, this, loaders)); + pageToadletRegistry.addPage(new LikePage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new UnlikePage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new DeletePostPage(deletePostTemplate, this, loaders)); + pageToadletRegistry.addPage(new DeleteReplyPage(deleteReplyTemplate, this, loaders)); + pageToadletRegistry.addPage(new LockSonePage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new UnlockSonePage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new FollowSonePage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new UnfollowSonePage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new ImageBrowserPage(imageBrowserTemplate, this, loaders)); + pageToadletRegistry.addPage(new CreateAlbumPage(createAlbumTemplate, this, loaders)); + pageToadletRegistry.addPage(new EditAlbumPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new DeleteAlbumPage(deleteAlbumTemplate, this, loaders)); + pageToadletRegistry.addPage(new UploadImagePage(invalidTemplate, this, loaders)); + pageToadletRegistry.addPage(new EditImagePage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new DeleteImagePage(deleteImageTemplate, this, loaders)); + pageToadletRegistry.addPage(new TrustPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new DistrustPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new UntrustPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new MarkAsKnownPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new BookmarkPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new UnbookmarkPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new BookmarksPage(bookmarksTemplate, this, loaders)); + pageToadletRegistry.addPage(new SearchPage(searchTemplate, this, loaders)); + pageToadletRegistry.addPage(new DeleteSonePage(deleteSoneTemplate, this, loaders)); + pageToadletRegistry.addPage(new LoginPage(loginTemplate, this, loaders)); + pageToadletRegistry.addPage(new LogoutPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new OptionsPage(optionsTemplate, this, loaders)); + pageToadletRegistry.addPage(new RescuePage(rescueTemplate, this, loaders)); + pageToadletRegistry.addPage(new AboutPage(aboutTemplate, this, loaders, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(sonePlugin.getHomepage()))); + pageToadletRegistry.addPage(new SoneTemplatePage("noPermission.html", this, loaders, noPermissionTemplate, "Page.NoPermission.Title")); + pageToadletRegistry.addPage(new SoneTemplatePage("emptyImageTitle.html", this, loaders, emptyImageTitleTemplate, "Page.EmptyImageTitle.Title")); + pageToadletRegistry.addPage(new SoneTemplatePage("emptyAlbumTitle.html", this, loaders, emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title")); + pageToadletRegistry.addPage(new DismissNotificationPage(emptyTemplate, this, loaders)); + pageToadletRegistry.addPage(new SoneTemplatePage("invalid.html", this, loaders, invalidTemplate, "Page.Invalid.Title")); pageToadletRegistry.addPage(loaders.loadStaticPage("css/", "/static/css/", "text/css")); pageToadletRegistry.addPage(loaders.loadStaticPage("javascript/", "/static/javascript/", "text/javascript")); pageToadletRegistry.addPage(loaders.loadStaticPage("images/", "/static/images/", "image/png")); diff --git a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java index 30c8da5..c4b1813 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java @@ -31,6 +31,7 @@ import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; +import net.pterodactylus.sone.main.Loaders; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.template.TemplateContextFactory; @@ -61,26 +62,15 @@ public class FreenetTemplatePage implements FreenetPage, LinkEnabledCallback { /** The template to render. */ private final Template template; + private final Loaders loaders; /** Where to redirect for invalid form passwords. */ private final String invalidFormPasswordRedirectTarget; - /** - * Creates a new template page. - * - * @param path - * The path of the page - * @param templateContextFactory - * The template context factory - * @param template - * The template to render - * @param invalidFormPasswordRedirectTarget - * The target to redirect to if a POST request does not contain - * the correct form password - */ - public FreenetTemplatePage(String path, TemplateContextFactory templateContextFactory, Template template, String invalidFormPasswordRedirectTarget) { + public FreenetTemplatePage(String path, TemplateContextFactory templateContextFactory, Loaders loaders, Template template, String invalidFormPasswordRedirectTarget) { this.path = path; this.templateContextFactory = templateContextFactory; + this.loaders = loaders; this.template = template; this.invalidFormPasswordRedirectTarget = invalidFormPasswordRedirectTarget; } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt index 422364a..26a1769 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt @@ -11,10 +11,10 @@ import javax.inject.Inject * A [SoneTemplatePage] that stores information about Sone in the [TemplateContext]. */ @MenuName("About") -class AboutPage @Inject constructor(template: Template, webInterface: WebInterface, +class AboutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, private val pluginVersion: PluginVersion, private val pluginYear: PluginYear, - private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, template, "Page.About.Title") { + private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, loaders, template = template, pageTitleKey = "Page.About.Title") { override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { templateContext["version"] = pluginVersion.version diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt index 81cd332..c1415b0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -10,8 +11,8 @@ import javax.inject.Inject /** * Page that lets the user bookmark a post. */ -class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface) - : SoneTemplatePage("bookmark.html", webInterface, template, "Page.Bookmark.Title") { +class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) + : SoneTemplatePage("bookmark.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmark.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt index c73ce3d..f178e61 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.paginate import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -12,8 +13,8 @@ import javax.inject.Inject * Page that lets the user browse all his bookmarked posts. */ @MenuName("Bookmarks") -class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface) : - SoneTemplatePage("bookmarks.html", webInterface, template, "Page.Bookmarks.Title") { +class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + SoneTemplatePage("bookmarks.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmarks.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { soneRequest.core.bookmarkedPosts.let { posts -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt index 609c6cb..452d5a4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.text.TextFilter import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface @@ -13,8 +14,8 @@ import javax.inject.Inject /** * Page that lets the user create a new album. */ -class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface) { +class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt index aa5b94c..37568f2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.text.TextFilter import net.pterodactylus.sone.utils.asOptional import net.pterodactylus.sone.utils.isPOST @@ -13,8 +14,8 @@ import javax.inject.Inject /** * This page lets the user create a new [Post]. */ -class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface) { +class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt index 813412a..599a9ec 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.text.TextFilter import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface @@ -12,8 +13,8 @@ import javax.inject.Inject /** * This page lets the user post a reply to a post. */ -class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface) { +class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { val postId = soneRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt index 3abb927..cb4822b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import freenet.clients.http.ToadletContext import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -15,8 +16,8 @@ import javax.inject.Inject * The “create Sone” page lets the user create a new Sone. */ @MenuName("CreateSone") -class CreateSonePage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("createSone.html", webInterface, template, "Page.CreateSone.Title") { +class CreateSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("createSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.CreateSone.Title") { private val logger = Logger.getLogger(CreateSonePage::class.java.name) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt index deeadfb..4c1b28b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user delete an {@link Album}. */ -class DeleteAlbumPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface) { +class DeleteAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt index 70440f2..11efd94 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user delete an {@link Image}. */ -class DeleteImagePage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface) { +class DeleteImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt index d880fc5..b03d768 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.Inject /** * Lets the user delete a post they made. */ -class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface) { +class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt index 9655815..5f57bea 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user confirm the deletion of a profile field. */ -class DeleteProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface) { +class DeleteProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt index b20c4bb..af62489 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.Inject /** * This page lets the user delete a reply. */ -class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface) { +class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt index 972e444..c301869 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -14,8 +15,8 @@ import javax.inject.Inject * installation. */ @MenuName("DeleteSone") -class DeleteSonePage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface) { +class DeleteSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt index ae0cfe0..c7880bc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.template.Template @@ -9,8 +10,8 @@ import javax.inject.Inject /** * Page that lets the user dismiss a notification. */ -class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("dismissNotification.html", webInterface, template, "Page.DismissNotification.Title") { +class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("dismissNotification.html", webInterface, loaders, template = template, pageTitleKey = "Page.DismissNotification.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt index c29e974..1fee1e8 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -14,8 +15,8 @@ import javax.inject.Inject * * @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone) */ -class DistrustPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface) { +class DistrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt index 4e0cf5f..58bbb67 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -12,8 +13,8 @@ import javax.inject.Inject /** * Page that lets the user edit the name and description of an album. */ -class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface) { +class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt index 1870c02..c6c6acb 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Image.Modifier.ImageTitleMustNotBeEmpty import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.text.TextFilter import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface @@ -13,8 +14,8 @@ import javax.inject.Inject /** * Page that lets the user edit title and description of an {@link Image}. */ -class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface) { +class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt index 318bcf7..580ee72 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user edit the name of a profile field. */ -class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface) : - LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface) { +class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { currentSone.profile.let { profile -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt index e2392b4..f25b5b3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Profile.DuplicateField import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.text.TextFilter import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface @@ -14,8 +15,8 @@ import javax.inject.Inject * This page lets the user edit her profile. */ @MenuName("EditProfile") -class EditProfilePage @Inject constructor(template: Template, webInterface: WebInterface) : - LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface) { +class EditProfilePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { currentSone.profile.let { profile -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt index e961430..f4aa2e0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.Inject /** * This page lets the user follow another Sone. */ -class FollowSonePage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface) { +class FollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt index ba16e21..e2b2ec2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Album import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.paginate import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -15,8 +16,8 @@ import javax.inject.Inject * The image browser page is the entry page for the image management. */ @MenuName("ImageBrowser") -class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface) { +class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if ("album" in soneRequest.parameters) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt index 68e7e8f..aefef39 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.notify.PostVisibilityFilter import net.pterodactylus.sone.utils.paginate import net.pterodactylus.sone.utils.parameters @@ -15,8 +16,8 @@ import javax.inject.Inject * of all friends of the current user. */ @MenuName("Index") -class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, private val postVisibilityFilter: PostVisibilityFilter) : - LoggedInPage("index.html", template, "Page.Index.Title", webInterface) { +class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, private val postVisibilityFilter: PostVisibilityFilter) : + LoggedInPage("index.html", template, "Page.Index.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { (currentSone.posts + diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt index dd96832..65f4853 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.paginate import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -13,8 +14,8 @@ import javax.inject.Inject * This page shows all known Sones. */ @MenuName("KnownSones") -class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("knownSones.html", webInterface, template, "Page.KnownSones.Title") { +class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("knownSones.html", webInterface, loaders, template = template, pageTitleKey = "Page.KnownSones.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { getCurrentSone(soneRequest.toadletContext).let { currentSone -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt index 02f5043..3b0d0c5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -12,8 +13,8 @@ import javax.inject.Inject /** * Page that lets the user like [net.pterodactylus.sone.data.Post]s and [net.pterodactylus.sone.data.Reply]s. */ -class LikePage @Inject constructor(template: Template, webInterface: WebInterface) : - LoggedInPage("like.html", template, "Page.Like.Title", webInterface) { +class LikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + LoggedInPage("like.html", template, "Page.Like.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt index 49ead37..2d14ff3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* @@ -10,8 +11,8 @@ import javax.inject.Inject /** * This page lets the user lock a [net.pterodactylus.sone.data.Sone] to prevent it from being inserted. */ -class LockSonePage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("lockSone.html", webInterface, template, "Page.LockSone.Title") { +class LockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("lockSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.LockSone.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { soneRequest.parameters["returnPage", 256]!!.let { returnPage -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt index 94f94d0..72b5822 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.template.Template @@ -9,8 +10,8 @@ import net.pterodactylus.util.template.TemplateContext /** * Base class for [SoneTemplatePage] implementations that require a logged in user. */ -abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface) : - SoneTemplatePage(path, webInterface, template, pageTitleKey, true) { +abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface, loaders: Loaders) : + SoneTemplatePage(path, webInterface, loaders, template = template, pageTitleKey = pageTitleKey, requiresLogin = true) { final override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { handleRequest(soneRequest, getCurrentSone(soneRequest.toadletContext, false)!!, templateContext) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt index 96e8b27..70b96fc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import freenet.clients.http.ToadletContext import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.emptyToNull import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface @@ -14,8 +15,8 @@ import javax.inject.Inject * The login page lets the user log in. */ @MenuName("Login") -class LoginPage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("login.html", webInterface, template, "Page.Login.Title") { +class LoginPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("login.html", webInterface, loaders, template = template, pageTitleKey = "Page.Login.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt index 6978739..bfab7c8 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import freenet.clients.http.ToadletContext import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.template.Template @@ -12,8 +13,8 @@ import javax.inject.Inject * Logs a user out. */ @MenuName("Logout") -class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface) { +class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { setCurrentSone(soneRequest.toadletContext, null) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt index 5c1a720..22f21d8 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.* +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.* import net.pterodactylus.sone.web.* import net.pterodactylus.sone.web.page.* @@ -11,8 +12,8 @@ import javax.inject.* * Page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s, [Post]s, or * [Replie][net.pterodactylus.sone.data.Reply]s as known. */ -class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("markAsKnown.html", webInterface, template, "Page.MarkAsKnown.Title") { +class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("markAsKnown.html", webInterface, loaders, template = template, pageTitleKey = "Page.MarkAsKnown.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { val ids = soneRequest.parameters["id", 65536]!!.split(" ") diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt index a7bd2fa..d464db7 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.mapPresent import net.pterodactylus.sone.utils.paginate import net.pterodactylus.sone.utils.parameters @@ -14,8 +15,8 @@ import javax.inject.Inject * [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time. */ @MenuName("New") -class NewPage @Inject constructor( template: Template, webInterface: WebInterface): - SoneTemplatePage("new.html", webInterface, template, "Page.New.Title") { +class NewPage @Inject constructor( template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("new.html", webInterface, loaders, template = template, pageTitleKey = "Page.New.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) = getCurrentSone(soneRequest.toadletContext).let { currentSone -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt index c17cbe2..f8049a3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt @@ -3,6 +3,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.core.Preferences import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.emptyToNull import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters @@ -16,8 +17,8 @@ import javax.inject.Inject * This page lets the user edit the options of the Sone plugin. */ @MenuName("Options") -class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("options.html", webInterface, template, "Page.Options.Title") { +class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("options.html", webInterface, loaders, template = template, pageTitleKey = "Page.Options.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt index 0479133..ce25b7d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -13,8 +14,8 @@ import javax.inject.Inject * Page that lets the user control the rescue mode for a Sone. */ @MenuName("Rescue") -class RescuePage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface) { +class RescuePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { val soneRescuer = soneRequest.core.getSoneRescuer(currentSone) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt index 11c85dd..d980072 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt @@ -7,6 +7,7 @@ import freenet.support.Logger import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.PostReply import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.Pagination import net.pterodactylus.sone.utils.emptyToNull import net.pterodactylus.sone.utils.memoize @@ -28,11 +29,11 @@ import javax.inject.Inject * This page lets the user search for posts and replies that contain certain * words. */ -class SearchPage(template: Template, webInterface: WebInterface, ticker: Ticker = Ticker.systemTicker()) : - SoneTemplatePage("search.html", webInterface, template, "Page.Search.Title") { +class SearchPage(template: Template, webInterface: WebInterface, loaders: Loaders, ticker: Ticker = Ticker.systemTicker()) : + SoneTemplatePage("search.html", webInterface, loaders, template = template, pageTitleKey = "Page.Search.Title") { - @Inject constructor(template: Template, webInterface: WebInterface) : - this(template, webInterface, Ticker.systemTicker()) + @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + this(template, webInterface, loaders, Ticker.systemTicker()) private val cache: Cache, Pagination> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build() diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt index ac1e15f..7efd2bd 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt @@ -2,7 +2,7 @@ package net.pterodactylus.sone.web.pages import freenet.clients.http.* import net.pterodactylus.sone.data.Sone -import net.pterodactylus.sone.main.SonePlugin +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.emptyToNull import net.pterodactylus.sone.web.SessionProvider import net.pterodactylus.sone.web.WebInterface @@ -19,11 +19,12 @@ import java.net.URLEncoder open class SoneTemplatePage @JvmOverloads constructor( path: String, private val webInterface: WebInterface, + loaders: Loaders, template: Template, private val pageTitleKey: String? = null, private val requiresLogin: Boolean = false, private val pageTitle: (FreenetRequest) -> String = { pageTitleKey?.let(webInterface.l10n::getString) ?: "" } -) : FreenetTemplatePage(path, webInterface.templateContextFactory, template, "noPermission.html") { +) : FreenetTemplatePage(path, webInterface.templateContextFactory, loaders, template, "noPermission.html") { private val core = webInterface.core private val sessionProvider: SessionProvider = webInterface diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt index 7afe79c..93ccad0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -13,8 +14,8 @@ import javax.inject.Inject * Page that lets the user trust another Sone. This will assign a configurable * amount of trust to an identity. */ -class TrustPage @Inject constructor(template: Template, webInterface: WebInterface) : - LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface) { +class TrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt index ab8e42f..804390e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.* +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.* import net.pterodactylus.sone.web.* import net.pterodactylus.sone.web.page.* @@ -10,8 +11,8 @@ import javax.inject.* /** * Page that lets the user unbookmark a post. */ -class UnbookmarkPage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("unbookmark.html", webInterface, template, "Page.Unbookmark.Title") { +class UnbookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("unbookmark.html", webInterface, loaders, template = template, pageTitleKey = "Page.Unbookmark.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { when { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt index 11d456c..39b9749 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -12,8 +13,8 @@ import javax.inject.Inject /** * This page lets the user unfollow another Sone. */ -class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface) : - LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface) { +class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt index ab93fed..cfb072e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -12,8 +13,8 @@ import javax.inject.Inject /** * Page that lets the user unlike a [net.pterodactylus.sone.data.Post] or [net.pterodactylus.sone.data.Reply]. */ -class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface) { +class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt index f8cedb4..b39c9da 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -11,8 +12,8 @@ import javax.inject.Inject /** * This page lets the user unlock a [net.pterodactylus.sone.data.Sone] to allow its insertion. */ -class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("unlockSone.html", webInterface, template, "Page.UnlockSone.Title") { +class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("unlockSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.UnlockSone.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt index 2d0cc50..b9ed794 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -13,8 +14,8 @@ import javax.inject.Inject * Page that lets the user untrust another Sone. This will remove all trust * assignments for an identity. */ -class UntrustPage @Inject constructor(template: Template, webInterface: WebInterface) : - LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface) { +class UntrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : + LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt index 4310c6b..fcc1a0a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import freenet.support.api.Bucket import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.text.TextFilter import net.pterodactylus.sone.utils.emptyToNull import net.pterodactylus.sone.utils.headers @@ -21,8 +22,8 @@ import javax.inject.Inject /** * Page implementation that lets the user upload an image. */ -class UploadImagePage @Inject constructor(template: Template, webInterface: WebInterface): - LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface) { +class UploadImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface, loaders) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt index 2152f19..f3a5dd1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.template.* import net.pterodactylus.sone.utils.* import net.pterodactylus.sone.web.* @@ -11,8 +12,8 @@ import javax.inject.* /** * This page lets the user view a post and all its replies. */ -class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("viewPost.html", webInterface, template, "Page.ViewPost.Title") { +class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("viewPost.html", webInterface, loaders, template = template, pageTitleKey = "Page.ViewPost.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { templateContext["post"] = soneRequest.parameters["post"]?.let(soneRequest.core::getPost) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt index fd911ee..6f9f743 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.PostReply +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.template.SoneAccessor import net.pterodactylus.sone.utils.mapPresent import net.pterodactylus.sone.utils.paginate @@ -16,8 +17,8 @@ import javax.inject.Inject /** * Lets the user browser another Sone. */ -class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface): - SoneTemplatePage("viewSone.html", webInterface, template) { +class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): + SoneTemplatePage("viewSone.html", webInterface, loaders, template = template) { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { templateContext["soneId"] = soneRequest.parameters["sone"] diff --git a/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt index bfc2581..35d4afd 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt @@ -10,7 +10,7 @@ import org.mockito.ArgumentMatchers.* class FreenetTemplatePageTest { - private val page = FreenetTemplatePage("/test/path", null, null, "invalid-form-password") + private val page = FreenetTemplatePage("/test/path", null, null, null, "invalid-form-password") @Test fun `path is exposed correctly`() { @@ -64,7 +64,7 @@ class FreenetTemplatePageTest { @Test fun `isEnabled() returns false if full access only is true`() { - val page = object : FreenetTemplatePage("/test/path", null, null, null) { + val page = object : FreenetTemplatePage("/test/path", null, null, null, null) { override fun isFullAccessOnly() = true } assertThat(page.isEnabled(mock()), equalTo(false)) @@ -72,7 +72,7 @@ class FreenetTemplatePageTest { @Test fun `page with redirect target throws redirect exception on handleRequest`() { - val page = object : FreenetTemplatePage("/test/path", null, null, null) { + val page = object : FreenetTemplatePage("/test/path", null, null, null, null) { override fun getRedirectTarget(request: FreenetRequest?) = "foo" } val request = mock() @@ -84,7 +84,7 @@ class FreenetTemplatePageTest { @Test fun `page with full access only returns unauthorized on handleRequest with non-full access request`() { - val page = object : FreenetTemplatePage("/test/path", null, null, null) { + val page = object : FreenetTemplatePage("/test/path", null, null, null, null) { override fun isFullAccessOnly() = true } val request = deepMock() diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt index 1be5fa6..8866a46 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt @@ -13,7 +13,7 @@ import org.junit.Test /** * Unit test for [AboutPage]. */ -class AboutPageTest : WebPageTest({ template, webInterface -> AboutPage(template, webInterface, PluginVersion(version), PluginYear(year), PluginHomepage(homepage)) }) { +class AboutPageTest : WebPageTest({ template, webInterface, loaders -> AboutPage(template, webInterface, loaders, PluginVersion(version), PluginYear(year), PluginHomepage(homepage)) }) { companion object { private const val version = "0.1.2" diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt index 2a72bb3..e52accb 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt @@ -23,7 +23,7 @@ import org.mockito.ArgumentMatchers /** * Unit test for [IndexPage]. */ -class IndexPageTest: WebPageTest({ template, webInterface -> IndexPage(template, webInterface, postVisibilityFilter) }) { +class IndexPageTest: WebPageTest({ template, webInterface, loaders -> IndexPage(template, webInterface, loaders, postVisibilityFilter) }) { companion object { private val postVisibilityFilter = mock() diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt index 8aaf736..440fe1d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt @@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger /** * Unit test for [SearchPage]. */ -class SearchPageTest: WebPageTest({ template, webInterface -> SearchPage(template, webInterface, ticker) }) { +class SearchPageTest: WebPageTest({ template, webInterface, loaders -> SearchPage(template, webInterface, loaders, ticker) }) { companion object { val ticker = mock() diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt index 3eba7cf..c6db174 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt @@ -20,7 +20,7 @@ import org.junit.Test /** * Unit test for [SoneTemplatePage]. */ -class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : SoneTemplatePage("path.html", webInterface, template, requiresLogin = true) {} }) { +class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders -> object : SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = true) {} }) { init { request("index.html") @@ -28,14 +28,14 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : So @Test fun `page title is empty string if no page title key was given`() { - SoneTemplatePage("path.html", webInterface, template, requiresLogin = false).let { page -> + SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = false).let { page -> assertThat(page.getPageTitle(soneRequest), equalTo("")) } } @Test fun `page title is retrieved from l10n if page title key is given`() { - SoneTemplatePage("path.html", webInterface, template, "page.title", false).let { page -> + SoneTemplatePage("path.html", webInterface, loaders, template = template, pageTitleKey = "page.title", requiresLogin = false).let { page -> whenever(l10n.getString("page.title")).thenReturn("Page Title") assertThat(page.getPageTitle(soneRequest), equalTo("Page Title")) } @@ -148,7 +148,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : So @Test fun `handleRequest method is called`() { var called = false - val page = object : SoneTemplatePage("path.html", webInterface, template, requiresLogin = true) { + val page = object : SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = true) { override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { called = true } @@ -159,7 +159,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : So @Test fun `redirect does not happen if login is not required`() { - val page = SoneTemplatePage("page.html", webInterface, template, requiresLogin = false) + val page = SoneTemplatePage("page.html", webInterface, loaders, template = template, requiresLogin = false) assertThat(page.getRedirectTarget(freenetRequest), nullValue()) } @@ -211,7 +211,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : So @Test fun `page is enabled if no full access is required and login is not required`() { - SoneTemplatePage("path.html", webInterface, template, requiresLogin = false).let { page -> + SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = false).let { page -> assertThat(page.isEnabled(toadletContext), equalTo(true)) } } @@ -219,7 +219,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface -> object : So @Test fun `handle request with sone request is called`() { var called = false - val page = object : SoneTemplatePage("path.html", webInterface, template) { + val page = object : SoneTemplatePage("path.html", webInterface, loaders, template = template) { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { called = true } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt index 5d4f7a9..f5bab99 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt @@ -13,6 +13,7 @@ import net.pterodactylus.sone.data.PostReply import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.data.TemporaryImage import net.pterodactylus.sone.freenet.wot.OwnIdentity +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.test.deepMock import net.pterodactylus.sone.test.get import net.pterodactylus.sone.test.mock @@ -42,9 +43,10 @@ import kotlin.text.Charsets.UTF_8 /** * Base class for web page tests. */ -open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePage = { _, _ -> mock() }) { +open class WebPageTest(pageSupplier: (Template, WebInterface, Loaders) -> SoneTemplatePage = { _, _, _ -> mock() }) { val currentSone = mock() + val loaders = mock() val template = mock