Pepperminty Wiki Module API

core

Interfaces, Classes, Traits and Enums

ids
Provides an interface to interact with page ids.
page_renderer
Renders the HTML page that is sent to the client.

Table of Contents

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.
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.
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.
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.
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.
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.

Functions

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
see
http://stackoverflow.com/a/8891890/1460422

This Stackoverflow answer.

Return values
string

The full url, as requested by the client.

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
see
http://php.net/manual/en/function.filesize.php#106569

The original source

author

rommel

author

Edited by Starbeamrainbowlabs

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
see
http://goo.gl/zpgLgq

The original source. No longer exists, maybe the wayback machine caught it :-(

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
see
http://in.php.net/manual/en/function.glob.php#106595

The original source

author

Mike

Return values
array<string|int, mixed>

An array of the filepaths that match the given glob.

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
since
0.15.0
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.

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
see
http://www.pontikis.net/tip/?id=16

the source

see
http://www.php.net/manual/en/function.strpos.php#87061

the source that the above was based on

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
see
http://stackoverflow.com/a/1147952/1460422

From this stackoverflow answer

author

chaos

author

Edited by Starbeamrainbowlabs

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
see
http://stackoverflow.com/a/1147952/1460422

From this stackoverflow answer

author

chaos

author

Edited by Starbeamrainbowlabs

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
see
http://stackoverflow.com/a/1147952/1460422

From this stackoverflow answer

author

chaos

author

Edited by Starbeamrainbowlabs

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
see
http://stackoverflow.com/a/1147952/1460422

From this stackoverflow answer

author

chaos

author

Edited by Starbeamrainbowlabs

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
todo

Identify which platforms don't have it and whether we still need this

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.

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.

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.

Search results