Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/installMediaWiki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/Services/InlineImageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) )
] );
}
Expand Down
60 changes: 60 additions & 0 deletions tests/php/Integration/InlineImageFormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare( strict_types = 1 );

namespace Wikibase\LocalMedia\Tests\Integration;

use DataValues\StringValue;
use File;
use MediaWiki\MainConfigNames;
use MediaWikiIntegrationTestCase;
use ParserOptions;
use RepoGroup;
use Wikibase\LocalMedia\Services\InlineImageFormatter;
use Wikibase\LocalMedia\Services\LocalImageLinker;

/**
* @covers \Wikibase\LocalMedia\Services\InlineImageFormatter
*/
class InlineImageFormatterTest extends MediaWikiIntegrationTestCase {

public function testFileMetadataIncludesDimensions(): void {
$this->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 '<img src="thumbnail.png">';
}
};
}

private function newFormatter(): InlineImageFormatter {
return new InlineImageFormatter(
ParserOptions::newFromAnon(),
[],
'en',
new LocalImageLinker(),
'commons-media-caption'
);
}

}
Loading