MessagesReplacement

Summary: A drop in replacement for the PmWiki (:messages:) directive
Version:2024-05-31
Prerequisites: PmWiki 2.3.34; PHP 8.3
Status: beta
Maintainer: simon
Licence: GPL3#
Users: (view / edit)

Questions answered by this recipe

Can I display selected debugging messages from $MessagesFmt from only one, or from selected, message sources?
Can I make the messages from each message source hidden until shown on user demand?

Description

A drop in replacement for the PmWiki (:messages keys= :) directive. Based on code from PITS:01368.

The global variable $MessagesFmt is written to by PmWiki recipes with debug and similar information. By convention the array has two dimensions, the first a string identifying the source of the message, and the optional second dimension, a string with the debug message itself.

Differences are:

  • comma or space separated name parameters, with wildcards, can be supplied to select the groups of messages displayed
  • only messages for specified name parameters are displayed
  • name parameters are case insensitive
  • directive does not have to start at the beginning of a line
  • the output is placed within a HTML section of class=messages
  • groups of messages are separated by a blank line
  • groups of messages can be rolled up by using the details=show | hide parameter

Installation

  • download messagesreplacement-2024-05-31.phpΔ
  • copy to the /cookbook/ directory as messagesreplacement.php
  • add to config.php the line
    include_once ($FarmD/cookbook/messagesreplacement.php);

Usage

Place the directive, as described below, in your PmWiki page.

The recipe provides a page variable {$MessagesReplacementVersion} which contains the current version, and page variable $@MessagesReplacement for a (:if enabled MessagesReplacement:) recipe installation check.

Configuration

(:messages optional,list of names with,wildcards* keys="names,with,*wildcards" details=hide :)

Parameters are optional and case-insensitive:

  • names can include wild cards
  • keys= a comma separated list of names
  • details='show' or details = 'hide' provides a clickable name for each group of messages with initial value of show or hide

config.php settings

You can change the following in config.php. For example

$MessagesReplacementDebug = true; # results may vary
default: false
$MessagesReplacementHeading = true; # shows heading level 3 for each group of messages
default: false
$MessagesReplacementDetails = 'hide'; # rolls up each group of messages
default: empty (no details rollup available), values are 'hide' and 'show'

Change log / Release notes

2024-05-31 add key= parameter to maintain compatibility with built in directive 2024-04-27 fix PHP 8 warnings, add details=show||hide parameter 2022-02-02 Separate groups of messages, enable heading 2022-01-22 Initial version

See also

Contributors

Special thanks to Petko

Comments

See discussion at MessagesReplacement-Talk

User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Array
(
    [post_max_size] => 64M
    [$_POST keys] => 
    [$_REQUEST keys] => n
    [$_SERVER] => Array
        (
            [CONTEXT_DOCUMENT_ROOT] => /home/pmwiki/public_html
            [CONTEXT_PREFIX] => 
            [DOCUMENT_ROOT] => /home/pmwiki/public_html
            [GATEWAY_INTERFACE] => CGI/1.1
            [HTTPS] => on
            [HTTP_ACCEPT] => */*
            [HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
            [HTTP_COOKIE] => imstime=1777523613; PHPSESSID=gkiu9gfjpqb562im8o5f2u59s1
            [HTTP_HOST] => www.pmwiki.org
            [HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
            [HTTP_X_HTTPS] => 1
            [PATH] => /bin:/usr/bin
            [PHP_INI_SCAN_DIR] => /opt/cpanel/ea-php70/root/etc:/opt/cpanel/ea-php70/root/etc/php.d:.
            [QUERY_STRING] => n=Cookbook%2fMessagesReplacement
            [REDIRECT_HTTPS] => on
            [REDIRECT_QUERY_STRING] => n=Cookbook%2fMessagesReplacement
            [REDIRECT_SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/MessagesReplacement
            [REDIRECT_SCRIPT_URL] => /wiki/Cookbook/MessagesReplacement
            [REDIRECT_SSL_TLS_SNI] => www.pmwiki.org
            [REDIRECT_STATUS] => 200
            [REDIRECT_UNIQUE_ID] => afLbsZ9ZiWrfKoawz2hMzAAAAI4
            [REDIRECT_URL] => /wiki/Cookbook/MessagesReplacement
            [REMOTE_ADDR] => 216.73.216.31
            [REMOTE_PORT] => 2107
            [REQUEST_METHOD] => GET
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /wiki/Cookbook/MessagesReplacement
            [SCRIPT_FILENAME] => /home/pmwiki/public_html/index.php
            [SCRIPT_NAME] => /index.php
            [SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/MessagesReplacement
            [SCRIPT_URL] => /wiki/Cookbook/MessagesReplacement
            [SERVER_ADDR] => 23.254.203.248
            [SERVER_ADMIN] => webmaster@pmwiki.org
            [SERVER_NAME] => www.pmwiki.org
            [SERVER_PORT] => 443
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SIGNATURE] => 
            [SERVER_SOFTWARE] => Apache
            [SSL_TLS_SNI] => www.pmwiki.org
            [TZ] => America/Los_Angeles
            [UNIQUE_ID] => afLbsZ9ZiWrfKoawz2hMzAAAAI4
            [PHP_SELF] => /index.php
            [REQUEST_TIME_FLOAT] => 1777523633.1589
            [REQUEST_TIME] => 1777523633
            [argv] => Array
                (
                    [0] => n=Cookbook%2fMessagesReplacement
                )

            [argc] => 1
        )

)