module

package
v0.9.0-rc.53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package module is what a wikidot module is written against. The modules themselves live in internal/modules, one file each.

Index

Constants

This section is empty.

Variables

View Source
var Plugins interface {
	ModuleHasContent(name string) bool
	RenderModule(env Env, name string, params map[string]string, body string) (string, bool, error)
	Emit(site *db.Site, event string, payload map[string]any)
	PagePublic(ctx context.Context, site *db.Site, name string) bool
	ProfileSections(ctx context.Context, site *db.Site, owner, viewer *db.User) []ProfileSection
}

Plugins answers for module names the built-in registry does not know, and hears what happens on a site. It stays nil on an instance without plugins.

Functions

func BoolParam

func BoolParam(params map[string]string, key string, def bool) bool

BoolParam is get_boolean_param, where anything the list does not name reads as the default rather than as false.

func Builtin

func Builtin(name string) bool

func Emit

func Emit(site *db.Site, event string, payload map[string]any)

func HasContent

func HasContent(name string) bool

func HasItemBody

func HasItemBody(name string) bool

func IsInline

func IsInline(name string) bool

A module that renders a block cannot sit in a paragraph without closing it, so only the ones that render a span of their own answer true.

func ParseBool

func ParseBool(value string) (parsed, ok bool)

Callers have to tell a switch from a string, since one parameter can carry either.

func Ported

func Ported(name string) bool

Ported is derived from the renderers that registered themselves, so the list cannot drift from the code that answers.

func Register

func Register(name string, r Renderer)

Register is called from each module's own file. A name the registry does not know is a typo, so it panics rather than registering something unreachable.

func RegisterAPI

func RegisterAPI(module, method string, fn API)

func RegisterWriteAPI

func RegisterWriteAPI(module, method string, fn API)

A method registered here changes something, so the caller has to have checked the CSRF token before it runs.

func Render

func Render(env Env, name string, params map[string]string, body string) (string, error)

The path parameters are not folded in here, since the modules that want them disagree on which side wins.

Types

type API

type API func(env Env, params map[string]string) (wikijson.Object, error)

func LookupAPI

func LookupAPI(module, method string) (fn API, safe, ok bool)

type Data

type Data interface {
	TagArticles(categorySlug, name string, hiddenCategories []string) ([]db.Article, error)
	TagCategory(slug string) (db.TagCategory, error)
	HiddenCategories(user *db.User) ([]string, error)
	TagIDsByName(categorySlug, name string) ([]int64, error)
	TagCloud(limit *int) ([]db.CloudTag, error)
	WantedLinks(f db.WantedFilter, offset, limit int) ([]db.WantedLink, error)
	WantedLinkCount(f db.WantedFilter) (int, error)
	ArticleTagIDs(articleID int64) ([]int64, error)
	ArticleByRef(ref string) (*db.Article, error)
	UserByUsername(name string) (*db.User, error)
	UserByWikidotName(name string) (*db.User, error)
	SiteRatingMode() (string, error)
	CategoryRatingMode(category string) (string, error)
	VoteStats(articleID int64) (db.VoteStats, error)
	HasVoted(articleID int64, userID *int64) (bool, error)
	ListArticles(f db.ListFilter, offset int, limit *int) ([]db.Article, error)
	CountArticles(f db.ListFilter, offset int, limit *int) (int, error)
	LatestSource(articleID int64) (string, error)
	CategoryForm(category string) (*form.Definition, error)

	ArticleByID(id int64) (*db.Article, error)
	ArticleAuthors(articleID int64) ([]db.User, error)
	ArticleFiles(articleID int64) ([]db.ArticleFileEntry, error)
	CommentInfo(articleID int64) (db.CommentInfo, error)
	RenderUserByID(id *int64) (string, error)
	RenderUser(u db.User) (string, error)

	ArticleVotes(articleID int64) ([]db.ArticleVote, error)
	ReplaceVote(articleID, userID int64, rate *float64, roleID *int64) (*db.Vote, error)
	VoteGroupRole(userID *int64) (*int64, error)
	SeenAddress(user *db.User) error
	ArticleObject(article *db.Article, viewer *db.User) (*perms.Object, error)
	UserJSON(u *db.User) (wikijson.Object, error)

	SearchArticles(f db.SearchFilter, offset, limit int) ([]db.SearchHit, error)
	SearchCount(f db.SearchFilter) (int, error)
	TagIDsByFullName(category, name string) ([]int64, error)
	AuthorsOfArticles(ids []int64) (map[int64][]db.User, error)
	VoteStatsOfArticles(ids []int64) (map[int64]db.VoteStats, error)
	CommentCountsOfArticles(ids []int64) (map[int64]int, error)
	TagsOfArticles(ids []int64) (map[int64][]db.ArticleTag, error)
	UserByDisplayName(name string) (*db.User, error)

	SiteChanges(f db.SiteChangeFilter, offset, limit int) ([]db.SiteChange, error)
	SiteChangeCount(f db.SiteChangeFilter) (int, error)
	ArticleCategories(hidden []string) ([]string, error)
	SuggestTags(typed string, limit int) ([]db.Suggestion, error)
	SuggestCategories(hidden []string, typed string, limit int) ([]db.Suggestion, error)
	SuggestAuthors(typed string, limit int) ([]db.Suggestion, error)
	UserIDsByName(name string, partial bool) ([]int64, error)
	UsersByIDs(ids []int64) ([]db.User, error)

	ForumSections() ([]db.ForumSection, error)
	ForumSection(id int64) (*db.ForumSection, error)
	ForumCategories() ([]db.ForumCategory, error)
	ForumCategory(id int64) (*db.ForumCategory, error)
	ForumThreads(categoryID int64, sort db.ForumThreadSort, offset, limit int) ([]db.ForumThread, error)
	ForumCommentThreads(sort db.ForumThreadSort, offset, limit int) ([]db.ForumThread, error)
	ForumThreadPostCount(threadID int64) (int, error)
	ForumThreadLastPost(threadID int64, count int) (*db.ForumPost, error)
	ForumCategoryCounts(categoryID int64) (db.ForumCounts, error)
	ForumCommentCounts() (db.ForumCounts, error)
	ForumCategoryLastPost(categoryID int64) (*db.ForumLastPost, error)
	ForumCommentLastPost() (*db.ForumLastPost, error)

	ForumThreadsInCategories(categoryIDs []int64, offset, limit int) ([]db.ForumThread, error)
	ForumFirstPosts(threadIDs []int64) (map[int64]db.ForumThreadPost, error)
	ForumThreadPostCounts(threadIDs []int64) (map[int64]int, error)

	ForumThread(id int64) (*db.ForumThread, error)
	ForumRootPostCount(threadID int64) (int, error)
	ForumRootPosts(threadID int64, offset, limit int) ([]db.ForumThreadPost, error)
	ForumRootPostIDs(threadID int64) ([]int64, error)
	ForumPostReplies(postID int64) ([]db.ForumThreadPost, error)
	ForumPost(id int64) (*db.ForumThreadPost, error)
	ForumPostContents(postIDs []int64) (map[int64]db.ForumPostContent, error)
	RecentPostCount(categoryIDs []int64, comments bool) (int, error)
	RecentPosts(categoryIDs []int64, comments bool, offset, limit int) ([]db.RecentPost, error)
	UsernamesLower() (map[string]bool, error)
	VoteByUser(articleID int64, userID *int64) (float64, bool, error)
	UserByID(id int64) (*db.User, error)
	Members(all bool, roleID *int64, offset, limit int) ([]db.Member, error)
	MemberCount(all bool, roleID *int64) (int, error)
	RoleByRef(ref string) (*roles.Role, error)
	ArticleHasAuthor(articleID, userID int64) (bool, error)
	RolesByUser(id int64) ([]roles.Role, error)
	MembershipQuiz() (db.MembershipQuiz, error)
	AuthorRank(f db.AuthorRankFilter, offset, limit int) ([]db.AuthorRankRow, error)
	AuthorRankOf(f db.AuthorRankFilter, userID int64) (*db.AuthorRankRow, error)
	RatingTrend(articleID int64, average bool) ([]db.TrendPoint, error)
	SearchForum(f db.ForumSearchFilter, offset, limit int) ([]db.ForumSearchHit, error)
	QuizAttempts(userID int64) ([]quiz.Attempt, error)

	PostLikeCounts(postIDs []int64) (map[int64]int, error)
	PostsLikedBy(userID int64, postIDs []int64) (map[int64]bool, error)
	PostLikeCount(postID int64) (int, error)
	PostLikers(postID int64, offset, limit int) ([]db.User, error)
	LikePost(postID, userID int64) (bool, error)
	UnlikePost(postID, userID int64) error

	ArticleFavouriteCount(articleID int64) (int, error)
	HasFavourited(articleID, userID int64) (bool, error)
	AddFavourite(articleID, userID int64) error
	RemoveFavourite(articleID, userID int64) error

	TagsCategories() ([]db.TagsCategory, error)
	AllTags() ([]db.NamedTag, error)

	ForumPostVersions(postID int64) ([]db.ForumPostVersion, error)
	ForumPostSource(postID int64, at *time.Time) (string, error)
	CreateForumPost(w db.ForumPostWrite) (int64, error)
	CreateForumThread(w db.ForumThreadWrite, source string) (int64, int64, error)
	UpdateForumPost(postID int64, name, source, previous string, authorID *int64) error
	UpdateForumThread(threadID int64, e db.ForumThreadEdit) error
	DeleteForumPost(postID int64) error
	SendNotification(kind, meta string, recipients []int64) error
	WithoutMutes(threadID *int64, actorID *int64, readers []int64) ([]int64, error)
	ThreadSubscribers(threadID int64) ([]int64, error)
	SubscribeToThread(userID, threadID int64) error
	ActiveUsersByNames(names []string) ([]db.User, error)

	Subject(user *db.User) (perms.Subject, error)
	ForumSectionObject(s *db.ForumSection) *perms.Object
	ForumThreadObject(t *db.ForumThread, u *db.User) (*perms.Object, error)
	ForumPostObject(p *db.ForumThreadPost, thread *perms.Object, u *db.User) *perms.Object
}

