PEPPERMINTY_WIKI_BUILD
public
mixed
PEPPERMINTY_WIKI_BUILD
= \true
public
mixed
PEPPERMINTY_WIKI_BUILD
= \true
Registers a new Pepperminty Wiki module. All module files should call this first.
register_module(array<string|int, mixed> $settings) : mixed
An associative array defining the module.
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
The $_SERVER variable contents. Defaults to $_SERVER.
Whether to utilise the X-Forwarded-Host header when calculating the actual origin.
The actual origin of the user's request.
Get the full url, as requested by the client.
full_url([array<string|int, mixed> $s = false ][, bool $use_forwarded_host = false ]) : string
The $_SERVER variable. Defaults to $_SERVER.
Whether to take the X-Forwarded-Host header into account.
The full url, as requested by the client.
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.
The $_SERVER variable (defaults to $_SERVER)
Whether to use the x-forwarded-host header or ignore it.
The stem url, as described above
Converts a filesize into a human-readable string.
human_filesize(int $bytes[, int $decimals = 2 ]) : string
The number of bytes to convert.
The number of decimal places to preserve.
A human-readable filesize.
Calculates the time since a particular timestamp and returns a human-readable result.
human_time_since(int $time) : string
The timestamp to convert.
The time since the given timestamp as a human-readable string.
Renders a given number of seconds as something that humans can understand more easily.
human_time(int $seconds) : string
The number of seconds to render.
The rendered time.
A recursive glob() function.
glob_recursive(string $pattern, int $flags) : array<string|int, mixed>
The glob pattern to use to find filenames.
The glob flags to use when finding filenames.
An array of the filepaths that match the given glob.
Resolves a relative path against a given base directory.
path_resolve(string $path[, string|null $basePath = null ]) : string
The relative path to resolve.
The base directory to resolve against.
An absolute path.
Determines if a directory is empty or not.
is_directory_empty(string $dir) : bool
The path to the directory to check.
True if the directory is empty, or false if it is not empty.
Converts a filepath to a page name.
filepath_to_pagename(string $filepath) : string
The filepath to convert.
The extracted pagename.
Gets the name of the parent page to the specified page.
get_page_parent(string $pagename) : string|bool
The child page to get the parent page name for.
Gets a list of all the sub pages of the current page.
get_subpages(object $pageindex, string $pagename) : object
The pageindex to use to search.
The name of the page to list the sub pages of.
An object containing all the subpages and their respective distances from the given page name in the pageindex tree.
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.
The pagename to check.
Whether to create an associated directory for subpages or not.
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.
The string to make safe.
A safe version of the given string.
Slugifies a given string such that it can only contain a-z0-9-_.
slugify(string $text) : string
Also automatically makes it lowercase.
The text to operate on.
The slugified string.
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
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.
The mangled email address as a fragment of HTML.
Checks to see if $haystack starts with $needle.
starts_with(string $haystack, string $needle) : bool
The string to search.
The string to search for at the beginning of $haystack.
Whether $needle can be found at the beginning of $haystack.
Checks to see if $hackstack ends with $needle.
ends_with(string $haystack, string $needle) : bool
The matching bookend to starts_with.
The haystack to search..
The needle to look for.
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
The string to search.
The string to find.
An array of match indices, or false if nothing was found.
Tests whether a string starts with a specified substring.
startsWith(string $haystack, string $needle) : bool
The string to check against.
The substring to look for.
Whether the string starts with the specified substring.
Tests whether a string ends with a given substring.
endsWith(string $whole, string $end) : bool
The string to test against.
The substring test for.
Whether $whole ends in $end.
Replaces the first occurrence of $find with $replace.
str_replace_once(string $find, string $replace, string $subject) : string
The string to search for.
The string to replace the search string with.
The string ot perform the search and replace on.
The source string after the find and replace has been performed.
Returns the system's mime type mappings, considering the first extension listed to be cacnonical.
system_mime_type_extensions() : array<string|int, mixed>
An array of mime type mappings.
Converts a given mime type to it's associated file extension.
system_mime_type_extension(string $type) : string
The mime type to convert.
The extension for the given mime type.
Returns the system MIME type mapping of extensions to MIME types.
system_extension_mime_types() : array<string|int, mixed>
An array mapping file extensions to their associated mime types.
Converts a given file extension to it's associated mime type.
system_extension_mime_type(string $ext) : string
The extension to convert.
The mime type associated with the given extension.
Creates an images containing the specified text.
errorimage(string $text[, int $target_size = null ]) : resource
Useful for sending errors back to the client.
The text to include in the image.
The target width to aim for when creating the image. Not not specified, a value is determined automatically.
The handle to the generated GD image.
Generates a stack trace.
stack_trace([bool $log_trace = true ][, bool $full = false ]) : string
Whether to send the stack trace to the error log.
Whether to output a full description of all the variables involved.
A string prepresentation of a stack trace.
Calls var_dump() and returns the output.
var_dump_ret(mixed $var) : string
The thing to pass to var_dump().
The output captured from var_dump().
Calls var_dump(), shortening the output for various types.
var_dump_short(mixed $var) : string
The thing to pass to var_dump().
A shortened version of the var_dump() output.
Polyfill for PHP's native getallheaders() function on platforms that don't have it.
getallheaders() : mixed
Renders a timestamp in HTML.
render_timestamp(int $timestamp[, bool $absolute = false ][, bool $html = true ]) : string
The timestamp to render.
Whether the time should be displayed absolutely, or relative to the current time.
Whether the result should formatted as HTML (true) or plain text (false).
HTML representing the given timestamp.
Renders a page name in HTML.
render_pagename(object $rchange) : string
The recent change to render as a page name
HTML representing the name of the given page.
Renders an editor's or a group of editors name(s) in HTML.
render_editor(string $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.
HTML representing the given editor's name.
Minifies CSS. Uses simple computationally-cheap optimisations to reduce size.
minify_css(string $css_str) : string
CSS Minification ideas by Jean from catswhocode.com
The string of CSS to minify.
The minified CSS string.
Saves the settings file back to peppermint.json.
save_settings() : bool
Whether the settings were saved successfully.
Save the page index back to disk, respecting $settings->minify_pageindex
save_pageindex() : bool
Whether the page index was saved successfully or not.
Saves the currently logged in user's data back to peppermint.json.
save_userdata() : bool
Whether the user's data was saved successfully. Returns false if the user isn't logged in.
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.
The username to get the path to their user page for.
The path to the given user's page.
Extracts a username from a user page path.
extract_user_from_userpage(string $userPagename) : string
The suer page path to extract from.
The name of the user that the user page belongs to.
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
The username to send the email to.
The subject of the email.
The body of the email.
Whether to ignore user email verification status and send the email anyway. Defaults to false.
Whether the email was sent successfully or not. Currently, this may fail if the user doesn't have a registered email address.
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
A list of usernames to email.
The subject of the email.
The body of the email.
The number of emails sent successfully.
Recursively deletes a directory and it's contents.
delete_recursive(string $path[, bool $delete_self = true ]) : mixed
Adapted by Starbeamrainbowlabs
The path to the directory to delete.
Whether to delete the top-level directory. Set this to false to delete only a directory's contents
Generates a crytographically-safe random id of the given length.
crypto_id(int $length) : string
The length of id to generate.
The random id.
Returns whether we are both on the cli AND the cli is enabled.
is_cli() : bool
metrics2servertiming(stdClass $perfdata) : 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.
The cookie name to set.
The cookie value to set.
The expiry time to set on the cookie.
Registers a module.
register_module(array<string|int, mixed> $moduledata) : mixed
The module data to register.
Checks to see whether a module with the given id exists.
module_exists(string $id) : bool
The id to search for.
Whether a module is currently loaded with the given id.
Registers a new action handler.
add_action(string $action_name, callable $func) : mixed
The action to register.
The function to call when the specified action is requested.
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
The name of the action to search for
Whether an action with the specified name exists.
Register a new proprocessor that will be executed just before an edit is saved.
register_save_preprocessor(callable $func) : mixed
The function to register.
Adds a new help section to the help page.
add_help_section(string $index, string $title, string $content) : mixed
The string to index the new section under.
The title to display above the section.
The content to display.
Registers a statistic calculator against the system.
statistic_add(array<string|int, mixed> $stat_data) : mixed
The statistic object to register.
Checks whether a specified statistic has been registered.
has_statistic(string $stat_id) : bool
The id of the statistic to check the existence of.
Whether the specified statistic has been registered.
Registers a new parser.
add_parser(string $name, callable $parser_code, callable $hash_generator) : mixed
The name of the new parser to register.
The function to register as a new parser.
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.
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.
The source to render.
Whether the source string is 'untrusted' - i.e. a user comment. Untrusted source disallows HTML and protects against XSS attacks.
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.
The source rendered to HTML.
Calculates the standard deviation of an array of numbers.
standard_deviation(array<string|int, mixed> $array) : float
The array of numbers to calculate the standard deviation of.
The standard deviation of the numbers in the given array.
time_callable(mixed $callable) : mixed
tree_create() : mixed
tree_save(BkTree $tree) : mixed
tree_load() : mixed
test_search_linear() : mixed
writegraph() : mixed
test_auto() : mixed
Resolves a relative path against a given base directory.
path_resolve(string $path[, string|null $basePath = null ]) : string
The relative path to resolve.
The base directory to resolve against.
An absolute path.
lines_count(mixed $handle) : mixed
Renders the sidebar for a given pageindex.
render_sidebar(array<string|int, mixed> $pageindex[, string $root_pagename = "" ], mixed $depth) : string
The pageindex to render the sidebar for
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.
A HTML rendering of the sidebar for the given pageindex.
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.
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.
Starts the Pepperminty Wiki CLI Shell.
cli_shell() : mixed
This function kill the process if the current execution environment is not the CLI.
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.
The shell command to execute.
The exit code of the command executed.
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.
The name of command.
The description of the command.
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.
Given a page name, returns the absolute file path in which that page's comments are stored.
get_comment_filename(string $pagename) : string
The name pf the page to fetch the comments filename for.
The path to the file that the
Generates a new random comment id.
generate_comment_id() : string
A new random comment id.
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
The comment data to search.
The id of the comment to find.
The comment data with the specified id, or false if it wasn't found.
Deletes the first comment found with the specified id.
delete_comment(array<string|int, mixed> &$comment_data, string $target_id) : bool
An array of threaded comments to delete the comment from.
The id of the comment to delete.
Whether the comment was found and deleted or not.
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.
The comment data to search.
The comment id to fetch the thread for.
A list of the comments in the thread, with the deepest one at the end.
Renders a given comments tree to html.
render_comments(array<string|int, object> $comments_data, int $depth) : string
The comments tree to render.
For internal use only. Specifies the depth at which the comments are being rendered.
The given comments tree as html.
do_system_checks() : mixed
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!
The pageindex object of the page to operate on.
The page content to save as the new revision.
The old page content that is the current revision (before the update).
Whether the page index should be saved to disk.
The type of change to record this as in the history revision log
Updates the interwiki index cache file.
interwiki_index_update() : mixed
If the interwiki_index_location isn't defined, then this function will do nothing.
Parses an interwiki pagename into it's component parts.
interwiki_pagename_parse(string $interwiki_pagename) : array<string|int, string>
The interwiki pagename to parse.
An array containing the parsed components of the interwiki pagename, in the form ["prefix", "page_name"].
Resolves an interwiki pagename to the associated interwiki definition object.
interwiki_pagename_resolve(string $interwiki_pagename) : stdClass
An interwiki pagename. Should be in the form "prefix:page name".
The interwiki definition object.
Converts an interwiki pagename into a url.
interwiki_get_pagename_url(string $interwiki_pagename) : string
The interwiki pagename (in the form "prefix:page name")
A url that points to the specified interwiki page.
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
The page name to check.
Whether the given page name is an interwiki link or not.
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).
The text to estimate for.
The language code of the text - defaults to "en"
An array in the form [ low_time, high_time ] in minutes
Adds a new recent change to the recent changes file.
add_recent_change(array<string|int, mixed> $rchange) : mixed
The new change to add.
Renders a list of recent changes to HTML.
render_recent_changes(array<string|int, mixed> $recent_changes) : string
The recent changes to render.
The given recent changes as HTML.
Given a page name and timestamp, returns the associated page revision number.
find_revisionid_timestamp(string $pagename, mixed $timestamp) : int
The page name to obtain the revision number for.
The revision number of the given page at the given time.
Renders a single recent change
render_recent_change(object $rchange) : string
The recent change to render.
The recent change, rendered to HTML.
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.
The array of recent changes to render.
The recent changes as an Atom 1.0 feed.
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
The page index entry object to update.
The page content to operate on.
Calculates the standard deviation of an array of numbers.
standard_deviation(array<string|int, mixed> $array) : float
The array of numbers to calculate the standard deviation of.
The standard deviation of the numbers in the given array.
Given a page name, returns a list fo similar pages.
similar_suggest(string $pagename, string $content[, bool $limit_output = true ]) : array<string|int, mixed>
The name of the page to return suggestions for.
The content of the given page.
A list of suggested page names in the format pagename => rank.
Updates the wiki's statistics.
update_statistics([bool $update_all = false ][, bool $force = false ]) : mixed
Whether all the statistics should be checked and recalculated, or just as many as we have time for according to the settings.
Whether we should recalculate statistics that don't currently require recalculating anyway.
Loads and returns the statistics cache file.
stats_load() : object
The loaded & decoded statistics.
Saves the statistics back to disk.
stats_save(mixed $stats) : bool
Whether saving succeeded or not.
Updates the currently selected theme by fetching it from a remote url.
theme_update([bool $force_update = false ]) : bool
Whether to force an update - even if we've already updated recently.
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.
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
The maximum upload size supported bythe server, in bytes.
Parses a PHP size to an integer
parse_size(string $size) : int
The size to parse.
The number of bytees represented by the specified size string.
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.
The filename of the SVG file to check.
The size of the SVG image.
Calculates the size of the specified SVG file.
getsvgsize(string $svgFilename) : array<string|int, int>
The filename to calculate the size of.
The width and height respectively of the specified SVG file.
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.
The name of the user to send the verification code to.
Whether the verification code was sent successfully. If a user does not need to verify their email address, this returns true.
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/
The length of password to generate.
The generated random password.
Masks secrets in debug output.
debug_mask_secrets(string $text) : string
The text to mask.
The masked text.
Generates a unique hash of a page's content for edit conflict detection purposes.
generate_page_hash(string $page_data) : string
The page text to hash.
A hash of the given page text.
Gets a list of all the tags currently used across the wiki.
get_all_tags() : array<string|int, string>
A list of all unique tags present on all pages across the wiki.
Renders a list of pages as HTML.
generate_page_list(array<string|int, string> $pagelist) : string
A list of page names to include in the list.
The specified list of pages as HTML.
Recalculates and updates the password hashing cost.
do_password_hash_code_update() : mixed
Figures out the appropriate algorithm & options for hashing passwords based on the current settings.
hash_password_properties() : array<string|int, mixed>
The appropriate password hashing algorithm and options.
Hashes the given password according to the current settings defined in $settings.
hash_password(string $pass) : string
The password to hash.
The hashed password. Uses password_hash() under-the-hood, but with some additional extras to avoid known issues.
Verifies a user's password against a pre-generated hash.
verify_password(string $pass, string $hash) : bool
The user's password.
The hash to compare against.
Whether the password matches the has or not.
Determines if the provided password needs re-hashing or not.
hash_password_update(string $pass, string $hash) : string|null
The password to check.
The hash of the provided password to check.
Returns null if an updaste is not required - otherwise returns the new updated hash.
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.
Whether to output verbose progress information to the client or not.
The automatically calculated password hashing cost.
Attempts to 'auto-correct' a page name by trying different capitalisation combinations.
parsedown_pagename_resolve(string $pagename) : string
The page name to auto-correct.
The auto-corrected page name.
Logs a string to stdout, but only on the CLI.
log_str(string $line) : mixed
The line to log.
module_list_search(array<string|int, mixed> $list, string $id) : bool
module_list_find(array<string|int, mixed> $list, string $id) : mixed