jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/350087 )
Change subject: Redirect creation: Don't set EDIT_NEW on edit if the page exists
......................................................................
Redirect creation: Don't set EDIT_NEW on edit if the page exists
The purpose of this check was to allow creating redirects
as new pages, but only if a page existed before. But we
also set EDIT_NEW in case an existing page has deleted
revisions.
Fix this by just setting EDIT_NEW if the page doesn't exist
but it has existed before.
Bug: T163748
Change-Id: I1e2edd2089044e54c3e96b9306f54408615863c3
---
M repo/includes/Interactors/RedirectCreationInteractor.php
M repo/tests/phpunit/includes/Api/CreateRedirectTest.php
2 files changed, 99 insertions(+), 9 deletions(-)
Approvals:
jenkins-bot: Verified
Thiemo Mättig (WMDE): Looks good to me, approved
diff --git a/repo/includes/Interactors/RedirectCreationInteractor.php
b/repo/includes/Interactors/RedirectCreationInteractor.php
index ba150ff..0fbf441 100644
--- a/repo/includes/Interactors/RedirectCreationInteractor.php
+++ b/repo/includes/Interactors/RedirectCreationInteractor.php
@@ -255,7 +255,10 @@
if ( $bot ) {
$flags = $flags | EDIT_FORCE_BOT;
}
- if ( $this->entityTitleLookup->getTitleForId(
$redirect->getEntityId() )->isDeleted() ) {
+ $title = $this->entityTitleLookup->getTitleForId(
$redirect->getEntityId() );
+
+ if ( !$title->exists() && $title->isDeletedQuick() ) {
+ // Allow creating new pages as redirects, but only if
they existed before.
$flags = $flags | EDIT_NEW;
} else {
$flags = $flags | EDIT_UPDATE;
diff --git a/repo/tests/phpunit/includes/Api/CreateRedirectTest.php
b/repo/tests/phpunit/includes/Api/CreateRedirectTest.php
index bf580f4..6d44c36 100644
--- a/repo/tests/phpunit/includes/Api/CreateRedirectTest.php
+++ b/repo/tests/phpunit/includes/Api/CreateRedirectTest.php
@@ -108,10 +108,12 @@
/**
* @param array $params
* @param User|null $user
+ * @param RedirectCreationInteractor|null $interactor
RedirectCreationInteractor to use, mock interactor
+ * will be used if null provided.
*
* @return CreateRedirect
*/
- private function newApiModule( array $params, User $user = null ) {
+ private function newApiModule( array $params, User $user = null,
RedirectCreationInteractor $interactor = null ) {
if ( !$user ) {
$user = $GLOBALS['wgUser'];
}
@@ -130,12 +132,8 @@
$context = new RequestContext();
$context->setRequest( new FauxRequest() );
- return new CreateRedirect(
- $main,
- 'wbcreateredirect',
- new BasicEntityIdParser(),
- $errorReporter,
- new RedirectCreationInteractor(
+ if ( $interactor === null ) {
+ $interactor = new RedirectCreationInteractor(
$this->mockRepository,
$this->mockRepository,
$this->getPermissionCheckers(),
@@ -144,7 +142,15 @@
$this->getMockEditFilterHookRunner(),
$this->mockRepository,
$this->getMockEntityTitleLookup()
- )
+ );
+ }
+
+ return new CreateRedirect(
+ $main,
+ 'wbcreateredirect',
+ new BasicEntityIdParser(),
+ $errorReporter,
+ $interactor
);
}
@@ -238,6 +244,87 @@
}
}
+ public function
testGivenSourceHasDeletedRevisionsButExists_sourcePageIsUpdatedAsRedirect() {
+ global $wgUser;
+
+ $sourceId = new ItemId( 'Q11' );
+ $sourceItem = new Item( $sourceId );
+ $targetId = new ItemId( 'Q12' );
+ $targetItem = new Item( $targetId );
+
+ $params = array( 'from' => $sourceId->getSerialization(), 'to'
=> $targetId->getSerialization() );
+
+ $params['token'] = $wgUser->getToken();
+
+ $request = new FauxRequest( $params, true );
+
+ $main = new ApiMain( $request, true );
+ $main->getContext()->setUser( $wgUser );
+
+ $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+ $interactor = $wikibaseRepo->newRedirectCreationInteractor(
$wgUser, $main->getContext() );
+ $store = $wikibaseRepo->getEntityStore();
+
+ $store->saveEntity( $sourceItem, 'Created the source item',
$wgUser );
+ $store->deleteEntity( $sourceId, 'test reason', $wgUser );
+ $store->saveEntity( $sourceItem, 'Recreated the source item',
$wgUser );
+
+ $store->saveEntity( $targetItem, 'Created the target item',
$wgUser );
+
+ $module = $this->newApiModule( $params, $wgUser, $interactor );
+
+ $module->execute();
+ $result = $module->getResult();
+
+ $resultData = $result->getResultData( null, array(
+ 'BC' => array(),
+ 'Types' => array(),
+ 'Strip' => 'all',
+ ) );
+
+ $this->assertSuccess( $resultData );
+ }
+
+ public function
testGivenSourceHasDeletedRevisionsAndDoesNotExist_sourcePageIsCreatedAsRedirect()
{
+ global $wgUser;
+
+ $sourceId = new ItemId( 'Q11' );
+ $sourceItem = new Item( $sourceId );
+ $targetId = new ItemId( 'Q12' );
+ $targetItem = new Item( $targetId );
+
+ $params = array( 'from' => $sourceId->getSerialization(), 'to'
=> $targetId->getSerialization() );
+
+ $params['token'] = $wgUser->getToken();
+
+ $request = new FauxRequest( $params, true );
+
+ $main = new ApiMain( $request, true );
+ $main->getContext()->setUser( $wgUser );
+
+ $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+ $interactor = $wikibaseRepo->newRedirectCreationInteractor(
$wgUser, $main->getContext() );
+ $store = $wikibaseRepo->getEntityStore();
+
+ $store->saveEntity( $sourceItem, 'Created the source item',
$wgUser );
+ $store->deleteEntity( $sourceId, 'test reason', $wgUser );
+
+ $store->saveEntity( $targetItem, 'Created the target item',
$wgUser );
+
+ $module = $this->newApiModule( $params, $wgUser, $interactor );
+
+ $module->execute();
+ $result = $module->getResult();
+
+ $resultData = $result->getResultData( null, array(
+ 'BC' => array(),
+ 'Types' => array(),
+ 'Strip' => 'all',
+ ) );
+
+ $this->assertSuccess( $resultData );
+ }
+
public function testSetRedirect_noPermission() {
$this->setExpectedException( ApiUsageException::class );
--
To view, visit https://gerrit.wikimedia.org/r/350087
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1e2edd2089044e54c3e96b9306f54408615863c3
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits