admins (advanced)
This page describes an internal function in PmWiki's engine called FmtPageName()
.
The contents are not intended for those with a weak heart
;-)
Also see: PmWiki.Functions
FmtPageName($fmt, $pagename)
Returns $fmt
, with @@$variable@@ and @@internationalisation@@ substitutions performed, under the assumption that the current page is pagename
. As a rule is used to pre-process all variables which by convention have a "Fmt" suffix (like $GroupFooterFmt), but also other strings that require interpolation, notably the page template (.tmpl) file. See PmWiki.Variables for an (incomplete) list of available variables, PmWiki.Internationalizations for internationalisation.
The function FmtPageName()
applies internationalization-substitutions
and $Variable-substitions to the string @@$fmt@@ under the assumption that the
current page is
.
$pagename
The substitutions go as follows:
$XyzFmt
with value of any corresponding global variable.
$[...]
phrases (internationalized phrase), using the currently loaded translation tables.
{$ScriptUrl}
with $ScriptUrl
(to defer processing to the URI processing phase)
{Group.Page$Var}
are not replaced. If there are no more $-sequences, then return the formatted string and exit the function
robots.php
to hide actions from robots.
$Var
rather than the usual PV form of {$Var}
.
URIs
to use the syntax @@$ScriptUrl?n=<Group>.<Name> instead of $ScriptUrl/<Group>/<Name>@@. In any case, replace $ScriptUrl with its value. If there are no more $-sequences, then return the formatted string and exit the function
Note that FmtPageName()
is automatically aware of any global
variables. However, since modifying global variables may be expensive, the
array $FmtV
exists as a way to avoid rebuilding the variable cache for
values that change frequently.
According to PM, as a general rule it's unwise to be calling FmtPageName()
on strings that are coming from page markup, as this exposes the ability for people to view the values of variables that perhaps they shouldn't see. This is also why page variables (which come from markup) use PageVar()
and PageTextVar()
and don't go through FmtPageName()
.
To be very specific, here's what Pm wrote regarding different ways of defining a variable that can be used by FmtPageName (when it is formatting a string):
FmtPageName()
automatically performs substitution on all global variables that aren't arrays. If the variable is going to change value over repeated calls to FmtPageName()
, it's probably better to use $FmtV
as in the next item.
Also see: Cookbook:Functions#FmtPageName
Finally, here's something else Pm wrote that is related and explains why we have this function:
$ScriptUrl/$Group/$Name to $ScriptUrl?n=$Group.$Name
for sites that cannot handle PATH_INFO urls
FmtPageName()
subroutine. Because some things are extremely dynamic, such as the url or group for an arbitrary page that is not the current one, those things cannot be simple global PHP variables. Or, if they do become global variables, they're variables that cannot be trusted to hold a value for very long because some other routine (that may happen to be formatting a string for a different page) will come along and change that global variable for whatever it happens to be doing.
$page = ReadPage($pagename); PCache($pagename, $page); $ptitle = FmtPageName('$Title', $pagename); $pauthor = FmtPageName('$LastModifiedBy', $pagename);
This page may have a more recent version on pmwiki.org: PmWiki:FmtPageName, and a talk page: PmWiki:FmtPageName-Talk.