Pepperminty Wiki Module API

Application

Interfaces, Classes, Traits and Enums

Parsedown
ParsedownExtra
Parsedown
ParsedownExtra
BkTree
A serialisable BK-Tree Implementation.
JsonStorageBox
Represents a key-value data store.
Nilsimsa
The MIT License (MIT)
BkTree
A serialisable BK-Tree Implementation.
StorageBox
Represents a key-value data store.
Slimdown
Modified by Starbeamrainbowlabs (starbeamrainbowlabs)
PeppermintParsedown
The Peppermint-flavoured Parsedown parser.
Parsedown
ParsedownExtra

Table of Contents

PEPPERMINTY_WIKI_BUILD  = \true
register_module()  : mixed
Registers a new Pepperminty Wiki module. All module files should call this first.
url_stem()  : string
Get the stem URL at which this Pepperminty Wiki instance is located You can just append ?get_params_here to this and it will be a valid URL.
path_resolve()  : string
Resolves a relative path against a given base directory.
is_directory_empty()  : bool
Determines if a directory is empty or not.
filepath_to_pagename()  : string
Converts a filepath to a page name.
slugify()  : string
Slugifies a given string such that it can only contain a-z0-9-_.
minify_css()  : string
Minifies CSS. Uses simple computationally-cheap optimisations to reduce size.
delete_recursive()  : mixed
Recursively deletes a directory and it's contents.
crypto_id()  : string
Generates a crytographically-safe random id of the given length.
is_cli()  : bool
Returns whether we are both on the cli AND the cli is enabled.
metrics2servertiming()  : string
send_cookie()  : void
Sets a cookie on the client via the set-cookie header.
standard_deviation()  : float
Calculates the standard deviation of an array of numbers.
time_callable()  : mixed
tree_create()  : mixed
tree_save()  : mixed
tree_load()  : mixed
test_search_linear()  : mixed
writegraph()  : mixed
test_auto()  : mixed
path_resolve()  : string
Resolves a relative path against a given base directory.
lines_count()  : mixed
ensure_cli()  : void
Ensures that the current execution environment is the command-line interface.
cli()  : void
Parses $_SERVER["argv"] and provides a command-line interface.
cli_shell()  : mixed
Starts the Pepperminty Wiki CLI Shell.
cli_exec()  : int
Executes a given Pepperminty Wiki shell command.
cli_register()  : void
Registers a new CLI command.
do_system_checks()  : mixed
interwiki_index_update()  : mixed
Updates the interwiki index cache file.
estimate_reading_time()  : array<string|int, mixed>
Estimates the reading time for a given lump of text.
find_revisionid_timestamp()  : int
Given a page name and timestamp, returns the associated page revision number.
render_recent_change_atom()  : string
Renders a list of recent changes as an Atom 1.0 feed.
standard_deviation()  : float
Calculates the standard deviation of an array of numbers.
similar_suggest()  : array<string|int, mixed>
Given a page name, returns a list fo similar pages.
theme_update()  : bool
Updates the currently selected theme by fetching it from a remote url.
email_user_verify()  : bool
Sends a verification email to the specified user, assuming they need to verify their email address.
generate_password()  : string
Generates a new (cryptographically secure) random password that's also readable (i.e. consonant-vowel-consonant).
debug_mask_secrets()  : string
Masks secrets in debug output.
generate_page_hash()  : string
Generates a unique hash of a page's content for edit conflict detection purposes.
do_password_hash_code_update()  : mixed
Recalculates and updates the password hashing cost.
hash_password_properties()  : array<string|int, mixed>
Figures out the appropriate algorithm & options for hashing passwords based on the current settings.
verify_password()  : bool
Verifies a user's password against a pre-generated hash.
hash_password_update()  : string|null
Determines if the provided password needs re-hashing or not.
hash_password_compute_cost()  : int
Computes the appropriate cost value for password_hash based on the settings automatically.
parsedown_pagename_resolve()  : string
Attempts to 'auto-correct' a page name by trying different capitalisation combinations.
log_str()  : mixed
Logs a string to stdout, but only on the CLI.
module_list_search()  : bool
module_list_find()  : mixed

Constants

PEPPERMINTY_WIKI_BUILD

public mixed PEPPERMINTY_WIKI_BUILD = \true

Functions

register_module()

Registers a new Pepperminty Wiki module. All module files should call this first.

register_module(array<string|int, mixed> $settings) : mixed
Parameters
$settings : array<string|int, mixed>

An associative array defining the module.

Return values
mixed —

url_stem()

Get the stem URL at which this Pepperminty Wiki instance is located You can just append ?get_params_here to this and it will be a valid URL.

url_stem([array<string|int, mixed> $s = false ][, bool $use_forwarded_host = false ]) : string

Uses full_url() under the hood. Note that this is based on the URL of the current request.

Parameters
$s : array<string|int, mixed> = false

The $_SERVER variable (defaults to $_SERVER)

$use_forwarded_host : bool = false

Whether to use the x-forwarded-host header or ignore it.

Return values
string —

The stem url, as described above

path_resolve()

Resolves a relative path against a given base directory.

