From da9ca28a0027f9ea4d288fa2b20ccaf34619480f Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Fri, 12 Jun 2026 01:07:14 +0200 Subject: [PATCH 1/3] Pass language to File::getDimensionsString for MediaWiki 1.47 compatibility Fixes https://github.com/ProfessionalWiki/WikibaseLocalMedia/issues/47 File::getDimensionsString() gained a required $lang parameter in MediaWiki 1.47 (optional since 1.46), so calling it without arguments threw an ArgumentCountError when rendering local media values. Passing the content language works across the whole supported range: it is harmlessly ignored on 1.45 and earlier, satisfies the optional parameter on 1.46, and the required one on 1.47+. The existing formatting tests format a non-existent file and never reach the metadata path. InlineImageFormatterTest stubs RepoGroup to return a file, exercising getDimensionsString so a regression is caught on versions where the parameter is required. CI: add REL1_44/45/46 to the matrix, and repair the install script so the matrix runs again: disable Composer 2.10's security-advisory blocking (older branches pin flagged dependency versions) and allow dev/beta stability for the master job's Wikibase dependencies. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/ci.yml | 9 +++ .github/workflows/installMediaWiki.sh | 10 ++++ src/Services/InlineImageFormatter.php | 3 +- .../Integration/InlineImageFormatterTest.php | 60 +++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/php/Integration/InlineImageFormatterTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc2ad43..e5eaab3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,15 @@ jobs: - mw: 'REL1_43' php: 8.3 experimental: false + - mw: 'REL1_44' + php: 8.2 + experimental: false + - mw: 'REL1_45' + php: 8.3 + experimental: false + - mw: 'REL1_46' + php: 8.4 + experimental: false - mw: 'master' php: 8.4 experimental: true diff --git a/.github/workflows/installMediaWiki.sh b/.github/workflows/installMediaWiki.sh index 3ee0757..c6dd6d8 100644 --- a/.github/workflows/installMediaWiki.sh +++ b/.github/workflows/installMediaWiki.sh @@ -10,6 +10,16 @@ mv mediawiki-$MW_BRANCH mediawiki cd mediawiki +# Composer 2.10+ refuses to install dependency versions flagged by security advisories. +# Older MediaWiki branches pin such versions; allow them here as this is a throwaway CI install. +php -r '$f = "composer.json"; $c = json_decode( file_get_contents( $f ), true ); $c["config"]["policy"]["advisories"]["block"] = false; file_put_contents( $f, json_encode( $c, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . "\n" );' + +# Wikibase's development branch pulls in beta/dev stability dependencies. +if [ "$MW_BRANCH" == "master" ]; then + composer config minimum-stability dev + composer config prefer-stable true +fi + composer install php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser diff --git a/src/Services/InlineImageFormatter.php b/src/Services/InlineImageFormatter.php index b16f481..5863892 100644 --- a/src/Services/InlineImageFormatter.php +++ b/src/Services/InlineImageFormatter.php @@ -136,7 +136,8 @@ private function getCaptionHtml( Title $title, ?File $file = null ): string { private function getFileMetaHtml( File $file ): string { return $this->language->semicolonList( [ - $file->getDimensionsString(), + // @phpstan-ignore arguments.count ($lang required since MW 1.47, ignored on older versions) + $file->getDimensionsString( $this->language ), htmlspecialchars( $this->language->formatSize( (int)$file->getSize() ) ) ] ); } diff --git a/tests/php/Integration/InlineImageFormatterTest.php b/tests/php/Integration/InlineImageFormatterTest.php new file mode 100644 index 0000000..b9c7260 --- /dev/null +++ b/tests/php/Integration/InlineImageFormatterTest.php @@ -0,0 +1,60 @@ +overrideConfigValue( MainConfigNames::ResponsiveImages, false ); + $this->setService( 'RepoGroup', $this->newRepoGroupFindingFile() ); + + $html = $this->newFormatter()->format( new StringValue( 'Jonas-revenge.png' ) ); + + $this->assertStringContainsString( '800 × 600 pixels', $html ); + } + + private function newRepoGroupFindingFile(): RepoGroup { + $file = $this->createStub( File::class ); + $file->method( 'transform' )->willReturn( $this->newThumbnail() ); + $file->method( 'getDimensionsString' )->willReturn( '800 × 600 pixels' ); + $file->method( 'getSize' )->willReturn( 12345 ); + + $repoGroup = $this->createStub( RepoGroup::class ); + $repoGroup->method( 'findFile' )->willReturn( $file ); + + return $repoGroup; + } + + private function newThumbnail(): object { + return new class { + public function toHtml(): string { + return ''; + } + }; + } + + private function newFormatter(): InlineImageFormatter { + return new InlineImageFormatter( + ParserOptions::newFromAnon(), + [], + 'en', + new LocalImageLinker(), + 'commons-media-caption' + ); + } + +} From f843c88ebdf7d332163c097b43c0375dab85ec57 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Fri, 12 Jun 2026 01:15:22 +0200 Subject: [PATCH 2/3] Fix CI for MediaWiki 1.45-1.47 Wikibase REL1_45 and later pull in a beta-stability dependency, so allow dev/beta stability for every branch (prefer-stable keeps everything else on stable). MediaWiki 1.46 dropped tests/phpunit/phpunit.php, so generate the PHPUnit config and run vendor/bin/phpunit there instead. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/ci.yml | 9 ++++++++- .github/workflows/installMediaWiki.sh | 9 ++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5eaab3..cd5f50e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,7 +91,14 @@ jobs: run: composer update - name: Run PHPUnit - run: php tests/phpunit/phpunit.php extensions/WikibaseLocalMedia/tests/ + run: | + # MediaWiki 1.46 dropped tests/phpunit/phpunit.php in favour of a generated config. + if [ -f tests/phpunit/phpunit.php ]; then + php tests/phpunit/phpunit.php extensions/WikibaseLocalMedia/tests/ + else + composer phpunit:config + vendor/bin/phpunit extensions/WikibaseLocalMedia/tests/ + fi PHPStan: name: "PHPStan: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}" diff --git a/.github/workflows/installMediaWiki.sh b/.github/workflows/installMediaWiki.sh index c6dd6d8..070b1d4 100644 --- a/.github/workflows/installMediaWiki.sh +++ b/.github/workflows/installMediaWiki.sh @@ -14,11 +14,10 @@ cd mediawiki # Older MediaWiki branches pin such versions; allow them here as this is a throwaway CI install. php -r '$f = "composer.json"; $c = json_decode( file_get_contents( $f ), true ); $c["config"]["policy"]["advisories"]["block"] = false; file_put_contents( $f, json_encode( $c, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . "\n" );' -# Wikibase's development branch pulls in beta/dev stability dependencies. -if [ "$MW_BRANCH" == "master" ]; then - composer config minimum-stability dev - composer config prefer-stable true -fi +# Wikibase's REL1_45 and later branches pull in beta/dev stability dependencies. +# prefer-stable keeps everything that has a stable release on its stable release. +composer config minimum-stability dev +composer config prefer-stable true composer install php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser From d9519e23cf6ef69fca09ea59662190ba03859aff Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Fri, 12 Jun 2026 01:20:30 +0200 Subject: [PATCH 3/3] Clone MediaWiki in CI so the 1.46+ PHPUnit config can be generated The GitHub tarball omits export-ignored files such as phpunit.xml.template, which MediaWiki 1.46 and later need to generate their PHPUnit config. Clone the repository instead, and bump the MediaWiki cache key so stale tarball caches are rebuilt. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/ci.yml | 6 +++--- .github/workflows/installMediaWiki.sh | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd5f50e..446edc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: mediawiki !mediawiki/extensions/ !mediawiki/vendor/ - key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1 + key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2 - name: Cache Composer cache uses: actions/cache@v4 @@ -131,7 +131,7 @@ jobs: mediawiki mediawiki/extensions/ mediawiki/vendor/ - key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1 + key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2 - name: Cache Composer cache uses: actions/cache@v4 @@ -200,7 +200,7 @@ jobs: uses: actions/cache@v4 with: path: ~/.composer/cache - key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1 + key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2 - uses: actions/checkout@v4 with: diff --git a/.github/workflows/installMediaWiki.sh b/.github/workflows/installMediaWiki.sh index 070b1d4..f05f98e 100644 --- a/.github/workflows/installMediaWiki.sh +++ b/.github/workflows/installMediaWiki.sh @@ -3,10 +3,9 @@ MW_BRANCH=$1 EXTENSION_NAME=$2 -wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv - -tar -zxf $MW_BRANCH.tar.gz -mv mediawiki-$MW_BRANCH mediawiki +# Clone rather than download the tarball: since MediaWiki 1.46 the test runner needs +# phpunit.xml.template, which is marked export-ignore and therefore absent from tarballs. +git clone --depth=1 --branch="$MW_BRANCH" https://github.com/wikimedia/mediawiki.git mediawiki cd mediawiki