struct Wikicr::Page

Overview

A Page is the representation in the wiki of something that can be accessed from an url /pages/*path.

It is used to associate path, url and data. Is is can also jails the path into the OPTIONS.basedir to be sure that there is no attack by writing files outside of the directory where the pages must be stored.

Included Modules

Defined in:

lib/page.cr
lib/page/index.cr
lib/page/index/entry.cr
lib/page/internal_links.cr
lib/page/table_of_content.cr

Constant Summary

PAGES_SUB_DIRECTORY = "pages/"

Directory where the pages are stored

URL_PREFIX = "/pages"

Beginning of the url of a page

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Wikicr::Page::InternalLinks

internal_links(index_context : Wikicr::Page::Index) internal_links

Class methods inherited from module Wikicr::Page::InternalLinks

get_link(begin_link_text, page_search_text, index, page) : Link get_link, links(path : String, index : Wikicr::Page::Index, page : Wikicr::Page) links, links_in_content(content : String, index : Wikicr::Page::Index, page : Wikicr::Page) links_in_content

Instance methods inherited from module Wikicr::Page::TableOfContent

toc : Toc toc

Class methods inherited from module Wikicr::Page::TableOfContent

get_toc_line(line : String) : TocLine | Nil get_toc_line, toc(path : String) : Toc toc

Constructor Detail

def self.new(url : String, real_url : Bool = false, read_title : Bool = false) #

[View source]

Class Method Detail

def self.read_title(path : String) : String | Nil #

[View source]
def self.sanitize(url : String) #

[View source]
def self.url_to_file(url : String) #

translate a name ("/test/title" for example) into a file path ("/srv/data/test/ttle.md)


[View source]

Instance Method Detail

def commit!(user : Wikicr::User, message, other_files : Array(String) = [] of String) #

Save the modifications on the file into the git repository

TODO lock before commit

TODO security of jailed_file and self.name ?


[View source]
def delete(user : Wikicr::User) #

Deletes the file, and commit


[View source]
def dirname #

Get the directory of the file (~/data/test/home becomes ~/data/test)


[View source]
def exists? #

Checks if the file exists


[View source]
def jail #

verify if the file is in the current dir (avoid ../ etc.) it will raise a Error403 if the file is out of the basedir


[View source]
def path : String #

Path of the file that contains the page


[View source]
def read #

Reads the file and returns the content.


[View source]
def read_title! #

[View source]
def real_url : String #

Complete Url of the page


[View source]
def real_url_dirname #

Real url without the page itself (/test/home becomes /test)


[View source]
def rename(user : Wikicr::User, new_url) #

TODO verify if the new_page already exists Move the current page into another place and commit


[View source]
def title : String #

Title of the page


[View source]
def url : String #

Url of the page (without any prefix)


[View source]
def url_dirname #

Url without the page itself (/pages/test/home becomes /pages/test)


[View source]
def write(user : Wikicr::User, body) #

Writes into the file, and commit.


[View source]