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

Summary: add parameter to (:messages:) page directive
Created: 2015-06-01 00:31
Status: InProgress
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

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

2024 review

I totally forgot this was discussed here, anyway, there should be something like this for 2.3.34. --Petko

I have created a recipe that is similar to this: Cookbook:MessagesReplacement as suggested in the feedback from Oct 2021 based on the code snippet from above


I've released the core changes but haven't documented them. I'll try to find some time before the next PmWiki version to review the recipe features and see how we can have better compatibility between the two. I also plan to refactor the code to allow adding messages with wiki markup. How do you use the recipe, is it from other recipes, which features could be added to the core? --Petko

Please see Cookbook:MessagesReplacement for features I see as being useful. Thanks -- simon