[pmwiki-users] Page Variables recipe

Martin Fick fick at fgm.com
Wed Nov 23 14:43:21 CST 2005

  I created a recipe which allows access to any page's
variables using the following simple notation:


  I know that we discussed a series of shorterhand notations
as well, but I think we wanted to at least have this
notation, so here is my quick implementation.

  I have a test page setup here:


  Feel free to mess with any page on this wiki.

  Potential issue: this will put every page referenced into
the PCache.

  Should I put this in the Cookbook as a recipe or do you
think this  is something that might actually go in the core
before I get my  recipe up?


<?php if (!defined('PmWiki')) exit();

  Version 1.0   11/23/05  Author: Martin Fick

  To install this recipe, simply put this in your cookbook directory
  and add include_once("cookbook/pagevars.php"); to your config.php.

  Page Variables:

  {$Group} - page's group name, as in "PmWiki"
  {$Groupspaced} - spaced group name, as in "Pm Wiki"
  {$Name} - page name, as in "MarkupVariables"
  {$Namespaced} - spaced page name, as in "Markup Variables"
  {$FullName} - page's full name, as in "PmWiki.MarkupVariables"
  {$Title} - page title (may differ from Name), as in "MarkupVariables"
  {$Titlespaced} - title/spaced page name, as in "Markup Variables"
  {$LastModified} - date page was edited, as in "August 31, 2005, at 10:18 PM"
  {$LastModifiedBy} - page's last editor, as in "Pm"
  {$LastModifiedHost} - IP of page's last editor, as in ""



# {pagename$var} substitutions
 Markup('$[pagename$fmt]','>$[fmt]', "/{([$PageNameChars\.\/]+?)" .

function pagevars($var, $pagename)
  global $PCache, $EnablePageListProtect;

	if ($var == '$Title' || $var == '$Titlesapced') $pvar='title';
	if ($var == '$LastModified')                    $pvar='time';
	if ($var == '$LastModifiedBy')                  $pvar='author';
	if ($var == '$LastModifiedHost')                $pvar='host';

	if ($pvar && ! isset($PCache[$pagename][$pvar]))
		$page = IsEnabled($EnablePageListProtect, 0) ?
			RetrieveAuthPage($pagename, 'read', false, READPAGE_CURRENT)
			: ReadPage($pagename, READPAGE_CURRENT);
		$PCache[$pagename]= $page;
	//Non-existing pages should return blank time, not the current time.
	if ($var == '$LastModified' && !PageExists($pagename)) return "";
	return FmtPageName($var,$pagename);

More information about the pmwiki-users mailing list