From b2c4e5957c94a0ffd538c8f5c308762e8be25060 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 12 Nov 2026 11:08:52 -0500 Subject: [PATCH 1/6] Stop testing MediaWiki 1.39 to 1.42 in CI Composer now refuses to install package versions with known security advisories. MediaWiki 1.39 to 1.42 pin dependencies that have one, such as PHPUnit 9.6.16 and Guzzle, so these jobs fail while installing MediaWiki, before any test runs. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d6d755..e52659d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,18 +13,6 @@ jobs: fail-fast: false matrix: include: - - mw: 'REL1_39' - php: 8.0 - 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 From f1ea76e1fe2ec1537833000fbac833dfa730ea56 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 12 Nov 2026 11:08:52 -0500 Subject: [PATCH 2/6] Update mediawiki-codesniffer to 52 Composer refuses to install mediawiki-codesniffer 40 because the PHP_CodeSniffer version it pins has a security advisory, so the code style and static analysis CI jobs failed during composer install. Version 52 requires PHP_CodeSniffer 3.13.6, which has the fix. Apply the new rules with phpcbf: static arrow functions, explicit nullable types and whitespace. Co-Authored-By: Claude Opus 5.5 --- composer.json | 2 +- src/Application/Export/EntityMapper.php | 2 +- src/Application/Export/ExportUseCase.php | 2 +- src/Application/PropertyIdList.php | 6 +++--- src/Application/PropertyIdListParser.php | 3 +-- src/EntryPoints/ExportApi.php | 3 +-- src/EntryPoints/SpecialWikibaseExport.php | 4 ++-- src/Presentation/WideCsvPresenter.php | 2 +- tests/Application/Export/ProductionValueSetCreatorTest.php | 3 +-- tests/Presentation/WideCsvPresenterTest.php | 6 ++++-- tests/TestDoubles/FakeStatementsMapper.php | 2 +- tests/TestDoubles/TimeHelper.php | 4 ++-- 12 files changed, 19 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index a9dea82..fdd0c52 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require-dev": { "vimeo/psalm": "^4.30.0", "phpstan/phpstan": "^1.8.11", - "mediawiki/mediawiki-codesniffer": "^40.0.0" + "mediawiki/mediawiki-codesniffer": "^52.0.0" }, "extra": { "installer-name": "WikibaseExport" diff --git a/src/Application/Export/EntityMapper.php b/src/Application/Export/EntityMapper.php index bbdd1f9..789bd0f 100644 --- a/src/Application/Export/EntityMapper.php +++ b/src/Application/Export/EntityMapper.php @@ -56,7 +56,7 @@ private function buildValueSetList( EntityDocument $entity ): ValueSetList { } return new ValueSetList( - array_merge( ...array_map( fn( ValueSetList $l ) => $l->sets, $lists ) ) + array_merge( ...array_map( static fn ( ValueSetList $l ) => $l->sets, $lists ) ) ); } diff --git a/src/Application/Export/ExportUseCase.php b/src/Application/Export/ExportUseCase.php index e0ce222..e5d17ed 100644 --- a/src/Application/Export/ExportUseCase.php +++ b/src/Application/Export/ExportUseCase.php @@ -80,7 +80,7 @@ private function exportHeaders( StatementsMapper ...$mappers ): void { $this->presenter->presentExportStarted( array_reduce( $mappers, - fn( ColumnHeaders $c, StatementsMapper $mapper ) => $c->plus( $mapper->createColumnHeaders() ), + static fn ( ColumnHeaders $c, StatementsMapper $mapper ) => $c->plus( $mapper->createColumnHeaders() ), new ColumnHeaders() ) ); diff --git a/src/Application/PropertyIdList.php b/src/Application/PropertyIdList.php index 787758e..3bacfc8 100644 --- a/src/Application/PropertyIdList.php +++ b/src/Application/PropertyIdList.php @@ -27,10 +27,10 @@ public function __construct( array $ids = [] ) { public function intersect( self $ids ): self { return new self( array_map( - fn ( string $id ) => new NumericPropertyId( $id ), + static fn ( string $id ) => new NumericPropertyId( $id ), array_intersect( - array_map( fn( PropertyId $id ) => $id->getSerialization(), $this->ids ), - array_map( fn( PropertyId $id ) => $id->getSerialization(), $ids->ids ), + array_map( static fn ( PropertyId $id ) => $id->getSerialization(), $this->ids ), + array_map( static fn ( PropertyId $id ) => $id->getSerialization(), $ids->ids ), ) ) ); diff --git a/src/Application/PropertyIdListParser.php b/src/Application/PropertyIdListParser.php index fac4777..7db1c9a 100644 --- a/src/Application/PropertyIdListParser.php +++ b/src/Application/PropertyIdListParser.php @@ -22,8 +22,7 @@ public function parse( array $idStrings ): PropertyIdList { foreach ( $idStrings as $idString ) { try { $ids[] = new NumericPropertyId( $idString ); - } - catch ( \InvalidArgumentException ) { + } catch ( \InvalidArgumentException ) { } } diff --git a/src/EntryPoints/ExportApi.php b/src/EntryPoints/ExportApi.php index c8c4c83..d9913e1 100644 --- a/src/EntryPoints/ExportApi.php +++ b/src/EntryPoints/ExportApi.php @@ -77,8 +77,7 @@ private function parseIds( array $ids ): array { foreach ( $ids as $id ) { try { $idObjects[] = $parser->parse( $id ); - } - catch ( EntityIdParsingException ) { + } catch ( EntityIdParsingException ) { } } diff --git a/src/EntryPoints/SpecialWikibaseExport.php b/src/EntryPoints/SpecialWikibaseExport.php index 00635a1..9d39735 100644 --- a/src/EntryPoints/SpecialWikibaseExport.php +++ b/src/EntryPoints/SpecialWikibaseExport.php @@ -90,12 +90,12 @@ private function configToVars( Config $config ): array { 'defaultStartYear' => $config->defaultStartYear, 'defaultEndYear' => $config->defaultEndYear, 'groupedProperties' => array_map( - fn( PropertyId $id ) => $id->getSerialization(), + static fn ( PropertyId $id ) => $id->getSerialization(), $config->getPropertiesGroupedByYear()->ids ), 'showUngroupedProperties' => $this->shouldShowUngroupedProperties( $config ), 'ungroupedProperties' => array_map( - fn( PropertyId $id ) => $id->getSerialization(), + static fn ( PropertyId $id ) => $id->getSerialization(), $config->getUngroupedProperties()->ids ), 'showConfigLink' => $this->shouldShowConfigLink(), diff --git a/src/Presentation/WideCsvPresenter.php b/src/Presentation/WideCsvPresenter.php index 0e45fd6..d9c4732 100644 --- a/src/Presentation/WideCsvPresenter.php +++ b/src/Presentation/WideCsvPresenter.php @@ -41,7 +41,7 @@ private function writeHeaderRow( ColumnHeaders $headers ): void { array_merge( [ 'ID', 'Label' ], array_map( - fn( ColumnHeader $header ) => $header->text, + static fn ( ColumnHeader $header ) => $header->text, $headers->headers ) ) diff --git a/tests/Application/Export/ProductionValueSetCreatorTest.php b/tests/Application/Export/ProductionValueSetCreatorTest.php index 335dcdf..6e22a18 100644 --- a/tests/Application/Export/ProductionValueSetCreatorTest.php +++ b/tests/Application/Export/ProductionValueSetCreatorTest.php @@ -74,8 +74,7 @@ public function testHandlesEmptyStatementList(): void { $this->assertEquals( new ValueSet( [] ), $this->newValueSetCreator()->statementsToValueSet( - new StatementList( - ) + new StatementList() ) ); } diff --git a/tests/Presentation/WideCsvPresenterTest.php b/tests/Presentation/WideCsvPresenterTest.php index 533f0eb..29ccef4 100644 --- a/tests/Presentation/WideCsvPresenterTest.php +++ b/tests/Presentation/WideCsvPresenterTest.php @@ -49,7 +49,8 @@ public function testMultipleEntities(): void { Q42,"Item One",Foo,Bar Q43,"Item Two",MoreFoo,MoreBar -CSV, +CSV +, $presenter ); } @@ -83,7 +84,8 @@ public function testMultipleValuesPerProperty(): void { Four","Two Three" -CSV, +CSV +, $presenter ); } diff --git a/tests/TestDoubles/FakeStatementsMapper.php b/tests/TestDoubles/FakeStatementsMapper.php index 1cc39dd..a7898b5 100644 --- a/tests/TestDoubles/FakeStatementsMapper.php +++ b/tests/TestDoubles/FakeStatementsMapper.php @@ -28,7 +28,7 @@ public function createColumnHeaders(): ColumnHeaders { public function buildValueSetList( StatementList $statements ): ValueSetList { return new ValueSetList( [ new ValueSet( array_map( - fn( Snak $snak ) => $this->header . ' ' . $snak->getPropertyId()->getSerialization(), + fn ( Snak $snak ) => $this->header . ' ' . $snak->getPropertyId()->getSerialization(), $statements->getMainSnaks() ) ) ] ); diff --git a/tests/TestDoubles/TimeHelper.php b/tests/TestDoubles/TimeHelper.php index f4c8795..052056e 100644 --- a/tests/TestDoubles/TimeHelper.php +++ b/tests/TestDoubles/TimeHelper.php @@ -47,7 +47,7 @@ public static function newDay( string $isoLikeTime ): TimeValue { ); } - public static function newTimeRangeStatement( ?int $startYear, ?int $endYear, string $pId = 'P1', DataValue $value = null ): Statement { + public static function newTimeRangeStatement( ?int $startYear, ?int $endYear, string $pId = 'P1', ?DataValue $value = null ): Statement { $snaks = []; if ( $startYear !== null ) { @@ -73,7 +73,7 @@ public static function newTimeRangeStatement( ?int $startYear, ?int $endYear, st ); } - public static function newDayRangeStatement( ?string $startDay, ?string $endDay, string $pId = 'P1', DataValue $value = null ): Statement { + public static function newDayRangeStatement( ?string $startDay, ?string $endDay, string $pId = 'P1', ?DataValue $value = null ): Statement { $snaks = []; if ( $startDay !== null ) { From 775fb529833f6c620de0db9b3323d1b0e006f31b Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 12 Nov 2026 12:23:11 -0500 Subject: [PATCH 3/6] Require MediaWiki 1.43 Raise the minimum MediaWiki and Wikibase version to 1.43, the oldest version CI still tests. Stop declaring a PHP version in composer.json: MediaWiki enforces its own minimum. The README's requirements no longer name the releases for older MediaWiki versions, a list that would keep growing; the release notes record when support was dropped. Remove what only older versions needed: the string return of the special pages' getDescription() for MediaWiki before 1.41, its PHPStan baseline entries, Psalm baseline entries left over from a MediaWiki 1.39 check, and the skip of three edge-to-edge API tests on PHP 8.1 and later, which skipped them on every PHP version MediaWiki 1.43 supports. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +++--- composer.json | 1 - extension.json | 2 +- phpstan-baseline.neon | 10 ---------- psalm-baseline.xml | 11 ----------- src/EntryPoints/SpecialWikibaseExport.php | 11 ++--------- src/EntryPoints/SpecialWikibaseExportConfig.php | 11 ++--------- tests/EntryPoints/ExportApiTest.php | 2 -- tests/EntryPoints/SearchEntitiesApiTest.php | 3 --- tests/WikibaseExportIntegrationTest.php | 6 ------ 10 files changed, 8 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 189fde4..8090c8d 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ For more information, refer to the [REST API documentation]. Platform requirements: -* [PHP] 8.0 or later (tested up to 8.4) -* [MediaWiki] 1.37 or later (tested up to 1.43) (versions 1.37 and 1.38 require Wikibase Export 1.0.0) -* [Wikibase] 1.37 or later (tested up to 1.43) +* [PHP] 8.1 or later (tested up to 8.4) +* [MediaWiki] 1.43 or later (tested up to 1.43) +* [Wikibase] 1.43 or later (tested up to 1.43) The recommended way to install Wikibase Export is using [Composer] with [MediaWiki's built-in support for Composer][Composer install]. diff --git a/composer.json b/composer.json index fdd0c52..81e4ad4 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ } ], "require": { - "php": ">=8.0", "composer/installers": "^2|^1.0.1", "opis/json-schema": "^2.3.0", "wmde/clock": "^1.0.0" diff --git a/extension.json b/extension.json index 670016c..3a00b83 100644 --- a/extension.json +++ b/extension.json @@ -17,7 +17,7 @@ "descriptionmsg": "wikibase-export-description", "requires": { - "MediaWiki": ">= 1.39.0", + "MediaWiki": ">= 1.43.0", "extensions": { "WikibaseRepository": "*" } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7c3f895..b330d34 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -19,13 +19,3 @@ parameters: message: "#^Cannot cast mixed to string\\.$#" count: 1 path: src/WikibaseExportExtension.php - - - - message: "#^If condition is always true\\.$#" - count: 1 - path: src/EntryPoints/SpecialWikibaseExport.php - - - - message: "#^If condition is always true\\.$#" - count: 1 - path: src/EntryPoints/SpecialWikibaseExportConfig.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 019ed71..f420616 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7,17 +7,6 @@ array_map - - - profileContext - - - MW_VERSION - - - getRankedSearchResults - - $key diff --git a/src/EntryPoints/SpecialWikibaseExport.php b/src/EntryPoints/SpecialWikibaseExport.php index 9d39735..224bbb3 100644 --- a/src/EntryPoints/SpecialWikibaseExport.php +++ b/src/EntryPoints/SpecialWikibaseExport.php @@ -38,15 +38,8 @@ public function getGroupName(): string { return 'wikibase'; } - /** - * @return string|Message Returns string in MW < 1.41 and Message in MW >= 1.41 - */ - public function getDescription() { - if ( version_compare( MW_VERSION, '1.41', '>=' ) ) { - return $this->msg( 'special-wikibase-export' ); - } else { - return $this->msg( 'special-wikibase-export' )->escaped(); - } + public function getDescription(): Message { + return $this->msg( 'special-wikibase-export' ); } private function shouldShowConfigLink(): bool { diff --git a/src/EntryPoints/SpecialWikibaseExportConfig.php b/src/EntryPoints/SpecialWikibaseExportConfig.php index a73b776..6221a60 100644 --- a/src/EntryPoints/SpecialWikibaseExportConfig.php +++ b/src/EntryPoints/SpecialWikibaseExportConfig.php @@ -28,15 +28,8 @@ public function getGroupName(): string { return 'wikibase'; } - /** - * @return string|Message Returns string in MW < 1.41 and Message in MW >= 1.41 - */ - public function getDescription() { - if ( version_compare( MW_VERSION, '1.41', '>=' ) ) { - return $this->msg( 'special-wikibase-export-config' ); - } else { - return $this->msg( 'special-wikibase-export-config' )->escaped(); - } + public function getDescription(): Message { + return $this->msg( 'special-wikibase-export-config' ); } } diff --git a/tests/EntryPoints/ExportApiTest.php b/tests/EntryPoints/ExportApiTest.php index f4f6898..f7ec938 100644 --- a/tests/EntryPoints/ExportApiTest.php +++ b/tests/EntryPoints/ExportApiTest.php @@ -51,8 +51,6 @@ public function setUp(): void { } public function testEdgeToEdge(): void { - $this->skipOnPhp81AndLater(); - $this->saveProperty( TimeHelper::START_TIME_ID, 'time', 'Start time' ); $this->saveProperty( TimeHelper::END_TIME_ID, 'time', 'End time' ); $this->saveProperty( TimeHelper::POINT_IN_TIME_ID, 'time', 'Point in time' ); diff --git a/tests/EntryPoints/SearchEntitiesApiTest.php b/tests/EntryPoints/SearchEntitiesApiTest.php index cd3bf36..65bb150 100644 --- a/tests/EntryPoints/SearchEntitiesApiTest.php +++ b/tests/EntryPoints/SearchEntitiesApiTest.php @@ -63,8 +63,6 @@ private function saveCompany( string $id, string $label ): void { } public function testEdgeToEdge(): void { - $this->skipOnPhp81AndLater(); - $this->saveProperty( self::INSTANCE_OF_ID, 'string', 'instance of' ); $this->saveCompany( 'Q10', 'Company Foo' ); @@ -128,7 +126,6 @@ public function testEdgeToEdge(): void { } public function testNoMatchesReturnsEmptyResult(): void { - $this->skipOnPhp81AndLater(); $this->saveProperty( self::INSTANCE_OF_ID, 'string', 'instance of' ); $response = $this->executeHandler( diff --git a/tests/WikibaseExportIntegrationTest.php b/tests/WikibaseExportIntegrationTest.php index 25579c4..1f2a7a8 100644 --- a/tests/WikibaseExportIntegrationTest.php +++ b/tests/WikibaseExportIntegrationTest.php @@ -58,12 +58,6 @@ protected function saveProperty( string $pId, string $type, string $label ): voi ); } - protected function skipOnPhp81AndLater(): void { - if ( version_compare( PHP_VERSION, '8.1.0' ) >= 0 ) { - $this->markTestSkipped( 'Wikibase does not yet work with PHP 8.1' ); - } - } - protected function getPageHtml( string $pageTitle ): string { $title = \Title::newFromText( $pageTitle ); From 7897ee4c44d5a102bca4cc6cf3388b836c999677 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 12 Nov 2026 12:23:12 -0500 Subject: [PATCH 4/6] Use namespaced MediaWiki classes Fixes https://github.com/ProfessionalWiki/WikibaseExport/issues/190 MediaWiki 1.47 removed the global aliases of Title, Html and EditPage, so on 1.47 every page view failed in the BeforePageDisplay hook. Import the namespaced classes, which all exist in MediaWiki 1.43, for every class that has one there: Title, TitleParser, MalformedTitleException, Content, JsonContent, Html, Message, SpecialPage, EditPage, OutputPage and IContextSource. Skin, Article, WikiPage and SpecialPageTestBase keep their global names: MediaWiki 1.43 has no namespaced version of them, and their aliases still exist in 1.47. Co-Authored-By: Claude Opus 5.5 --- src/EntryPoints/MediaWikiHooks.php | 9 +++++---- src/EntryPoints/SpecialWikibaseExport.php | 4 ++-- src/EntryPoints/SpecialWikibaseExportConfig.php | 6 +++--- src/Persistence/PageContentConfigLookup.php | 4 ++-- src/Persistence/PageContentFetcher.php | 6 +++--- src/Presentation/ExportConfigEditPageTextBuilder.php | 9 ++++----- src/WikibaseExportExtension.php | 2 +- tests/WikibaseExportIntegrationTest.php | 9 +++++---- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/EntryPoints/MediaWikiHooks.php b/src/EntryPoints/MediaWikiHooks.php index cddfb72..ea2bd87 100644 --- a/src/EntryPoints/MediaWikiHooks.php +++ b/src/EntryPoints/MediaWikiHooks.php @@ -4,14 +4,15 @@ namespace ProfessionalWiki\WikibaseExport\EntryPoints; -use EditPage; -use OutputPage; +use MediaWiki\EditPage\EditPage; +use MediaWiki\Html\Html; +use MediaWiki\Output\OutputPage; +use MediaWiki\Title\Title; use ProfessionalWiki\WikibaseExport\Persistence\ConfigJsonValidator; use ProfessionalWiki\WikibaseExport\Presentation\ConfigJsonErrorFormatter; use ProfessionalWiki\WikibaseExport\Presentation\ExportConfigEditPageTextBuilder; use ProfessionalWiki\WikibaseExport\WikibaseExportExtension; use Skin; -use Title; class MediaWikiHooks { @@ -30,7 +31,7 @@ public static function onEditFilter( EditPage $editPage, ?string $text, ?string if ( !$validator->validate( $text ) ) { $errors = $validator->getErrors(); - $error = \Html::errorBox( + $error = Html::errorBox( wfMessage( 'wikibase-export-config-invalid', count( $errors ) )->escaped() . ConfigJsonErrorFormatter::format( $errors ) ); diff --git a/src/EntryPoints/SpecialWikibaseExport.php b/src/EntryPoints/SpecialWikibaseExport.php index 224bbb3..d56fbca 100644 --- a/src/EntryPoints/SpecialWikibaseExport.php +++ b/src/EntryPoints/SpecialWikibaseExport.php @@ -5,10 +5,10 @@ namespace ProfessionalWiki\WikibaseExport\EntryPoints; use MediaWiki\MediaWikiServices; -use Message; +use MediaWiki\Message\Message; +use MediaWiki\SpecialPage\SpecialPage; use ProfessionalWiki\WikibaseExport\Application\Config; use ProfessionalWiki\WikibaseExport\WikibaseExportExtension; -use SpecialPage; use Wikibase\DataModel\Entity\PropertyId; class SpecialWikibaseExport extends SpecialPage { diff --git a/src/EntryPoints/SpecialWikibaseExportConfig.php b/src/EntryPoints/SpecialWikibaseExportConfig.php index 6221a60..2a35568 100644 --- a/src/EntryPoints/SpecialWikibaseExportConfig.php +++ b/src/EntryPoints/SpecialWikibaseExportConfig.php @@ -4,9 +4,9 @@ namespace ProfessionalWiki\WikibaseExport\EntryPoints; -use Message; -use SpecialPage; -use Title; +use MediaWiki\Message\Message; +use MediaWiki\SpecialPage\SpecialPage; +use MediaWiki\Title\Title; class SpecialWikibaseExportConfig extends SpecialPage { diff --git a/src/Persistence/PageContentConfigLookup.php b/src/Persistence/PageContentConfigLookup.php index fa44dd8..51f35cb 100644 --- a/src/Persistence/PageContentConfigLookup.php +++ b/src/Persistence/PageContentConfigLookup.php @@ -4,7 +4,7 @@ namespace ProfessionalWiki\WikibaseExport\Persistence; -use JsonContent; +use MediaWiki\Content\JsonContent; use ProfessionalWiki\WikibaseExport\Application\Config; class PageContentConfigLookup implements ConfigLookup { @@ -19,7 +19,7 @@ public function __construct( public function getConfig(): Config { $content = $this->contentFetcher->getPageContent( 'MediaWiki:' . $this->pageName ); - if ( $content instanceof \JsonContent ) { + if ( $content instanceof JsonContent ) { return $this->configFromJsonContent( $content ); } diff --git a/src/Persistence/PageContentFetcher.php b/src/Persistence/PageContentFetcher.php index 15170c7..5fd9fb0 100644 --- a/src/Persistence/PageContentFetcher.php +++ b/src/Persistence/PageContentFetcher.php @@ -4,10 +4,10 @@ namespace ProfessionalWiki\WikibaseExport\Persistence; -use Content; -use MalformedTitleException; +use MediaWiki\Content\Content; use MediaWiki\Revision\RevisionLookup; -use TitleParser; +use MediaWiki\Title\MalformedTitleException; +use MediaWiki\Title\TitleParser; class PageContentFetcher { diff --git a/src/Presentation/ExportConfigEditPageTextBuilder.php b/src/Presentation/ExportConfigEditPageTextBuilder.php index 7178913..0e99be2 100644 --- a/src/Presentation/ExportConfigEditPageTextBuilder.php +++ b/src/Presentation/ExportConfigEditPageTextBuilder.php @@ -4,11 +4,10 @@ namespace ProfessionalWiki\WikibaseExport\Presentation; -use Html; -use IContextSource; -use Message; -use SpecialPage; -use Title; +use MediaWiki\Context\IContextSource; +use MediaWiki\Html\Html; +use MediaWiki\SpecialPage\SpecialPage; +use MediaWiki\Title\Title; class ExportConfigEditPageTextBuilder { diff --git a/src/WikibaseExportExtension.php b/src/WikibaseExportExtension.php index 42a77ca..1b7a16d 100644 --- a/src/WikibaseExportExtension.php +++ b/src/WikibaseExportExtension.php @@ -6,6 +6,7 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Permissions\Authority; +use MediaWiki\Title\Title; use ProfessionalWiki\WikibaseExport\Application\Config; use ProfessionalWiki\WikibaseExport\Application\EntitySourceFactory; use ProfessionalWiki\WikibaseExport\Application\Export\ExportPresenter; @@ -24,7 +25,6 @@ use ProfessionalWiki\WikibaseExport\Persistence\ConfigLookup; use ProfessionalWiki\WikibaseExport\Persistence\PageContentConfigLookup; use ProfessionalWiki\WikibaseExport\Persistence\PageContentFetcher; -use Title; use Wikibase\Repo\WikibaseRepo; use WMDE\Clock\SystemClock; diff --git a/tests/WikibaseExportIntegrationTest.php b/tests/WikibaseExportIntegrationTest.php index 1f2a7a8..9271632 100644 --- a/tests/WikibaseExportIntegrationTest.php +++ b/tests/WikibaseExportIntegrationTest.php @@ -3,9 +3,10 @@ namespace ProfessionalWiki\WikibaseExport\Tests; use Article; +use MediaWiki\EditPage\EditPage; +use MediaWiki\Title\Title; use MediaWikiIntegrationTestCase; use ProfessionalWiki\WikibaseExport\WikibaseExportExtension; -use Title; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\NumericPropertyId; use Wikibase\DataModel\Entity\Property; @@ -59,7 +60,7 @@ protected function saveProperty( string $pId, string $type, string $label ): voi } protected function getPageHtml( string $pageTitle ): string { - $title = \Title::newFromText( $pageTitle ); + $title = Title::newFromText( $pageTitle ); $article = new Article( $title, 0 ); $article->getContext()->getOutput()->setTitle( $title ); @@ -70,12 +71,12 @@ protected function getPageHtml( string $pageTitle ): string { } protected function getEditPageHtml( string $pageTitle ): string { - $title = \Title::newFromText( $pageTitle ); + $title = Title::newFromText( $pageTitle ); $article = new Article( $title, 0 ); $article->getContext()->getOutput()->setTitle( $title ); - $editPage = new \EditPage( $article ); + $editPage = new EditPage( $article ); $editPage->setContextTitle( $title ); $editPage->getContext()->setUser( $this->getTestSysop()->getUser() ); $editPage->edit(); From bd5351dcb502cedd06a48153572de70e08429a16 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 12 Nov 2026 12:23:12 -0500 Subject: [PATCH 5/6] Replace MediaWiki APIs removed or deprecated after 1.43 MediaWiki 1.47 removed the EditFilter hook, so invalid configuration on MediaWiki:WikibaseExport got saved. Validate it in the EditFilterMergedContent hook instead, which MediaWiki 1.43 also has. The hook refuses the edit with one message that includes the error table, so API clients now get the errors too, instead of "hookaborted". The message needs a parameter for the table, which the translations of wikibase-export-config-invalid lack, so it gets a new key, wikibase-export-config-invalid-errors. Since MediaWiki 1.45, getRevisionByTitle() emits a deprecation warning when given a LinkTarget. Look the config page up with PageLookup and pass the resulting page to it; a PageReference that is not a page identity fails on MediaWiki 1.43. Since MediaWiki 1.47, deletePage() in tests fails for a page that does not exist. Stop deleting the config page after each ConfigPageSmokeTest test: MediaWiki resets the tables between tests since 1.42. Co-Authored-By: Claude Opus 5.5 --- extension.json | 2 +- i18n/en.json | 2 +- i18n/qqq.json | 2 +- src/EntryPoints/MediaWikiHooks.php | 28 ++++++-- src/Persistence/PageContentFetcher.php | 13 ++-- src/WikibaseExportExtension.php | 2 +- .../ConfigPageEditValidationTest.php | 64 +++++++++++++++++++ tests/Presentation/ConfigPageSmokeTest.php | 5 -- tests/WikibaseExportIntegrationTest.php | 10 --- 9 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 tests/EntryPoints/ConfigPageEditValidationTest.php diff --git a/extension.json b/extension.json index 3a00b83..939ca0c 100644 --- a/extension.json +++ b/extension.json @@ -38,7 +38,7 @@ "AlternateEdit": "ProfessionalWiki\\WikibaseExport\\EntryPoints\\MediaWikiHooks::onAlternateEdit", "BeforePageDisplay": "ProfessionalWiki\\WikibaseExport\\EntryPoints\\MediaWikiHooks::onBeforePageDisplay", "ContentHandlerDefaultModelFor": "ProfessionalWiki\\WikibaseExport\\EntryPoints\\MediaWikiHooks::onContentHandlerDefaultModelFor", - "EditFilter": "ProfessionalWiki\\WikibaseExport\\EntryPoints\\MediaWikiHooks::onEditFilter", + "EditFilterMergedContent": "ProfessionalWiki\\WikibaseExport\\EntryPoints\\MediaWikiHooks::onEditFilterMergedContent", "EditFormPreloadText": "ProfessionalWiki\\WikibaseExport\\EntryPoints\\MediaWikiHooks::onEditFormPreloadText" }, diff --git a/i18n/en.json b/i18n/en.json index 3951186..38f27c1 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -27,7 +27,7 @@ "wikibase-export-config-header-label": "Property Label (e.g. \"Operating revenue 2022\")", "wikibase-export-download": "Download", - "wikibase-export-config-invalid": "Your changes were not saved. They contain the following {{PLURAL:$1|error|errors}}:", + "wikibase-export-config-invalid-errors": "Your changes were not saved. They contain the following {{PLURAL:$1|error|errors}}:$2", "wikibase-export-config-incomplete": "An administrator needs to configure Wikibase Export before it can be used.", "wikibase-export-config-incomplete-link": "You can [[MediaWiki:WikibaseExport|configure this form]].", diff --git a/i18n/qqq.json b/i18n/qqq.json index 1707112..e9622c4 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -28,7 +28,7 @@ "wikibase-export-config-header-id": "This is the text of an option.", "wikibase-export-config-header-label": "This is the text of an option.", "wikibase-export-download": "This is the text on a button. Used for $1 in {{Msg-mw|Wikibase-export-intro}}", - "wikibase-export-config-invalid": "Error message shown when attempting to save invalid configuration on MediaWiki:WikibaseExport", + "wikibase-export-config-invalid-errors": "Error message shown when attempting to save invalid configuration on MediaWiki:WikibaseExport.\n\nParameters:\n* $1 - Number of errors\n* $2 - Table listing each error", "wikibase-export-config-incomplete": "Error message shown on \"Special:WikibaseExport\" when required configuration is incomplete.", "wikibase-export-config-incomplete-link": "Config page link shown on \"Special:WikibaseExport\" when required configuration is incomplete.", "wikibase-export-config-help-documentation": "Link to documentation displayed on \"MediaWiki:WikibaseExport\"", diff --git a/src/EntryPoints/MediaWikiHooks.php b/src/EntryPoints/MediaWikiHooks.php index ea2bd87..9590bbb 100644 --- a/src/EntryPoints/MediaWikiHooks.php +++ b/src/EntryPoints/MediaWikiHooks.php @@ -4,10 +4,14 @@ namespace ProfessionalWiki\WikibaseExport\EntryPoints; +use MediaWiki\Content\Content; +use MediaWiki\Context\IContextSource; use MediaWiki\EditPage\EditPage; -use MediaWiki\Html\Html; +use MediaWiki\Message\Message; use MediaWiki\Output\OutputPage; +use MediaWiki\Status\Status; use MediaWiki\Title\Title; +use MediaWiki\User\User; use ProfessionalWiki\WikibaseExport\Persistence\ConfigJsonValidator; use ProfessionalWiki\WikibaseExport\Presentation\ConfigJsonErrorFormatter; use ProfessionalWiki\WikibaseExport\Presentation\ExportConfigEditPageTextBuilder; @@ -22,18 +26,28 @@ public static function onContentHandlerDefaultModelFor( Title $title, ?string &$ } } - public static function onEditFilter( EditPage $editPage, ?string $text, ?string $section, string &$error ): void { - if ( !is_string( $text ) || !WikibaseExportExtension::getInstance()->isConfigTitle( $editPage->getTitle() ) ) { + public static function onEditFilterMergedContent( + IContextSource $context, + Content $content, + Status $status, + string $summary, + User $user, + bool $minorEdit + ): void { + $title = $context->getTitle(); + + if ( $title === null || !WikibaseExportExtension::getInstance()->isConfigTitle( $title ) ) { return; } $validator = ConfigJsonValidator::newInstance(); - if ( !$validator->validate( $text ) ) { + if ( !$validator->validate( $content->serialize() ) ) { $errors = $validator->getErrors(); - $error = Html::errorBox( - wfMessage( 'wikibase-export-config-invalid', count( $errors ) )->escaped() . - ConfigJsonErrorFormatter::format( $errors ) + $status->fatal( + 'wikibase-export-config-invalid-errors', + count( $errors ), + Message::rawParam( ConfigJsonErrorFormatter::format( $errors ) ) ); } } diff --git a/src/Persistence/PageContentFetcher.php b/src/Persistence/PageContentFetcher.php index 5fd9fb0..13acf2b 100644 --- a/src/Persistence/PageContentFetcher.php +++ b/src/Persistence/PageContentFetcher.php @@ -5,26 +5,25 @@ namespace ProfessionalWiki\WikibaseExport\Persistence; use MediaWiki\Content\Content; +use MediaWiki\Page\PageLookup; use MediaWiki\Revision\RevisionLookup; -use MediaWiki\Title\MalformedTitleException; -use MediaWiki\Title\TitleParser; class PageContentFetcher { public function __construct( - private TitleParser $titleParser, + private PageLookup $pageLookup, private RevisionLookup $revisionLookup ) { } public function getPageContent( string $pageTitle ): ?Content { - try { - $title = $this->titleParser->parseTitle( $pageTitle ); - } catch ( MalformedTitleException ) { + $page = $this->pageLookup->getPageByText( $pageTitle ); + + if ( $page === null ) { return null; } - $revision = $this->revisionLookup->getRevisionByTitle( $title ); + $revision = $this->revisionLookup->getRevisionByTitle( $page ); return $revision?->getContent( 'main' ); } diff --git a/src/WikibaseExportExtension.php b/src/WikibaseExportExtension.php index 1b7a16d..7c5aa9c 100644 --- a/src/WikibaseExportExtension.php +++ b/src/WikibaseExportExtension.php @@ -79,7 +79,7 @@ private function newConfigLookup(): ConfigLookup { public function newPageContentConfigLookup(): PageContentConfigLookup { return new PageContentConfigLookup( contentFetcher: new PageContentFetcher( - MediaWikiServices::getInstance()->getTitleParser(), + MediaWikiServices::getInstance()->getPageStore(), MediaWikiServices::getInstance()->getRevisionLookup() ), deserializer: $this->newConfigDeserializer(), diff --git a/tests/EntryPoints/ConfigPageEditValidationTest.php b/tests/EntryPoints/ConfigPageEditValidationTest.php new file mode 100644 index 0000000..2b6da04 --- /dev/null +++ b/tests/EntryPoints/ConfigPageEditValidationTest.php @@ -0,0 +1,64 @@ +expectApiErrorCode( 'wikibase-export-config-invalid-errors' ); + + $this->edit( self::CONFIG_PAGE, self::INVALID_CONFIG ); + } + + public function testRefusalNamesTheInvalidSetting(): void { + $this->assertStringContainsString( 'defaultStartYear', $this->getRefusalText() ); + } + + public function testSavesValidConfig(): void { + $this->assertSame( + 'Success', + $this->edit( self::CONFIG_PAGE, Valid::configJson() )['edit']['result'] + ); + } + + public function testSavesOtherPagesWithoutValidatingThem(): void { + $this->assertSame( + 'Success', + $this->edit( 'WikibaseExport', self::INVALID_CONFIG )['edit']['result'] + ); + } + + private function edit( string $pageName, string $text ): array { + return $this->doApiRequestWithToken( [ + 'action' => 'edit', + 'title' => $pageName, + 'text' => $text, + ] )[0]; + } + + private function getRefusalText(): string { + try { + $this->edit( self::CONFIG_PAGE, self::INVALID_CONFIG ); + } catch ( ApiUsageException $exception ) { + return $exception->getMessage(); + } + + $this->fail( 'The edit was saved' ); + } + +} diff --git a/tests/Presentation/ConfigPageSmokeTest.php b/tests/Presentation/ConfigPageSmokeTest.php index dcf5e5f..ed13916 100644 --- a/tests/Presentation/ConfigPageSmokeTest.php +++ b/tests/Presentation/ConfigPageSmokeTest.php @@ -12,11 +12,6 @@ */ class ConfigPageSmokeTest extends WikibaseExportIntegrationTest { - public function tearDown(): void { - $this->deleteConfigPage(); - parent::tearDown(); - } - public function testSmoke(): void { $this->editConfigPage( config: Valid::configJson() ); $this->assertStringContainsString( diff --git a/tests/WikibaseExportIntegrationTest.php b/tests/WikibaseExportIntegrationTest.php index 9271632..ca6b412 100644 --- a/tests/WikibaseExportIntegrationTest.php +++ b/tests/WikibaseExportIntegrationTest.php @@ -14,7 +14,6 @@ use Wikibase\DataModel\Term\Term; use Wikibase\DataModel\Term\TermList; use Wikibase\Repo\WikibaseRepo; -use WikiPage; class WikibaseExportIntegrationTest extends MediaWikiIntegrationTestCase { @@ -30,15 +29,6 @@ protected function editConfigPage( string $config ): void { ); } - protected function deleteConfigPage(): void { - /** - * @var Title $title - */ - $title = Title::newFromText( 'MediaWiki:' . WikibaseExportExtension::CONFIG_PAGE_TITLE ); - - $this->deletePage( new WikiPage( $title ) ); - } - protected function saveEntity( EntityDocument $entity ): void { WikibaseRepo::getEntityStore()->saveEntity( entity: $entity, From fb47b44a81d0a5aa59eca09a214bd8e151af6b94 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 12 Nov 2026 12:23:12 -0500 Subject: [PATCH 6/6] Search entities through WbSearch when Wikibase has it Wikibase 1.47 removed WikibaseRepo::getEntitySearchHelper(), so the subject search of Special:WikibaseExport failed on MediaWiki 1.47. Use WbSearch::getItemSearchHelper(), added in Wikibase 1.46, when it exists, and getEntitySearchHelper() before that. PHPStan and Psalm run against MediaWiki 1.43, whose Wikibase has no WbSearch, so their errors on that branch are baselined. Also drop setup that the no-matches search test does not need. Co-Authored-By: Claude Opus 5.5 --- phpstan-baseline.neon | 10 ++++++++++ psalm-baseline.xml | 12 ++++++++++++ src/WikibaseExportExtension.php | 13 ++++++++++++- tests/EntryPoints/SearchEntitiesApiTest.php | 2 -- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b330d34..7231ebd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15,6 +15,16 @@ parameters: count: 1 path: src/Presentation/WideCsvPresenter.php + - + message: "#^Call to function method_exists\\(\\) with 'Wikibase\\\\\\\\Repo\\\\\\\\Domains\\\\\\\\Search\\\\\\\\WbSearch' and 'getItemSearchHelper' will always evaluate to false\\.$#" + count: 1 + path: src/WikibaseExportExtension.php + + - + message: "#^Class Wikibase\\\\Repo\\\\Domains\\\\Search\\\\WbSearch not found\\.$#" + count: 1 + path: src/WikibaseExportExtension.php + - message: "#^Cannot cast mixed to string\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f420616..ebe1a64 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -17,4 +17,16 @@ isset( $this->stream ) + + + WbSearch::class + + + EntitySearchHelper + + + WbSearch + WbSearch + + diff --git a/src/WikibaseExportExtension.php b/src/WikibaseExportExtension.php index 7c5aa9c..fb6acd1 100644 --- a/src/WikibaseExportExtension.php +++ b/src/WikibaseExportExtension.php @@ -25,6 +25,8 @@ use ProfessionalWiki\WikibaseExport\Persistence\ConfigLookup; use ProfessionalWiki\WikibaseExport\Persistence\PageContentConfigLookup; use ProfessionalWiki\WikibaseExport\Persistence\PageContentFetcher; +use Wikibase\Repo\Api\EntitySearchHelper; +use Wikibase\Repo\Domains\Search\WbSearch; use Wikibase\Repo\WikibaseRepo; use WMDE\Clock\SystemClock; @@ -133,10 +135,19 @@ public function newSearchEntitiesUseCase( SearchEntitiesPresenter $presenter ): return new SearchEntitiesUseCase( subjectFilterPropertyId: $this->getConfig()->subjectFilterPropertyId, subjectFilterPropertyValue: $this->getConfig()->subjectFilterPropertyValue, - entitySearchHelper: WikibaseRepo::getEntitySearchHelper(), + entitySearchHelper: $this->getItemSearchHelper(), entityLookup: WikibaseRepo::getEntityLookup(), presenter: $presenter ); } + private function getItemSearchHelper(): EntitySearchHelper { + // Wikibase 1.46 added WbSearch::getItemSearchHelper(), and 1.47 removed WikibaseRepo::getEntitySearchHelper() + if ( method_exists( WbSearch::class, 'getItemSearchHelper' ) ) { + return WbSearch::getItemSearchHelper(); + } + + return WikibaseRepo::getEntitySearchHelper(); + } + } diff --git a/tests/EntryPoints/SearchEntitiesApiTest.php b/tests/EntryPoints/SearchEntitiesApiTest.php index 65bb150..651a1f3 100644 --- a/tests/EntryPoints/SearchEntitiesApiTest.php +++ b/tests/EntryPoints/SearchEntitiesApiTest.php @@ -126,8 +126,6 @@ public function testEdgeToEdge(): void { } public function testNoMatchesReturnsEmptyResult(): void { - $this->saveProperty( self::INSTANCE_OF_ID, 'string', 'instance of' ); - $response = $this->executeHandler( WikibaseExportExtension::searchEntitiesApiFactory(), new RequestData( [