diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc2ad43..446edc2 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 @@ -57,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 @@ -82,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 }}" @@ -115,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 @@ -184,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 3ee0757..f05f98e 100644 --- a/.github/workflows/installMediaWiki.sh +++ b/.github/workflows/installMediaWiki.sh @@ -3,13 +3,21 @@ 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 +# 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 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 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' + ); + } + +}