Page MenuHomePhabricator

Mpdf extension / Mpdf library outdated and causing errors and warnings
Open, MediumPublic

Description

Setup

  • MediaWiki 1.33.0 (8e36379) 17:11, 5. Jul. 2019
  • PHP 7.2.19-0ubuntu0.18.04.1 (apache2handler)
  • Mpdf 0.9 (f6982a1) 11:33, 11. Okt. 2018

Issue
The Mpdf library is outdated and is causing errors and warnings:

  • ErrorException from line 10894 of /../vendor/mpdf/mpdf/mpdf.php: PHP Deprecated: The each() function is deprecated.
  • ErrorException from line 30648 of /../vendor/mpdf/mpdf/mpdf.php: PHP Warning: A non-numeric value encountered

Details

Event Timeline

Kghbln renamed this task from Mpdf extension / Mpdf libary outdated and causing errors and warnings to Mpdf extension / Mpdf library outdated and causing errors and warnings.Jul 8 2019, 2:03 PM
Kghbln updated the task description. (Show Details)

@Kghbln: Did @Pastakhov explicitly agree to work on fixing this task? Asking as you set Pastakhov as task assignee.

He is the only one working on the extension. However ...

Kghbln added a subscriber: Pastakhov.

yes, I'm one, I'll fix it when I get some time

@Pastakhov I will be great if you could have a peep.

Still remains for this new setup:

  • Mpdf 1.0 (3ac9540) 11:00, 12 July 2020
  • MediaWiki 1.35.0-rc.2 (37ef236) 17:21, 22 August 2020
  • PHP 7.2.24-0ubuntu0.18.04.6 (apache2handler)
  • mpdf/mpdf 6.1.3 GPL-2.0

I just saw this error with PHP 7.3.19 and it can be resolved by using mPDF v7 or v8. I tested quickly with v7, at first sight it mostly work except the constructor whose the signature changed:

diff --git a/MpdfAction.php b/MpdfAction.php
index c68a8d4..bca1249 100644
--- a/MpdfAction.php
+++ b/MpdfAction.php
@@ -95 +95 @@ class MpdfAction extends Action {
-                       $mpdf = new mPDF( $mode, $format, 0, '', $marginLeft, $marginRight, $marginTop, $marginBottom, $marginHeader, $marginFooter, $orientation );
+                       $mpdf = new \Mpdf\Mpdf( [ 'mode' => $mode, 'format' => $format, 'default_font_size' => 0, 'default_font' => '', 'margin_left' => $marginLeft, 'margin_right' => $marginRight, 'margin_top' => $marginTop, 'margin_bottom' => $marginBottom, 'margin_header' => $marginHeader, 'margin_footer' => $marginFooter, 'orientation' => $orientation ] );

According to requirements with PHP versions, the v8 also supports PHP 7.4, it could be worth testing if it works with the minimal patch above.

Change #1041660 had a related patch set uploaded (by Seb35; author: Seb35):

[mediawiki/extensions/Mpdf@master] Upgrade the library mPDF to 8.0.13

https://gerrit.wikimedia.org/r/1041660

The linked patch should work on PHP 5.6 → 8.1 according to the requirements of the library mPDF and I tested it on PHP 7.4. I will test it on PHP 8.1 in a few days.

Also, I link this task to T323797, which is similar in the sense "Upgrade the underlying library mPDF".

Seb35 triaged this task as Medium priority.Jun 15 2024, 10:15 AM

The patch from @Seb35 worked well until MediaWiki 1.43.5 - however, the MediaWiki Docker images for 1.43 (.6) are based on PHP 8.3.29, which is supported since mpdf 8.2.1

So I think, we would need to upgrade mpdf to 8.2.1.

I can file a patch for review, but unfortunately can only test on MediaWiki 1.43.6. @Pastakhov Do you have better testing capabilities? :)