Fixed PHP 7.0 bug

25 views
Skip to first unread message

mikifus

unread,
May 10, 2016, 3:39:10 AM5/10/16
to MediaWiki Widgets
Hi,

I know this doesn't belong here, I didn't want to open an account with the LDAP thing.

I used the extension on PHP 7.0, it broke my test site. The bug is due to a deprecated command being used in preg_replace. I just fixed it as it was easier than downgrading PHP.

On Widgets/WidgetRenderer.php, line 140, method processEncodedWidgetOutput, replace this:

  $text = preg_replace(
  '/ENCODED_CONTENT ' . self::$mRandomString . '([0-9a-zA-Z\/+]+=*)* END_ENCODED_CONTENT/esm',
  'base64_decode("$1")',
  $text
  );

With this:

$text = preg_replace_callback(
'/ENCODED_CONTENT ' . self::$mRandomString . '([0-9a-zA-Z\/+]+=*)* END_ENCODED_CONTENT/sm',
function($matches) {
                                  return base64_decode($matches[1]);
},
$text
);

The full method looks like this:

public static function processEncodedWidgetOutput( &$out, &$text ) {
// Find all hidden content and restore to normal
$text = preg_replace_callback(
'/ENCODED_CONTENT ' . self::$mRandomString . '([0-9a-zA-Z\/+]+=*)* END_ENCODED_CONTENT/sm',
function($matches) {
                                  return base64_decode($matches[1]);
},
$text
);

return true;
}

I only tested this in my own environment.

Karsten Hoffmeyer

unread,
May 10, 2016, 5:15:24 AM5/10/16
to MediaWiki Widgets
Heiya Mikifus,

first of all thanks a lot for reporting the issue and posting a solution for it. That's the way.

I just had a look and it appears that this fix was already authored back in 2013 [0] and is part of the releases made for the Widgets extension starting with version 1.0. I believe that you are still using an earlier version? Try to move in the code for the 1.2.1 release and you should be fine too.

Cheers Karsten

[0] https://phabricator.wikimedia.org/rEWID0bb49ddcd139daa87dec38655e8ca11f4c62814f

mikifus

unread,
May 10, 2016, 4:04:44 PM5/10/16
to MediaWiki Widgets
Hi!

Stupid me, I didn't check the version twice. I actually downloaded the lastest version but looks like something failed during the update, I see the fix is way better implemented than mine.

Thanks!
Reply all
Reply to author
Forward
0 new messages