01319: preg_replace with /e modifier deprecated

Summary: preg_replace with /e modifier deprecated
Created: 2013-08-06 11:51
Status: InProgress
Category: Feature
Assigned:
Priority: 434
Version: 2.2.53
OS: Linux, Apache, PHP 5.5.0

Please see Troubleshooting on how to find out which recipes cause the warnings to appear.

Description: On my webserver, I cannot use pmwiki any more because Apache's mod_sec module blocks the invocations of preg_replace with the /e modifier. Since the use of /e is highly discouraged as of PHP 5.5.0, see http://php.net/manual/en/reference.pcre.pattern.modifiers.php, it would be great if pmwiki could be updated.

Or: Multiple messages appear: "Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in pmwiki.php on line 1663"

There is a work in progress and the core shouldn't rely on this deprecated feature as of PmWiki version 2.2.56. We'll migrate any needed modules progressively. Please test the latest version and report any problems. --Petko September 30, 2013, at 04:37 PM

Sorry to tell, but here same problem. Version 2.2.56 does not help... Karl Loncarek? October 28, 2013, at 03:07 PM

Is the version 2.2.56 working without any modules/recipes/customizations enabled? If yes, which recipes, when enabled, cause the problem? If no, I'd like to test that server in real time, please contact me at 5ko [snail] 5ko [period] fr. --Petko October 28, 2013, at 03:45 PM

OK, found the problem. I used an old version of pagestoreGZ. After disabling it and adding "error_reporting(E_ALL & ~E_DEPRECATED ^ E_NOTICE); " to pmwiki.php it worked again. Thanks nevertheless. Karl Loncarek? October 29, 2013, at 04:01 AM

I'm seeing this in 2.2.61 whenever any of the following, all freshly installed from the cookbook area of PMwiki.org, are enabled:

  1. markuptounstyled.php
  2. signalwhenmarkup.php
  3. slimtoc.php
  4. extendmarkup.php
  5. break_page.php
  6. pagetoc.php
  7. sectionedit.php
  8. autotoc.php
  9. includeSite.php
  10. swf-sites.php
  11. JavaScript-Editable.php
  12. AMmathjax.php

The current php is - 5.5.7, again freshly installed.

The spellchecker.php is working fine in the install. Bob Sanders?

Thanks for your report. I released a new version of Cookbook.AutoTOC which should fix the problem with this recipe. You may try contacting the other authors and ask them to update their recipes for PHP 5.5. --Petko February 05, 2014, at 11:34 AM

To follow up, this was happening on cleanly installed Gentoo system. The php.ini that is getting installed is a development php, which has all warnings and such turned on. Replacing those with production php.ini solved all the issues. My apologies for not realizing that before posting the above. Bob?

Having this problem with multiple messages of Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/cornellbox/cornellbox.com/pmwiki/pmwiki.php on line 1698 Using version 2.2.80 and running PHP 5.6 --psproefrock? Oct 30, 2015

Please follow the instructions at PmWiki.Troubleshooting to find out which recipes need to be updated for PHP 5.6: enable diagnostics then go to pmwiki.php?action=ruleset; alternatively disable all recipes and re-enable them one after another to see which ones cause the warnings to appear. --Petko October 30, 2015, at 11:32 PM

That's very useful. It helped narrow down the problem to the skin I was using and helped get that cleared. --psproefrock? Dec 13, 2015

Problems with specific recipes

I hope this is the right place for this question (I followed the link from Troubleshooting).

I'm updating everything in PHP 5.5 and I am not able to update some recipes by myself: Cluster and Tagger. I asked for help to the author, but she has not time «at the moment, nor in the forseeable future» ( Kathryn Andersen). This puts me in trouble since these two recipes are important to the structure of my site under construction. So I ask for help to the PmWiki's experts, if and when you have time. Thanks in advance. -- Frank - May 15, 2014, at 10:22 PM

I've never used these recipes but I modified them to use the Markup_e() function which is compatible with PHP 5.5 and I don't get "deprecated" warnings. Get Attach:cluster.php and Attach:tagger.php, try them and report any problems (I still haven't used them). --Petko May 15, 2014, at 10:51 PM

Perfect. Both recipes work without problems. Thanks a lot Petko, very fast and accurate... impressive! -- Frank - May 16, 2014, at 03:54 AM


Problems with the blix skin

NOTE: I've now submitted a patch for this (please see ps below)


The blix skin fails with newer versions of PHP

I found the problem (see below) and created a github ticket, but no response from the author.

  Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

thanks

ps. in trying to figure out my own solution, I notice that the SkinGuidelines page still shows an example with the now disallowed /e modifier:

The skin maintainer DaveG has been active and very helpful in the PmWiki community for many years. Try contacting him directly via e-mail at "pmwiki (snail) solidgone (period) com". If impossible, as the license of the skin permits modification and distribution, it could be forked. --Petko March 04, 2015, at 08:28 PM


Cookbook:ImageMap

Also finding this problem on the Imagemap recipe. The imagemap.php is only a short file but I have no idea how to amend it. --Dragonfly July 11, 2015, at 10:43 AM

I sent a message to the developer, should be fixed soon. If you're in a hurry, replace line 53:

  Markup('area', 'directives', "/\\(:area (.*?)?\\s*?:\\)/e", "MapArea('$1')");

with:

  Markup_e('area', 'directives', "/\\(:area (.*?)?\\s*?:\\)/", "MapArea(\$m[1])");

Or wait for the release of the new version by Hans. --Petko July 11, 2015, at 07:14 AM

That's great, thanks very much! That's also showed me how to fix a couple of others I'd found. Much obliged. --Dragonfly July 21, 2015, at 2:54 PM

If these are recipes from the Cookbook, feel free to contact their authors or leave the solutions at the talk pages. --Petko July 21, 2015, at 09:27 AM


Cookbook:PageTableOfContents has been fixed as of 2015-08-14. greenman? September 08, 2015, at 04:50 PM


or swf.php

Also finding this problem on the flash, flash2, swf-sites, swf recipe. Where can i find help to correct the problem.

In swf.php i tried to change this line :

Markup('swf', '<urllink',

  "/\\b(?>(\\L))([^\\s$UrlExcludeChars]+\\.swf)/e",
  "Keep(\$GLOBALS['LinkFunctions']['$1'](\$pagename,'$1','$1',NULL,'$1$2',
    \$GLOBALS['SwfTagFmt']), 'L')");

