diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3dcdfb6..791ea37 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,36 +12,30 @@ on:
jobs:
test:
name: "PHPUnit: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
+ continue-on-error: ${{ matrix.experimental }}
strategy:
+ fail-fast: false
matrix:
include:
- - mw: 'REL1_43'
- php: 8.3
- - mw: 'REL1_42'
- php: 8.2
- - mw: 'REL1_41'
- php: 8.1
- - mw: 'REL1_40'
- php: 8.0
- mw: 'REL1_39'
php: 8.0
- composer: v2
- - mw: 'REL1_38'
- php: 8.0
- composer: v2
- - mw: 'REL1_37'
- php: 8.0
- composer: v2
- - mw: 'REL1_36'
- php: 7.4
- composer: v1
- - mw: 'REL1_35'
- php: 7.3
- composer: v1
- - mw: 'REL1_34'
- php: 7.2
- composer: v1
+ experimental: false
+ - mw: 'REL1_40'
+ php: 8.1
+ experimental: false
+ - mw: 'REL1_41'
+ php: 8.2
+ experimental: false
+ - mw: 'REL1_42'
+ php: 8.2
+ experimental: false
+ - mw: 'REL1_43'
+ php: 8.3
+ experimental: false
+ - mw: 'master'
+ php: 8.4
+ experimental: true
runs-on: ubuntu-latest
@@ -56,25 +50,25 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl
- tools: composer:${{ matrix.composer }}
+ tools: composer:v2
- name: Cache MediaWiki
id: cache-mediawiki
- uses: actions/cache@v2
+ uses: actions/cache@v4
with:
path: |
mediawiki
!mediawiki/extensions/
!mediawiki/vendor/
- key: mw_${{ matrix.mw }}-php${{ matrix.php }}-v21
+ key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1
- name: Cache Composer cache
- uses: actions/cache@v2
+ uses: actions/cache@v4
with:
path: ~/.composer/cache
key: composer-php${{ matrix.php }}
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
with:
path: EarlyCopy
@@ -83,7 +77,7 @@ jobs:
working-directory: ~
run: bash EarlyCopy/.github/workflows/installMediaWiki.sh ${{ matrix.mw }} WikibaseLocalMedia
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
with:
path: mediawiki/extensions/WikibaseLocalMedia
@@ -92,3 +86,119 @@ jobs:
- name: Run PHPUnit
run: php tests/phpunit/phpunit.php extensions/WikibaseLocalMedia/tests/
+
+ PHPStan:
+ name: "PHPStan: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
+
+ strategy:
+ matrix:
+ include:
+ - mw: 'REL1_43'
+ php: '8.3'
+
+ runs-on: ubuntu-latest
+
+ defaults:
+ run:
+ working-directory: mediawiki
+
+ steps:
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: mbstring
+ tools: composer, cs2pr
+
+ - name: Cache MediaWiki
+ id: cache-mediawiki
+ uses: actions/cache@v4
+ with:
+ path: |
+ mediawiki
+ mediawiki/extensions/
+ mediawiki/vendor/
+ key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1
+
+ - name: Cache Composer cache
+ uses: actions/cache@v4
+ with:
+ path: ~/.composer/cache
+ key: composer_static_analysis
+
+ - uses: actions/checkout@v4
+ with:
+ path: EarlyCopy
+
+ - name: Install MediaWiki
+ if: steps.cache-mediawiki.outputs.cache-hit != 'true'
+ working-directory: ~
+ run: bash EarlyCopy/.github/workflows/installMediaWiki.sh ${{ matrix.mw }} WikibaseLocalMedia
+
+ - uses: actions/checkout@v4
+ with:
+ path: mediawiki/extensions/WikibaseLocalMedia
+
+ - name: Composer allow-plugins
+ run: composer config --no-plugins allow-plugins.composer/installers true
+
+ - run: composer update
+
+ - name: Composer install
+ run: cd extensions/WikibaseLocalMedia && composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
+
+ - name: PHPStan
+ run: cd extensions/WikibaseLocalMedia && php vendor/bin/phpstan analyse --error-format=checkstyle --no-progress | cs2pr
+
+ phpcs:
+ name: "Code style: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
+
+ strategy:
+ matrix:
+ include:
+ - mw: 'REL1_43'
+ php: '8.3'
+
+ runs-on: ubuntu-latest
+
+ defaults:
+ run:
+ working-directory: mediawiki/extensions/WikibaseLocalMedia
+
+ steps:
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: mbstring, intl, php-ast
+ tools: composer
+
+ - name: Cache MediaWiki
+ id: cache-mediawiki
+ uses: actions/cache@v4
+ with:
+ path: |
+ mediawiki
+ !mediawiki/extensions/
+ !mediawiki/vendor/
+ key: mw_static_analysis
+
+ - name: Cache Composer cache
+ uses: actions/cache@v4
+ with:
+ path: ~/.composer/cache
+ key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v1
+
+ - name: Install MediaWiki
+ if: steps.cache-mediawiki.outputs.cache-hit != 'true'
+ working-directory: ~
+ run: bash EarlyCopy/.github/workflows/installMediaWiki.sh ${{ matrix.mw }} WikibaseLocalMedia
+
+ - uses: actions/checkout@v4
+ with:
+ path: mediawiki/extensions/WikibaseLocalMedia
+
+ - name: Composer install
+ run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
+
+ - run: vendor/bin/phpcs -p -s
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..cc93ade
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,34 @@
+# Commands run from inside the MediaWiki container ##########################################################
+
+ci: test cs
+test: phpunit
+cs: phpcs stan
+
+phpunit:
+ifdef filter
+ php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --filter $(filter)
+else
+ php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist
+endif
+
+perf:
+ php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --group Performance
+
+phpcs:
+ vendor/bin/phpcs -p -s --standard=$(shell pwd)/phpcs.xml
+
+stan:
+ vendor/bin/phpstan analyse --configuration=phpstan.neon --memory-limit=2G
+
+stan-baseline:
+ vendor/bin/phpstan analyse --configuration=phpstan.neon --memory-limit=2G --generate-baseline
+
+
+
+# Commands run from the host machine #######################################################################
+
+npm-install:
+ docker run -it --rm -v "$(CURDIR)":/home/node/app -w /home/node/app -u node node:22 npm install
+
+lint:
+ docker run -it --rm -v "$(CURDIR)":/home/node/app -w /home/node/app -u node node:22 npm run lint
diff --git a/README.md b/README.md
index 3c6925d..da6d1df 100644
--- a/README.md
+++ b/README.md
@@ -22,9 +22,9 @@ Also see [this animated gif](https://twitter.com/i/status/1286293710112731137).
## Platform requirements
-* [PHP] 7.2 or later, including PHP 8.0
-* [MediaWiki] 1.34 up to 1.39
-* [Wikibase Repository] REL1_34, REL1_35, REL1_36, REL1_37, REL1_38, or REL1_39
+* [PHP] 7.4 or later
+* [MediaWiki] 1.39 or later
+* [Wikibase Repository] REL1_39 or later
For more information on the different versions of this extension, see the [release notes](#release-notes).
diff --git a/composer.json b/composer.json
index d353434..7f497ac 100644
--- a/composer.json
+++ b/composer.json
@@ -44,16 +44,17 @@
"source": "https://github.com/ProfessionalWiki/WikibaseLocalMedia/issues"
},
"require": {
- "php": ">=7.2",
+ "php": ">=7.4",
"composer/installers": "^2|^1.0.1"
},
"require-dev": {
- "vimeo/psalm": "dev-master",
- "phpstan/phpstan": "dev-master"
+ "phpstan/phpstan": "^2.1.6",
+ "mediawiki/mediawiki-codesniffer": "^46.0.0"
},
"config": {
"allow-plugins": {
- "composer/installers": true
+ "composer/installers": true,
+ "dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
diff --git a/extension.json b/extension.json
index 9844213..1bb7f3b 100644
--- a/extension.json
+++ b/extension.json
@@ -2,7 +2,7 @@
"name": "Wikibase Local Media",
"type": "wikibase",
- "version": "1.1.0",
+ "version": "2.0.0",
"author": [
"[https://www.EntropyWins.wtf/mediawiki Jeroen De Dauw]",
@@ -16,7 +16,7 @@
"license-name": "GPL-2.0-or-later",
"requires": {
- "MediaWiki": ">= 1.34.0",
+ "MediaWiki": ">= 1.39.0",
"extensions": {
"WikibaseRepository": "*"
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..d89a78e
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,9 @@
+
+
+ src/
+ tests/php
+
+
+
+
+
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
new file mode 100644
index 0000000..69014cd
--- /dev/null
+++ b/phpstan-baseline.neon
@@ -0,0 +1,91 @@
+parameters:
+ ignoreErrors:
+ -
+ message: '#^Access to undefined constant Wikibase\\Repo\\Rdf\\PropertyRdfBuilder\:\:OBJECT_PROPERTY\.$#'
+ identifier: classConstant.notFound
+ count: 1
+ path: src/HookHandlers.php
+
+ -
+ message: '#^Method Wikibase\\LocalMedia\\HookHandlers\:\:onResourceLoaderGetConfigVars\(\) has parameter \$vars with no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: src/HookHandlers.php
+
+ -
+ message: '#^Method Wikibase\\LocalMedia\\HookHandlers\:\:onWikibaseClientDataTypes\(\) has parameter \$dataTypeDefinitions with no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: src/HookHandlers.php
+
+ -
+ message: '#^Method Wikibase\\LocalMedia\\HookHandlers\:\:onWikibaseRepoDataTypes\(\) has parameter \$dataTypeDefinitions with no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: src/HookHandlers.php
+
+ -
+ message: '#^Method Wikibase\\LocalMedia\\Services\\FormatterBuilder\:\:__construct\(\) has parameter \$thumbLimits with no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: src/Services/FormatterBuilder.php
+
+ -
+ message: '#^Parameter \#3 \$languageCode of class Wikibase\\LocalMedia\\Services\\InlineImageFormatter constructor expects string, mixed given\.$#'
+ identifier: argument.type
+ count: 1
+ path: src/Services/FormatterBuilder.php
+
+ -
+ message: '#^Property Wikibase\\LocalMedia\\Services\\FormatterBuilder\:\:\$thumbLimits type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: src/Services/FormatterBuilder.php
+
+ -
+ message: '#^Instanceof between DataValues\\StringValue and DataValues\\StringValue will always evaluate to true\.$#'
+ identifier: instanceof.alwaysTrue
+ count: 1
+ path: src/Services/ImageLinkFormatter.php
+
+ -
+ message: '#^Constructor of class Wikibase\\LocalMedia\\Services\\InlineImageFormatter has an unused parameter \$languageCode\.$#'
+ identifier: constructor.unusedParameter
+ count: 1
+ path: src/Services/InlineImageFormatter.php
+
+ -
+ message: '#^Instanceof between DataValues\\StringValue and DataValues\\StringValue will always evaluate to true\.$#'
+ identifier: instanceof.alwaysTrue
+ count: 1
+ path: src/Services/InlineImageFormatter.php
+
+ -
+ message: '#^Method Wikibase\\LocalMedia\\Services\\InlineImageFormatter\:\:__construct\(\) has parameter \$thumbLimits with no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: src/Services/InlineImageFormatter.php
+
+ -
+ message: '#^Property Wikibase\\LocalMedia\\Services\\InlineImageFormatter\:\:\$thumbLimits type has no value type specified in iterable type array\.$#'
+ identifier: missingType.iterableValue
+ count: 1
+ path: src/Services/InlineImageFormatter.php
+
+ -
+ message: '#^Cannot call method getFullURL\(\) on MediaWiki\\Title\\Title\|null\.$#'
+ identifier: method.nonObject
+ count: 1
+ path: src/Services/LocalMediaRdfBuilder.php
+
+ -
+ message: '#^Parameter \#1 \$text of method MediaWiki\\Title\\TitleFactory\:\:newFromText\(\) expects int\|string\|null, mixed given\.$#'
+ identifier: argument.type
+ count: 1
+ path: src/Services/LocalMediaRdfBuilder.php
+
+ -
+ message: '#^Parameter \#2 \$thumbLimits of class Wikibase\\LocalMedia\\Services\\FormatterBuilder constructor expects array, mixed given\.$#'
+ identifier: argument.type
+ count: 1
+ path: src/WikibaseLocalMedia.php
\ No newline at end of file
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..a9bbdb1
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,14 @@
+includes:
+ - phpstan-baseline.neon
+
+parameters:
+ level: 9
+ paths:
+ - src
+ scanDirectories:
+ - ../../includes
+ - ../../tests/phpunit
+ - ../../vendor
+ - ../../extensions/Wikibase
+ bootstrapFiles:
+ - ../../includes/AutoLoader.php
\ No newline at end of file
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..8459bbd
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,12 @@
+
+
+
+ tests/
+
+
+
+
+ src
+
+
+
\ No newline at end of file
diff --git a/src/HookHandlers.php b/src/HookHandlers.php
index 87ccc78..b5da962 100644
--- a/src/HookHandlers.php
+++ b/src/HookHandlers.php
@@ -4,8 +4,8 @@
namespace Wikibase\LocalMedia;
-use ValueFormatters\FormatterOptions;
use MediaWiki\MediaWikiServices;
+use ValueFormatters\FormatterOptions;
final class HookHandlers {
@@ -13,24 +13,22 @@ public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ): v
$dataTypeDefinitions['PT:localMedia'] = [
'value-type' => 'string',
'expert-module' => 'jquery.valueview.experts.LocalMediaType',
- 'validator-factory-callback' => function() {
+ 'validator-factory-callback' => static function () {
return WikibaseLocalMedia::getGlobalInstance()->getValueValidators();
},
- 'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
- return WikibaseLocalMedia::getGlobalInstance()->getFormatterBuilder()->newFormatter( $format, $options );
+ 'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
+ return WikibaseLocalMedia::getGlobalInstance()
+ ->getFormatterBuilder()->newFormatter( $format, $options );
},
- 'rdf-builder-factory-callback' => function () {
+ 'rdf-builder-factory-callback' => static function () {
return WikibaseLocalMedia::getGlobalInstance()->getRdfBuilder();
},
- 'rdf-data-type' => function() {
+ 'rdf-data-type' => static function () {
+ /** @since MediaWiki 1.37 */
if ( class_exists( 'Wikibase\Repo\Rdf\PropertySpecificComponentsRdfBuilder' ) ) {
return \Wikibase\Repo\Rdf\PropertySpecificComponentsRdfBuilder::OBJECT_PROPERTY;
}
- if ( class_exists( 'Wikibase\Rdf\PropertyRdfBuilder' ) ) {
- return \Wikibase\Rdf\PropertyRdfBuilder::OBJECT_PROPERTY;
- }
-
return \Wikibase\Repo\Rdf\PropertyRdfBuilder::OBJECT_PROPERTY;
},
];
@@ -39,8 +37,9 @@ public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ): v
public static function onWikibaseClientDataTypes( array &$dataTypeDefinitions ): void {
$dataTypeDefinitions['PT:localMedia'] = [
'value-type' => 'string',
- 'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
- return WikibaseLocalMedia::getGlobalInstance()->getFormatterBuilder()->newFormatter( $format, $options );
+ 'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
+ return WikibaseLocalMedia::getGlobalInstance()
+ ->getFormatterBuilder()->newFormatter( $format, $options );
},
];
}
diff --git a/src/Services/FormatterBuilder.php b/src/Services/FormatterBuilder.php
index 8ee745e..3e7ba88 100644
--- a/src/Services/FormatterBuilder.php
+++ b/src/Services/FormatterBuilder.php
@@ -14,8 +14,8 @@
class FormatterBuilder {
- private $formatterBuilders;
- private $thumbLimits;
+ private WikibaseValueFormatterBuilders $formatterBuilders;
+ private array $thumbLimits;
public function __construct( WikibaseValueFormatterBuilders $formatterBuilders, array $thumbLimits ) {
$this->formatterBuilders = $formatterBuilders;
@@ -41,7 +41,7 @@ public function newFormatter( string $format, FormatterOptions $options ): Value
case SnakFormatter::FORMAT_WIKI:
return new CommonsThumbnailFormatter();
default:
- return $this->formatterBuilders->newStringFormatter( $format, $options );
+ return $this->formatterBuilders->newStringFormatter( $format );
}
}
diff --git a/src/Services/ImageLinkFormatter.php b/src/Services/ImageLinkFormatter.php
index f70a56c..073929c 100644
--- a/src/Services/ImageLinkFormatter.php
+++ b/src/Services/ImageLinkFormatter.php
@@ -12,8 +12,8 @@
class ImageLinkFormatter implements ValueFormatter {
- private $imageLinker;
- private $cssClass;
+ private ImageLinker $imageLinker;
+ private string $cssClass;
public function __construct( ImageLinker $imageLinker, string $cssClass ) {
$this->imageLinker = $imageLinker;
diff --git a/src/Services/InlineImageFormatter.php b/src/Services/InlineImageFormatter.php
index f43222b..99246f6 100644
--- a/src/Services/InlineImageFormatter.php
+++ b/src/Services/InlineImageFormatter.php
@@ -12,7 +12,6 @@
use Linker;
use MediaWiki\MediaWikiServices;
use ParserOptions;
-use RepoGroup;
use Title;
use ValueFormatters\ValueFormatter;
@@ -23,32 +22,18 @@
*/
class InlineImageFormatter implements ValueFormatter {
- const FALLBACK_THUMBNAIL_WIDTH = 320; // 320 the was default hardcoded value. Removed in T224189
+ // 320 the was default hardcoded value. Removed in T224189
+ private const FALLBACK_THUMBNAIL_WIDTH = 320;
- /**
- * @var Language
- */
- private $language;
+ private Language $language;
- /**
- * @var ParserOptions
- */
- private $parserOptions;
+ private ParserOptions $parserOptions;
- /**
- * @var array
- */
- private $thumbLimits;
+ private array $thumbLimits;
- /**
- * @var ImageLinker
- */
- private $imageLinker;
+ private ImageLinker $imageLinker;
- /**
- * @var string
- */
- private $captionCssClass;
+ private string $captionCssClass;
/**
* @param ParserOptions $parserOptions Options for thumbnail size
@@ -115,16 +100,11 @@ public function format( $value ) {
return $this->wrapThumb( $title, $thumb->toHtml() ) . $this->getCaptionHtml( $title, $file );
}
- private function getThumbWidth( $thumbSize ) {
+ private function getThumbWidth( int $thumbSize ): int {
return $this->thumbLimits[$thumbSize] ?? self::FALLBACK_THUMBNAIL_WIDTH;
}
- /**
- * @param Title $title
- * @param string $thumbHtml
- * @return string HTML
- */
- private function wrapThumb( Title $title, $thumbHtml ) {
+ private function wrapThumb( Title $title, string $thumbHtml ): string {
$attributes = [
'class' => 'image',
'href' => $this->imageLinker->buildUrl( $title )
@@ -137,12 +117,7 @@ private function wrapThumb( Title $title, $thumbHtml ) {
);
}
- /**
- * @param Title $title
- * @param File|null $file
- * @return string HTML
- */
- private function getCaptionHtml( Title $title, $file = null ) {
+ private function getCaptionHtml( Title $title, ?File $file = null ): string {
$attributes = [
'href' => $this->imageLinker->buildUrl( $title )
];
@@ -159,14 +134,10 @@ private function getCaptionHtml( Title $title, $file = null ) {
);
}
- /**
- * @param File $file
- * @return string HTML
- */
- private function getFileMetaHtml( File $file ) {
+ private function getFileMetaHtml( File $file ): string {
return $this->language->semicolonList( [
$file->getDimensionsString(),
- htmlspecialchars( $this->language->formatSize( $file->getSize() ) )
+ htmlspecialchars( $this->language->formatSize( (int)$file->getSize() ) )
] );
}
diff --git a/src/Services/LocalImageLinker.php b/src/Services/LocalImageLinker.php
index 20abbb8..e8838e4 100644
--- a/src/Services/LocalImageLinker.php
+++ b/src/Services/LocalImageLinker.php
@@ -13,4 +13,3 @@ public function buildUrl( Title $title ): string {
}
}
-
diff --git a/src/Services/LocalMediaRdfBuilder35.php b/src/Services/LocalMediaRdfBuilder.php
similarity index 82%
rename from src/Services/LocalMediaRdfBuilder35.php
rename to src/Services/LocalMediaRdfBuilder.php
index e7de0b1..e8cafb6 100644
--- a/src/Services/LocalMediaRdfBuilder35.php
+++ b/src/Services/LocalMediaRdfBuilder.php
@@ -8,12 +8,9 @@
use TitleFactory;
use Wikibase\Repo\Rdf\Values\ObjectUriRdfBuilder;
-/**
- * MediaWiki 1.35+
- */
-class LocalMediaRdfBuilder35 extends ObjectUriRdfBuilder {
+class LocalMediaRdfBuilder extends ObjectUriRdfBuilder {
- private $titleFactory;
+ private TitleFactory $titleFactory;
public function __construct( TitleFactory $titleFactory ) {
$this->titleFactory = $titleFactory;
diff --git a/src/Services/LocalMediaRdfBuilder34.php b/src/Services/LocalMediaRdfBuilder34.php
deleted file mode 100644
index d2e300d..0000000
--- a/src/Services/LocalMediaRdfBuilder34.php
+++ /dev/null
@@ -1,24 +0,0 @@
-getValue(), NS_FILE )->getFullURL();
- }
-
-}
diff --git a/src/WikibaseLocalMedia.php b/src/WikibaseLocalMedia.php
index d7ec659..8215078 100644
--- a/src/WikibaseLocalMedia.php
+++ b/src/WikibaseLocalMedia.php
@@ -7,13 +7,15 @@
use MediaWiki\MediaWikiServices;
use ValueValidators\ValueValidator;
use Wikibase\LocalMedia\Services\FormatterBuilder;
-use Wikibase\LocalMedia\Services\LocalMediaRdfBuilder34;
-use Wikibase\LocalMedia\Services\LocalMediaRdfBuilder35;
+use Wikibase\LocalMedia\Services\LocalMediaRdfBuilder;
use Wikibase\Repo\WikibaseRepo;
class WikibaseLocalMedia {
- protected static /* ?self */ $instance;
+ /**
+ * @var ?self
+ */
+ protected static $instance;
public static function getGlobalInstance(): self {
if ( !isset( self::$instance ) ) {
@@ -27,7 +29,7 @@ protected static function newDefault(): self {
return new static();
}
- protected final function __construct() {
+ final protected function __construct() {
}
/**
@@ -44,12 +46,8 @@ public function getFormatterBuilder(): FormatterBuilder {
);
}
- public function getRdfBuilder() {
- if ( method_exists( MediaWikiServices::getInstance(), 'getTitleFactory' ) ) {
- return new LocalMediaRdfBuilder35( MediaWikiServices::getInstance()->getTitleFactory() );
- }
-
- return new LocalMediaRdfBuilder34();
+ public function getRdfBuilder(): LocalMediaRdfBuilder {
+ return new LocalMediaRdfBuilder( MediaWikiServices::getInstance()->getTitleFactory() );
}
}
diff --git a/tests/php/Integration/FormattingTest.php b/tests/php/Integration/FormattingTest.php
index d016714..a8fb299 100644
--- a/tests/php/Integration/FormattingTest.php
+++ b/tests/php/Integration/FormattingTest.php
@@ -35,7 +35,7 @@ public function formattingProvider() {
}
private function newFormatterForFormat( string $format ): ValueFormatter {
- return $formatter = WikibaseLocalMedia::getGlobalInstance()->getFormatterBuilder()->newFormatter(
+ return WikibaseLocalMedia::getGlobalInstance()->getFormatterBuilder()->newFormatter(
$format,
$this->newOptions()
);
diff --git a/tests/php/Integration/ValidationTest.php b/tests/php/Integration/ValidationTest.php
index 3ec33cb..e77377e 100644
--- a/tests/php/Integration/ValidationTest.php
+++ b/tests/php/Integration/ValidationTest.php
@@ -18,8 +18,8 @@ public function testValidationSucceeds() {
$this->assertNotEmpty( $validators );
- foreach ( $validators as $validator ) {
- $this->assertEmpty( $validator->validate( new StringValue( 'Valid-value.png' ) )->getErrors() );
+ foreach ( $validators as $validator ) {
+ $this->assertCount( 0, $validator->validate( new StringValue( 'Valid-value.png' ) )->getErrors() );
}
}
@@ -30,7 +30,7 @@ public function testValidationFails() {
$errors = [];
- foreach ( $validators as $validator ) {
+ foreach ( $validators as $validator ) {
$errors = array_merge( $errors, $validator->validate( new StringValue( 'Invalid-value' ) )->getErrors() );
}
diff --git a/tests/php/Unit/ImageLinkFormatterTest.php b/tests/php/Unit/ImageLinkFormatterTest.php
index 33306a5..81c6ddd 100644
--- a/tests/php/Unit/ImageLinkFormatterTest.php
+++ b/tests/php/Unit/ImageLinkFormatterTest.php
@@ -21,8 +21,7 @@ public function testCssClass() {
'class="kittens"',
$formatter->format( new StringValue( 'MyImage.png' ) )
);
- }
- else {
+ } else {
$this->assertContains(
'class="kittens"',
$formatter->format( new StringValue( 'MyImage.png' ) )
diff --git a/tests/php/Unit/LocalMediaRdfBuilderTest.php b/tests/php/Unit/LocalMediaRdfBuilderTest.php
index 5341e55..0b64dcc 100644
--- a/tests/php/Unit/LocalMediaRdfBuilderTest.php
+++ b/tests/php/Unit/LocalMediaRdfBuilderTest.php
@@ -10,12 +10,12 @@
use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Snak\PropertyValueSnak;
-use Wikibase\LocalMedia\Services\LocalMediaRdfBuilder35;
+use Wikibase\LocalMedia\Services\LocalMediaRdfBuilder;
use Wikibase\LocalMedia\WikibaseLocalMedia;
use Wikimedia\Purtle\NTriplesRdfWriter;
/**
- * @covers \Wikibase\LocalMedia\Services\LocalMediaRdfBuilder35
+ * @covers \Wikibase\LocalMedia\Services\LocalMediaRdfBuilder
* @group Wikibase
* @group WikibaseRdf
* @license GPL-2.0-or-later
@@ -23,11 +23,7 @@
class LocalMediaRdfBuilderTest extends TestCase {
public function testAddValue() {
- if ( !method_exists( MediaWikiServices::getInstance(), 'getTitleFactory' ) ) {
- $this->markTestSkipped( 'Need MW 1.35+' );
- }
-
- $builder = new LocalMediaRdfBuilder35( MediaWikiServices::getInstance()->getTitleFactory() );
+ $builder = new LocalMediaRdfBuilder( MediaWikiServices::getInstance()->getTitleFactory() );
$writer = new NTriplesRdfWriter();
$writer->prefix( 'www', "http://www/" );