private val pluginYear: PluginYear,
private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", template, "Page.About.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
templateContext["version"] = pluginVersion.version
templateContext["year"] = pluginYear.year
templateContext["homepage"] = pluginHomepage.homepage
*/
class BookmarksPage(template: Template, webInterface: WebInterface): SoneTemplatePage("bookmarks.html", template, "Page.Bookmarks.Title", webInterface) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
webInterface.core.bookmarkedPosts.let { posts ->
val pagination = Pagination<Post>(posts.filter { it.isLoaded }.sortedByDescending { it.time }, webInterface.core.preferences.postsPerPage)
templateContext["pagination"] = pagination
class CreateAlbumPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val name = request.httpRequest.getPartAsStringFailsafe("name", 64).trim()
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val name = freenetRequest.httpRequest.getPartAsStringFailsafe("name", 64).trim()
if (name.isEmpty()) {
templateContext["nameMissing"] = true
return
}
- val description = request.httpRequest.getPartAsStringFailsafe("description", 256).trim()
- val currentSone = webInterface.getCurrentSoneCreatingSession(request.toadletContext)
- val parentId = request.httpRequest.getPartAsStringFailsafe("parent", 36)
+ val description = freenetRequest.httpRequest.getPartAsStringFailsafe("description", 256).trim()
+ val currentSone = webInterface.getCurrentSoneCreatingSession(freenetRequest.toadletContext)
+ val parentId = freenetRequest.httpRequest.getPartAsStringFailsafe("parent", 36)
val parent = if (parentId == "") currentSone.rootAlbum else webInterface.core.getAlbum(parentId)
val album = webInterface.core.createAlbum(currentSone, parent)
try {
album.modify().apply {
setTitle(name)
- setDescription(TextFilter.filter(request.httpRequest.getHeader("Host"), description))
+ setDescription(TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), description))
}.update()
} catch (e: AlbumTitleMustNotBeEmpty) {
throw RedirectException("emptyAlbumTitle.html")
class CreatePostPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("createPost.html", template, "Page.CreatePost.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
templateContext["returnPage"] = returnPage
- if (request.isPOST) {
- val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim()
+ if (freenetRequest.isPOST) {
+ val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim()
if (text == "") {
templateContext["errorTextEmpty"] = true
return
}
- val sender = webInterface.core.getLocalSone(request.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(request.toadletContext)
- val recipient = webInterface.core.getSone(request.httpRequest.getPartAsStringFailsafe("recipient", 43))
- webInterface.core.createPost(sender, recipient, TextFilter.filter(request.httpRequest.getHeader("Host"), text))
+ val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(freenetRequest.toadletContext)
+ val recipient = webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
+ webInterface.core.createPost(sender, recipient, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
throw RedirectException(returnPage)
}
}
class CreateReplyPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("createReply.html", template, "Page.CreateReply.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- val postId = request.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
- val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
- val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
- if (request.isPOST) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
+ val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
+ val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
+ if (freenetRequest.isPOST) {
if (text == "") {
templateContext["errorTextEmpty"] = true
return
}
val post = webInterface.core.getPost(postId).orNull() ?: throw RedirectException("noPermission.html")
- val sender = webInterface.core.getLocalSone(request.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(request.toadletContext)
- webInterface.core.createReply(sender, post, TextFilter.filter(request.httpRequest.getHeader("Host"), text))
+ val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(freenetRequest.toadletContext)
+ webInterface.core.createReply(sender, post, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
throw RedirectException(returnPage)
}
}
private val logger = Logger.getLogger(CreateSonePage::class.java.name)
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
templateContext["sones"] = webInterface.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
templateContext["identitiesWithoutSone"] = webInterface.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}".toLowerCase() }
- if (request.isPOST) {
- val identity = request.httpRequest.getPartAsStringFailsafe("identity", 43)
+ if (freenetRequest.isPOST) {
+ val identity = freenetRequest.httpRequest.getPartAsStringFailsafe("identity", 43)
webInterface.core.identityManager.allOwnIdentities.firstOrNull { it.id == identity }?.let { ownIdentity ->
val sone = webInterface.core.createSone(ownIdentity)
if (sone == null) {
logger.log(Level.SEVERE, "Could not create Sone for OwnIdentity: $ownIdentity")
}
- setCurrentSone(request.toadletContext, sone)
+ setCurrentSone(freenetRequest.toadletContext, sone)
throw RedirectException("index.html")
}
templateContext["errorNoIdentity"] = true
class DeleteAlbumPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
if (!album.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- if (request.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
+ if (freenetRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
throw RedirectException("imageBrowser.html?album=${album.id}")
}
webInterface.core.deleteAlbum(album)
throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}")
}
- val album = webInterface.core.getAlbum(request.httpRequest.getParam("album"))
+ val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getParam("album"))
templateContext["album"] = album ?: throw RedirectException("invalid.html")
}
class DeleteImagePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val image = webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- if (request.httpRequest.isPartSet("abortDelete")) {
+ if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
throw RedirectException("imageBrowser.html?image=${image.id}")
}
webInterface.core.deleteImage(image)
throw RedirectException("imageBrowser.html?album=${image.album.id}")
}
- val image = webInterface.core.getImage(request.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html")
+ val image = webInterface.core.getImage(freenetRequest.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
throw RedirectException("noPermission.html")
}
class DeletePostPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("deletePost.html", template, "Page.DeletePost.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val post = webInterface.core.getPost(request.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html")
- val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html")
+ val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
if (!post.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- if (request.httpRequest.isPartSet("confirmDelete")) {
+ if (freenetRequest.httpRequest.isPartSet("confirmDelete")) {
webInterface.core.deletePost(post)
throw RedirectException(returnPage)
- } else if (request.httpRequest.isPartSet("abortDelete")) {
+ } else if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
throw RedirectException(returnPage)
}
templateContext["post"] = post
templateContext["returnPage"] = returnPage
return
}
- templateContext["post"] = webInterface.core.getPost(request.httpRequest.getParam("post")).orNull() ?: throw RedirectException("noPermission.html")
- templateContext["returnPage"] = request.httpRequest.getParam("returnPage")
+ templateContext["post"] = webInterface.core.getPost(freenetRequest.httpRequest.getParam("post")).orNull() ?: throw RedirectException("noPermission.html")
+ templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage")
}
}
class DeleteProfileFieldPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- val currentSone = getCurrentSone(request.toadletContext)!!
- if (request.isPOST) {
- val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
- if (request.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ val currentSone = getCurrentSone(freenetRequest.toadletContext)!!
+ if (freenetRequest.isPOST) {
+ val field = currentSone.profile.getFieldById(freenetRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
+ if (freenetRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
currentSone.profile = currentSone.profile.apply { removeField(field) }
}
throw RedirectException("editProfile.html#profile-fields")
}
- val field = currentSone.profile.getFieldById(request.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+ val field = currentSone.profile.getFieldById(freenetRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
templateContext["field"] = field
}
class DeleteReplyPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val replyId = request.httpRequest.getPartAsStringFailsafe("reply", 36)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val replyId = freenetRequest.httpRequest.getPartAsStringFailsafe("reply", 36)
val reply = webInterface.core.getPostReply(replyId).orNull() ?: throw RedirectException("noPermission.html")
if (!reply.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
- if (request.httpRequest.isPartSet("confirmDelete")) {
+ val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ if (freenetRequest.httpRequest.isPartSet("confirmDelete")) {
webInterface.core.deleteReply(reply)
throw RedirectException(returnPage)
}
- if (request.httpRequest.isPartSet("abortDelete")) {
+ if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
throw RedirectException(returnPage)
}
templateContext["reply"] = replyId
templateContext["returnPage"] = returnPage
return
}
- templateContext["reply"] = request.httpRequest.getParam("reply")
- templateContext["returnPage"] = request.httpRequest.getParam("returnPage")
+ templateContext["reply"] = freenetRequest.httpRequest.getParam("reply")
+ templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage")
}
}
class DeleteSonePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- if (request.httpRequest.isPartSet("deleteSone")) {
- webInterface.core.deleteSone(getCurrentSone(request.toadletContext))
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ if (freenetRequest.httpRequest.isPartSet("deleteSone")) {
+ webInterface.core.deleteSone(getCurrentSone(freenetRequest.toadletContext))
}
throw RedirectException("index.html")
}
class DismissNotificationPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("dismissNotification.html", template, "Page.DismissNotification.Title", webInterface) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
- val notificationId = request.httpRequest.getPartAsStringFailsafe("notification", 36)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ val notificationId = freenetRequest.httpRequest.getPartAsStringFailsafe("notification", 36)
webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
throw RedirectException(returnPage)
}
class DistrustPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("distrust.html", template, "Page.Distrust.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val sone = webInterface.core.getSone(request.httpRequest.getPartAsStringFailsafe("sone", 44)).orNull()
- sone?.run { webInterface.core.distrustSone(getCurrentSone(request.toadletContext), this) }
- throw RedirectException(request.httpRequest.getPartAsStringFailsafe("returnPage", 256))
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val sone = webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sone", 44)).orNull()
+ sone?.run { webInterface.core.distrustSone(getCurrentSone(freenetRequest.toadletContext), this) }
+ throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
class EditAlbumPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
- if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
+ if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
album.parent?.moveAlbumUp(album)
webInterface.core.touchConfiguration()
throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
- } else if (request.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
+ } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
album.parent?.moveAlbumDown(album)
webInterface.core.touchConfiguration()
throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
} else {
try {
album.modify()
- .setTitle(request.httpRequest.getPartAsStringFailsafe("title", 100))
- .setDescription(request.httpRequest.getPartAsStringFailsafe("description", 1000))
+ .setTitle(freenetRequest.httpRequest.getPartAsStringFailsafe("title", 100))
+ .setDescription(freenetRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
.update()
} catch (e: AlbumTitleMustNotBeEmpty) {
throw RedirectException("emptyAlbumTitle.html")
class EditImagePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("editImage.html", template, "Page.EditImage.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val image = webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- request.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
- if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
+ freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
+ if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
image.album.moveImageUp(image)
webInterface.core.touchConfiguration()
- } else if (request.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
+ } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
image.album.moveImageDown(image)
webInterface.core.touchConfiguration()
} else {
try {
image.modify()
- .setTitle(request.httpRequest.getPartAsStringFailsafe("title", 100))
- .setDescription(TextFilter.filter(request.httpRequest.getHeader("Host"), request.httpRequest.getPartAsStringFailsafe("description", 1024)))
+ .setTitle(freenetRequest.httpRequest.getPartAsStringFailsafe("title", 100))
+ .setDescription(TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), freenetRequest.httpRequest.getPartAsStringFailsafe("description", 1024)))
.update()
webInterface.core.touchConfiguration()
} catch (e: ImageTitleMustNotBeEmpty) {
class EditProfileFieldPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- sessionProvider.getCurrentSone(request.toadletContext)!!.let { currentSone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ sessionProvider.getCurrentSone(freenetRequest.toadletContext)!!.let { currentSone ->
currentSone.profile.let { profile ->
- if (request.isPOST) {
- if (request.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
+ if (freenetRequest.isPOST) {
+ if (freenetRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
throw RedirectException("editProfile.html#profile-fields")
}
- val field = profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
- request.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
+ val field = profile.getFieldById(freenetRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
+ freenetRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
try {
if (name != field.name) {
field.name = name
}
}
}
- templateContext["field"] = profile.getFieldById(request.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+ templateContext["field"] = profile.getFieldById(freenetRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
}
}
}
class EditProfilePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("editProfile.html", template, "Page.EditProfile.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- request.currentSone!!.profile.let { profile ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ freenetRequest.currentSone!!.profile.let { profile ->
templateContext["firstName"] = profile.firstName
templateContext["middleName"] = profile.middleName
templateContext["lastName"] = profile.lastName
templateContext["birthYear"] = profile.birthYear
templateContext["avatarId"] = profile.avatar
templateContext["fields"] = profile.fields
- if (request.isPOST) {
- if (request.httpRequest.getPartAsStringFailsafe("save-profile", 4) == "true") {
- profile.firstName = request.httpRequest.getPartAsStringFailsafe("first-name", 256).trim()
- profile.middleName = request.httpRequest.getPartAsStringFailsafe("middle-name", 256).trim()
- profile.lastName = request.httpRequest.getPartAsStringFailsafe("last-name", 256).trim()
- profile.birthDay = request.httpRequest.getPartAsStringFailsafe("birth-day", 256).trim().toIntOrNull()
- profile.birthMonth = request.httpRequest.getPartAsStringFailsafe("birth-month", 256).trim().toIntOrNull()
- profile.birthYear = request.httpRequest.getPartAsStringFailsafe("birth-year", 256).trim().toIntOrNull()
- profile.setAvatar(webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("avatarId", 256).trim(), false))
+ if (freenetRequest.isPOST) {
+ if (freenetRequest.httpRequest.getPartAsStringFailsafe("save-profile", 4) == "true") {
+ profile.firstName = freenetRequest.httpRequest.getPartAsStringFailsafe("first-name", 256).trim()
+ profile.middleName = freenetRequest.httpRequest.getPartAsStringFailsafe("middle-name", 256).trim()
+ profile.lastName = freenetRequest.httpRequest.getPartAsStringFailsafe("last-name", 256).trim()
+ profile.birthDay = freenetRequest.httpRequest.getPartAsStringFailsafe("birth-day", 256).trim().toIntOrNull()
+ profile.birthMonth = freenetRequest.httpRequest.getPartAsStringFailsafe("birth-month", 256).trim().toIntOrNull()
+ profile.birthYear = freenetRequest.httpRequest.getPartAsStringFailsafe("birth-year", 256).trim().toIntOrNull()
+ profile.setAvatar(webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("avatarId", 256).trim(), false))
profile.fields.forEach { field ->
- field.value = TextFilter.filter(request.httpRequest.getHeader("Host"), request.httpRequest.getPartAsStringFailsafe("field-${field.id}", 400).trim())
+ field.value = TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), freenetRequest.httpRequest.getPartAsStringFailsafe("field-${field.id}", 400).trim())
}
webInterface.core.touchConfiguration()
throw RedirectException("editProfile.html")
- } else if (request.httpRequest.getPartAsStringFailsafe("add-field", 4) == "true") {
- val fieldName = request.httpRequest.getPartAsStringFailsafe("field-name", 100)
+ } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("add-field", 4) == "true") {
+ val fieldName = freenetRequest.httpRequest.getPartAsStringFailsafe("field-name", 100)
try {
profile.addField(fieldName)
- request.currentSone!!.profile = profile
+ freenetRequest.currentSone!!.profile = profile
webInterface.core.touchConfiguration()
throw RedirectException("editProfile.html#profile-fields")
} catch (e: DuplicateField) {
templateContext["duplicateFieldName"] = true
}
} else profile.fields.forEach { field ->
- if (request.httpRequest.getPartAsStringFailsafe("delete-field-${field.id}", 4) == "true") {
+ if (freenetRequest.httpRequest.getPartAsStringFailsafe("delete-field-${field.id}", 4) == "true") {
throw RedirectException("deleteProfileField.html?field=${field.id}")
- } else if (request.httpRequest.getPartAsStringFailsafe("edit-field-${field.id}", 4) == "true") {
+ } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("edit-field-${field.id}", 4) == "true") {
throw RedirectException("editProfileField.html?field=${field.id}")
- } else if (request.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") {
+ } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") {
profile.moveFieldDown(field)
- request.currentSone!!.profile = profile
+ freenetRequest.currentSone!!.profile = profile
throw RedirectException("editProfile.html#profile-fields")
- } else if (request.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") {
+ } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") {
profile.moveFieldUp(field)
- request.currentSone!!.profile = profile
+ freenetRequest.currentSone!!.profile = profile
throw RedirectException("editProfile.html#profile-fields")
}
}
class FollowSonePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("followSone.html", template, "Page.FollowSone.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- request.httpRequest.getPartAsStringFailsafe("sone", 1200).split(Regex("[ ,]+"))
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ freenetRequest.httpRequest.getPartAsStringFailsafe("sone", 1200).split(Regex("[ ,]+"))
.map { it to webInterface.core.getSone(it) }
.filter { it.second.isPresent }
.map { it.first to it.second.get() }
.forEach { sone ->
- webInterface.core.followSone(request.currentSone, sone.first)
+ webInterface.core.followSone(freenetRequest.currentSone, sone.first)
webInterface.core.markSoneKnown(sone.second)
}
- throw RedirectException(request.httpRequest.getPartAsStringFailsafe("returnPage", 256))
+ throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
class ImageBrowserPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if ("album" in request.parameters) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if ("album" in freenetRequest.parameters) {
templateContext["albumRequested"] = true
- templateContext["album"] = webInterface.core.getAlbum(request.parameters["album"]!!)
- templateContext["page"] = request.parameters["page"]
- } else if ("image" in request.parameters) {
+ templateContext["album"] = webInterface.core.getAlbum(freenetRequest.parameters["album"]!!)
+ templateContext["page"] = freenetRequest.parameters["page"]
+ } else if ("image" in freenetRequest.parameters) {
templateContext["imageRequested"] = true
- templateContext["image"] = webInterface.core.getImage(request.parameters["image"])
- } else if (request.parameters["mode"] == "gallery") {
+ templateContext["image"] = webInterface.core.getImage(freenetRequest.parameters["image"])
+ } else if (freenetRequest.parameters["mode"] == "gallery") {
templateContext["galleryRequested"] = true
webInterface.core.sones
.map(Sone::getRootAlbum)
.filterNot(Album::isEmpty)
.sortedBy(Album::getTitle)
.also { albums ->
- Pagination(albums, webInterface.core.preferences.imagesPerPage).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }.also { pagination ->
+ Pagination(albums, webInterface.core.preferences.imagesPerPage).apply { page = freenetRequest.parameters["page"]?.toIntOrNull() ?: 0 }.also { pagination ->
templateContext["albumPagination"] = pagination
templateContext["albums"] = pagination.items
}
}
} else {
templateContext["soneRequested"] = true
- templateContext["sone"] = webInterface.core.getSone(request.httpRequest.getParam("sone")).orNull() ?: getCurrentSone(request.toadletContext)
+ templateContext["sone"] = webInterface.core.getSone(freenetRequest.httpRequest.getParam("sone")).orNull() ?: getCurrentSone(freenetRequest.toadletContext)
}
}
class IndexPage(template: Template, webInterface: WebInterface, private val postVisibilityFilter: PostVisibilityFilter):
SoneTemplatePage("index.html", template, "Page.Index.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- getCurrentSone(request.toadletContext)!!.let { currentSone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ getCurrentSone(freenetRequest.toadletContext)!!.let { currentSone ->
(currentSone.posts +
currentSone.friends
.map { webInterface.core.getSone(it) }
.sortedByDescending { it.time }
.let { posts ->
Pagination(posts, webInterface.core.preferences.postsPerPage).apply {
- page = request.parameters["page"]?.toIntOrNull() ?: 0
+ page = freenetRequest.parameters["page"]?.toIntOrNull() ?: 0
}.let { pagination ->
templateContext["pagination"] = pagination
templateContext["posts"] = pagination.items
class KnownSonesPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("knownSones.html", template, "Page.KnownSones.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- getCurrentSone(request.toadletContext).let { currentSone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
Pagination(webInterface.core.sones
- .filterNot { request.parameters["filter"] == "followed" && currentSone != null && !currentSone.hasFriend(it.id) }
- .filterNot { request.parameters["filter"] == "not-followed" && currentSone != null && currentSone.hasFriend(it.id) }
- .filterNot { request.parameters["filter"] == "new" && it.isKnown }
- .filterNot { request.parameters["filter"] == "not-new" && !it.isKnown }
- .filterNot { request.parameters["filter"] == "own" && !it.isLocal }
- .filterNot { request.parameters["filter"] == "not-own" && it.isLocal }
+ .filterNot { freenetRequest.parameters["filter"] == "followed" && currentSone != null && !currentSone.hasFriend(it.id) }
+ .filterNot { freenetRequest.parameters["filter"] == "not-followed" && currentSone != null && currentSone.hasFriend(it.id) }
+ .filterNot { freenetRequest.parameters["filter"] == "new" && it.isKnown }
+ .filterNot { freenetRequest.parameters["filter"] == "not-new" && !it.isKnown }
+ .filterNot { freenetRequest.parameters["filter"] == "own" && !it.isLocal }
+ .filterNot { freenetRequest.parameters["filter"] == "not-own" && it.isLocal }
.sortedWith(
- when (request.parameters["sort"]) {
+ when (freenetRequest.parameters["sort"]) {
"images" -> Sone.IMAGE_COUNT_COMPARATOR
"name" -> Sone.NICE_NAME_COMPARATOR.reversed()
"posts" -> Sone.POST_COUNT_COMPARATOR
else -> Sone.LAST_ACTIVITY_COMPARATOR
}.let { comparator ->
- when (request.parameters["order"]) {
+ when (freenetRequest.parameters["order"]) {
"asc" -> comparator.reversed()
else -> comparator
}
}
- ), 25).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }
+ ), 25).apply { page = freenetRequest.parameters["page"]?.toIntOrNull() ?: 0 }
.let { pagination ->
templateContext["pagination"] = pagination
templateContext["knownSones"] = pagination.items
}
- templateContext["sort"] = request.parameters["sort"].let { sort -> if (sort in listOf("images", "name", "posts")) sort else "activity" }
- templateContext["order"] = request.parameters["order"].let { order -> if (order == "asc") "asc" else "desc" }
- templateContext["filter"] = request.parameters["filter"]
+ templateContext["sort"] = freenetRequest.parameters["sort"].let { sort -> if (sort in listOf("images", "name", "posts")) sort else "activity" }
+ templateContext["order"] = freenetRequest.parameters["order"].let { order -> if (order == "asc") "asc" else "desc" }
+ templateContext["filter"] = freenetRequest.parameters["filter"]
}
}
class LikePage(template: Template, webInterface: WebInterface)
: SoneTemplatePage("like.html", template, "Page.Like.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- getCurrentSone(request.toadletContext)!!.let { currentSone ->
- request.parameters["type", 16]?.also { type ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ getCurrentSone(freenetRequest.toadletContext)!!.let { currentSone ->
+ freenetRequest.parameters["type", 16]?.also { type ->
when(type) {
- "post" -> currentSone.addLikedPostId(request.parameters["post", 36]!!)
- "reply" -> currentSone.addLikedReplyId(request.parameters["reply", 36]!!)
+ "post" -> currentSone.addLikedPostId(freenetRequest.parameters["post", 36]!!)
+ "reply" -> currentSone.addLikedReplyId(freenetRequest.parameters["reply", 36]!!)
}
}
- throw RedirectException(request.parameters["returnPage", 256]!!)
+ throw RedirectException(freenetRequest.parameters["returnPage", 256]!!)
}
}
}
class LockSonePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("lockSone.html", template, "Page.LockSone.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- request.parameters["returnPage", 256]!!.let { returnPage ->
- request.parameters["sone", 44]!!
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ freenetRequest.parameters["returnPage", 256]!!.let { returnPage ->
+ freenetRequest.parameters["sone", 44]!!
.let { webInterface.core.getLocalSone(it) }
?.let { webInterface.core.lockSone(it) }
throw RedirectException(returnPage)
class LoginPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("login.html", template, "Page.Login.Title", webInterface) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val soneId = request.httpRequest.getPartAsStringFailsafe("sone-id", 43)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val soneId = freenetRequest.httpRequest.getPartAsStringFailsafe("sone-id", 43)
webInterface.core.getLocalSone(soneId)?.let { sone ->
- setCurrentSone(request.toadletContext, sone)
- val target = request.httpRequest.getParam("target").emptyToNull ?: "index.html"
+ setCurrentSone(freenetRequest.toadletContext, sone)
+ val target = freenetRequest.httpRequest.getParam("target").emptyToNull ?: "index.html"
throw RedirectException(target)
}
}
templateContext["identitiesWithoutSone"] = webInterface.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}" }
}
- override public fun getRedirectTarget(request: FreenetRequest) =
- getCurrentSone(request.toadletContext)?.let { "index.html" }
+ override public fun getRedirectTarget(freenetRequest: FreenetRequest) =
+ getCurrentSone(freenetRequest.toadletContext)?.let { "index.html" }
override fun isEnabled(toadletContext: ToadletContext) = when {
webInterface.core.preferences.isRequireFullAccess && !toadletContext.isAllowedFullAccess -> false
class LogoutPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("logout.html", template, "Page.Logout.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- setCurrentSone(request.toadletContext, null)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ setCurrentSone(freenetRequest.toadletContext, null)
throw RedirectException("index.html")
}
class MarkAsKnownPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("markAsKnown.html", template, "Page.MarkAsKnown.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- val ids = request.parameters["id", 65536]!!.split(" ")
- when (request.parameters["type", 5]) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ val ids = freenetRequest.parameters["id", 65536]!!.split(" ")
+ when (freenetRequest.parameters["type", 5]) {
"sone" -> ids.mapPresent(webInterface.core::getSone).forEach(webInterface.core::markSoneKnown)
"post" -> ids.mapPresent(webInterface.core::getPost).forEach(webInterface.core::markPostKnown)
"reply" -> ids.mapPresent(webInterface.core::getPostReply).forEach(webInterface.core::markReplyKnown)
else -> throw RedirectException("invalid.html")
}
- throw RedirectException(request.parameters["returnPage", 256]!!)
+ throw RedirectException(freenetRequest.parameters["returnPage", 256]!!)
}
}
class NewPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("new.html", template, "Page.New.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) =
- getCurrentSone(request.toadletContext).let { currentSone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) =
+ getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
(webInterface.getNewPosts(currentSone) + webInterface.getNewReplies(currentSone).mapPresent { it.post })
.distinct()
.sortedByDescending { it.time }
.let { posts ->
Pagination(posts, webInterface.core.preferences.postsPerPage).apply {
- page = request.parameters["page"]?.toIntOrNull() ?: 0
+ page = freenetRequest.parameters["page"]?.toIntOrNull() ?: 0
}.let { pagination ->
templateContext["pagination"] = pagination
templateContext["posts"] = pagination.items
class OptionsPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("options.html", template, "Page.Options.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
val fieldsWithErrors = mutableListOf<String>()
- getCurrentSone(request.toadletContext)?.options?.let { options ->
- val autoFollow = "auto-follow" in request.parameters
- val loadLinkedImages = request.parameters["load-linked-images"].emptyToNull
- val showCustomAvatars = request.parameters["show-custom-avatars"].emptyToNull
- val enableSoneInsertNotification = "enable-sone-insert-notifications" in request.parameters
- val showNewSoneNotification = "show-notification-new-sones" in request.parameters
- val showNewPostNotification = "show-notification-new-posts" in request.parameters
- val showNewReplyNotification = "show-notification-new-replies" in request.parameters
+ getCurrentSone(freenetRequest.toadletContext)?.options?.let { options ->
+ val autoFollow = "auto-follow" in freenetRequest.parameters
+ val loadLinkedImages = freenetRequest.parameters["load-linked-images"].emptyToNull
+ val showCustomAvatars = freenetRequest.parameters["show-custom-avatars"].emptyToNull
+ val enableSoneInsertNotification = "enable-sone-insert-notifications" in freenetRequest.parameters
+ val showNewSoneNotification = "show-notification-new-sones" in freenetRequest.parameters
+ val showNewPostNotification = "show-notification-new-posts" in freenetRequest.parameters
+ val showNewReplyNotification = "show-notification-new-replies" in freenetRequest.parameters
options.isAutoFollow = autoFollow
options.isSoneInsertNotificationEnabled = enableSoneInsertNotification
loadLinkedImages?.also { if (cantSetOption { options.loadLinkedImages = LoadExternalContent.valueOf(loadLinkedImages) }) fieldsWithErrors += "load-linked-images" }
showCustomAvatars?.also { if (cantSetOption { options.showCustomAvatars = LoadExternalContent.valueOf(showCustomAvatars) }) fieldsWithErrors += "show-custom-avatars" }
}
- val fullAccessRequired = "require-full-access" in request.parameters
- val fcpInterfaceActive = "fcp-interface-active" in request.parameters
+ val fullAccessRequired = "require-full-access" in freenetRequest.parameters
+ val fcpInterfaceActive = "fcp-interface-active" in freenetRequest.parameters
webInterface.core.preferences.isRequireFullAccess = fullAccessRequired
webInterface.core.preferences.isFcpInterfaceActive = fcpInterfaceActive
- val postsPerPage = request.parameters["posts-per-page"]?.toIntOrNull()
- val charactersPerPost = request.parameters["characters-per-post"]?.toIntOrNull()
- val postCutOffLength = request.parameters["post-cut-off-length"]?.toIntOrNull()
- val imagesPerPage = request.parameters["images-per-page"]?.toIntOrNull()
- val insertionDelay = request.parameters["insertion-delay"]?.toIntOrNull()
- val fcpFullAccessRequired = request.parameters["fcp-full-access-required"]?.toIntOrNull()
- val negativeTrust = request.parameters["negative-trust"]?.toIntOrNull()
- val positiveTrust = request.parameters["positive-trust"]?.toIntOrNull()
- val trustComment = request.parameters["trust-comment"]?.emptyToNull
+ val postsPerPage = freenetRequest.parameters["posts-per-page"]?.toIntOrNull()
+ val charactersPerPost = freenetRequest.parameters["characters-per-post"]?.toIntOrNull()
+ val postCutOffLength = freenetRequest.parameters["post-cut-off-length"]?.toIntOrNull()
+ val imagesPerPage = freenetRequest.parameters["images-per-page"]?.toIntOrNull()
+ val insertionDelay = freenetRequest.parameters["insertion-delay"]?.toIntOrNull()
+ val fcpFullAccessRequired = freenetRequest.parameters["fcp-full-access-required"]?.toIntOrNull()
+ val negativeTrust = freenetRequest.parameters["negative-trust"]?.toIntOrNull()
+ val positiveTrust = freenetRequest.parameters["positive-trust"]?.toIntOrNull()
+ val trustComment = freenetRequest.parameters["trust-comment"]?.emptyToNull
if (cantSetOption { it.setPostsPerPage(postsPerPage) }) fieldsWithErrors += "posts-per-page"
if (cantSetOption { it.setCharactersPerPost(charactersPerPost) }) fieldsWithErrors += "characters-per-post"
}
templateContext["fieldErrors"] = fieldsWithErrors
}
- getCurrentSone(request.toadletContext)?.options?.let { options ->
+ getCurrentSone(freenetRequest.toadletContext)?.options?.let { options ->
templateContext["auto-follow"] = options.isAutoFollow
templateContext["show-notification-new-sones"] = options.isShowNewSoneNotifications
templateContext["show-notification-new-posts"] = options.isShowNewPostNotifications
class RescuePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("rescue.html", template, "Page.Rescue.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- val soneRescuer = webInterface.core.getSoneRescuer(getCurrentSone(request.toadletContext)!!)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ val soneRescuer = webInterface.core.getSoneRescuer(getCurrentSone(freenetRequest.toadletContext)!!)
templateContext["soneRescuer"] = soneRescuer
- if (request.isPOST) {
- request.parameters["edition", 9]?.toIntOrNull()?.also {
+ if (freenetRequest.isPOST) {
+ freenetRequest.parameters["edition", 9]?.toIntOrNull()?.also {
if (it > -1) {
soneRescuer.setEdition(it.toLong())
}
}
- if (request.parameters["fetch", 8] == "true") {
+ if (freenetRequest.parameters["fetch", 8] == "true") {
soneRescuer.startNextFetch()
}
throw RedirectException("rescue.html")
private val cache: Cache<Iterable<Phrase>, Pagination<Post>> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build()
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
val phrases = try {
- request.parameters["query"].emptyToNull?.parse()
+ freenetRequest.parameters["query"].emptyToNull?.parse()
} catch (te: TextException) {
redirect("index.html")
}
val sonePagination = webInterface.core.sones
.scoreAndPaginate(phrases) { it.allText() }
- .apply { page = request.parameters["sonePage"].emptyToNull?.toIntOrNull() ?: 0 }
+ .apply { page = freenetRequest.parameters["sonePage"].emptyToNull?.toIntOrNull() ?: 0 }
val postPagination = cache.get(phrases) {
webInterface.core.sones
.flatMap(Sone::getPosts)
.filter { Post.FUTURE_POSTS_FILTER.apply(it) }
.scoreAndPaginate(phrases) { it.allText() }
- }.apply { page = request.parameters["postPage"].emptyToNull?.toIntOrNull() ?: 0 }
+ }.apply { page = freenetRequest.parameters["postPage"].emptyToNull?.toIntOrNull() ?: 0 }
templateContext["sonePagination"] = sonePagination
templateContext["soneHits"] = sonePagination.items
fun requiresLogin() = requiresLogin
- override public fun getPageTitle(request: FreenetRequest) =
+ override public fun getPageTitle(freenetRequest: FreenetRequest) =
pageTitleKey?.let(webInterface.l10n::getString) ?: ""
override public fun getStyleSheets() =
handleRequest(freenetRequest, templateContext)
}
- internal open fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ internal open fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
}
- override public fun getRedirectTarget(request: FreenetRequest): String? {
- if (requiresLogin && getCurrentSone(request.toadletContext) == null) {
- val parameters = request.httpRequest.parameterNames
- .flatMap { name -> request.httpRequest.getMultipleParam(name).map { name to it } }
+ override public fun getRedirectTarget(freenetRequest: FreenetRequest): String? {
+ if (requiresLogin && getCurrentSone(freenetRequest.toadletContext) == null) {
+ val parameters = freenetRequest.httpRequest.parameterNames
+ .flatMap { name -> freenetRequest.httpRequest.getMultipleParam(name).map { name to it } }
.joinToString("&") { "${it.first.urlEncode}=${it.second.urlEncode}" }
.emptyToNull
- return "login.html?target=${request.httpRequest.path}${parameters?.let { ("?" + it).urlEncode } ?: ""}"
+ return "login.html?target=${freenetRequest.httpRequest.path}${parameters?.let { ("?" + it).urlEncode } ?: ""}"
}
return null
}
class TrustPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("trust.html", template, "Page.Trust.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- getCurrentSone(request.toadletContext)?.also { currentSone ->
- webInterface.core.getSone(request.parameters["sone"]).let { sone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ getCurrentSone(freenetRequest.toadletContext)?.also { currentSone ->
+ webInterface.core.getSone(freenetRequest.parameters["sone"]).let { sone ->
webInterface.core.trustSone(currentSone, sone)
}
}
- throw RedirectException(request.parameters["returnPage", 256])
+ throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
class UnbookmarkPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("unbookmark.html", template, "Page.Unbookmark.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
when {
- request.isGET && (request.parameters["post"] == "allNotLoaded") -> {
+ freenetRequest.isGET && (freenetRequest.parameters["post"] == "allNotLoaded") -> {
webInterface.core.bookmarkedPosts
.filterNot(Post::isLoaded)
.forEach(webInterface.core::unbookmarkPost)
throw RedirectException("bookmarks.html")
}
- request.isPOST -> {
- request.parameters["post", 36]
+ freenetRequest.isPOST -> {
+ freenetRequest.parameters["post", 36]
.let(webInterface.core::getPost)
.also(webInterface.core::unbookmarkPost)
- throw RedirectException(request.parameters["returnPage", 256])
+ throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
}
class UnfollowSonePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- getCurrentSone(request.toadletContext)!!.also { currentSone ->
- request.parameters["sone"]!!.split(Regex("[ ,]+"))
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ getCurrentSone(freenetRequest.toadletContext)!!.also { currentSone ->
+ freenetRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
.forEach { webInterface.core.unfollowSone(currentSone, it) }
}
- throw RedirectException(request.parameters["returnPage", 256])
+ throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
class UnlikePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("unlike.html", template, "Page.Unlike.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- when (request.parameters["type"]) {
- "post" -> getCurrentSone(request.toadletContext)!!.removeLikedPostId(request.parameters["post"]!!)
- "reply" -> getCurrentSone(request.toadletContext)!!.removeLikedReplyId(request.parameters["reply"]!!)
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ when (freenetRequest.parameters["type"]) {
+ "post" -> getCurrentSone(freenetRequest.toadletContext)!!.removeLikedPostId(freenetRequest.parameters["post"]!!)
+ "reply" -> getCurrentSone(freenetRequest.toadletContext)!!.removeLikedReplyId(freenetRequest.parameters["reply"]!!)
}
- throw RedirectException(request.parameters["returnPage", 256])
+ throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
class UnlockSonePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("unlockSone.html", template, "Page.UnlockSone.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- request.parameters["sone", 44]
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ freenetRequest.parameters["sone", 44]
.let(webInterface.core::getLocalSone)
?.also(webInterface.core::unlockSone)
- throw RedirectException(request.parameters["returnPage", 256])
+ throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
class UntrustPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("untrust.html", template, "Page.Untrust.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- getCurrentSone(request.toadletContext)!!.also { currentSone ->
- request.parameters["sone", 44]
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ getCurrentSone(freenetRequest.toadletContext)!!.also { currentSone ->
+ freenetRequest.parameters["sone", 44]
.let(webInterface.core::getSone)
.also { webInterface.core.untrustSone(currentSone, it) }
}
- throw RedirectException(request.parameters["returnPage", 256])
+ throw RedirectException(freenetRequest.parameters["returnPage", 256])
}
}
class UploadImagePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("uploadImage.html", template, "Page.UploadImage.Title", webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- if (request.isPOST) {
- val parentAlbum = request.parameters["parent"]!!.let(webInterface.core::getAlbum) ?: throw RedirectException("noPermission.html")
- if (parentAlbum.sone != getCurrentSone(request.toadletContext)) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ if (freenetRequest.isPOST) {
+ val parentAlbum = freenetRequest.parameters["parent"]!!.let(webInterface.core::getAlbum) ?: throw RedirectException("noPermission.html")
+ if (parentAlbum.sone != getCurrentSone(freenetRequest.toadletContext)) {
throw RedirectException("noPermission.html")
}
- val title = request.parameters["title", 200].emptyToNull ?: throw RedirectException("emptyImageTitle.html")
+ val title = freenetRequest.parameters["title", 200].emptyToNull ?: throw RedirectException("emptyImageTitle.html")
- val uploadedFile = request.httpRequest.getUploadedFile("image")
+ val uploadedFile = freenetRequest.httpRequest.getUploadedFile("image")
val bytes = uploadedFile.data.use { it.toByteArray() }
val bufferedImage = bytes.toImage()
if (bufferedImage == null) {
}
val temporaryImage = webInterface.core.createTemporaryImage(bytes.mimeType, bytes)
- webInterface.core.createImage(getCurrentSone(request.toadletContext), parentAlbum, temporaryImage).modify().apply {
+ webInterface.core.createImage(getCurrentSone(freenetRequest.toadletContext), parentAlbum, temporaryImage).modify().apply {
setWidth(bufferedImage.width)
setHeight(bufferedImage.height)
setTitle(title)
- setDescription(TextFilter.filter(request.headers["Host"], request.parameters["description", 4000]))
+ setDescription(TextFilter.filter(freenetRequest.headers["Host"], freenetRequest.parameters["description", 4000]))
}.update()
throw RedirectException("imageBrowser.html?album=${parentAlbum.id}")
}
class ViewPostPage(template: Template, webInterface: WebInterface):
SoneTemplatePage("viewPost.html", template, "Page.ViewPost.Title", webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- templateContext["post"] = request.parameters["post"].let(webInterface.core::getPost).orNull()
- templateContext["raw"] = request.parameters["raw"] == "true"
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ templateContext["post"] = freenetRequest.parameters["post"].let(webInterface.core::getPost).orNull()
+ templateContext["raw"] = freenetRequest.parameters["raw"] == "true"
}
override fun isLinkExcepted(link: URI?) = true
- public override fun getPageTitle(request: FreenetRequest) =
- (request.parameters["post"].let(webInterface.core::getPost).let {
+ public override fun getPageTitle(freenetRequest: FreenetRequest) =
+ (freenetRequest.parameters["post"].let(webInterface.core::getPost).let {
if (it.text.length > 20) {
it.text.substring(0..19) + "…"
} else {
it.text
} + " - ${SoneAccessor.getNiceName(it.sone)} - "
- } ?: "") + super.getPageTitle(request)
+ } ?: "") + super.getPageTitle(freenetRequest)
}
class ViewSonePage(template: Template, webInterface: WebInterface):
SoneTemplatePage("viewSone.html", template, webInterface, false) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
- templateContext["soneId"] = request.parameters["sone"]
- request.parameters["sone"].let(webInterface.core::getSone).let { sone ->
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ templateContext["soneId"] = freenetRequest.parameters["sone"]
+ freenetRequest.parameters["sone"].let(webInterface.core::getSone).let { sone ->
templateContext["sone"] = sone
val sonePosts = sone.posts
val directedPosts = webInterface.core.getDirectedPosts(sone.id)
(sonePosts + directedPosts)
.sortedByDescending(Post::getTime)
.paginate(webInterface.core.preferences.postsPerPage)
- .apply { page = request.parameters["postPage"]?.toIntOrNull() ?: 0 }
+ .apply { page = freenetRequest.parameters["postPage"]?.toIntOrNull() ?: 0 }
.also {
templateContext["postPagination"] = it
templateContext["posts"] = it.items
.minus(directedPosts)
.sortedByDescending { webInterface.core.getReplies(it.id).first().time }
.paginate(webInterface.core.preferences.postsPerPage)
- .apply { page = request.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 }
+ .apply { page = freenetRequest.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 }
.also {
templateContext["repliedPostPagination"] = it
templateContext["repliedPosts"] = it.items
override fun isLinkExcepted(link: URI?) = true
- public override fun getPageTitle(request: FreenetRequest): String =
- request.parameters["sone"].let(webInterface.core::getSone).let { sone ->
+ public override fun getPageTitle(freenetRequest: FreenetRequest): String =
+ freenetRequest.parameters["sone"].let(webInterface.core::getSone).let { sone ->
"${SoneAccessor.getNiceName(sone)} - ${webInterface.l10n.getString("Page.ViewSone.Title")}"
} ?: webInterface.l10n.getString("Page.ViewSone.Page.TitleWithoutSone")
fun `handleRequest method is called`() {
var called = false
val page = object : SoneTemplatePage("path.html", template, webInterface, true) {
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
called = true
}
}