pWiki/bootstrap/Doc/Path.md
Alex A. Naanou 0ccd3c8514 notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2022-04-09 11:11:47 +03:00

7.4 KiB
Executable File

pWiki pWiki Path

A Wiki is a set of pages, each uniquely defined by it's title. Titles are traditionally formatted as WikiWords. pWiki closely follows this culture, while not restricting either page title formatting nor page nesting (nested paths), though in the general case following the Wiki style is recommended.

Basic terminology

Path
One or more strings (or parts) separated by "/" that identifies a view.

We call the last part in a path sequence a title.

We call the sub-path without the title a basedir or simply dir.

In pWiki, there is no distinction between a page and a directory, thus we do not use the later term, instead, we may use the term sub-page.

Paths are case sensitive.

Page
A set of data associated with a path.

A page is identified by it's path, but this does not require every sub-path of that path to exist -- the full path is the identifier.

Not every path identifies a page, but every path resolves to a page.

Some pages are bootstrapped, i.e. are predefined in pWiki, these pages can be overridden but can not be removed. This is done to make it simple to revert to the default state if something goes wrong.

View
A path that resolves to a page that may or may not be at (identified by) that specific path.

A view's path may match that of a specific page or may not match any page directly, but any view will resolve to a page via the acquisition process

Any page is a view, every view resolves to a page, but not every view is a page.

(see: Page acquisiton below)

\WikiWord
A WikiWork is a specially formated string that is treated as a link in page text

In pWiki a simple WikiWord is any string starting with a capital letter, must contain at least and one more capital letter and can consist of letters, numbers, underscores (WikiWord itself is a good example)

A WikiWord path (WikiPath) is a set of path parts separated by '/' the first part must start with a capital letter and the rest can contain letters, numbers and/or underscores (example: Path/to/somepage).

Note that this is not actually a part of the path specification but it is part of the Wiki culture and a convenient way to automatically link to pages (handled by pWiki macros when rendering pages).

Special path characters
Titles of user pages must not contain the leading underscore _ character, such paths are used internally.

Page acquisition

pWiki path system differs from how traditional file system paths are handled. In pWiki if a path does not reference a page directly (i.e. it's a view), a search is conducted to find an alternative page. This search is called page acquisition.

Acquisition process:
A set of rules defining how a page is retrieved via a path.

This is used as a simple and uniform mechanism to:

  • Get default pages for specific situations
    Like [Templates/EmptyPage] to handle the page not found condition.
  • Define generic templates/pages accessible by multiple pages in path
    A good example would be the viewer used to show this page [Templates/_view] and all of it's chrome like the path in the header and links in the footer (seen: when viewing through pWiki)
  • Overload default templates/pages

The acquisition order/rules:

  1. if path matches a specific page, target page is found
  2. if path does not match a page:
  3. if title matches a page in the parent path, page is found
  4. repeat until we either have a match or reach root (empty basedir)
  5. if no match is found, check if title exists in [Templates] in basedir
  6. if no match is found, check if title exists in [/System]
  7. if no match is found, repeat process for EmptyPage instead of title

Example:

For path Path/To/Page the following paths are checked in order and the first matching page is returned:

  • Check path as-is then go up:
    • Path/To/Page
    • Path/Page
    • Page
  • Check in Templates, in path and up:
    • Path/To/Templates/Page
    • Path/Templates/Page
    • Templates/Page
  • Check root System:
    • System/Page
  • Check EmptyPage in path, then in templates:
    • Path/To/EmptyPage
    • Path/EmptyPage
    • EmptyPage
    • Path/To/Templates/EmptyPage
    • Path/Templates/EmptyPage
    • Templates/EmptyPage (This is guaranteed to exist)

Exceptions:

  • System/settings is global and can not be overloaded for use as system configuration. This is done for security reasons.

Default pages

EmptyPage
A page resolved when a page does not exist. Used as a template for new/empty pages.

This page is guaranteed to exist by the system.

Located at: Templates/EmptyPage

EmptyToDo
Used as a template for new/empty ToDo pages.

Located at: Templates/EmptyToDo

EmptyOutline
Used as a template for new/empty outline pages.

Located at: Templates/EmptyOutline

NoMatch
Returned when pattern matches no pages.

Relative and absolute paths

pWiki follows the traditional path semantics with one addition, the ">>" that is similar to ".." but works in the opposite direction, consuming the next, i.e. child, path element instead of parent.

To illustrate the relative and absolute mechanics:

Title Source Page Path Resolves to
"." - current \SourcePage \./Target/Page \SourcePage/Target/Page
".." - parent \SourcePage \../Target/Page \Target/Page
">>" \SourcePage >>/Target/Page \SourcePage/Page
"/" - root dir \SourcePage /Target/Page /Target/Page

Note that neither a leading ".." at root level, nor a trailing ">>" in any path, will have any effect, and will simply be ignored (e.g. "/../Page" is same as "/Page" and "\Path/>>" is the same as "Path")

Path patterns

Path patterns are used to match/iterate multiple pages. The syntax is similar to path glob patterns.

  • "*" - matches any page in a sub-path on one level
  • "**" - matches any page in a sub-path recursively

Note that neither will match parts of paths that do not explicitly identify pages.

Example:

XXX revise...

For the following paths:

WikiHome
SomePage
Path/to/OtherPage
Path/Page

Patterns and their matches:

  • * will match:
    • WikiHome
    • SomePage
  • ** will match:
    • WikiHome
    • SomePage
    • Path/to/OtherPage
    • Path/Page
  • \Path/* will match:
    • Path/Page

Note that neither \Path nor \Path/to does not refer to any real pages, thus neither is matched by any of the patterns explicitly.

Path actions

XXX path elements that perform actions on pages but do not actually correspond to actual pages.

Path variables

Path variables are resolved when path is resolved or accessed.

$NOW
Replaced with the current time.

Also see the \@now() macro: [Doc/Macros].

$PATH
Replaced with current page path.

$BASE
Replaced with current page basedir.

$TITLE
Replaced with current page title.

$INDEX
Replaced with current page index in pattern matching.