path_resolve(string $path[, string|null $basePath = null ]) : string
Parameters
$path : string

The relative path to resolve.

$basePath : string|null = null

The base directory to resolve against.

Tags
since
0.20.0
source
Return values
string —

An absolute path.

is_directory_empty()

Determines if a directory is empty or not.

is_directory_empty(string $dir) : bool
Parameters
$dir : string

The path to the directory to check.

Tags
ref

https://stackoverflow.com/a/7497848/1460422

Return values
bool —

True if the directory is empty, or false if it is not empty.

filepath_to_pagename()

Converts a filepath to a page name.

filepath_to_pagename(string $filepath) : string
Parameters
$filepath : string

The filepath to convert.

Return values
string —

The extracted pagename.

slugify()

Slugifies a given string such that it can only contain a-z0-9-_.

slugify(string $text) : string

Also automatically makes it lowercase.

Parameters
$text : string

The text to operate on.

Return values
string —

The slugified string.

minify_css()

Minifies CSS. Uses simple computationally-cheap optimisations to reduce size.

minify_css(string $css_str) : string

CSS Minification ideas by Jean from catswhocode.com

Parameters
$css_str : string

The string of CSS to minify.

Tags
source
since
0.20.0
Return values
string —

The minified CSS string.

delete_recursive()

Recursively deletes a directory and it's contents.

delete_recursive(string $path[, bool $delete_self = true ]) : mixed

Adapted by Starbeamrainbowlabs

Parameters
$path : string

The path to the directory to delete.

$delete_self : bool = true

Whether to delete the top-level directory. Set this to false to delete only a directory's contents

Tags
source
Return values
mixed —

crypto_id()

Generates a crytographically-safe random id of the given length.

crypto_id(int $length) : string
Parameters
$length : int

The length of id to generate.

Return values
string —

The random id.

is_cli()

Returns whether we are both on the cli AND the cli is enabled.

is_cli() : bool
Return values
bool —

metrics2servertiming()

metrics2servertiming(stdClass $perfdata) : string
Parameters
$perfdata : stdClass
Return values
string —

Sets a cookie on the client via the set-cookie header.

send_cookie(string $key, string $value, int $expires) : void

Uses setcookie() under-the-hood.

Parameters
$key : string

The cookie name to set.

$value : string

The cookie value to set.

$expires : int

The expiry time to set on the cookie.

Return values
void —

standard_deviation()

Calculates the standard deviation of an array of numbers.

standard_deviation(array<string|int, mixed> $array) : float
Parameters
$array : array<string|int, mixed>

The array of numbers to calculate the standard deviation of.

Tags
source
Return values
float —

The standard deviation of the numbers in the given array.

time_callable()

time_callable(mixed $callable) : mixed
Parameters
$callable : mixed
Return values
mixed —

tree_create()

tree_create() : mixed
Return values
mixed —

tree_load()

tree_load() : mixed
Return values
mixed —

test_search_linear()

test_search_linear() : mixed
Return values
mixed —

writegraph()

writegraph() : mixed
Return values
mixed —

test_auto()

test_auto() : mixed
Return values
mixed —

path_resolve()

Resolves a relative path against a given base directory.

path_resolve(string $path[, string|null $basePath = null ]) : string
Parameters
$path : string

The relative path to resolve.

$basePath : string|null = null

The base directory to resolve against.

Tags
since
0.20.0
source
Return values
string —

An absolute path.

lines_count()

lines_count(mixed $handle) : mixed
Parameters
$handle : mixed
Return values
mixed —

ensure_cli()

Ensures that the current execution environment is the command-line interface.

ensure_cli() : void

This function will not return if thisthe current execution environment is not the CLI.

Return values
void —

cli()

Parses $_SERVER["argv"] and provides a command-line interface.

cli() : void

This function kill the process if the current execution environment is not the CLI.

Return values
void —

cli_shell()

Starts the Pepperminty Wiki CLI Shell.

cli_shell() : mixed

This function kill the process if the current execution environment is not the CLI.

Return values
mixed —

cli_exec()

Executes a given Pepperminty Wiki shell command.

cli_exec(string|array<string|int, mixed> $string) : int

This function kill the process if the current execution environment is not the CLI. The returned exit code functions as a normal shell process exit code does.

Parameters
$string : string|array<string|int, mixed>

The shell command to execute.

Return values
int —

The exit code of the command executed.

cli_register()

Registers a new CLI command.

cli_register(string $name, string $description, callable $function) : void

Throws an error if a CLI command with the specified name already exists.

Parameters
$name : string

The name of command.

$description : string

The description of the command.

$function : callable

The function to execute when this command is executed. An array is passed as the first and only argument containing the arguments passed when the command was invoked.

Return values
void —

interwiki_index_update()

Updates the interwiki index cache file.

interwiki_index_update() : mixed

If the interwiki_index_location isn't defined, then this function will do nothing.

Return values
mixed —

estimate_reading_time()

Estimates the reading time for a given lump of text.

estimate_reading_time(string $text[, string $lang = "en" ]) : array<string|int, mixed>