type Env

type Env struct {
	// Name is what the wikitext spelled, which is what an error block about
	// this module has to quote back.
	Name string

	Page *page.Context
	Loc  *i18n.Localizer
	Site *db.Site
	User *db.User
	Data Data

	// Render runs the wikitext a module produced through ftml. A module that
	// lists pages has to, since what it writes is source and not markup.
	Render func(source string, pc *page.Context) (string, error)

	RenderMessage func(source string) (string, error)

	// A module that summarises a forum post asks for the same pass without the
	// markup, and only when its format wants a summary.
	RenderMessageText func(source string) (string, error)

	Vars page.VarSource
}

func (Env) MediaDomain

func (e Env) MediaDomain() string

func (Env) Text

func (e Env) Text(id string, args ...any) string

type Error

type Error struct{ Message string }

Error is the failure that reaches the reader as a block on the page rather than as a broken response.

func (*Error) Error

func (e *Error) Error() string

type Info

type Info struct {
	Name       string
	HasContent bool
	ItemBody   bool
	Inline     bool
	Removed    bool
}

func All

func All() []Info

func Lookup

func Lookup(name string) (Info, bool)

type ProfileSection

type ProfileSection struct {
	Plugin string
	Title  string
	Body   string
	Badge  bool
}

type Renderer

type Renderer func(env Env, params map[string]string, body string) (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL