01453: Deprecated create_function() in Monobook skin

Summary: Deprecated create_function() in Monobook skin
Created: 2020-03-25 08:17
Status: Closed - fix provided in Skins:Monobook
Category: Cookbook
Priority: 3
Version: 2.2.127
OS: PHP 7.3

Description: Hello,

I noticed that the deprecated function "create_function()" is still used in 2 scripts:

- pmwiki.php

- scripts/pagelist.php

In the newer versions of PHP, I get an error message when I visit my Wiki page:

Deprecated: Function create_function() is deprecated in /.../wiki/pmwiki.php on line 501

Daniel Marschall? March 25, 2020, at 08:18 AM

It is not used by PmWiki itself but by older addons which can register this function to be called. Please see PmWiki:Troubleshooting and update your addons. The current philosophy adopted by the community is to leave the possibility for older installation to still use their older addons, and for new installations to see the warning message rather than have their features disabled -- this will allow the administrators to update their installations. --Petko March 25, 2020, at 08:28 AM

Thank you for your quick reply. I do not use any addons. I use the pure PMwiki installation, and I get the warning message "Function create_function() is deprecated in /.../wiki/pmwiki.php on line 501" I have run "grep -r create_function" to see where this deprecated function is used. It is used in pmwiki.php at function PCCF() [unfortunately, I have no idea what "PCCF" means, so I can't tell what is happening there] as well as in scripts/pagelist.php at function PageListSort(). Both functions are part of PMwiki and not by an addon. --Daniel Marschall? March 25, 2020, at 10:42 AM

PCCF() means "PmWiki Create Callback Function" and was used between PHP 5.5 and 7.2 to allow an easier migration of addons. Maybe I wasn't clear: there is a way PmWiki to call create_function() but only if an addon or a local customization code registers a request for such a call. By itself, in a pure PmWiki core installation, that function should never be called. If you really have no addons/skins installed, and nothing in config.php that might call PCCF(), or PPRE(), or Markup_e() or create_function(), or a custom pagelist sort order $PageListSortCmp, it is possible that we forgot something that causes the call in the core, this would be a bug and we will fix it as soon as possible, as in, today. Can you tell me more, what steps should I do to experience this bug? --Petko March 25, 2020, at 10:57 AM

Thank you for the clarification. I noticed that actually there was a skin installed, called monobook ( https://www.pmwiki.org/wiki/Skins/Monobook ). The latest version is installed, but it uses the function Markup_e() which calls PCCF(). I have created a small patch (which is hopefully correct) and attached it to this page. Can you please check it and update the monobook skin? --Daniel Marschall? March 25, 2020, at 11:43 AM Attach:monobook_fix.diff

Thanks, this looks correct but anonymous functions only work with PHP 5.3 or newer. For the update to also work in earlier PHP versions, I'd use named functions in the last argument to Markup() -- and some of these can already be used directly:
Markup('noleft', 'directives', '/\\(:noleft:\\)/i', 'NoLeftBar');
similarly for "nosidebar" and "notabs";
"showright" can be done with a named function like this:
Markup('showright', 'directives', '/\\(:showright:\\)/', 'mu_showright');
function mu_showright() { global $action; if ($action == 'browse') SetTmplDisplay('PageRightFmt', 1); }
"noright" already exists in the core and can be dropped. I'll notify Dfaure for this. --Petko March 25, 2020, at 12:03 PM

The page Skins:Monobook now provides a replacement to monobook.php for recent PHP versions. --Petko