with this:

Markup_e('swf', '<urllink',

  "/\\b(?>(\\L))([^\\s$UrlExcludeChars]+\\.swf)/",
  "Keep(\$GLOBALS['LinkFunctions'][\$m[1]](\$pagename,\$m[1],\$m[1],NULL,\$m[1]\$m[2],
    \$GLOBALS['SwfTagFmt']), 'L')");

but I generated unexpected '$m' (T_VARIABLE) error .

At the end of the third line, there should be a dot between \$m[1] and \$m[2]: NULL,\$m[1].\$m[2], --Petko December 11, 2015, at 08:00 PM

In Flash.php i tried to change this line :

Markup('flash', '<img', "/\\(:flash (.*?:)(.*?)(\\s.*?)?\\s*?:\\)/e", "ShowFlash('$1','$2','$3')");

with

Markup_e('flash', '<img', "/\\(:flash (.*?:)(.*?)(\\s.*?)?\\s*?:\\)", "ShowFlash('$1','$2','$3')");

This time, there is no error but it does not embed my swf file in my page. I don't understand what are the '$1' etc and if i must change them by \$m[1] (which changes nothing) or in another variable.

An idea?

--Jvamp January 25, 2016, at 01:30 AM Dec 12, 2015, at 00:57 AM

Yes, you should change '$1' to \$m[1], also note you have deleted the last "/e", you should only delete "e" and keep "/":
Markup_e('flash', '<img', "/\\(:flash (.*?:)(.*?)(\\s.*?)?\\s*?:\\)/", "ShowFlash(\$m[1], \$m[2], \$m[3])");
Note, this should fix your Markup_e() calls without errors, but I haven't tested the modules. --Petko December 11, 2015, at 08:00 PM

For Flash, it works!!! Thanks a lot.

So the correct code is

Markup_e('swf', '<urllink',

  "/\\b(?>(\\L))([^\\s$UrlExcludeChars]+\\.swf)/",
  "Keep(\$GLOBALS['LinkFunctions'][\$m[1]](\$pagename,\$m[1],\$m[2],NULL,\$m[1].\$m[2],
    \$GLOBALS['SwfTagFmt']), 'L')");

Should i change flash.php in the cookbook ?

--Jvamp January 25, 2016, at 01:30 AM Dec 13, 2015, at 11:01 AM

Try to contact the maintainers via e-mail if you can, and/or write to the talk page. If they cannot update their modules, and if the license permits modification and redistribution, feel free to upload the correct files (make sure you have tested them well). Otherwise you may link to this page so someone else needing the modules can find the informaiton. --Petko December 12, 2015, at 04:13 AM


Problems with PopupIFrame

Some days ago I asked for the update (php 7.2) of PopupIFrame to the author (Ccox), but it seems that he is too busy or is no longer the recipe maintainer. May some expert help me? The markup is too complex for me (there is not just the Markup_e, but $pagename and Keep also, so I do not know what to do). Thanks.

Frank - Feb 24, 2018, at 05:45 PM

Here is one way to update this (change Markup_e to Markup, then see "### change line" for more):

  Markup('popiframe1','<links','/%popiframe\\s*(.*?)%\\[\\[(.*?)\\]\\]/',
    "PopupIFrame"); ### change line

  Markup('popiframe2','<popiframe1',
    "/%popiframe\\s*(.*?)%(?>\\[\\[([^|\\]]*)\\|\\s*)(.*?)\\s*\\]\\]($SuffixPattern)/",
    "PopupIFrame"); ### change line

  function PopupIFrame ($m) {                 ### change line
    extract($GLOBALS["MarkupToHTML"]);        ### add line
    @list($m0, $opts, $tgt, $lbl, $sfx) = $m; ### add line

The Keep() block does not need to change. --Petko February 24, 2018, at 11:30 AM

Thank you so much -- Frank - Feb 25, 2018, at 01:23 AM


I searched for genealogy and when going to result https://www.pmwiki.org/wiki/Christian/GenealogySoftware I saw that the here mentioned issue is relevant for pmwiki.org itself... LaPingvino?

That group had an older addon enabled (table of contents). Now disabled. There may be other pages with older addons enabled here. Only such addons can cause these messages, see Troubleshooting. --Petko