API Documentation
Interfaces, Classes, Traits and Enums
- Parsedown
- ParsedownExtra
- Parsedown
- ParsedownExtra
- ids
- Provides an interface to interact with page ids.
- page_renderer
- Renders the HTML page that is sent to the client.
- 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_origin() : string
- Get the actual absolute origin of the request sent by the user.
- full_url() : string
- Get the full url, as requested by the client.
- 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.
- human_filesize() : string
- Converts a filesize into a human-readable string.
- human_time_since() : string
- Calculates the time since a particular timestamp and returns a human-readable result.
- human_time() : string
- Renders a given number of seconds as something that humans can understand more easily.
- glob_recursive() : array<string|int, mixed>
- A recursive glob() function.
- 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.
- get_page_parent() : string|bool
- Gets the name of the parent page to the specified page.
- get_subpages() : object
- Gets a list of all the sub pages of the current page.
- check_subpage_parents() : mixed
- Makes sure that a subpage's parents exist.
- makepathsafe() : string
- Makes a path (or page name) safe.
- slugify() : string
- Slugifies a given string such that it can only contain a-z0-9-_.
- hide_email() : string
- Hides an email address from bots. Returns a fragment of HTML that contains the mangled email address.
- starts_with() : bool
- Checks to see if $haystack starts with $needle.
- ends_with() : bool
- Checks to see if $hackstack ends with $needle.
- mb_stripos_all() : array<string|int, mixed>|false
- Case-insensitively finds all occurrences of $needle in $haystack. Handles UTF-8 characters correctly.
- startsWith() : bool
- Tests whether a string starts with a specified substring.
- endsWith() : bool
- Tests whether a string ends with a given substring.
- str_replace_once() : string
- Replaces the first occurrence of $find with $replace.
- system_mime_type_extensions() : array<string|int, mixed>
- Returns the system's mime type mappings, considering the first extension listed to be cacnonical.
- system_mime_type_extension() : string
- Converts a given mime type to it's associated file extension.
- system_extension_mime_types() : array<string|int, mixed>
- Returns the system MIME type mapping of extensions to MIME types.
- system_extension_mime_type() : string
- Converts a given file extension to it's associated mime type.
- errorimage() : resource
- Creates an images containing the specified text.
- stack_trace() : string
- Generates a stack trace.
- var_dump_ret() : string
- Calls var_dump() and returns the output.
- var_dump_short() : string
- Calls var_dump(), shortening the output for various types.
- getallheaders() : mixed
- Polyfill for PHP's native getallheaders() function on platforms that don't have it.
- render_timestamp() : string
- Renders a timestamp in HTML.
- render_pagename() : string
- Renders a page name in HTML.
- render_editor() : string
- Renders an editor's or a group of editors name(s) in HTML.
- minify_css() : string
- Minifies CSS. Uses simple computationally-cheap optimisations to reduce size.
- save_settings() : bool
- Saves the settings file back to peppermint.json.
- save_pageindex() : bool
- Save the page index back to disk, respecting $settings->minify_pageindex
- save_userdata() : bool
- Saves the currently logged in user's data back to peppermint.json.
- get_user_pagename() : string
- Figures out the path to the user page for a given username.
- extract_user_from_userpage() : string
- Extracts a username from a user page path.
- email_user() : bool
- Sends a plain text email to a user, replacing {username} with the specified username.
- email_users() : int
- Sends a plain text email to a list of users, replacing {username} with each user's name.
- 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.
- register_module() : mixed
- Registers a module.
- module_exists() : bool
- Checks to see whether a module with the given id exists.
- add_action() : mixed
- Registers a new action handler.
- has_action() : bool
- Figures out whether a given action is currently registered.
- register_save_preprocessor() : mixed
- Register a new proprocessor that will be executed just before an edit is saved.
- add_help_section() : mixed
- Adds a new help section to the help page.
- statistic_add() : mixed
- Registers a statistic calculator against the system.
- has_statistic() : bool
- Checks whether a specified statistic has been registered.
- add_parser() : mixed
- Registers a new parser.
- parse_page_source() : string
- Parses the specified page source using the parser specified in the settings into HTML.
- 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
- render_sidebar() : string
- Renders the sidebar for a given pageindex.
- 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.
- get_comment_filename() : string
- Given a page name, returns the absolute file path in which that page's comments are stored.
- generate_comment_id() : string
- Generates a new random comment id.
- find_comment() : object
- Finds the comment with specified id by way of an almost-breadth-first search.
- delete_comment() : bool
- Deletes the first comment found with the specified id.
- fetch_comment_thread() : array<string|int, object>
- Fetches all the parent comments of the specified comment id, including the comment itself at the end.
- render_comments() : string
- Renders a given comments tree to html.
- do_system_checks() : mixed
- history_add_revision() : mixed
- Adds a history revision against a page.
- interwiki_index_update() : mixed
- Updates the interwiki index cache file.
- interwiki_pagename_parse() : array<string|int, string>
- Parses an interwiki pagename into it's component parts.
- interwiki_pagename_resolve() : stdClass
- Resolves an interwiki pagename to the associated interwiki definition object.
- interwiki_get_pagename_url() : string
- Converts an interwiki pagename into a url.
- is_interwiki_link() : bool
- Returns whether a given pagename is an interwiki link or not.
- estimate_reading_time() : array<string|int, mixed>
- Estimates the reading time for a given lump of text.
- add_recent_change() : mixed
- Adds a new recent change to the recent changes file.
- render_recent_changes() : string
- Renders a list of recent changes to HTML.
- find_revisionid_timestamp() : int
- Given a page name and timestamp, returns the associated page revision number.
- render_recent_change() : string
- Renders a single recent change
- render_recent_change_atom() : string
- Renders a list of recent changes as an Atom 1.0 feed.
- update_redirect_metadata() : mixed
- Updates the metadata associated with redirects in the pageindex entry specified utilising the provided page content.
- 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.
- update_statistics() : mixed
- Updates the wiki's statistics.
- stats_load() : object
- Loads and returns the statistics cache file.
- stats_save() : bool
- Saves the statistics back to disk.
- theme_update() : bool
- Updates the currently selected theme by fetching it from a remote url.
- get_max_upload_size() : int
- Calculates the actual maximum upload size supported by the server Returns a file size limit in bytes based on the PHP upload_max_filesize and post_max_size
- parse_size() : int
- Parses a PHP size to an integer
- upload_check_svg() : array<string|int, int>
- Checks an uploaded SVG file to make sure it's (at least somewhat) safe.
- getsvgsize() : array<string|int, int>
- Calculates the size of the specified SVG file.
- 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.
- get_all_tags() : array<string|int, string>
- Gets a list of all the tags currently used across the wiki.
- generate_page_list() : string
- Renders a list of pages as HTML.
- 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.
- hash_password() : string
- Hashes the given password according to the current settings defined in $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_origin()
Get the actual absolute origin of the request sent by the user.
url_origin([array<string|int, mixed> $s = false ][, bool $use_forwarded_host = false ]) : string
Parameters
- $s : array<string|int, mixed> = false
-
The $_SERVER variable contents. Defaults to $_SERVER.
- $use_forwarded_host : bool = false
-
Whether to utilise the X-Forwarded-Host header when calculating the actual origin.
Return values
string —The actual origin of the user's request.
full_url()
Get the full url, as requested by the client.
full_url([array<string|int, mixed> $s = false ][, bool $use_forwarded_host = false ]) : string
Parameters
- $s : array<string|int, mixed> = false
-
The $_SERVER variable. Defaults to $_SERVER.
- $use_forwarded_host : bool = false
-
Whether to take the X-Forwarded-Host header into account.
Tags
Return values
string —The full url, as requested by the client.
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
human_filesize()
Converts a filesize into a human-readable string.
human_filesize(int $bytes[, int $decimals = 2 ]) : string
Parameters
- $bytes : int
-
The number of bytes to convert.
- $decimals : int = 2
-
The number of decimal places to preserve.
Tags
Return values
string —A human-readable filesize.
human_time_since()
Calculates the time since a particular timestamp and returns a human-readable result.
human_time_since(int $time) : string
Parameters
- $time : int
-
The timestamp to convert.
Tags
Return values
string —The time since the given timestamp as a human-readable string.
human_time()
Renders a given number of seconds as something that humans can understand more easily.
human_time(int $seconds) : string
Parameters
- $seconds : int
-
The number of seconds to render.
Return values
string —The rendered time.
glob_recursive()
A recursive glob() function.
glob_recursive(string $pattern, int $flags) : array<string|int, mixed>
Parameters
- $pattern : string
-
The glob pattern to use to find filenames.
- $flags : int
-
The glob flags to use when finding filenames.
Tags
Return values
array<string|int, mixed> —An array of the filepaths that match the given glob.
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
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
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.
get_page_parent()
Gets the name of the parent page to the specified page.
get_page_parent(string $pagename) : string|bool
Parameters
- $pagename : string
-
The child page to get the parent page name for.
Tags
Return values
string|bool —get_subpages()
Gets a list of all the sub pages of the current page.
get_subpages(object $pageindex, string $pagename) : object
Parameters
- $pageindex : object
-
The pageindex to use to search.
- $pagename : string
-
The name of the page to list the sub pages of.
Return values
object —An object containing all the subpages and their respective distances from the given page name in the pageindex tree.
check_subpage_parents()
Makes sure that a subpage's parents exist.
check_subpage_parents(string $pagename[, bool $create_dir = true ]) : mixed
Note this doesn't check the pagename itself.
Parameters
- $pagename : string
-
The pagename to check.
- $create_dir : bool = true
-
Whether to create an associated directory for subpages or not.
Return values
mixed —makepathsafe()
Makes a path (or page name) safe.
makepathsafe(string $string) : string
A safe path / page name may not contain: Forward-slashes at the beginning Multiple dots in a row Odd characters (e.g. ?%*:|"<>() etc.) A safe path may, however, contain unicode characters such as éôà etc.
Parameters
- $string : string
-
The string to make safe.
Return values
string —A safe version of the given string.
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.
hide_email()
Hides an email address from bots. Returns a fragment of HTML that contains the mangled email address.
hide_email(string $email[, string $display_text = null ]) : string
Parameters
- $email : string
- $display_text : string = null
-
The display text for the resulting HTML - if null then the original email address is used. Note that because it's base64 encoded and then textContent is used, one does not need to run either htmlentities() or rawurlencode() over this value as it's completely safe.
Return values
string —The mangled email address as a fragment of HTML.
starts_with()
Checks to see if $haystack starts with $needle.
starts_with(string $haystack, string $needle) : bool
Parameters
- $haystack : string
-
The string to search.
- $needle : string
-
The string to search for at the beginning of $haystack.
Return values
bool —Whether $needle can be found at the beginning of $haystack.
ends_with()
Checks to see if $hackstack ends with $needle.
ends_with(string $haystack, string $needle) : bool
The matching bookend to starts_with.
Parameters
- $haystack : string
-
The haystack to search..
- $needle : string
-
The needle to look for.
Return values
bool —mb_stripos_all()
Case-insensitively finds all occurrences of $needle in $haystack. Handles UTF-8 characters correctly.
mb_stripos_all(string $haystack, string $needle) : array<string|int, mixed>|false
Parameters
- $haystack : string
-
The string to search.
- $needle : string
-
The string to find.
Tags
Return values
array<string|int, mixed>|false —An array of match indices, or false if nothing was found.
startsWith()
Tests whether a string starts with a specified substring.
startsWith(string $haystack, string $needle) : bool
Parameters
- $haystack : string
-
The string to check against.
- $needle : string
-
The substring to look for.
Return values
bool —Whether the string starts with the specified substring.
endsWith()
Tests whether a string ends with a given substring.
endsWith(string $whole, string $end) : bool
Parameters
- $whole : string
-
The string to test against.
- $end : string
-
The substring test for.
Return values
bool —Whether $whole ends in $end.
str_replace_once()
Replaces the first occurrence of $find with $replace.
str_replace_once(string $find, string $replace, string $subject) : string
Parameters
- $find : string
-
The string to search for.
- $replace : string
-
The string to replace the search string with.
- $subject : string
-
The string ot perform the search and replace on.
Return values
string —The source string after the find and replace has been performed.
system_mime_type_extensions()
Returns the system's mime type mappings, considering the first extension listed to be cacnonical.
system_mime_type_extensions() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of mime type mappings.
system_mime_type_extension()
Converts a given mime type to it's associated file extension.
system_mime_type_extension(string $type) : string
Parameters
- $type : string
-
The mime type to convert.
Tags
Return values
string —The extension for the given mime type.
system_extension_mime_types()
Returns the system MIME type mapping of extensions to MIME types.
system_extension_mime_types() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array mapping file extensions to their associated mime types.
system_extension_mime_type()
Converts a given file extension to it's associated mime type.
system_extension_mime_type(string $ext) : string
Parameters
- $ext : string
-
The extension to convert.
Tags
Return values
string —The mime type associated with the given extension.
errorimage()
Creates an images containing the specified text.
errorimage(string $text[, int $target_size = null ]) : resource
Useful for sending errors back to the client.
Parameters
- $text : string
-
The text to include in the image.
- $target_size : int = null
-
The target width to aim for when creating the image. Not not specified, a value is determined automatically.
Return values
resource —The handle to the generated GD image.
stack_trace()
Generates a stack trace.
stack_trace([bool $log_trace = true ][, bool $full = false ]) : string
Parameters
- $log_trace : bool = true
-
Whether to send the stack trace to the error log.
- $full : bool = false
-
Whether to output a full description of all the variables involved.
Return values
string —A string prepresentation of a stack trace.
var_dump_ret()
Calls var_dump() and returns the output.
var_dump_ret(mixed $var) : string
Parameters
- $var : mixed
-
The thing to pass to var_dump().
Return values
string —The output captured from var_dump().
var_dump_short()
Calls var_dump(), shortening the output for various types.
var_dump_short(mixed $var) : string
Parameters
- $var : mixed
-
The thing to pass to var_dump().
Return values
string —A shortened version of the var_dump() output.
getallheaders()
Polyfill for PHP's native getallheaders() function on platforms that don't have it.
getallheaders() : mixed
Tags
Return values
mixed —render_timestamp()
Renders a timestamp in HTML.
render_timestamp(int $timestamp[, bool $absolute = false ][, bool $html = true ]) : string
Parameters
- $timestamp : int
-
The timestamp to render.
- $absolute : bool = false
-
Whether the time should be displayed absolutely, or relative to the current time.
- $html : bool = true
-
Whether the result should formatted as HTML (true) or plain text (false).
Return values
string —HTML representing the given timestamp.
render_pagename()
Renders a page name in HTML.
render_pagename(object $rchange) : string
Parameters
- $rchange : object
-
The recent change to render as a page name
Return values
string —HTML representing the name of the given page.
render_editor()
Renders an editor's or a group of editors name(s) in HTML.
render_editor(string $editorName) : string
Parameters
- $editorName : string
-
The name of the editor to render. Note that this may contain ARBITRARY HTML! In other words, make sure that the editor name(s) are sanitized (e.g. htmlentities()'d) before padding to this function.
Return values
string —HTML representing the given editor's name.
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
Return values
string —The minified CSS string.
save_settings()
Saves the settings file back to peppermint.json.
save_settings() : bool
Return values
bool —Whether the settings were saved successfully.
save_pageindex()
Save the page index back to disk, respecting $settings->minify_pageindex
save_pageindex() : bool
Return values
bool —Whether the page index was saved successfully or not.
save_userdata()
Saves the currently logged in user's data back to peppermint.json.
save_userdata() : bool
Return values
bool —Whether the user's data was saved successfully. Returns false if the user isn't logged in.
get_user_pagename()
Figures out the path to the user page for a given username.
get_user_pagename(string $username) : string
Does not check to make sure the user acutally exists.
Parameters
- $username : string
-
The username to get the path to their user page for.
Return values
string —The path to the given user's page.
extract_user_from_userpage()
Extracts a username from a user page path.
extract_user_from_userpage(string $userPagename) : string
Parameters
- $userPagename : string
-
The suer page path to extract from.
Return values
string —The name of the user that the user page belongs to.
email_user()
Sends a plain text email to a user, replacing {username} with the specified username.
email_user(string $username, string $subject, string $body[, bool $ignore_verification = false ]) : bool
Parameters
- $username : string
-
The username to send the email to.
- $subject : string
-
The subject of the email.
- $body : string
-
The body of the email.
- $ignore_verification : bool = false
-
Whether to ignore user email verification status and send the email anyway. Defaults to false.
Return values
bool —Whether the email was sent successfully or not. Currently, this may fail if the user doesn't have a registered email address.
email_users()
Sends a plain text email to a list of users, replacing {username} with each user's name.
email_users(array<string|int, string> $usernames, string $subject, string $body) : int
Parameters
- $usernames : array<string|int, string>
-
A list of usernames to email.
- $subject : string
-
The subject of the email.
- $body : string
-
The body of the email.
Return values
int —The number of emails sent successfully.
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
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 —send_cookie()
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 —register_module()
Registers a module.
register_module(array<string|int, mixed> $moduledata) : mixed
Parameters
- $moduledata : array<string|int, mixed>
-
The module data to register.
Return values
mixed —module_exists()
Checks to see whether a module with the given id exists.
module_exists(string $id) : bool
Parameters
- $id : string
-
The id to search for.
Return values
bool —Whether a module is currently loaded with the given id.
add_action()
Registers a new action handler.
add_action(string $action_name, callable $func) : mixed
Parameters
- $action_name : string
-
The action to register.
- $func : callable
-
The function to call when the specified action is requested.
Return values
mixed —has_action()
Figures out whether a given action is currently registered.
has_action(string $action_name) : bool
Only guaranteed to be accurate in inside an existing action function
Parameters
- $action_name : string
-
The name of the action to search for
Return values
bool —Whether an action with the specified name exists.
register_save_preprocessor()
Register a new proprocessor that will be executed just before an edit is saved.
register_save_preprocessor(callable $func) : mixed
Parameters
- $func : callable
-
The function to register.
Return values
mixed —add_help_section()
Adds a new help section to the help page.
add_help_section(string $index, string $title, string $content) : mixed
Parameters
- $index : string
-
The string to index the new section under.
- $title : string
-
The title to display above the section.
- $content : string
-
The content to display.
Return values
mixed —statistic_add()
Registers a statistic calculator against the system.
statistic_add(array<string|int, mixed> $stat_data) : mixed
Parameters
- $stat_data : array<string|int, mixed>
-
The statistic object to register.
Return values
mixed —has_statistic()
Checks whether a specified statistic has been registered.
has_statistic(string $stat_id) : bool
Parameters
- $stat_id : string
-
The id of the statistic to check the existence of.
Return values
bool —Whether the specified statistic has been registered.
add_parser()
Registers a new parser.
add_parser(string $name, callable $parser_code, callable $hash_generator) : mixed
Parameters
- $name : string
-
The name of the new parser to register.
- $parser_code : callable
-
The function to register as a new parser.
- $hash_generator : callable
-
A function that should take a single argument of the input source text, and return a unique hash for that content. The return value is used as the filename for cache entries, so should be safe to use as such.
Return values
mixed —parse_page_source()
Parses the specified page source using the parser specified in the settings into HTML.
parse_page_source(string $source[, bool $untrusted = false ][, bool $use_cache = true ]) : string
The specified parser may (though it's unlikely) render it to other things.
Parameters
- $source : string
-
The source to render.
- $untrusted : bool = false
-
Whether the source string is 'untrusted' - i.e. a user comment. Untrusted source disallows HTML and protects against XSS attacks.
- $use_cache : bool = true
-
Whether to use the on-disk cache. Has no effect if parser caching is disabled in peppermint.json, or the source string is too small.
Return values
string —The source rendered to HTML.
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
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_save()
tree_save(BkTree $tree) : mixed
Parameters
- $tree : BkTree
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
Return values
string —An absolute path.
lines_count()
lines_count(mixed $handle) : mixed
Parameters
- $handle : mixed
Return values
mixed —render_sidebar()
Renders the sidebar for a given pageindex.
render_sidebar(array<string|int, mixed> $pageindex[, string $root_pagename = "" ], mixed $depth) : string
Parameters
- $pageindex : array<string|int, mixed>
-
The pageindex to render the sidebar for
- $root_pagename : string = ""
-
The pagename that should be considered the root of the rendering. You don't usually need to use this, it is used by the algorithm itself since it is recursive.
- $depth : mixed
Return values
string —A HTML rendering of the sidebar for the given pageindex.
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 —get_comment_filename()
Given a page name, returns the absolute file path in which that page's comments are stored.
get_comment_filename(string $pagename) : string
Parameters
- $pagename : string
-
The name pf the page to fetch the comments filename for.
Return values
string —The path to the file that the
generate_comment_id()
Generates a new random comment id.
generate_comment_id() : string
Return values
string —A new random comment id.
find_comment()
Finds the comment with specified id by way of an almost-breadth-first search.
find_comment(array<string|int, mixed> $comment_data, string $comment_id) : object
Parameters
- $comment_data : array<string|int, mixed>
-
The comment data to search.
- $comment_id : string
-
The id of the comment to find.
Return values
object —The comment data with the specified id, or false if it wasn't found.
delete_comment()
Deletes the first comment found with the specified id.
delete_comment(array<string|int, mixed> &$comment_data, string $target_id) : bool
Parameters
- $comment_data : array<string|int, mixed>
-
An array of threaded comments to delete the comment from.
- $target_id : string
-
The id of the comment to delete.
Return values
bool —Whether the comment was found and deleted or not.
fetch_comment_thread()
Fetches all the parent comments of the specified comment id, including the comment itself at the end.
fetch_comment_thread(array<string|int, mixed> $comment_data, string $comment_id) : array<string|int, object>
Useful for figuring out who needs notifying when a new comment is posted.
Parameters
- $comment_data : array<string|int, mixed>
-
The comment data to search.
- $comment_id : string
-
The comment id to fetch the thread for.
Return values
array<string|int, object> —A list of the comments in the thread, with the deepest one at the end.
render_comments()
Renders a given comments tree to html.
render_comments(array<string|int, object> $comments_data, int $depth) : string
Parameters
- $comments_data : array<string|int, object>
-
The comments tree to render.
- $depth : int
-
For internal use only. Specifies the depth at which the comments are being rendered.
Return values
string —The given comments tree as html.
do_system_checks()
do_system_checks() : mixed
Return values
mixed —history_add_revision()
Adds a history revision against a page.
history_add_revision(object &$pageinfo, string &$newsource, string &$oldsource[, bool $save_pageindex = true ][, string $change_type = "edit" ]) : mixed
Note: Does not update the current page content! This function only records a new revision against a page name. Thus it is possible to have a disparity between the history revisions and the actual content displayed in the current revision if you're not careful!
Parameters
- $pageinfo : object
-
The pageindex object of the page to operate on.
- $newsource : string
-
The page content to save as the new revision.
- $oldsource : string
-
The old page content that is the current revision (before the update).
- $save_pageindex : bool = true
-
Whether the page index should be saved to disk.
- $change_type : string = "edit"
-
The type of change to record this as in the history revision log
Return values
mixed —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 —interwiki_pagename_parse()
Parses an interwiki pagename into it's component parts.
interwiki_pagename_parse(string $interwiki_pagename) : array<string|int, string>
Parameters
- $interwiki_pagename : string
-
The interwiki pagename to parse.
Return values
array<string|int, string> —An array containing the parsed components of the interwiki pagename, in the form ["prefix", "page_name"].
interwiki_pagename_resolve()
Resolves an interwiki pagename to the associated interwiki definition object.
interwiki_pagename_resolve(string $interwiki_pagename) : stdClass
Parameters
- $interwiki_pagename : string
-
An interwiki pagename. Should be in the form "prefix:page name".
Return values
stdClass —The interwiki definition object.
interwiki_get_pagename_url()
Converts an interwiki pagename into a url.
interwiki_get_pagename_url(string $interwiki_pagename) : string
Parameters
- $interwiki_pagename : string
-
The interwiki pagename (in the form "prefix:page name")
Return values
string —A url that points to the specified interwiki page.
is_interwiki_link()
Returns whether a given pagename is an interwiki link or not.
is_interwiki_link(string $pagename) : bool
Note that this doesn't guarantee that it's a valid interwiki link - only that it looks like one :P
Parameters
- $pagename : string
-
The page name to check.
Return values
bool —Whether the given page name is an interwiki link or not.
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
add_recent_change()
Adds a new recent change to the recent changes file.
add_recent_change(array<string|int, mixed> $rchange) : mixed
Parameters
- $rchange : array<string|int, mixed>
-
The new change to add.
Return values
mixed —render_recent_changes()
Renders a list of recent changes to HTML.
render_recent_changes(array<string|int, mixed> $recent_changes) : string
Parameters
- $recent_changes : array<string|int, mixed>
-
The recent changes to render.
Return values
string —The given recent changes as HTML.
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()
Renders a single recent change
render_recent_change(object $rchange) : string
Parameters
- $rchange : object
-
The recent change to render.
Return values
string —The recent change, rendered to HTML.
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.
update_redirect_metadata()
Updates the metadata associated with redirects in the pageindex entry specified utilising the provided page content.
update_redirect_metadata(object &$index_entry, string &$pagedata) : mixed
Parameters
- $index_entry : object
-
The page index entry object to update.
- $pagedata : string
-
The page content to operate on.
Return values
mixed —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
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.
update_statistics()
Updates the wiki's statistics.
update_statistics([bool $update_all = false ][, bool $force = false ]) : mixed
Parameters
- $update_all : bool = false
-
Whether all the statistics should be checked and recalculated, or just as many as we have time for according to the settings.
- $force : bool = false
-
Whether we should recalculate statistics that don't currently require recalculating anyway.
Return values
mixed —stats_load()
Loads and returns the statistics cache file.
stats_load() : object
Return values
object —The loaded & decoded statistics.
stats_save()
Saves the statistics back to disk.
stats_save(mixed $stats) : bool
Parameters
- $stats : mixed
Return values
bool —Whether saving succeeded or not.
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.
get_max_upload_size()
Calculates the actual maximum upload size supported by the server Returns a file size limit in bytes based on the PHP upload_max_filesize and post_max_size
get_max_upload_size() : int
Tags
Return values
int —The maximum upload size supported bythe server, in bytes.
parse_size()
Parses a PHP size to an integer
parse_size(string $size) : int
Parameters
- $size : string
-
The size to parse.
Tags
Return values
int —The number of bytees represented by the specified size string.
upload_check_svg()
Checks an uploaded SVG file to make sure it's (at least somewhat) safe.
upload_check_svg(string $temp_filename) : array<string|int, int>
Sends an error to the client if a problem is found.
Parameters
- $temp_filename : string
-
The filename of the SVG file to check.
Return values
array<string|int, int> —The size of the SVG image.
getsvgsize()
Calculates the size of the specified SVG file.
getsvgsize(string $svgFilename) : array<string|int, int>
Parameters
- $svgFilename : string
-
The filename to calculate the size of.
Return values
array<string|int, int> —The width and height respectively of the specified SVG file.
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.
get_all_tags()
Gets a list of all the tags currently used across the wiki.
get_all_tags() : array<string|int, string>
Tags
Return values
array<string|int, string> —A list of all unique tags present on all pages across the wiki.
generate_page_list()
Renders a list of pages as HTML.
generate_page_list(array<string|int, string> $pagelist) : string
Parameters
- $pagelist : array<string|int, string>
-
A list of page names to include in the list.
Return values
string —The specified list of pages as HTML.
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.
hash_password()
Hashes the given password according to the current settings defined in $settings.
hash_password(string $pass) : string
Parameters
- $pass : string
-
The password to hash.
Return values
string —The hashed password. Uses password_hash() under-the-hood, but with some additional extras to avoid known issues.
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()
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