Skip to content

Commit 832d4e7

Browse files
JeroenDeDauwclaude
andauthored
Pass language to File::getDimensionsString for MediaWiki 1.47 compatibility (#48)
* Pass language to File::getDimensionsString for MediaWiki 1.47 compatibility Fixes #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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bf2801c commit 832d4e7

4 files changed

Lines changed: 94 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ jobs:
3030
- mw: 'REL1_43'
3131
php: 8.3
3232
experimental: false
33+
- mw: 'REL1_44'
34+
php: 8.2
35+
experimental: false
36+
- mw: 'REL1_45'
37+
php: 8.3
38+
experimental: false
39+
- mw: 'REL1_46'
40+
php: 8.4
41+
experimental: false
3342
- mw: 'master'
3443
php: 8.4
3544
experimental: true
@@ -57,7 +66,7 @@ jobs:
5766
mediawiki
5867
!mediawiki/extensions/
5968
!mediawiki/vendor/
60-
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1
69+
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
6170

6271
- name: Cache Composer cache
6372
uses: actions/cache@v4
@@ -82,7 +91,14 @@ jobs:
8291
run: composer update
8392

8493
- name: Run PHPUnit
85-
run: php tests/phpunit/phpunit.php extensions/WikibaseLocalMedia/tests/
94+
run: |
95+
# MediaWiki 1.46 dropped tests/phpunit/phpunit.php in favour of a generated config.
96+
if [ -f tests/phpunit/phpunit.php ]; then
97+
php tests/phpunit/phpunit.php extensions/WikibaseLocalMedia/tests/
98+
else
99+
composer phpunit:config
100+
vendor/bin/phpunit extensions/WikibaseLocalMedia/tests/
101+
fi
86102
87103
PHPStan:
88104
name: "PHPStan: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
@@ -115,7 +131,7 @@ jobs:
115131
mediawiki
116132
mediawiki/extensions/
117133
mediawiki/vendor/
118-
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1
134+
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
119135

120136
- name: Cache Composer cache
121137
uses: actions/cache@v4
@@ -184,7 +200,7 @@ jobs:
184200
uses: actions/cache@v4
185201
with:
186202
path: ~/.composer/cache
187-
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1
203+
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
188204

189205
- uses: actions/checkout@v4
190206
with:

.github/workflows/installMediaWiki.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
MW_BRANCH=$1
44
EXTENSION_NAME=$2
55

6-
wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv
7-
8-
tar -zxf $MW_BRANCH.tar.gz
9-
mv mediawiki-$MW_BRANCH mediawiki
6+
# Clone rather than download the tarball: since MediaWiki 1.46 the test runner needs
7+
# phpunit.xml.template, which is marked export-ignore and therefore absent from tarballs.
8+
git clone --depth=1 --branch="$MW_BRANCH" https://github.com/wikimedia/mediawiki.git mediawiki
109

1110
cd mediawiki
1211

12+
# Composer 2.10+ refuses to install dependency versions flagged by security advisories.
13+
# Older MediaWiki branches pin such versions; allow them here as this is a throwaway CI install.
14+
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" );'
15+
16+
# Wikibase's REL1_45 and later branches pull in beta/dev stability dependencies.
17+
# prefer-stable keeps everything that has a stable release on its stable release.
18+
composer config minimum-stability dev
19+
composer config prefer-stable true
20+
1321
composer install
1422
php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser
1523

src/Services/InlineImageFormatter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ private function getCaptionHtml( Title $title, ?File $file = null ): string {
136136

137137
private function getFileMetaHtml( File $file ): string {
138138
return $this->language->semicolonList( [
139-
$file->getDimensionsString(),
139+
// @phpstan-ignore arguments.count ($lang required since MW 1.47, ignored on older versions)
140+
$file->getDimensionsString( $this->language ),
140141
htmlspecialchars( $this->language->formatSize( (int)$file->getSize() ) )
141142
] );
142143
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare( strict_types = 1 );
4+
5+
namespace Wikibase\LocalMedia\Tests\Integration;
6+
7+
use DataValues\StringValue;
8+
use File;
9+
use MediaWiki\MainConfigNames;
10+
use MediaWikiIntegrationTestCase;
11+
use ParserOptions;
12+
use RepoGroup;
13+
use Wikibase\LocalMedia\Services\InlineImageFormatter;
14+
use Wikibase\LocalMedia\Services\LocalImageLinker;
15+
16+
/**
17+
* @covers \Wikibase\LocalMedia\Services\InlineImageFormatter
18+
*/
19+
class InlineImageFormatterTest extends MediaWikiIntegrationTestCase {
20+
21+
public function testFileMetadataIncludesDimensions(): void {
22+
$this->overrideConfigValue( MainConfigNames::ResponsiveImages, false );
23+
$this->setService( 'RepoGroup', $this->newRepoGroupFindingFile() );
24+
25+
$html = $this->newFormatter()->format( new StringValue( 'Jonas-revenge.png' ) );
26+
27+
$this->assertStringContainsString( '800 × 600 pixels', $html );
28+
}
29+
30+
private function newRepoGroupFindingFile(): RepoGroup {
31+
$file = $this->createStub( File::class );
32+
$file->method( 'transform' )->willReturn( $this->newThumbnail() );
33+
$file->method( 'getDimensionsString' )->willReturn( '800 × 600 pixels' );
34+
$file->method( 'getSize' )->willReturn( 12345 );
35+
36+
$repoGroup = $this->createStub( RepoGroup::class );
37+
$repoGroup->method( 'findFile' )->willReturn( $file );
38+
39+
return $repoGroup;
40+
}
41+
42+
private function newThumbnail(): object {
43+
return new class {
44+
public function toHtml(): string {
45+
return '<img src="thumbnail.png">';
46+
}
47+
};
48+
}
49+
50+
private function newFormatter(): InlineImageFormatter {
51+
return new InlineImageFormatter(
52+
ParserOptions::newFromAnon(),
53+
[],
54+
'en',
55+
new LocalImageLinker(),
56+
'commons-media-caption'
57+
);
58+
}
59+
60+
}

0 commit comments

Comments
 (0)