2013-10-27 04:53:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-07-18 23:33:15 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
|
|
|
|
use MediaWiki\Block\Restriction\PageRestriction;
|
2020-08-27 09:27:10 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-05-02 03:17:21 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2021-06-01 23:06:18 +00:00
|
|
|
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
|
2019-07-18 23:33:15 +00:00
|
|
|
|
2013-10-27 04:53:39 +00:00
|
|
|
/**
|
|
|
|
|
* Tests for action=revisiondelete
|
|
|
|
|
* @covers APIRevisionDelete
|
|
|
|
|
* @group API
|
|
|
|
|
* @group medium
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class ApiRevisionDeleteTest extends ApiTestCase {
|
2021-06-01 23:06:18 +00:00
|
|
|
use MockAuthorityTrait;
|
2013-10-27 04:53:39 +00:00
|
|
|
|
2014-08-16 12:53:24 +00:00
|
|
|
public static $page = 'Help:ApiRevDel_test';
|
2016-02-17 09:09:32 +00:00
|
|
|
public $revs = [];
|
2013-10-27 04:53:39 +00:00
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2013-10-27 04:53:39 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
// Make a few edits for us to play with
|
|
|
|
|
for ( $i = 1; $i <= 5; $i++ ) {
|
2021-05-12 06:53:27 +00:00
|
|
|
$this->editPage( self::$page, MWCryptRand::generateHex( 10 ), 'summary' );
|
2019-07-04 21:24:34 +00:00
|
|
|
$this->revs[] = Title::newFromText( self::$page )->getLatestRevID( Title::READ_LATEST );
|
2013-10-27 04:53:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testHidingRevisions() {
|
2021-06-01 23:06:18 +00:00
|
|
|
$performer = $this->mockAnonAuthorityWithPermissions( [ 'writeapi', 'deleterevision' ] );
|
2013-10-27 04:53:39 +00:00
|
|
|
$revid = array_shift( $this->revs );
|
2021-06-01 23:06:18 +00:00
|
|
|
$out = $this->doApiRequestWithToken( [
|
2013-10-27 04:53:39 +00:00
|
|
|
'action' => 'revisiondelete',
|
|
|
|
|
'type' => 'revision',
|
|
|
|
|
'target' => self::$page,
|
|
|
|
|
'ids' => $revid,
|
|
|
|
|
'hide' => 'content|user|comment',
|
2021-06-01 23:06:18 +00:00
|
|
|
], null, $performer );
|
2013-10-27 04:53:39 +00:00
|
|
|
// Check the output
|
|
|
|
|
$out = $out[0]['revisiondelete'];
|
2021-03-07 20:00:46 +00:00
|
|
|
$this->assertEquals( 'Success', $out['status'] );
|
2013-10-27 04:53:39 +00:00
|
|
|
$this->assertArrayHasKey( 'items', $out );
|
|
|
|
|
$item = $out['items'][0];
|
2016-12-19 16:36:09 +00:00
|
|
|
$this->assertTrue( $item['userhidden'], 'userhidden' );
|
|
|
|
|
$this->assertTrue( $item['commenthidden'], 'commenthidden' );
|
|
|
|
|
$this->assertTrue( $item['texthidden'], 'texthidden' );
|
2021-03-07 20:00:46 +00:00
|
|
|
$this->assertEquals( $revid, $item['id'] );
|
2013-10-27 04:53:39 +00:00
|
|
|
|
|
|
|
|
// Now check that that revision was actually hidden
|
2021-05-02 03:17:21 +00:00
|
|
|
$revRecord = $this->getServiceContainer()
|
|
|
|
|
->getRevisionLookup()
|
|
|
|
|
->getRevisionById( $revid );
|
|
|
|
|
$this->assertNull( $revRecord->getContent( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC ) );
|
|
|
|
|
$this->assertNull( $revRecord->getComment( RevisionRecord::FOR_PUBLIC ) );
|
|
|
|
|
$this->assertNull( $revRecord->getUser( RevisionRecord::FOR_PUBLIC ) );
|
2013-10-27 04:53:39 +00:00
|
|
|
|
|
|
|
|
// Now test unhiding!
|
2021-06-01 23:06:18 +00:00
|
|
|
$out2 = $this->doApiRequestWithToken( [
|
2013-10-27 04:53:39 +00:00
|
|
|
'action' => 'revisiondelete',
|
|
|
|
|
'type' => 'revision',
|
|
|
|
|
'target' => self::$page,
|
|
|
|
|
'ids' => $revid,
|
|
|
|
|
'show' => 'content|user|comment',
|
2021-06-01 23:06:18 +00:00
|
|
|
], null, $performer );
|
2013-10-27 04:53:39 +00:00
|
|
|
|
|
|
|
|
// Check the output
|
|
|
|
|
$out2 = $out2[0]['revisiondelete'];
|
2021-03-07 20:00:46 +00:00
|
|
|
$this->assertEquals( 'Success', $out2['status'] );
|
2013-10-27 04:53:39 +00:00
|
|
|
$this->assertArrayHasKey( 'items', $out2 );
|
|
|
|
|
$item = $out2['items'][0];
|
|
|
|
|
|
2016-12-19 16:36:09 +00:00
|
|
|
$this->assertFalse( $item['userhidden'], 'userhidden' );
|
|
|
|
|
$this->assertFalse( $item['commenthidden'], 'commenthidden' );
|
|
|
|
|
$this->assertFalse( $item['texthidden'], 'texthidden' );
|
2013-10-27 04:53:39 +00:00
|
|
|
|
2021-03-07 20:00:46 +00:00
|
|
|
$this->assertEquals( $revid, $item['id'] );
|
2013-10-27 04:53:39 +00:00
|
|
|
|
2021-05-02 03:17:21 +00:00
|
|
|
// Now check that that revision was actually unhidden
|
|
|
|
|
$revRecord = $this->getServiceContainer()
|
|
|
|
|
->getRevisionLookup()
|
|
|
|
|
->getRevisionById( $revid );
|
|
|
|
|
$this->assertNotNull( $revRecord->getContent( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC ) );
|
|
|
|
|
$this->assertNotNull( $revRecord->getComment( RevisionRecord::FOR_PUBLIC ) );
|
|
|
|
|
$this->assertNotNull( $revRecord->getUser( RevisionRecord::FOR_PUBLIC ) );
|
2013-10-27 04:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUnhidingOutput() {
|
2021-06-01 23:06:18 +00:00
|
|
|
$performer = $this->mockAnonAuthorityWithPermissions( [ 'writeapi', 'deleterevision' ] );
|
2013-10-27 04:53:39 +00:00
|
|
|
$revid = array_shift( $this->revs );
|
|
|
|
|
// Hide revisions
|
2021-06-01 23:06:18 +00:00
|
|
|
$this->doApiRequestWithToken( [
|
2013-10-27 04:53:39 +00:00
|
|
|
'action' => 'revisiondelete',
|
|
|
|
|
'type' => 'revision',
|
|
|
|
|
'target' => self::$page,
|
|
|
|
|
'ids' => $revid,
|
|
|
|
|
'hide' => 'content|user|comment',
|
2021-06-01 23:06:18 +00:00
|
|
|
], null, $performer );
|
2013-10-27 04:53:39 +00:00
|
|
|
|
2021-06-01 23:06:18 +00:00
|
|
|
$out = $this->doApiRequestWithToken( [
|
2013-10-27 04:53:39 +00:00
|
|
|
'action' => 'revisiondelete',
|
|
|
|
|
'type' => 'revision',
|
|
|
|
|
'target' => self::$page,
|
|
|
|
|
'ids' => $revid,
|
|
|
|
|
'show' => 'comment',
|
2021-06-01 23:06:18 +00:00
|
|
|
], null, $performer );
|
2013-10-27 04:53:39 +00:00
|
|
|
$out = $out[0]['revisiondelete'];
|
2021-03-07 20:00:46 +00:00
|
|
|
$this->assertEquals( 'Success', $out['status'] );
|
2013-10-27 04:53:39 +00:00
|
|
|
$this->assertArrayHasKey( 'items', $out );
|
|
|
|
|
$item = $out['items'][0];
|
2016-12-19 16:36:09 +00:00
|
|
|
// Check it has userhidden & texthidden
|
|
|
|
|
// but not commenthidden
|
|
|
|
|
$this->assertTrue( $item['userhidden'], 'userhidden' );
|
|
|
|
|
$this->assertFalse( $item['commenthidden'], 'commenthidden' );
|
|
|
|
|
$this->assertTrue( $item['texthidden'], 'texthidden' );
|
2021-03-07 20:00:46 +00:00
|
|
|
$this->assertEquals( $revid, $item['id'] );
|
2013-10-27 04:53:39 +00:00
|
|
|
}
|
2019-07-18 23:33:15 +00:00
|
|
|
|
|
|
|
|
public function testPartiallyBlockedPage() {
|
|
|
|
|
$this->setExpectedApiException( 'apierror-blocked-partial' );
|
2021-06-01 23:06:18 +00:00
|
|
|
$performer = $this->mockAnonAuthorityWithPermissions( [ 'writeapi', 'deleterevision' ] );
|
2019-07-18 23:33:15 +00:00
|
|
|
|
|
|
|
|
$block = new DatabaseBlock( [
|
2021-06-01 23:06:18 +00:00
|
|
|
'address' => $performer->getUser(),
|
2021-06-02 09:44:38 +00:00
|
|
|
'by' => static::getTestSysop()->getUser(),
|
2019-07-18 23:33:15 +00:00
|
|
|
'sitewide' => false,
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$block->setRestrictions( [
|
|
|
|
|
new PageRestriction( 0, Title::newFromText( self::$page )->getArticleID() )
|
|
|
|
|
] );
|
2020-08-27 09:27:10 +00:00
|
|
|
MediaWikiServices::getInstance()->getDatabaseBlockStore()->insertBlock( $block );
|
2019-07-18 23:33:15 +00:00
|
|
|
|
|
|
|
|
$revid = array_shift( $this->revs );
|
|
|
|
|
|
2021-06-01 23:06:18 +00:00
|
|
|
$this->doApiRequestWithToken( [
|
2019-07-18 23:33:15 +00:00
|
|
|
'action' => 'revisiondelete',
|
|
|
|
|
'type' => 'revision',
|
|
|
|
|
'target' => self::$page,
|
|
|
|
|
'ids' => $revid,
|
|
|
|
|
'hide' => 'content|user|comment',
|
2021-06-01 23:06:18 +00:00
|
|
|
], null, $performer );
|
2019-07-18 23:33:15 +00:00
|
|
|
}
|
2013-10-27 04:53:39 +00:00
|
|
|
}
|