[pmwiki-devel] Testing if a page exists

Petko Yotov 5ko at 5ko.fr
Mon Nov 4 00:37:11 PST 2024


On 04/11/2024 09:14, Simon wrote:
> In a recipe how do I test
> 1) if a page of a given name exists?

   if(PageExists($pagename)) {
     # page exists in at least one of the page store classes
   }

> 2) if the called pagename of the current page and action exists (e.g.
> NoGroup/Nopage?action=browse)

1. To get the current $pagename, from a Markup function you can do:

   extract($GLOBALS['MarkupToHTML']);

This creates a local variable $pagename within the function. This 
$pagename is what MarkupToHTML() was called with.

This is recommended if your recipe may need to work with recipes that 
export multiple pages like static websites, backups, PDF exports, or 
similar.

If your function is registered as $MarkupDirectiveFunctions, the first 
argument is $pagename, it is what MarkupToHTML() was called with.

If the recipe doesn't need to work when exporting multiple pages, you 
can set:

   global $pagename;

2. To test if the *current* action exists, check if 
$HandleActions[$action] exists and is callable. Both $HandleActions and 
$action are global variables.

If it doesn't/isn't, then PmWiki should call $HandleActions['browse'].

It may not be reliable to check if an action different from the current 
one exists, as some recipes are loaded conditionally.

Petko



More information about the pmwiki-devel mailing list