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
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
}
],
"require": {
"php": ">=8.0",
"composer/installers": "^2|^1.0.1",
"opis/json-schema": "^2.3.0",
"wmde/clock": "^1.0.0"
},
"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"
Expand Down
4 changes: 2 additions & 2 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"descriptionmsg": "wikibase-export-description",

"requires": {
"MediaWiki": ">= 1.39.0",
"MediaWiki": ">= 1.43.0",
"extensions": {
"WikibaseRepository": "*"
}
Expand All @@ -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"
},

Expand Down
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]].",

Expand Down
2 changes: 1 addition & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down
10 changes: 5 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ parameters:
path: src/Presentation/WideCsvPresenter.php

-
message: "#^Cannot cast mixed to string\\.$#"
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: "#^If condition is always true\\.$#"
message: "#^Class Wikibase\\\\Repo\\\\Domains\\\\Search\\\\WbSearch not found\\.$#"
count: 1
path: src/EntryPoints/SpecialWikibaseExport.php
path: src/WikibaseExportExtension.php

-
message: "#^If condition is always true\\.$#"
message: "#^Cannot cast mixed to string\\.$#"
count: 1
path: src/EntryPoints/SpecialWikibaseExportConfig.php
path: src/WikibaseExportExtension.php
23 changes: 12 additions & 11 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
<code>array_map</code>
</ImpureFunctionCall>
</file>
<file src="src/Application/SearchEntities/SearchEntitiesUseCase.php">
<InvalidNamedArgument occurrences="1">
<code>profileContext</code>
</InvalidNamedArgument>
<MixedArgument occurrences="1">
<code>MW_VERSION</code>
</MixedArgument>
<TooManyArguments occurrences="1">
<code>getRankedSearchResults</code>
</TooManyArguments>
</file>
<file src="src/Presentation/ConfigJsonErrorFormatter.php">
<MixedArgumentTypeCoercion occurrences="1">
<code>$key</code>
Expand All @@ -28,4 +17,16 @@
<code>isset( $this-&gt;stream )</code>
</RedundantPropertyInitializationCheck>
</file>
<file src="src/WikibaseExportExtension.php">
<MixedArgument occurrences="1">
<code>WbSearch::class</code>
</MixedArgument>
<MixedInferredReturnType occurrences="1">
<code>EntitySearchHelper</code>
</MixedInferredReturnType>
<UndefinedClass occurrences="2">
<code>WbSearch</code>
<code>WbSearch</code>
</UndefinedClass>
</file>
</files>
2 changes: 1 addition & 1 deletion src/Application/Export/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Application/Export/ExportUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
);
Expand Down
6 changes: 3 additions & 3 deletions src/Application/PropertyIdList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
)
)
);
Expand Down
3 changes: 1 addition & 2 deletions src/Application/PropertyIdListParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function parse( array $idStrings ): PropertyIdList {
foreach ( $idStrings as $idString ) {
try {
$ids[] = new NumericPropertyId( $idString );
}
catch ( \InvalidArgumentException ) {
} catch ( \InvalidArgumentException ) {
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/EntryPoints/ExportApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private function parseIds( array $ids ): array {
foreach ( $ids as $id ) {
try {
$idObjects[] = $parser->parse( $id );
}
catch ( EntityIdParsingException ) {
} catch ( EntityIdParsingException ) {
}
}

Expand Down
33 changes: 24 additions & 9 deletions src/EntryPoints/MediaWikiHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

namespace ProfessionalWiki\WikibaseExport\EntryPoints;

use EditPage;
use OutputPage;
use MediaWiki\Content\Content;
use MediaWiki\Context\IContextSource;
use MediaWiki\EditPage\EditPage;
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;
use ProfessionalWiki\WikibaseExport\WikibaseExportExtension;
use Skin;
use Title;

class MediaWikiHooks {

Expand All @@ -21,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 ) )
);
}
}
Expand Down
19 changes: 6 additions & 13 deletions src/EntryPoints/SpecialWikibaseExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -90,12 +83,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(),
Expand Down
17 changes: 5 additions & 12 deletions src/EntryPoints/SpecialWikibaseExportConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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' );
}

}
4 changes: 2 additions & 2 deletions src/Persistence/PageContentConfigLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ProfessionalWiki\WikibaseExport\Persistence;

use JsonContent;
use MediaWiki\Content\JsonContent;
use ProfessionalWiki\WikibaseExport\Application\Config;

class PageContentConfigLookup implements ConfigLookup {
Expand All @@ -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 );
}

Expand Down
15 changes: 7 additions & 8 deletions src/Persistence/PageContentFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@

namespace ProfessionalWiki\WikibaseExport\Persistence;

use Content;
use MalformedTitleException;
use MediaWiki\Content\Content;
use MediaWiki\Page\PageLookup;
use MediaWiki\Revision\RevisionLookup;
use 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' );
}
Expand Down
9 changes: 4 additions & 5 deletions src/Presentation/ExportConfigEditPageTextBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Loading
Loading