Ref https://github.com/sbrl/Pepperminty-Wiki/issues/172 (has snippet of original code from Firefox & link to study from which the numbers are taken).

Parameters
$text : string

The text to estimate for.

$lang : string = "en"

The language code of the text - defaults to "en"

Return values
array<string|int, mixed> —

An array in the form [ low_time, high_time ] in minutes

find_revisionid_timestamp()

Given a page name and timestamp, returns the associated page revision number.

find_revisionid_timestamp(string $pagename, mixed $timestamp) : int
Parameters
$pagename : string

The page name to obtain the revision number for.

$timestamp : mixed
Return values
int —

The revision number of the given page at the given time.

render_recent_change_atom()

Renders a list of recent changes as an Atom 1.0 feed.

render_recent_change_atom(array<string|int, mixed> $recent_changes) : string

Requires the XMLWriter PHP class.

Parameters
$recent_changes : array<string|int, mixed>

The array of recent changes to render.

Return values
string —

The recent changes as an Atom 1.0 feed.

standard_deviation()

Calculates the standard deviation of an array of numbers.

standard_deviation(array<string|int, mixed> $array) : float
Parameters
$array : array<string|int, mixed>

The array of numbers to calculate the standard deviation of.

Tags
source
Return values
float —

The standard deviation of the numbers in the given array.

similar_suggest()

Given a page name, returns a list fo similar pages.

similar_suggest(string $pagename, string $content[, bool $limit_output = true ]) : array<string|int, mixed>
Parameters
$pagename : string

The name of the page to return suggestions for.

$content : string

The content of the given page.

$limit_output : bool = true
Return values
array<string|int, mixed> —

A list of suggested page names in the format pagename => rank.

theme_update()

Updates the currently selected theme by fetching it from a remote url.

theme_update([bool $force_update = false ]) : bool
Parameters
$force_update : bool = false

Whether to force an update - even if we've already updated recently.

Return values
bool —

Whether the update was sucessful. It might fail because of network issues, or the theme update requires a newer version of Pepperminty Wiki than is currently installed.

email_user_verify()

Sends a verification email to the specified user, assuming they need to verify their email address.

email_user_verify(string $username) : bool

If a user does not need to verify their email address, no verification email is sent and true is returned.

Parameters
$username : string

The name of the user to send the verification code to.

Return values
bool —

Whether the verification code was sent successfully. If a user does not need to verify their email address, this returns true.

generate_password()

Generates a new (cryptographically secure) random password that's also readable (i.e. consonant-vowel-consonant).

generate_password(string $length) : string

This implementation may be changed in the future to use random dictionary words instead - ref https://xkcd.com/936/

Parameters
$length : string

The length of password to generate.

Return values
string —

The generated random password.

debug_mask_secrets()

Masks secrets in debug output.

debug_mask_secrets(string $text) : string
Parameters
$text : string

The text to mask.

Return values
string —

The masked text.

generate_page_hash()

Generates a unique hash of a page's content for edit conflict detection purposes.

generate_page_hash(string $page_data) : string
Parameters
$page_data : string

The page text to hash.

Return values
string —

A hash of the given page text.

do_password_hash_code_update()

Recalculates and updates the password hashing cost.

do_password_hash_code_update() : mixed
Return values
mixed —

hash_password_properties()

Figures out the appropriate algorithm & options for hashing passwords based on the current settings.

hash_password_properties() : array<string|int, mixed>
Return values
array<string|int, mixed> —

The appropriate password hashing algorithm and options.

verify_password()

Verifies a user's password against a pre-generated hash.

verify_password(string $pass, string $hash) : bool
Parameters
$pass : string

The user's password.

$hash : string

The hash to compare against.

Return values
bool —

Whether the password matches the has or not.

hash_password_update()

Determines if the provided password needs re-hashing or not.

hash_password_update(string $pass, string $hash) : string|null
Parameters
$pass : string

The password to check.

$hash : string

The hash of the provided password to check.

Return values
string|null —

Returns null if an updaste is not required - otherwise returns the new updated hash.

hash_password_compute_cost()

Computes the appropriate cost value for password_hash based on the settings automatically.

hash_password_compute_cost([bool $verbose = false ]) : int

Starts at 10 and works upwards in increments of 1. Goes on until a value is found that's greater than the target - or 10x the target time elapses.

Parameters
$verbose : bool = false

Whether to output verbose progress information to the client or not.

Return values
int —

The automatically calculated password hashing cost.

parsedown_pagename_resolve()

Attempts to 'auto-correct' a page name by trying different capitalisation combinations.

parsedown_pagename_resolve(string $pagename) : string
Parameters
$pagename : string

The page name to auto-correct.

Return values
string —

The auto-corrected page name.

log_str()

Logs a string to stdout, but only on the CLI.

log_str(string $line) : mixed
Parameters
$line : string

The line to log.

Return values
mixed —
module_list_search(array<string|int, mixed> $list, string $id) : bool
Parameters
$list : array<string|int, mixed>
$id : string
Return values
bool —

module_list_find()

module_list_find(array<string|int, mixed> $list, string $id) : mixed
Parameters
$list : array<string|int, mixed>
$id : string
Return values
mixed —

Search results