Page MenuHomePhabricator

0001-SECURITY-Run-EditFilterMergedContent-hook-on-edits.patch

Authored By
Lucas_Werkmeister_WMDE
Jul 4 2023, 8:35 AM
Size
44 KB
Referenced Files
None
Subscribers
None

0001-SECURITY-Run-EditFilterMergedContent-hook-on-edits.patch

From 3b766987f655b56b317115e15996a0298837ee3c Mon Sep 17 00:00:00 2001
From: Lucas Werkmeister <lucas.werkmeister@wikimedia.de>
Date: Wed, 21 Jun 2023 17:30:57 +0200
Subject: [PATCH] SECURITY: Run EditFilterMergedContent hook on edits
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This provides integration with AbuseFilter and other extensions that
might want to block edits.
The current SchemaInserter / SchemaUpdater interfaces aren’t really
designed for propagating information about why an edit failed – they
just potentially throw a RuntimeException. (The SchemaUpdater callers at
least catch that exception and turn it into a Status, without any
details of course – whereas the SchemaInserter caller, NewEntitySchema,
doesn’t catch the errors at all.) This means users won’t see any details
about why the edit failed (e.g. that it was blocked), but I think that’s
okay for the initial security patch. We can improve it later on Gerrit.
In MediaWikiRevisionSchemaUpdater, introduce a factory method so that we
don’t have to add all the new services in each caller (three actions and
one special page). Ideally, this should probably become a factory
service later.
Bug: T339016
Change-Id: Id71ece831c929fadb1710634de9a7be5f02e0b0e
---
maintenance/createPreexistingSchemas.php | 7 +-
.../MediaWikiRevisionSchemaInserter.php | 81 ++++---
.../MediaWikiRevisionSchemaUpdater.php | 144 +++++++-----
src/MediaWiki/Actions/RestoreSubmitAction.php | 10 +-
src/MediaWiki/Actions/SchemaEditAction.php | 11 +-
src/MediaWiki/Actions/UndoSubmitAction.php | 9 +-
src/MediaWiki/Specials/NewEntitySchema.php | 6 +-
...SetEntitySchemaLabelDescriptionAliases.php | 11 +-
.../MediaWikiRevisionSchemaInserterTest.php | 74 +++++-
.../MediaWikiRevisionSchemaUpdaterTest.php | 212 ++++++++++++++++--
.../PageHistoryLineEndingHandlerTest.php | 21 +-
11 files changed, 432 insertions(+), 154 deletions(-)
diff --git a/maintenance/createPreexistingSchemas.php b/maintenance/createPreexistingSchemas.php
index 61b4c5274b..8ddd4a48c7 100644
--- a/maintenance/createPreexistingSchemas.php
+++ b/maintenance/createPreexistingSchemas.php
@@ -15,6 +15,7 @@
use EntitySchema\DataAccess\WatchlistUpdater;
use Maintenance;
use MediaWiki\MediaWikiServices;
+use RequestContext;
use RuntimeException;
use User;
@@ -168,11 +169,15 @@ private function createSchema( $idString, array $dataMap, User $user ) {
$fixedIdGenerator = new FixedIdGenerator( (int)trim( $idString, 'E' ) );
+ $services = MediaWikiServices::getInstance();
$schemaInserter = new MediaWikiRevisionSchemaInserter(
$pageUpdaterFactory,
new WatchlistUpdater( $user, NS_ENTITYSCHEMA_JSON ),
$fixedIdGenerator,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ RequestContext::getMain(),
+ $services->getLanguageFactory(),
+ $services->getHookContainer(),
+ $services->getTitleFactory()
);
try {
diff --git a/src/DataAccess/MediaWikiRevisionSchemaInserter.php b/src/DataAccess/MediaWikiRevisionSchemaInserter.php
index 52bcea8d59..0e22d70f25 100644
--- a/src/DataAccess/MediaWikiRevisionSchemaInserter.php
+++ b/src/DataAccess/MediaWikiRevisionSchemaInserter.php
@@ -3,13 +3,19 @@
namespace EntitySchema\DataAccess;
use CommentStoreComment;
+use DerivativeContext;
use EntitySchema\Domain\Model\SchemaId;
use EntitySchema\Domain\Storage\IdGenerator;
use EntitySchema\MediaWiki\Content\EntitySchemaContent;
use EntitySchema\Services\SchemaConverter\SchemaConverter;
+use IContextSource;
+use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Languages\LanguageFactory;
use MediaWiki\Revision\SlotRecord;
+use MediaWiki\Storage\PageUpdater;
use RuntimeException;
+use Status;
+use TitleFactory;
/**
* @license GPL-2.0-or-later
@@ -23,19 +29,28 @@ class MediaWikiRevisionSchemaInserter implements SchemaInserter {
private $idGenerator;
/** @var WatchlistUpdater */
private $watchListUpdater;
+ private IContextSource $context;
/** @var LanguageFactory */
private $languageFactory;
+ private HookContainer $hookContainer;
+ private TitleFactory $titleFactory;
public function __construct(
MediaWikiPageUpdaterFactory $pageUpdaterFactory,
WatchlistUpdater $watchListUpdater,
IdGenerator $idGenerator,
- LanguageFactory $languageFactory
+ IContextSource $context,
+ LanguageFactory $languageFactory,
+ HookContainer $hookContainer,
+ TitleFactory $titleFactory
) {
$this->idGenerator = $idGenerator;
$this->pageUpdaterFactory = $pageUpdaterFactory;
$this->watchListUpdater = $watchListUpdater;
+ $this->context = $context;
$this->languageFactory = $languageFactory;
+ $this->hookContainer = $hookContainer;
+ $this->titleFactory = $titleFactory;
}
/**
@@ -63,37 +78,28 @@ public function insertSchema(
$schemaText
);
- $updater = $this->pageUpdaterFactory->getPageUpdater( $id->getId() );
- $updater->setContent(
- SlotRecord::MAIN,
- new EntitySchemaContent( $persistentRepresentation )
- );
-
$schemaConverter = new SchemaConverter();
$schemaData = $schemaConverter->getMonolingualNameBadgeData(
$persistentRepresentation,
$language
);
- $updater->saveRevision(
- CommentStoreComment::newUnsavedComment(
- '/* ' . self::AUTOCOMMENT_NEWSCHEMA . ' */' . $schemaData->label,
- [
- 'key' => 'entityschema-summary-newschema-nolabel',
- 'language' => $language,
- 'label' => $schemaData->label,
- 'description' => $schemaData->description,
- 'aliases' => $schemaData->aliases,
- 'schemaText_truncated' => $this->truncateSchemaTextForCommentData(
- $schemaConverter->getSchemaText( $persistentRepresentation )
- ),
- ]
- ),
- EDIT_NEW | EDIT_INTERNAL
+ $summary = CommentStoreComment::newUnsavedComment(
+ '/* ' . self::AUTOCOMMENT_NEWSCHEMA . ' */' . $schemaData->label,
+ [
+ 'key' => 'entityschema-summary-newschema-nolabel',
+ 'language' => $language,
+ 'label' => $schemaData->label,
+ 'description' => $schemaData->description,
+ 'aliases' => $schemaData->aliases,
+ 'schemaText_truncated' => $this->truncateSchemaTextForCommentData(
+ $schemaConverter->getSchemaText( $persistentRepresentation )
+ ),
+ ]
);
- if ( !$updater->wasSuccessful() ) {
- throw new RuntimeException( 'The revision could not be saved' );
- }
+ $updater = $this->pageUpdaterFactory->getPageUpdater( $id->getId() );
+ $content = new EntitySchemaContent( $persistentRepresentation );
+ $this->saveRevision( $updater, $content, $summary );
$this->watchListUpdater->optionallyWatchNewSchema( $id );
@@ -105,4 +111,29 @@ private function truncateSchemaTextForCommentData( $schemaText ) {
return $language->truncateForVisual( $schemaText, 5000 );
}
+ private function saveRevision(
+ PageUpdater $updater,
+ EntitySchemaContent $content,
+ CommentStoreComment $summary
+ ): void {
+ $context = new DerivativeContext( $this->context );
+ $context->setTitle( $this->titleFactory->castFromPageIdentity( $updater->getPage() ) );
+ $status = Status::newGood();
+ if ( !$this->hookContainer->run(
+ 'EditFilterMergedContent',
+ [ $context, $content, &$status, $summary->text, $this->context->getUser(), false ]
+ ) ) {
+ throw new RuntimeException( $status->getWikiText() );
+ }
+
+ $updater->setContent( SlotRecord::MAIN, $content );
+ $updater->saveRevision(
+ $summary,
+ EDIT_NEW | EDIT_INTERNAL
+ );
+ if ( !$updater->wasSuccessful() ) {
+ throw new RuntimeException( 'The revision could not be saved' );
+ }
+ }
+
}
diff --git a/src/DataAccess/MediaWikiRevisionSchemaUpdater.php b/src/DataAccess/MediaWikiRevisionSchemaUpdater.php
index 8104e8a7e4..4d7d226cab 100644
--- a/src/DataAccess/MediaWikiRevisionSchemaUpdater.php
+++ b/src/DataAccess/MediaWikiRevisionSchemaUpdater.php
@@ -3,16 +3,23 @@
namespace EntitySchema\DataAccess;
use CommentStoreComment;
+use DerivativeContext;
use EntitySchema\Domain\Model\SchemaId;
use EntitySchema\MediaWiki\Content\EntitySchemaContent;
use EntitySchema\Services\SchemaConverter\FullArraySchemaData;
use EntitySchema\Services\SchemaConverter\SchemaConverter;
+use IContextSource;
use InvalidArgumentException;
+use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Languages\LanguageFactory;
+use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionLookup;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\SlotRecord;
+use MediaWiki\Storage\PageUpdater;
use RuntimeException;
+use Status;
+use TitleFactory;
/**
* @license GPL-2.0-or-later
@@ -31,21 +38,44 @@ class MediaWikiRevisionSchemaUpdater implements SchemaUpdater {
private $pageUpdaterFactory;
/** @var WatchlistUpdater */
private $watchListUpdater;
+ private IContextSource $context;
/** @var RevisionLookup */
private $revisionLookup;
/** @var LanguageFactory */
private $languageFactory;
+ private HookContainer $hookContainer;
+ private TitleFactory $titleFactory;
public function __construct(
MediaWikiPageUpdaterFactory $pageUpdaterFactory,
WatchlistUpdater $watchListUpdater,
+ IContextSource $context,
RevisionLookup $revisionLookup,
- LanguageFactory $languageFactory
+ LanguageFactory $languageFactory,
+ HookContainer $hookContainer,
+ TitleFactory $titleFactory
) {
$this->pageUpdaterFactory = $pageUpdaterFactory;
$this->watchListUpdater = $watchListUpdater;
+ $this->context = $context;
$this->revisionLookup = $revisionLookup;
$this->languageFactory = $languageFactory;
+ $this->hookContainer = $hookContainer;
+ $this->titleFactory = $titleFactory;
+ }
+
+ // TODO this should probably be a service in the service container
+ public static function newFromContext( IContextSource $context ): self {
+ $services = MediaWikiServices::getInstance();
+ return new self(
+ new MediaWikiPageUpdaterFactory( $context->getUser() ),
+ new WatchlistUpdater( $context->getUser(), NS_ENTITYSCHEMA_JSON ),
+ $context,
+ $services->getRevisionLookup(),
+ $services->getLanguageFactory(),
+ $services->getHookContainer(),
+ $services->getTitleFactory()
+ );
}
private function truncateSchemaTextForCommentData( $schemaText ) {
@@ -82,26 +112,16 @@ public function overwriteWholeSchema(
throw new EditConflict();
}
- $updater->setContent(
- SlotRecord::MAIN,
- new EntitySchemaContent(
- SchemaEncoder::getPersistentRepresentation(
- $id,
- $labels,
- $descriptions,
- $aliasGroups,
- $schemaText
- )
+ $content = new EntitySchemaContent(
+ SchemaEncoder::getPersistentRepresentation(
+ $id,
+ $labels,
+ $descriptions,
+ $aliasGroups,
+ $schemaText
)
);
-
- $updater->saveRevision(
- $summary,
- EDIT_UPDATE | EDIT_INTERNAL
- );
- if ( !$updater->wasSuccessful() ) {
- throw new RuntimeException( 'The revision could not be saved' );
- }
+ $this->saveRevision( $updater, $content, $summary );
$this->watchListUpdater->optionallyWatchEditedSchema( $id );
}
@@ -144,23 +164,16 @@ static function ( FullArraySchemaData $schemaData ) use ( $langCode, $label, $de
$aliases
);
- $updater->setContent(
- SlotRecord::MAIN,
- new EntitySchemaContent(
- SchemaEncoder::getPersistentRepresentation(
- $id,
- $schemaData->labels,
- $schemaData->descriptions,
- $schemaData->aliases,
- $schemaData->schemaText
- )
+ $content = new EntitySchemaContent(
+ SchemaEncoder::getPersistentRepresentation(
+ $id,
+ $schemaData->labels,
+ $schemaData->descriptions,
+ $schemaData->aliases,
+ $schemaData->schemaText
)
);
-
- $updater->saveRevision( $autoComment, EDIT_UPDATE | EDIT_INTERNAL );
- if ( !$updater->wasSuccessful() ) {
- throw new RuntimeException( 'The revision could not be saved' );
- }
+ $this->saveRevision( $updater, $content, $autoComment );
$this->watchListUpdater->optionallyWatchEditedSchema( $id );
}
@@ -256,6 +269,19 @@ static function ( FullArraySchemaData $schemaData ) use ( $schemaText ) {
return;
}
+ $commentText = '/* ' . self::AUTOCOMMENT_UPDATED_SCHEMATEXT . ' */' . $userSummary;
+ $summary = CommentStoreComment::newUnsavedComment(
+ $commentText,
+ [
+ 'key' => self::AUTOCOMMENT_UPDATED_SCHEMATEXT,
+ 'userSummary' => $userSummary,
+ 'schemaText_truncated' => $this->truncateSchemaTextForCommentData(
+ // TODO use unpatched $schemaText or patched $schemaData->schemaText here?
+ $schemaData->schemaText
+ ),
+ ]
+ );
+
$persistentRepresentation = SchemaEncoder::getPersistentRepresentation(
$id,
$schemaData->labels,
@@ -264,29 +290,8 @@ static function ( FullArraySchemaData $schemaData ) use ( $schemaText ) {
$schemaData->schemaText
);
- $updater->setContent(
- SlotRecord::MAIN,
- new EntitySchemaContent( $persistentRepresentation )
- );
-
- $commentText = '/* ' . self::AUTOCOMMENT_UPDATED_SCHEMATEXT . ' */' . $userSummary;
- $updater->saveRevision(
- CommentStoreComment::newUnsavedComment(
- $commentText,
- [
- 'key' => self::AUTOCOMMENT_UPDATED_SCHEMATEXT,
- 'userSummary' => $userSummary,
- 'schemaText_truncated' => $this->truncateSchemaTextForCommentData(
- // TODO use unpatched $schemaText or patched $schemaData->schemaText here?
- $schemaData->schemaText
- ),
- ]
- ),
- EDIT_UPDATE | EDIT_INTERNAL
- );
- if ( !$updater->wasSuccessful() ) {
- throw new RuntimeException( 'The revision could not be saved' );
- }
+ $content = new EntitySchemaContent( $persistentRepresentation );
+ $this->saveRevision( $updater, $content, $summary );
$this->watchListUpdater->optionallyWatchEditedSchema( $id );
}
@@ -302,4 +307,29 @@ private function checkSchemaExists( RevisionRecord $parentRevision = null ) {
}
}
+ private function saveRevision(
+ PageUpdater $updater,
+ EntitySchemaContent $content,
+ CommentStoreComment $summary
+ ): void {
+ $context = new DerivativeContext( $this->context );
+ $context->setTitle( $this->titleFactory->castFromPageIdentity( $updater->getPage() ) );
+ $status = Status::newGood();
+ if ( !$this->hookContainer->run(
+ 'EditFilterMergedContent',
+ [ $context, $content, &$status, $summary->text, $this->context->getUser(), false ]
+ ) ) {
+ throw new RuntimeException( $status->getWikiText() );
+ }
+
+ $updater->setContent( SlotRecord::MAIN, $content );
+ $updater->saveRevision(
+ $summary,
+ EDIT_UPDATE | EDIT_INTERNAL
+ );
+ if ( !$updater->wasSuccessful() ) {
+ throw new RuntimeException( 'The revision could not be saved' );
+ }
+ }
+
}
diff --git a/src/MediaWiki/Actions/RestoreSubmitAction.php b/src/MediaWiki/Actions/RestoreSubmitAction.php
index ad870c4940..ac122bed07 100644
--- a/src/MediaWiki/Actions/RestoreSubmitAction.php
+++ b/src/MediaWiki/Actions/RestoreSubmitAction.php
@@ -5,14 +5,11 @@
namespace EntitySchema\MediaWiki\Actions;
use CommentStoreComment;
-use EntitySchema\DataAccess\MediaWikiPageUpdaterFactory;
use EntitySchema\DataAccess\MediaWikiRevisionSchemaUpdater;
-use EntitySchema\DataAccess\WatchlistUpdater;
use EntitySchema\Domain\Model\SchemaId;
use EntitySchema\MediaWiki\Content\EntitySchemaContent;
use EntitySchema\Services\SchemaConverter\PersistenceSchemaData;
use EntitySchema\Services\SchemaConverter\SchemaConverter;
-use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\SlotRecord;
use RuntimeException;
@@ -102,12 +99,7 @@ private function storeRestoredSchema(
CommentStoreComment $summary
): Status {
- $schemaUpdater = new MediaWikiRevisionSchemaUpdater(
- new MediaWikiPageUpdaterFactory( $this->getUser() ),
- new WatchlistUpdater( $this->getUser(), NS_ENTITYSCHEMA_JSON ),
- MediaWikiServices::getInstance()->getRevisionLookup(),
- MediaWikiServices::getInstance()->getLanguageFactory()
- );
+ $schemaUpdater = MediaWikiRevisionSchemaUpdater::newFromContext( $this->getContext() );
try {
$schemaUpdater->overwriteWholeSchema(
diff --git a/src/MediaWiki/Actions/SchemaEditAction.php b/src/MediaWiki/Actions/SchemaEditAction.php
index ba606c49be..93440dbdac 100644
--- a/src/MediaWiki/Actions/SchemaEditAction.php
+++ b/src/MediaWiki/Actions/SchemaEditAction.php
@@ -6,9 +6,7 @@
use Article;
use EntitySchema\DataAccess\EditConflict;
-use EntitySchema\DataAccess\MediaWikiPageUpdaterFactory;
use EntitySchema\DataAccess\MediaWikiRevisionSchemaUpdater;
-use EntitySchema\DataAccess\WatchlistUpdater;
use EntitySchema\Domain\Model\SchemaId;
use EntitySchema\MediaWiki\Content\EntitySchemaContent;
use EntitySchema\Presentation\InputValidator;
@@ -107,15 +105,8 @@ public function onSubmit( $data ) {
return $output->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1\n</div>",
[ 'missingsummary', $this->msg( $this->submitMsgKey )->text() ] );
}
- $updaterFactory = new MediaWikiPageUpdaterFactory( $user );
$id = new SchemaId( $this->getTitle()->getText() );
- $watchListUpdater = new WatchlistUpdater( $user, NS_ENTITYSCHEMA_JSON );
- $schemaUpdater = new MediaWikiRevisionSchemaUpdater(
- $updaterFactory,
- $watchListUpdater,
- MediaWikiServices::getInstance()->getRevisionLookup(),
- MediaWikiServices::getInstance()->getLanguageFactory()
- );
+ $schemaUpdater = MediaWikiRevisionSchemaUpdater::newFromContext( $this->getContext() );
try {
$schemaUpdater->updateSchemaText(
diff --git a/src/MediaWiki/Actions/UndoSubmitAction.php b/src/MediaWiki/Actions/UndoSubmitAction.php
index 5d3fe96418..f940d7e3ef 100644
--- a/src/MediaWiki/Actions/UndoSubmitAction.php
+++ b/src/MediaWiki/Actions/UndoSubmitAction.php
@@ -5,9 +5,7 @@
namespace EntitySchema\MediaWiki\Actions;
use CommentStoreComment;
-use EntitySchema\DataAccess\MediaWikiPageUpdaterFactory;
use EntitySchema\DataAccess\MediaWikiRevisionSchemaUpdater;
-use EntitySchema\DataAccess\WatchlistUpdater;
use EntitySchema\Domain\Model\SchemaId;
use EntitySchema\Services\SchemaConverter\FullArraySchemaData;
use MediaWiki\MediaWikiServices;
@@ -95,12 +93,7 @@ private function undo(): Status {
}
private function storePatchedSchema( FullArraySchemaData $patchedSchema, int $baseRevId ): Status {
- $schemaUpdater = new MediaWikiRevisionSchemaUpdater(
- new MediaWikiPageUpdaterFactory( $this->getUser() ),
- new WatchlistUpdater( $this->getUser(), NS_ENTITYSCHEMA_JSON ),
- MediaWikiServices::getInstance()->getRevisionLookup(),
- MediaWikiServices::getInstance()->getLanguageFactory()
- );
+ $schemaUpdater = MediaWikiRevisionSchemaUpdater::newFromContext( $this->getContext() );
$summary = $this->createSummaryCommentForUndoRev(
$this->getContext()->getRequest()->getText( 'wpSummary' ),
diff --git a/src/MediaWiki/Specials/NewEntitySchema.php b/src/MediaWiki/Specials/NewEntitySchema.php
index 3b5b888252..0e5a209110 100644
--- a/src/MediaWiki/Specials/NewEntitySchema.php
+++ b/src/MediaWiki/Specials/NewEntitySchema.php
@@ -82,11 +82,15 @@ public function submitCallback( array $data, HTMLForm $form ): Status {
$pageUpdaterFactory = new MediaWikiPageUpdaterFactory( $this->getUser() );
+ $services = MediaWikiServices::getInstance();
$schemaInserter = new MediaWikiRevisionSchemaInserter(
$pageUpdaterFactory,
new WatchlistUpdater( $this->getUser(), NS_ENTITYSCHEMA_JSON ),
$this->idGenerator,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getContext(),
+ $services->getLanguageFactory(),
+ $services->getHookContainer(),
+ $services->getTitleFactory()
);
$newId = $schemaInserter->insertSchema(
$data[self::FIELD_LANGUAGE],
diff --git a/src/MediaWiki/Specials/SetEntitySchemaLabelDescriptionAliases.php b/src/MediaWiki/Specials/SetEntitySchemaLabelDescriptionAliases.php
index 2e941060b8..f99f06e07c 100644
--- a/src/MediaWiki/Specials/SetEntitySchemaLabelDescriptionAliases.php
+++ b/src/MediaWiki/Specials/SetEntitySchemaLabelDescriptionAliases.php
@@ -5,9 +5,7 @@
namespace EntitySchema\MediaWiki\Specials;
use EntitySchema\DataAccess\EditConflict;
-use EntitySchema\DataAccess\MediaWikiPageUpdaterFactory;
use EntitySchema\DataAccess\MediaWikiRevisionSchemaUpdater;
-use EntitySchema\DataAccess\WatchlistUpdater;
use EntitySchema\Domain\Model\SchemaId;
use EntitySchema\Presentation\InputValidator;
use EntitySchema\Services\SchemaConverter\NameBadge;
@@ -72,8 +70,6 @@ public function execute( $subPage ): void {
}
public function submitEditFormCallback( array $data ): Status {
- $updaterFactory = new MediaWikiPageUpdaterFactory( $this->getContext()->getUser() );
- $watchListUpdater = new WatchlistUpdater( $this->getUser(), NS_ENTITYSCHEMA_JSON );
try {
$id = new SchemaId( $data[self::FIELD_ID] );
} catch ( InvalidArgumentException $e ) {
@@ -82,12 +78,7 @@ public function submitEditFormCallback( array $data ): Status {
$title = Title::makeTitle( NS_ENTITYSCHEMA_JSON, $id->getId() );
$this->checkBlocked( $title );
$aliases = array_map( 'trim', explode( '|', $data[self::FIELD_ALIASES] ) );
- $schemaUpdater = new MediaWikiRevisionSchemaUpdater(
- $updaterFactory,
- $watchListUpdater,
- MediaWikiServices::getInstance()->getRevisionLookup(),
- MediaWikiServices::getInstance()->getLanguageFactory()
- );
+ $schemaUpdater = MediaWikiRevisionSchemaUpdater::newFromContext( $this->getContext() );
try {
$schemaUpdater->updateSchemaNameBadge(
diff --git a/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaInserterTest.php b/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaInserterTest.php
index b41cf006a9..e849c386b7 100644
--- a/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaInserterTest.php
+++ b/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaInserterTest.php
@@ -3,16 +3,23 @@
namespace EntitySchema\Tests\Integration\DataAccess;
use CommentStoreComment;
+use Content;
use EntitySchema\DataAccess\MediaWikiPageUpdaterFactory;
use EntitySchema\DataAccess\MediaWikiRevisionSchemaInserter;
use EntitySchema\DataAccess\WatchlistUpdater;
use EntitySchema\Domain\Storage\IdGenerator;
use EntitySchema\MediaWiki\Content\EntitySchemaContent;
-use MediaWiki\MediaWikiServices;
+use IContextSource;
+use MediaWiki\HookContainer\HookContainer;
+use MediaWiki\Page\PageIdentityValue;
+use MediaWiki\Request\FauxRequest;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Storage\PageUpdater;
use MediaWikiIntegrationTestCase;
+use RequestContext;
use RuntimeException;
+use Status;
+use User;
/**
* @license GPL-2.0-or-later
@@ -59,7 +66,10 @@ public function testInsertSchema() {
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchNewSchema' ),
$idGenerator,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ new RequestContext(),
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->createConfiguredMock( HookContainer::class, [ 'run' => true ] ),
+ $this->getServiceContainer()->getTitleFactory()
);
$inserter->insertSchema( $language,
@@ -91,7 +101,10 @@ public function testInsertSchema_commentWithCleanedUpParameters() {
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchNewSchema' ),
$idGenerator,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ new RequestContext(),
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->createConfiguredMock( HookContainer::class, [ 'run' => true ] ),
+ $this->getServiceContainer()->getTitleFactory()
);
$inserter->insertSchema(
@@ -117,6 +130,56 @@ public function testInsertSchema_saveFails() {
);
}
+ public function testInsertSchema_rejectedByEditFilter() {
+ $originalRequest = new FauxRequest();
+ $originalUser = $this->getTestUser()->getUser();
+ $originalContext = new RequestContext();
+ $originalContext->setRequest( $originalRequest );
+ $originalContext->setUser( $originalUser );
+ $pageIdentity = new PageIdentityValue( 1, NS_ENTITYSCHEMA_JSON, 'E123', false );
+ $this->setTemporaryHook(
+ 'EditFilterMergedContent',
+ function (
+ IContextSource $context,
+ Content $content,
+ Status $status,
+ string $summary,
+ User $user,
+ bool $minoredit
+ ) use ( $originalRequest, $originalUser, $pageIdentity ) {
+ $this->assertSame( $originalRequest, $context->getRequest() );
+ $this->assertSame( $originalUser, $user );
+ $this->assertTrue( $context->getTitle()->isSamePageAs( $pageIdentity ) );
+ $this->assertInstanceOf( EntitySchemaContent::class, $content );
+ $this->assertSame(
+ '/* ' . MediaWikiRevisionSchemaInserter::AUTOCOMMENT_NEWSCHEMA . ' */test label',
+ $summary
+ );
+ $this->assertFalse( $minoredit );
+
+ $status->fatal( __CLASS__ );
+ return false;
+ }
+ );
+ $pageUpdater = $this->createMock( PageUpdater::class );
+ $pageUpdater->method( 'getPage' )
+ ->willReturn( $pageIdentity );
+ $pageUpdater->expects( $this->never() )
+ ->method( 'saveRevision' );
+ $inserter = new MediaWikiRevisionSchemaInserter(
+ $this->getPageUpdaterFactory( $pageUpdater ),
+ $this->getMockWatchlistUpdater(),
+ $this->createConfiguredMock( IdGenerator::class, [ 'getNewId' => 123 ] ),
+ $originalContext,
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
+ );
+
+ $this->expectException( RuntimeException::class );
+ $inserter->insertSchema( 'en', 'test label' );
+ }
+
private function getPageUpdaterFactoryExpectingContent(
EntitySchemaContent $expectedContent
): MediaWikiPageUpdaterFactory {
@@ -166,7 +229,10 @@ private function newMediaWikiRevisionSchemaInserterFailingToSave(): MediaWikiRev
$this->getPageUpdaterFactory( $pageUpdater ),
$this->getMockWatchlistUpdater(),
$idGenerator,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ new RequestContext(),
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->createConfiguredMock( HookContainer::class, [ 'run' => true ] ),
+ $this->getServiceContainer()->getTitleFactory()
);
}
diff --git a/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaUpdaterTest.php b/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaUpdaterTest.php
index 9f83799603..cf62d5af92 100644
--- a/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaUpdaterTest.php
+++ b/tests/phpunit/integration/DataAccess/MediaWikiRevisionSchemaUpdaterTest.php
@@ -3,6 +3,7 @@
namespace EntitySchema\Tests\Integration\DataAccess;
use CommentStoreComment;
+use Content;
use DomainException;
use EntitySchema\DataAccess\EditConflict;
use EntitySchema\DataAccess\MediaWikiPageUpdaterFactory;
@@ -11,21 +12,26 @@
use EntitySchema\Domain\Model\SchemaId;
use EntitySchema\MediaWiki\Content\EntitySchemaContent;
use EntitySchema\Services\SchemaConverter\NameBadge;
+use IContextSource;
use InvalidArgumentException;
-use MediaWiki\MediaWikiServices;
+use MediaWiki\Page\PageIdentityValue;
+use MediaWiki\Request\FauxRequest;
use MediaWiki\Revision\RevisionLookup;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Storage\PageUpdater;
-use PHPUnit\Framework\TestCase;
+use MediaWikiIntegrationTestCase;
+use RequestContext;
use RuntimeException;
+use Status;
+use User;
/**
* @covers \EntitySchema\DataAccess\MediaWikiRevisionSchemaUpdater
* @covers \EntitySchema\DataAccess\SchemaUpdateGuard
* @license GPL-2.0-or-later
*/
-class MediaWikiRevisionSchemaUpdaterTest extends TestCase {
+class MediaWikiRevisionSchemaUpdaterTest extends MediaWikiIntegrationTestCase {
/** @var RevisionRecord|null */
private $baseRevision;
@@ -119,8 +125,64 @@ private function newMediaWikiRevisionSchemaUpdaterFailingToSave(): MediaWikiRevi
return new MediaWikiRevisionSchemaUpdater(
$this->getPageUpdaterFactory( $pageUpdater ),
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
+ );
+ }
+
+ private function newMediaWikiRevisionSchemaUpdaterWithEditFilter(): MediaWikiRevisionSchemaUpdater {
+ $existingContent = new EntitySchemaContent( '{}' );
+ $this->parentRevision = $this->createMockRevisionRecord( $existingContent );
+
+ $originalRequest = new FauxRequest();
+ $originalUser = $this->getTestUser()->getUser();
+ $originalContext = new RequestContext();
+ $originalContext->setRequest( $originalRequest );
+ $originalContext->setUser( $originalUser );
+ $pageIdentity = new PageIdentityValue( 1, NS_ENTITYSCHEMA_JSON, 'E123', false );
+ $this->setTemporaryHook(
+ 'EditFilterMergedContent',
+ function (
+ IContextSource $context,
+ Content $content,
+ Status $status,
+ string $summary,
+ User $user,
+ bool $minoredit
+ ) use ( $originalRequest, $originalUser, $pageIdentity ) {
+ $this->assertSame( $originalRequest, $context->getRequest() );
+ $this->assertSame( $originalUser, $user );
+ $this->assertTrue( $context->getTitle()->isSamePageAs( $pageIdentity ) );
+ $this->assertInstanceOf( EntitySchemaContent::class, $content );
+ $this->assertStringStartsWith( '/* entityschema-summary-', $summary );
+ $this->assertFalse( $minoredit );
+
+ $status->fatal( __CLASS__ );
+ return false;
+ }
+ );
+
+ $pageUpdater = $this->createMock( PageUpdater::class );
+ $pageUpdater->method( 'grabParentRevision' )
+ ->willReturn( $this->parentRevision );
+ $pageUpdater->method( 'getPage' )
+ ->willReturn( $pageIdentity );
+ $pageUpdater->expects( $this->never() )
+ ->method( 'saveRevision' );
+
+ $mockRevLookup = $this->createMockRevisionLookup( [ $this->parentRevision ] );
+
+ return new MediaWikiRevisionSchemaUpdater(
+ $this->getPageUpdaterFactory( $pageUpdater ),
+ $this->getMockWatchlistUpdater(),
+ $originalContext,
+ $mockRevLookup,
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
}
@@ -133,8 +195,11 @@ public function testOverwriteWholeSchema_throwsForNonExistantPage() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$this->expectException( RuntimeException::class );
@@ -184,8 +249,11 @@ public function testOverwriteWholeSchema_throwsForInvalidParams(
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( $exceptionMessage );
@@ -231,8 +299,11 @@ public function testOverwriteWholeSchema_WritesExpectedContentForOverwritingMono
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schmeaUpdater->overwriteWholeSchema(
new SchemaId( 'E1' ),
@@ -261,6 +332,23 @@ public function testOverwriteWholeSchema_saveFails() {
);
}
+ public function testOverwriteWholeSchema_editFilterFails() {
+ $schmeaUpdater = $this->newMediaWikiRevisionSchemaUpdaterWithEditFilter();
+
+ $this->expectException( RuntimeException::class );
+ $schmeaUpdater->overwriteWholeSchema(
+ new SchemaId( 'E1' ),
+ [],
+ [],
+ [],
+ 'lalalala',
+ 1,
+ CommentStoreComment::newUnsavedComment(
+ '/* ' . MediaWikiRevisionSchemaUpdater::AUTOCOMMENT_RESTORE . ' */'
+ )
+ );
+ }
+
/**
* @param string|null $methodToExpect
*
@@ -284,8 +372,11 @@ public function testUpdateSchemaText_throwsForInvalidParams() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$this->expectException( InvalidArgumentException::class );
@@ -316,8 +407,11 @@ public function testUpdateSchemaText_throwsForUnknownSerializationVersion() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$this->expectException( DomainException::class );
@@ -346,8 +440,11 @@ public function testUpdateSchemaText_throwsForEditConflict() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$this->expectException( EditConflict::class );
@@ -390,8 +487,11 @@ public function testUpdateSchemaText_WritesExpectedContentForOverwritingSchemaTe
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schmeaUpdater->updateSchemaText(
@@ -449,8 +549,11 @@ public function testUpdateSchemaText_mergesChangesInNameBadge() {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schemaUpdater->updateSchemaText(
new SchemaId( $id ),
@@ -540,8 +643,11 @@ public function testUpdateSchemaText_mergesChangesInSchemaText() {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schemaUpdater->updateSchemaText(
new SchemaId( $id ),
@@ -562,6 +668,17 @@ public function testUpdateSchemaText_saveFails() {
);
}
+ public function testUpdateSchemaText_editFilterFails() {
+ $schmeaUpdater = $this->newMediaWikiRevisionSchemaUpdaterWithEditFilter();
+
+ $this->expectException( RuntimeException::class );
+ $schmeaUpdater->updateSchemaText(
+ new SchemaId( 'E1' ),
+ 'qwerty',
+ 1
+ );
+ }
+
public function testUpdateSchemaText_comment() {
$expectedComment = CommentStoreComment::newUnsavedComment(
'/* ' . MediaWikiRevisionSchemaUpdater::AUTOCOMMENT_UPDATED_SCHEMATEXT . ' */user given',
@@ -591,8 +708,11 @@ public function testUpdateSchemaText_comment() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schmeaUpdater->updateSchemaText(
@@ -620,8 +740,11 @@ public function testUpdateSchemaText_onlySerializationVersionChanges() {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schemaUpdater->updateSchemaText(
@@ -662,8 +785,11 @@ public function testUpdateSchemaNameBadgeSuccess() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schmeaUpdater->updateSchemaNameBadge(
@@ -725,8 +851,11 @@ public function testUpdateMultiLingualSchemaNameBadgeSuccess() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schmeaUpdater->updateSchemaNameBadge(
@@ -787,8 +916,11 @@ public function testUpdateSchemaNameBadge_comment(
$writer = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$writer->updateSchemaNameBadge(
@@ -908,8 +1040,11 @@ public function testUpdateSchemaNameBadge_throwsForEditConflict() {
$schmeaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$this->expectException( EditConflict::class );
@@ -966,8 +1101,11 @@ public function testUpdateSchemaNameBadgeSuccessNonConflictingEdit() {
$updater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$updater->updateSchemaNameBadge(
@@ -1028,8 +1166,11 @@ public function testUpdateNameBadge_mergesChangesInSchemaText() {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schemaUpdater->updateSchemaNameBadge(
new SchemaId( $id ),
@@ -1090,8 +1231,11 @@ public function testUpdateNameBadge_mergesChangesInOtherLanguage() {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schemaUpdater->updateSchemaNameBadge(
new SchemaId( $id ),
@@ -1151,8 +1295,11 @@ public function testUpdateNameBadge_mergesChangesInSameLanguage() {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater( 'optionallyWatchEditedSchema' ),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schemaUpdater->updateSchemaNameBadge(
new SchemaId( $id ),
@@ -1179,6 +1326,20 @@ public function testUpdateSchemaNameBadge_saveFails() {
);
}
+ public function testUpdateSchemaNameBadge_editFilterFails() {
+ $schmeaUpdater = $this->newMediaWikiRevisionSchemaUpdaterWithEditFilter();
+
+ $this->expectException( RuntimeException::class );
+ $schmeaUpdater->updateSchemaNameBadge(
+ new SchemaId( 'E1' ),
+ 'en',
+ 'test label',
+ 'test description',
+ [ 'test alias' ],
+ 1
+ );
+ }
+
public function testUpdateSchemaNameBadge_onlySerializationVersionChanges() {
$this->parentRevision = $this->createMockRevisionRecord(
new EntitySchemaContent( json_encode( [
@@ -1196,8 +1357,11 @@ public function testUpdateSchemaNameBadge_onlySerializationVersionChanges() {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$pageUpdaterFactory,
$this->getMockWatchlistUpdater(),
+ new RequestContext(),
$mockRevLookup,
- MediaWikiServices::getInstance()->getLanguageFactory()
+ $this->getServiceContainer()->getLanguageFactory(),
+ $this->getServiceContainer()->getHookContainer(),
+ $this->getServiceContainer()->getTitleFactory()
);
$schemaUpdater->updateSchemaNameBadge(
diff --git a/tests/phpunit/integration/MediaWiki/Hooks/PageHistoryLineEndingHandlerTest.php b/tests/phpunit/integration/MediaWiki/Hooks/PageHistoryLineEndingHandlerTest.php
index c49469c978..2cb78b22f2 100644
--- a/tests/phpunit/integration/MediaWiki/Hooks/PageHistoryLineEndingHandlerTest.php
+++ b/tests/phpunit/integration/MediaWiki/Hooks/PageHistoryLineEndingHandlerTest.php
@@ -10,6 +10,7 @@
use EntitySchema\DataAccess\MediaWikiRevisionSchemaUpdater;
use EntitySchema\DataAccess\WatchlistUpdater;
use EntitySchema\Domain\Storage\IdGenerator;
+use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Languages\LanguageFactory;
use MediaWiki\Request\FauxRequest;
use MediaWikiIntegrationTestCase;
@@ -23,14 +24,23 @@
class PageHistoryLineEndingHandlerTest extends MediaWikiIntegrationTestCase {
public function testOneRestoreLink(): void {
+ $context = new RequestContext();
+ $context->setRequest( new FauxRequest() );
+
$updaterFactory = new MediaWikiPageUpdaterFactory( $this->getTestUser()->getUser() );
$watchListUpdater = $this->createMock( WatchlistUpdater::class );
$languageFactory = $this->createMock( LanguageFactory::class );
+ $hookContainer = $this->createConfiguredMock( HookContainer::class,
+ [ 'run' => true ] );
+ $titleFactory = $this->getServiceContainer()->getTitleFactory();
$schemaInserter = new MediaWikiRevisionSchemaInserter(
$updaterFactory,
$watchListUpdater,
$this->createConfiguredMock( IdGenerator::class, [ 'getNewId' => 1 ] ),
- $languageFactory
+ $context,
+ $languageFactory,
+ $hookContainer,
+ $titleFactory
);
$schemaId = $schemaInserter->insertSchema( 'en' );
@@ -38,18 +48,19 @@ public function testOneRestoreLink(): void {
$schemaUpdater = new MediaWikiRevisionSchemaUpdater(
$updaterFactory,
$watchListUpdater,
+ $context,
$revisionLookup,
- $languageFactory
+ $languageFactory,
+ $hookContainer,
+ $titleFactory
);
$schemaTitle = $this->getServiceContainer()
->getTitleFactory()
->makeTitleSafe( NS_ENTITYSCHEMA_JSON, $schemaId->getId() );
+ $context->setTitle( $schemaTitle );
$baseRevId = $revisionLookup->getKnownCurrentRevision( $schemaTitle )->getId();
$schemaUpdater->updateSchemaText( $schemaId, 'a', $baseRevId );
- $context = new RequestContext();
- $context->setRequest( new FauxRequest() );
- $context->setTitle( $schemaTitle );
$action = $this->getServiceContainer()
->getActionFactory()
->getAction(
--
2.39.2

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10914862
Default Alt Text
0001-SECURITY-Run-EditFilterMergedContent-hook-on-edits.patch (44 KB)

Event Timeline