[pmwiki-users] Custom page specific variable assignment syntax

Kevin R. Bulgrien kevinb at systemsdesignusa.com
Tue Aug 28 09:55:34 PDT 2018


This note regards page specific variables described here:

  https://www.pmwiki.org/wiki/PmWiki/PageVariables

It is a suggestion to consider a minor addition to the
Custom page variables section to add an example of using
a user-defined function to construct a value to assign to
a custom page variable.

My task involved finding a way to keep two (almost) wiki
sites consistent during a transition period using only
periodic rsync of the master wiki to a temporary replica.
Both domain and http vs. https changes occurred.  The 
main challenge was that some wiki content used hard-coded
http://... URLs to other areas of the web space outside
the wiki but on the same server.  These links broke when
rsyncing updates to a different server.  I hoped not to
change rendered content simply because I was moving the
wiki to a new platform, and envisioned using computed
variables that could be used in place of the hard-coded
URLs.

Use of custom page variables appeared viable, but I found
it difficult to gain understanding of syntax rules that
apply to defining a Page Variable via a moderately
complex expression.  I tried a number of simple syntax
structures with intermittent success though each time I
tried to modify the simple examples, the change would
invariably break some syntax rule I was not able to
discern.

In the end, by looking at various cookbook files, I found
a function call assignment syntax structure that worked
immediately and completely removed complexity of syntax.

So much time was spent trying to get other syntax forms
to work that it seems a documentation change could help
others if it showed an example using a user-function to
assign the FmtPV value.

Without meaning to imply that the following example is
without fault, the following illustrates the format:

function BaseURL()
{
  $URLPrefix = "http";
  if (! empty($_SERVER['HTTPS']))
  {
    if($_SERVER['HTTPS'] == 'on')
    {
      $URLPrefix .= "s";
    }
  }
  return $URLPrefix .= "://" . $_SERVER['HTTP_HOST'] . "/Wiki";
}
$FmtPV['$BaseURL'] = 'BaseURL()';

It seems it could be helpful if the custom page variable
documentation mentioned a function call example as it has
a very simple syntax and allows for complex computation of
values to assign.  Even if understanding of the existing
documentation is due to my own issues, perhaps I am not
alone and there are others who might benefit from adding
an example like this.

I placed this code in config.php and made a handful of changes
to replace hard coded URL text with {$BaseURL} references on a
few affected wiki pages (though the code could have been placed
in a cookbook PHP file included by config.php as cookbook files
normally are).

I am willing to edit the wiki myself to add a short example
(probably without full text of the user-function) if it does
not create a synchronization issue for other language pages
I cannot edit, or, if this is seen as undesirable, to simply
let this mailing list note suffice to put the information
out there for others.

-- 
Kevin R. Bulgrien



More information about the pmwiki-users mailing list