Skip to content

Commit da9ca28

Browse files
JeroenDeDauwclaude
andcommitted
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>
1 parent bf2801c commit da9ca28

4 files changed

Lines changed: 81 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 0 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

.github/workflows/installMediaWiki.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ mv mediawiki-$MW_BRANCH mediawiki
1010

1111
cd mediawiki
1212

13+
# Composer 2.10+ refuses to install dependency versions flagged by security advisories.
14+
# Older MediaWiki branches pin such versions; allow them here as this is a throwaway CI install.
15+
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" );'
16+
17+
# Wikibase's development branch pulls in beta/dev stability dependencies.
18+
if [ "$MW_BRANCH" == "master" ]; then
19+
composer config minimum-stability dev
20+
composer config prefer-stable true
21+
fi
22+
1323
composer install
1424
php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser
1525

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)