01368: add parameter to (:messages:) page directive

Summary: add parameter to (:messages:) page directive
Created: 2015-06-01 00:31
Status: Open
Category: Feature
From: simon
Priority: 4
Version: 2.2.143
OS: n/a

Description: The (:messages:) page directive displays all messages from all recipes and scripts that generate them (eg Passwords). This can lead to confusion, or a message being lost in a list of other messages.

The messages are added to the $MessagesFmt array by the various PmWiki scripts and recipes. The array allows a key to be specified, e.g. MyRecipe could log a message to $Messages['MyRecipe'].

This feature request asks for an optional parameter to be added to the messages directive. If the parameter is supplied only the values for the specific index in the array are displayed.

(:messages 'MyRecipe':)

simon June 01, 2015, at 12:33 AM, updated simon October 26, 2021, at 01:00 AM

You have suggested this in the talk page 12 years ago, and nobody else has reported they need it. Are there any technical obstacles in the PmWiki core preventing you from writing a recipe doing exactly this, documenting it and supporting it? I don't see any. You are free to override the existing directive, or define a new one, and use that in your forms. --Petko October 26, 2021, at 08:46 AM

Here is one way to do it -- you can start from here, or not.

## (:messages:)
Markup('messages', 'directives', '/^\\(:messages(?: (.+?))?:\\)/i', "FmtMessages");

function FmtMessages($m) {
  global $MessagesFmt;

  if(count($m) == 1) $keys = '*';
  else $keys = $m[1];

  if(! count($MessagesFmt)) return '';

  $arr = [];
  foreach($MessagesFmt as $k=>$v) {
    if(is_integer($k)) $k = '';
    if(!isset($arr[$k])) $arr[$k] = [];

    foreach((array)$v as $vv) {
      $arr[$k][] = $vv;
  $out = [];
  $foundkeys = MatchNames(array_keys($arr), $keys);
  foreach($foundkeys as $k) {
    $out[] = implode('', (array)$arr[$k]);

  return '<:block>'.Keep(FmtPageName(
    implode('',(array)$out), $pagename));

function AddMessageFmt($msg, $key = '') {
  global $MessagesFmt;
  if(!isset($MessagesFmt[$key])) $MessagesFmt[$key] = [];
  if(!is_array($MessagesFmt[$key])) $MessagesFmt[$key] = (array)$MessagesFmt[$key];
  $MessagesFmt[$key][] = $msg;

Then in a wiki page you can use (:messages key1,key2:) or (:messages key*,-key2:) --Petko October 27, 2021, at 07:21 AM