2012-05-02 17:35:42 +00:00
|
|
|
<?php
|
2013-10-21 21:09:13 +00:00
|
|
|
|
2023-02-09 18:59:23 +00:00
|
|
|
use MediaWiki\Category\Category;
|
2021-10-21 12:04:01 +00:00
|
|
|
use MediaWiki\Content\Renderer\ContentRenderer;
|
2021-12-10 02:36:13 +00:00
|
|
|
use MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate;
|
2018-08-28 15:34:25 +00:00
|
|
|
use MediaWiki\Edit\PreparedEdit;
|
2022-06-16 14:12:03 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2021-01-18 15:25:52 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
|
|
|
|
use MediaWiki\Page\PageIdentityValue;
|
2021-03-16 00:21:03 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
2020-06-15 22:15:16 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2020-07-03 00:20:38 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2018-01-27 01:48:19 +00:00
|
|
|
use MediaWiki\Storage\RevisionSlotsUpdate;
|
2021-05-26 03:35:05 +00:00
|
|
|
use MediaWiki\Tests\Unit\DummyServicesTrait;
|
2021-03-16 00:21:03 +00:00
|
|
|
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-06-16 14:12:03 +00:00
|
|
|
use PHPUnit\Framework\Assert;
|
2018-03-09 22:05:47 +00:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-01-27 01:48:19 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage
|
2019-12-17 16:20:32 +00:00
|
|
|
* @group Database
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
2019-12-17 16:20:32 +00:00
|
|
|
class WikiPageDbTest extends MediaWikiLangTestCase {
|
2021-05-26 03:35:05 +00:00
|
|
|
use DummyServicesTrait;
|
2021-03-16 00:21:03 +00:00
|
|
|
use MockAuthorityTrait;
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2021-08-20 19:56:10 +00:00
|
|
|
/** @var WikiPage[] */
|
2017-11-27 13:49:04 +00:00
|
|
|
private $pagesToDelete;
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2021-03-08 03:23:08 +00:00
|
|
|
parent::setUp();
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2021-03-08 03:23:08 +00:00
|
|
|
$this->pagesToDelete = [];
|
2013-02-14 11:56:23 +00:00
|
|
|
$this->tablesUsed = array_merge(
|
2012-10-08 15:26:11 +00:00
|
|
|
$this->tablesUsed,
|
2021-03-08 03:23:08 +00:00
|
|
|
[
|
|
|
|
|
'page',
|
2013-02-14 11:56:23 +00:00
|
|
|
'revision',
|
2017-12-04 12:11:26 +00:00
|
|
|
'redirect',
|
2017-06-06 17:39:14 +00:00
|
|
|
'archive',
|
2017-11-30 18:23:01 +00:00
|
|
|
'category',
|
2017-04-21 16:17:59 +00:00
|
|
|
'ip_changes',
|
2013-02-14 11:56:23 +00:00
|
|
|
'text',
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2019-12-17 16:20:32 +00:00
|
|
|
'slots',
|
|
|
|
|
'content',
|
|
|
|
|
'slot_roles',
|
|
|
|
|
'content_models',
|
|
|
|
|
|
2013-02-14 11:56:23 +00:00
|
|
|
'recentchanges',
|
|
|
|
|
'logging',
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2013-02-14 11:56:23 +00:00
|
|
|
'page_props',
|
|
|
|
|
'pagelinks',
|
|
|
|
|
'categorylinks',
|
|
|
|
|
'langlinks',
|
|
|
|
|
'externallinks',
|
|
|
|
|
'imagelinks',
|
|
|
|
|
'templatelinks',
|
2021-03-08 03:23:08 +00:00
|
|
|
'iwlinks'
|
|
|
|
|
]
|
|
|
|
|
);
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function tearDown(): void {
|
2017-11-27 13:49:04 +00:00
|
|
|
foreach ( $this->pagesToDelete as $p ) {
|
2021-10-30 15:45:49 +00:00
|
|
|
if ( $p->exists() ) {
|
|
|
|
|
$this->deletePage( $p, "testing done." );
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-16 14:12:03 +00:00
|
|
|
ParserOptions::clearStaticCache();
|
2012-05-23 21:09:15 +00:00
|
|
|
parent::tearDown();
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-23 06:53:01 +00:00
|
|
|
/**
|
2014-10-31 10:44:16 +00:00
|
|
|
* @param Title|string $title
|
|
|
|
|
* @param string|null $model
|
2012-05-23 06:53:01 +00:00
|
|
|
* @return WikiPage
|
|
|
|
|
*/
|
2017-11-27 13:49:04 +00:00
|
|
|
private function newPage( $title, $model = null ) {
|
2012-09-19 18:07:56 +00:00
|
|
|
if ( is_string( $title ) ) {
|
2012-11-01 12:48:18 +00:00
|
|
|
$ns = $this->getDefaultWikitextNS();
|
|
|
|
|
$title = Title::newFromText( $title, $ns );
|
2012-09-19 18:07:56 +00:00
|
|
|
}
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
$p = new WikiPage( $title );
|
|
|
|
|
|
2017-11-27 13:49:04 +00:00
|
|
|
$this->pagesToDelete[] = $p;
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
return $p;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-23 06:53:01 +00:00
|
|
|
/**
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string|Title|WikiPage $page
|
2018-03-09 22:05:47 +00:00
|
|
|
* @param string|Content|Content[] $content
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param int|null $model
|
2021-03-16 00:21:03 +00:00
|
|
|
* @param Authority|null $performer
|
2012-05-23 06:53:01 +00:00
|
|
|
*
|
|
|
|
|
* @return WikiPage
|
|
|
|
|
*/
|
2021-03-16 00:21:03 +00:00
|
|
|
protected function createPage( $page, $content, $model = null, Authority $performer = null ) {
|
2012-11-01 12:48:18 +00:00
|
|
|
if ( is_string( $page ) || $page instanceof Title ) {
|
2012-09-19 18:07:56 +00:00
|
|
|
$page = $this->newPage( $page, $model );
|
2012-05-23 06:53:01 +00:00
|
|
|
}
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2022-10-21 02:26:49 +00:00
|
|
|
$performer ??= $this->getTestUser()->getUser();
|
2018-03-09 22:05:47 +00:00
|
|
|
|
|
|
|
|
if ( is_string( $content ) ) {
|
|
|
|
|
$content = ContentHandler::makeContent( $content, $page->getTitle(), $model );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !is_array( $content ) ) {
|
2023-01-03 15:24:42 +00:00
|
|
|
$content = [ SlotRecord::MAIN => $content ];
|
2018-03-09 22:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-16 00:21:03 +00:00
|
|
|
$updater = $page->newPageUpdater( $performer );
|
2018-03-09 22:05:47 +00:00
|
|
|
|
|
|
|
|
foreach ( $content as $role => $cnt ) {
|
|
|
|
|
$updater->setContent( $role, $cnt );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$updater->saveRevision( CommentStoreComment::newUnsavedComment( "testing" ) );
|
2018-11-19 11:39:56 +00:00
|
|
|
if ( !$updater->wasSuccessful() ) {
|
|
|
|
|
$this->fail( $updater->getStatus()->getWikiText() );
|
|
|
|
|
}
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 09:30:43 +00:00
|
|
|
public function testSerialization_fails() {
|
|
|
|
|
$this->expectException( LogicException::class );
|
|
|
|
|
$page = $this->createPage( __METHOD__, __METHOD__ );
|
|
|
|
|
serialize( $page );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideTitlesThatCannotExist() {
|
2021-01-19 19:57:24 +00:00
|
|
|
yield 'Special' => [ NS_SPECIAL, 'Recentchanges' ]; // existing special page
|
|
|
|
|
yield 'Invalid character' => [ NS_MAIN, '#' ]; // bad character
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideTitlesThatCannotExist
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructionWithPageThatCannotExist( $ns, $text ) {
|
|
|
|
|
$title = Title::makeTitle( $ns, $text );
|
2021-08-30 12:42:57 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
new WikiPage( $title );
|
2021-01-19 19:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
2018-01-27 01:48:19 +00:00
|
|
|
* @covers WikiPage::prepareContentForEdit
|
2021-06-23 10:43:46 +00:00
|
|
|
* @covers WikiPage::getCurrentUpdate
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
|
|
|
|
public function testPrepareContentForEdit() {
|
2021-03-16 00:21:03 +00:00
|
|
|
$performer = $this->mockUserAuthorityWithPermissions(
|
|
|
|
|
$this->getTestUser()->getUserIdentity(),
|
|
|
|
|
[ 'edit' ]
|
|
|
|
|
);
|
|
|
|
|
$sysop = $this->getTestUser( [ 'sysop' ] )->getUserIdentity();
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2021-03-16 00:21:03 +00:00
|
|
|
$page = $this->createPage( __METHOD__, __METHOD__, null, $performer );
|
2018-01-27 01:48:19 +00:00
|
|
|
$title = $page->getTitle();
|
|
|
|
|
|
|
|
|
|
$content = ContentHandler::makeContent(
|
|
|
|
|
"[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
|
|
|
|
|
. " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
|
|
|
|
|
$title,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
|
|
|
|
$content2 = ContentHandler::makeContent(
|
|
|
|
|
"At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
|
|
|
|
|
. "Stet clita kasd [[gubergren]], no sea takimata sanctus est. ~~~~",
|
|
|
|
|
$title,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
|
|
|
|
|
2021-03-16 00:21:03 +00:00
|
|
|
$edit = $page->prepareContentForEdit( $content, null, $performer->getUser(), null, false );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
ParserOptions::class,
|
|
|
|
|
$edit->popts,
|
|
|
|
|
"pops"
|
|
|
|
|
);
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString( '</a>', $edit->output->getText(), "output" );
|
|
|
|
|
$this->assertStringContainsString(
|
2018-01-27 01:48:19 +00:00
|
|
|
'consetetur sadipscing elitr',
|
|
|
|
|
$edit->output->getText(),
|
|
|
|
|
"output"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $content->equals( $edit->newContent ), "newContent field" );
|
|
|
|
|
$this->assertTrue( $content->equals( $edit->pstContent ), "pstContent field" );
|
|
|
|
|
$this->assertSame( $edit->output, $edit->output, "output field" );
|
|
|
|
|
$this->assertSame( $edit->popts, $edit->popts, "popts field" );
|
|
|
|
|
$this->assertSame( null, $edit->revid, "revid field" );
|
|
|
|
|
|
2021-06-23 10:43:46 +00:00
|
|
|
// PreparedUpdate matches PreparedEdit
|
|
|
|
|
$update = $page->getCurrentUpdate();
|
|
|
|
|
$this->assertSame( $edit->output, $update->getCanonicalParserOutput() );
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
// Re-using the prepared info if possible
|
2021-03-16 00:21:03 +00:00
|
|
|
$sameEdit = $page->prepareContentForEdit( $content, null, $performer->getUser(), null, false );
|
2018-08-28 15:34:25 +00:00
|
|
|
$this->assertPreparedEditEquals( $edit, $sameEdit, 'equivalent PreparedEdit' );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertSame( $edit->pstContent, $sameEdit->pstContent, 're-use output' );
|
|
|
|
|
$this->assertSame( $edit->output, $sameEdit->output, 're-use output' );
|
|
|
|
|
|
2021-06-23 10:43:46 +00:00
|
|
|
// re-using the same PreparedUpdate
|
|
|
|
|
$this->assertSame( $update, $page->getCurrentUpdate() );
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
// Not re-using the same PreparedEdit if not possible
|
2021-03-16 00:21:03 +00:00
|
|
|
$edit2 = $page->prepareContentForEdit( $content2, null, $performer->getUser(), null, false );
|
2018-08-28 15:34:25 +00:00
|
|
|
$this->assertPreparedEditNotEquals( $edit, $edit2 );
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString( 'At vero eos', $edit2->pstContent->serialize(), "content" );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2021-06-23 10:43:46 +00:00
|
|
|
// Not re-using the same PreparedUpdate
|
|
|
|
|
$this->assertNotSame( $update, $page->getCurrentUpdate() );
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
// Check pre-safe transform
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString( '[[gubergren]]', $edit2->pstContent->serialize() );
|
|
|
|
|
$this->assertStringNotContainsString( '~~~~', $edit2->pstContent->serialize() );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$edit3 = $page->prepareContentForEdit( $content2, null, $sysop, null, false );
|
2018-08-28 15:34:25 +00:00
|
|
|
$this->assertPreparedEditNotEquals( $edit2, $edit3 );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// TODO: test with passing revision, then same without revision.
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 22:15:16 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::doEditUpdates
|
|
|
|
|
*/
|
|
|
|
|
public function testDoEditUpdates() {
|
2021-03-16 00:21:03 +00:00
|
|
|
$user = $this->getTestUser()->getUserIdentity();
|
2020-06-15 22:15:16 +00:00
|
|
|
|
|
|
|
|
// NOTE: if site stats get out of whack and drop below 0,
|
|
|
|
|
// that causes a DB error during tear-down. So bump the
|
|
|
|
|
// numbers high enough to not drop below 0.
|
|
|
|
|
$siteStatsUpdate = SiteStatsUpdate::factory(
|
|
|
|
|
[ 'edits' => 1000, 'articles' => 1000, 'pages' => 1000 ]
|
|
|
|
|
);
|
|
|
|
|
$siteStatsUpdate->doUpdate();
|
|
|
|
|
|
|
|
|
|
$page = $this->createPage( __METHOD__, __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$comment = CommentStoreComment::newUnsavedComment( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$contentHandler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
// PST turns [[|foo]] into [[foo]]
|
|
|
|
|
$content = $contentHandler->unserializeContent( __METHOD__ . ' [[|foo]][[bar]]' );
|
|
|
|
|
|
|
|
|
|
$revRecord = new MutableRevisionRecord( $page->getTitle() );
|
|
|
|
|
$revRecord->setContent( SlotRecord::MAIN, $content );
|
|
|
|
|
$revRecord->setUser( $user );
|
|
|
|
|
$revRecord->setTimestamp( '20170707040404' );
|
|
|
|
|
$revRecord->setPageId( $page->getId() );
|
|
|
|
|
$revRecord->setId( 9989 );
|
|
|
|
|
$revRecord->setMinorEdit( true );
|
|
|
|
|
$revRecord->setComment( $comment );
|
|
|
|
|
|
|
|
|
|
$page->doEditUpdates( $revRecord, $user );
|
|
|
|
|
|
|
|
|
|
// TODO: test various options; needs temporary hooks
|
|
|
|
|
|
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
|
$res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $page->getId() ] );
|
|
|
|
|
$n = $res->numRows();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 1, $n, 'pagelinks should contain only one link if PST was not applied' );
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 16:19:12 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::doUserEditContent
|
|
|
|
|
* @covers WikiPage::prepareContentForEdit
|
|
|
|
|
*/
|
|
|
|
|
public function testDoUserEditContent() {
|
2022-08-01 19:14:41 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::PageCreationLog, true );
|
2017-12-22 20:40:13 +00:00
|
|
|
|
2017-11-27 13:49:04 +00:00
|
|
|
$page = $this->newPage( __METHOD__ );
|
2012-11-01 12:48:18 +00:00
|
|
|
$title = $page->getTitle();
|
2012-04-24 16:00:21 +00:00
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
$user1 = $this->getTestUser()->getUser();
|
|
|
|
|
// Use the confirmed group for user2 to make sure the user is different
|
|
|
|
|
$user2 = $this->getTestUser( [ 'confirmed' ] )->getUser();
|
|
|
|
|
|
2014-04-24 12:50:36 +00:00
|
|
|
$content = ContentHandler::makeContent(
|
|
|
|
|
"[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
|
2013-02-14 11:56:23 +00:00
|
|
|
. " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
|
2014-04-24 12:50:36 +00:00
|
|
|
$title,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
2012-04-24 16:00:21 +00:00
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
$preparedEditBefore = $page->prepareContentForEdit( $content, null, $user1 );
|
|
|
|
|
|
2020-06-22 16:19:12 +00:00
|
|
|
$status = $page->doUserEditContent( $content, $user1, "[[testing]] 1", EDIT_NEW );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $status, 'OK' );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertTrue( $status->value['new'], 'new' );
|
2022-11-14 20:17:19 +00:00
|
|
|
$this->assertNotNull( $status->getNewRevision(), 'revision-record' );
|
2021-05-02 02:44:33 +00:00
|
|
|
|
2022-11-14 20:17:19 +00:00
|
|
|
$statusRevRecord = $status->getNewRevision();
|
2021-05-02 02:44:33 +00:00
|
|
|
$this->assertSame( $statusRevRecord->getId(), $page->getRevisionRecord()->getId() );
|
|
|
|
|
$this->assertSame( $statusRevRecord->getSha1(), $page->getRevisionRecord()->getSha1() );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$statusRevRecord->getContent( SlotRecord::MAIN )->equals( $content ),
|
|
|
|
|
'equals'
|
|
|
|
|
);
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2021-04-21 19:33:04 +00:00
|
|
|
$revRecord = $page->getRevisionRecord();
|
|
|
|
|
$recentChange = $this->getServiceContainer()
|
|
|
|
|
->getRevisionStore()
|
|
|
|
|
->getRecentChange( $revRecord );
|
|
|
|
|
$preparedEditAfter = $page->prepareContentForEdit( $content, $revRecord, $user1 );
|
2018-07-08 19:01:32 +00:00
|
|
|
|
2021-04-21 19:33:04 +00:00
|
|
|
$this->assertNotNull( $recentChange );
|
|
|
|
|
$this->assertSame( $revRecord->getId(), (int)$recentChange->getAttribute( 'rc_this_oldid' ) );
|
2012-04-24 16:00:21 +00:00
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
// make sure that cached ParserOutput gets re-used throughout
|
|
|
|
|
$this->assertSame( $preparedEditBefore->output, $preparedEditAfter->output );
|
|
|
|
|
|
2017-12-22 20:40:13 +00:00
|
|
|
$id = $page->getId();
|
|
|
|
|
|
|
|
|
|
// Test page creation logging
|
|
|
|
|
$this->assertSelect(
|
|
|
|
|
'logging',
|
|
|
|
|
[ 'log_type', 'log_action' ],
|
|
|
|
|
[ 'log_page' => $id ],
|
|
|
|
|
[ [ 'create', 'create' ] ]
|
|
|
|
|
);
|
|
|
|
|
|
2012-05-23 06:53:01 +00:00
|
|
|
$this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
|
2017-12-22 20:40:13 +00:00
|
|
|
$this->assertTrue( $id > 0, "WikiPage should have new page id" );
|
2012-04-24 16:00:21 +00:00
|
|
|
$this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
|
|
|
|
|
$this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
|
|
|
|
|
|
2012-05-23 06:53:01 +00:00
|
|
|
# ------------------------
|
2017-08-04 18:53:34 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-02-17 09:09:32 +00:00
|
|
|
$res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
|
2012-05-23 06:53:01 +00:00
|
|
|
$n = $res->numRows();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
2020-05-30 10:36:42 +00:00
|
|
|
$this->assertSame( 1, $n, 'pagelinks should contain one link from the page' );
|
2012-05-23 06:53:01 +00:00
|
|
|
|
2012-04-24 16:00:21 +00:00
|
|
|
# ------------------------
|
|
|
|
|
$page = new WikiPage( $title );
|
|
|
|
|
|
|
|
|
|
$retrieved = $page->getContent();
|
|
|
|
|
$this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
# ------------------------
|
|
|
|
|
$page = new WikiPage( $title );
|
|
|
|
|
|
|
|
|
|
// try null edit, with a different user
|
2020-06-22 16:19:12 +00:00
|
|
|
$status = $page->doUserEditContent( $content, $user2, 'This changes nothing', EDIT_UPDATE, false );
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $status, 'OK' );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertFalse( $status->value['new'], 'new' );
|
2022-11-14 20:17:19 +00:00
|
|
|
$this->assertNull( $status->getNewRevision(), 'revision-record' );
|
2021-04-21 04:35:50 +00:00
|
|
|
$this->assertNotNull( $page->getRevisionRecord() );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$page->getRevisionRecord()->getContent( SlotRecord::MAIN )->equals( $content ),
|
|
|
|
|
'equals'
|
|
|
|
|
);
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2012-04-24 16:00:21 +00:00
|
|
|
# ------------------------
|
2014-04-24 12:50:36 +00:00
|
|
|
$content = ContentHandler::makeContent(
|
|
|
|
|
"At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
|
2018-01-27 01:48:19 +00:00
|
|
|
. "Stet clita kasd [[gubergren]], no sea takimata sanctus est. ~~~~",
|
2014-04-24 12:50:36 +00:00
|
|
|
$title,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
2012-04-24 16:00:21 +00:00
|
|
|
|
2020-06-22 16:19:12 +00:00
|
|
|
$status = $page->doUserEditContent( $content, $user1, "testing 2", EDIT_UPDATE );
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $status, 'OK' );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertFalse( $status->value['new'], 'new' );
|
2022-11-14 20:17:19 +00:00
|
|
|
$this->assertNotNull( $status->getNewRevision(), 'revision-record' );
|
|
|
|
|
$statusRevRecord = $status->getNewRevision();
|
2021-05-02 02:44:33 +00:00
|
|
|
$this->assertSame( $statusRevRecord->getId(), $page->getRevisionRecord()->getId() );
|
|
|
|
|
$this->assertSame( $statusRevRecord->getSha1(), $page->getRevisionRecord()->getSha1() );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertFalse(
|
2021-05-02 02:44:33 +00:00
|
|
|
$statusRevRecord->getContent( SlotRecord::MAIN )->equals( $content ),
|
2018-01-27 01:48:19 +00:00
|
|
|
'not equals (PST must substitute signature)'
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-21 04:35:50 +00:00
|
|
|
$revRecord = $page->getRevisionRecord();
|
|
|
|
|
$recentChange = $this->getServiceContainer()
|
|
|
|
|
->getRevisionStore()
|
|
|
|
|
->getRecentChange( $revRecord );
|
|
|
|
|
$this->assertNotNull( $recentChange );
|
|
|
|
|
$this->assertSame( $revRecord->getId(), (int)$recentChange->getAttribute( 'rc_this_oldid' ) );
|
2012-04-24 16:00:21 +00:00
|
|
|
|
|
|
|
|
# ------------------------
|
|
|
|
|
$page = new WikiPage( $title );
|
|
|
|
|
|
|
|
|
|
$retrieved = $page->getContent();
|
2018-01-27 01:48:19 +00:00
|
|
|
$newText = $retrieved->serialize();
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString( '[[gubergren]]', $newText, 'New text must replace old text.' );
|
|
|
|
|
$this->assertStringNotContainsString( '~~~~', $newText, 'PST must substitute signature.' );
|
2012-04-30 13:32:31 +00:00
|
|
|
|
|
|
|
|
# ------------------------
|
2017-08-04 18:53:34 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-02-17 09:09:32 +00:00
|
|
|
$res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
|
2012-04-30 13:32:31 +00:00
|
|
|
$n = $res->numRows();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
2020-06-22 16:19:12 +00:00
|
|
|
// two in page text and two in signature
|
|
|
|
|
$this->assertEquals( 4, $n, 'pagelinks should contain four links from the page' );
|
2012-04-24 16:00:21 +00:00
|
|
|
}
|
2012-09-19 18:07:56 +00:00
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideNonPageTitle() {
|
2021-01-20 16:36:38 +00:00
|
|
|
yield 'bad case and char' => [ Title::makeTitle( NS_MAIN, 'lower case and bad # char' ) ];
|
|
|
|
|
yield 'empty' => [ Title::makeTitle( NS_MAIN, '' ) ];
|
|
|
|
|
yield 'special' => [ Title::makeTitle( NS_SPECIAL, 'Dummy' ) ];
|
|
|
|
|
yield 'relative' => [ Title::makeTitle( NS_MAIN, '', '#section' ) ];
|
|
|
|
|
yield 'interwiki' => [ Title::makeTitle( NS_MAIN, 'Foo', '', 'acme' ) ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideNonPageTitle
|
|
|
|
|
* @covers WikiPage::doUserEditContent
|
|
|
|
|
*/
|
|
|
|
|
public function testDoUserEditContent_bad_page( $title ) {
|
|
|
|
|
$user1 = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$content = ContentHandler::makeContent(
|
|
|
|
|
"Yadda yadda",
|
|
|
|
|
$title,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
|
|
|
|
|
2021-01-18 15:25:52 +00:00
|
|
|
$this->filterDeprecated( '/WikiPage constructed on a Title that cannot exist as a page/' );
|
2021-01-20 16:36:38 +00:00
|
|
|
try {
|
|
|
|
|
$page = $this->newPage( $title );
|
2021-01-18 15:25:52 +00:00
|
|
|
$page->doUserEditContent( $content, $user1, "[[testing]] 1", EDIT_NEW );
|
2021-01-20 16:36:38 +00:00
|
|
|
} catch ( Exception $ex ) {
|
|
|
|
|
// Throwing is an acceptable way to react to an invalid title,
|
|
|
|
|
// as long as no garbage is written to the database.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$row = $this->db->selectRow(
|
|
|
|
|
'page',
|
|
|
|
|
'*',
|
|
|
|
|
[
|
|
|
|
|
'page_namespace' => $title->getNamespace(),
|
|
|
|
|
'page_title' => $title->getDBkey()
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $row );
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
/**
|
2020-06-22 16:19:12 +00:00
|
|
|
* @covers WikiPage::doUserEditContent
|
2018-07-08 19:01:32 +00:00
|
|
|
*/
|
2020-06-22 16:19:12 +00:00
|
|
|
public function testDoUserEditContent_twice() {
|
2018-07-08 19:01:32 +00:00
|
|
|
$title = Title::newFromText( __METHOD__ );
|
2022-09-01 21:18:41 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2018-07-08 19:01:32 +00:00
|
|
|
$content = ContentHandler::makeContent( '$1 van $2', $title );
|
|
|
|
|
|
2020-06-22 16:19:12 +00:00
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
// Make sure we can do the exact same save twice.
|
|
|
|
|
// This tests checks that internal caches are reset as appropriate.
|
2020-06-22 16:19:12 +00:00
|
|
|
$status1 = $page->doUserEditContent( $content, $user, __METHOD__ );
|
|
|
|
|
$status2 = $page->doUserEditContent( $content, $user, __METHOD__ );
|
2018-07-08 19:01:32 +00:00
|
|
|
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $status1, 'OK' );
|
|
|
|
|
$this->assertStatusOK( $status2, 'OK' );
|
2018-07-08 19:01:32 +00:00
|
|
|
|
2022-11-14 20:17:19 +00:00
|
|
|
$this->assertNotNull( $status1->getNewRevision(), 'OK' );
|
|
|
|
|
$this->assertNull( $status2->getNewRevision(), 'OK' );
|
2018-07-08 19:01:32 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
2018-02-28 23:03:26 +00:00
|
|
|
* Undeletion is covered in PageArchiveTest::testUndeleteRevisions()
|
|
|
|
|
* TODO: Revision deletion
|
|
|
|
|
*
|
2017-11-28 13:41:07 +00:00
|
|
|
* @covers WikiPage::doDeleteArticleReal
|
2013-10-21 21:09:13 +00:00
|
|
|
*/
|
2020-09-10 16:56:04 +00:00
|
|
|
public function testDoDeleteArticleReal() {
|
2014-04-24 12:50:36 +00:00
|
|
|
$page = $this->createPage(
|
2017-11-27 13:49:04 +00:00
|
|
|
__METHOD__,
|
2014-04-24 12:50:36 +00:00
|
|
|
"[[original text]] foo",
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
2012-05-02 17:35:42 +00:00
|
|
|
$id = $page->getId();
|
2021-08-20 19:56:10 +00:00
|
|
|
$user = $this->getTestSysop()->getUser();
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2021-08-20 19:56:10 +00:00
|
|
|
$reason = "testing deletion";
|
|
|
|
|
$status = $page->doDeleteArticleReal( $reason, $user );
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2014-04-24 12:50:36 +00:00
|
|
|
$this->assertFalse(
|
|
|
|
|
$page->getTitle()->getArticleID() > 0,
|
|
|
|
|
"Title object should now have page id 0"
|
|
|
|
|
);
|
2012-05-23 06:53:01 +00:00
|
|
|
$this->assertFalse( $page->getId() > 0, "WikiPage should now have page id 0" );
|
2014-04-24 12:50:36 +00:00
|
|
|
$this->assertFalse(
|
|
|
|
|
$page->exists(),
|
|
|
|
|
"WikiPage::exists should return false after page was deleted"
|
|
|
|
|
);
|
|
|
|
|
$this->assertNull(
|
|
|
|
|
$page->getContent(),
|
|
|
|
|
"WikiPage::getContent should return null after page was deleted"
|
|
|
|
|
);
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
$t = Title::newFromText( $page->getTitle()->getPrefixedText() );
|
2014-04-24 12:50:36 +00:00
|
|
|
$this->assertFalse(
|
|
|
|
|
$t->exists(),
|
|
|
|
|
"Title::exists should return false after page was deleted"
|
|
|
|
|
);
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2015-09-22 19:07:05 +00:00
|
|
|
// Run the job queue
|
2021-04-28 02:13:58 +00:00
|
|
|
$this->runJobs();
|
2015-09-22 19:07:05 +00:00
|
|
|
|
2012-05-02 17:35:42 +00:00
|
|
|
# ------------------------
|
2017-08-04 18:53:34 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-02-17 09:09:32 +00:00
|
|
|
$res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
|
2012-05-02 17:35:42 +00:00
|
|
|
$n = $res->numRows();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
2019-09-17 14:31:49 +00:00
|
|
|
$this->assertSame( 0, $n, 'pagelinks should contain no more links from the page' );
|
2020-09-10 16:56:04 +00:00
|
|
|
|
2021-08-20 19:56:10 +00:00
|
|
|
// Test deletion logging
|
2018-02-28 23:03:26 +00:00
|
|
|
$logId = $status->getValue();
|
2022-01-12 20:13:39 +00:00
|
|
|
$commentQuery = $this->getServiceContainer()->getCommentStore()->getJoin( 'log_comment' );
|
2018-02-28 23:03:26 +00:00
|
|
|
$this->assertSelect(
|
2021-04-19 00:58:38 +00:00
|
|
|
[ 'logging' ] + $commentQuery['tables'], /* table */
|
2018-02-28 23:03:26 +00:00
|
|
|
[
|
|
|
|
|
'log_type',
|
|
|
|
|
'log_action',
|
2018-11-07 19:50:27 +00:00
|
|
|
'log_comment' => $commentQuery['fields']['log_comment_text'],
|
2021-04-19 00:58:38 +00:00
|
|
|
'log_actor',
|
2018-02-28 23:03:26 +00:00
|
|
|
'log_namespace',
|
|
|
|
|
'log_title',
|
|
|
|
|
],
|
|
|
|
|
[ 'log_id' => $logId ],
|
|
|
|
|
[ [
|
|
|
|
|
'delete',
|
|
|
|
|
'delete',
|
2021-08-20 19:56:10 +00:00
|
|
|
$reason,
|
2021-04-19 00:58:38 +00:00
|
|
|
(string)$user->getActorId(),
|
2018-02-28 23:03:26 +00:00
|
|
|
(string)$page->getTitle()->getNamespace(),
|
|
|
|
|
$page->getTitle()->getDBkey(),
|
|
|
|
|
] ],
|
|
|
|
|
[],
|
2021-04-19 00:58:38 +00:00
|
|
|
$commentQuery['joins']
|
2018-02-28 23:03:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: Test more stuff about suppression.
|
|
|
|
|
*
|
|
|
|
|
* @covers WikiPage::doDeleteArticleReal
|
|
|
|
|
*/
|
|
|
|
|
public function testDoDeleteArticleReal_suppress() {
|
|
|
|
|
$page = $this->createPage(
|
|
|
|
|
__METHOD__,
|
|
|
|
|
"[[original text]] foo",
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$user = $this->getTestSysop()->getUser();
|
|
|
|
|
$status = $page->doDeleteArticleReal(
|
|
|
|
|
/* reason */ "testing deletion",
|
2020-03-31 02:44:56 +00:00
|
|
|
$user,
|
2021-08-20 19:56:10 +00:00
|
|
|
/* suppress */ true
|
2018-02-28 23:03:26 +00:00
|
|
|
);
|
2021-08-20 19:56:10 +00:00
|
|
|
|
|
|
|
|
// Test suppression logging
|
2018-02-28 23:03:26 +00:00
|
|
|
$logId = $status->getValue();
|
2022-01-12 20:13:39 +00:00
|
|
|
$commentQuery = $this->getServiceContainer()->getCommentStore()->getJoin( 'log_comment' );
|
2018-02-28 23:03:26 +00:00
|
|
|
$this->assertSelect(
|
2021-04-19 00:58:38 +00:00
|
|
|
[ 'logging' ] + $commentQuery['tables'], /* table */
|
2018-02-28 23:03:26 +00:00
|
|
|
[
|
|
|
|
|
'log_type',
|
|
|
|
|
'log_action',
|
2018-11-07 19:50:27 +00:00
|
|
|
'log_comment' => $commentQuery['fields']['log_comment_text'],
|
2021-04-19 00:58:38 +00:00
|
|
|
'log_actor',
|
2018-02-28 23:03:26 +00:00
|
|
|
'log_namespace',
|
|
|
|
|
'log_title',
|
|
|
|
|
],
|
|
|
|
|
[ 'log_id' => $logId ],
|
|
|
|
|
[ [
|
|
|
|
|
'suppress',
|
|
|
|
|
'delete',
|
|
|
|
|
'testing deletion',
|
2021-04-19 00:58:38 +00:00
|
|
|
(string)$user->getActorId(),
|
2018-02-28 23:03:26 +00:00
|
|
|
(string)$page->getTitle()->getNamespace(),
|
|
|
|
|
$page->getTitle()->getDBkey(),
|
|
|
|
|
] ],
|
|
|
|
|
[],
|
2021-04-19 00:58:38 +00:00
|
|
|
$commentQuery['joins']
|
2018-02-28 23:03:26 +00:00
|
|
|
);
|
|
|
|
|
|
2022-01-12 20:13:39 +00:00
|
|
|
$archive = new PageArchive( $page->getTitle(), $this->getServiceContainer()->getMainConfig() );
|
2023-05-22 06:06:49 +00:00
|
|
|
$archivedRevs = $archive->listRevisions();
|
2021-08-21 00:14:04 +00:00
|
|
|
if ( !$archivedRevs || $archivedRevs->numRows() !== 1 ) {
|
|
|
|
|
$this->fail( 'Unexpected number of archived revisions' );
|
|
|
|
|
}
|
2022-01-12 20:13:39 +00:00
|
|
|
$archivedRev = $this->getServiceContainer()->getRevisionStore()
|
2021-08-21 00:14:04 +00:00
|
|
|
->newRevisionFromArchiveRow( $archivedRevs->current() );
|
|
|
|
|
|
2018-02-28 23:03:26 +00:00
|
|
|
$this->assertNull(
|
2021-08-21 00:14:04 +00:00
|
|
|
$archivedRev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC ),
|
|
|
|
|
"Archived content should be null after the page was suppressed for general users"
|
2018-02-28 23:03:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertNull(
|
2021-08-21 00:14:04 +00:00
|
|
|
$archivedRev->getContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
RevisionRecord::FOR_THIS_USER,
|
|
|
|
|
$this->getTestUser()->getUser()
|
|
|
|
|
),
|
|
|
|
|
"Archived content should be null after the page was suppressed for individual users"
|
2018-02-28 23:03:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertNull(
|
2021-08-21 00:14:04 +00:00
|
|
|
$archivedRev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user ),
|
|
|
|
|
"Archived content should be null after the page was suppressed even for a sysop"
|
2018-02-28 23:03:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::doDeleteUpdates
|
|
|
|
|
*/
|
2012-05-18 16:58:21 +00:00
|
|
|
public function testDoDeleteUpdates() {
|
2021-08-23 15:38:52 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::doDeleteUpdates' );
|
2021-03-16 00:21:03 +00:00
|
|
|
$user = $this->getTestUser()->getUserIdentity();
|
2014-04-24 12:50:36 +00:00
|
|
|
$page = $this->createPage(
|
2017-11-27 13:49:04 +00:00
|
|
|
__METHOD__,
|
2014-04-24 12:50:36 +00:00
|
|
|
"[[original text]] foo",
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
2012-05-18 16:58:21 +00:00
|
|
|
$id = $page->getId();
|
2018-03-09 22:05:47 +00:00
|
|
|
$page->loadPageData(); // make sure the current revision is cached.
|
2012-05-18 16:58:21 +00:00
|
|
|
|
2015-09-22 19:07:05 +00:00
|
|
|
// Similar to MovePage logic
|
2021-04-29 02:37:11 +00:00
|
|
|
wfGetDB( DB_PRIMARY )->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
|
2020-04-08 02:49:07 +00:00
|
|
|
$page->doDeleteUpdates(
|
|
|
|
|
$page->getId(),
|
|
|
|
|
$page->getContent(),
|
|
|
|
|
$page->getRevisionRecord(),
|
|
|
|
|
$user
|
|
|
|
|
);
|
2012-05-18 16:58:21 +00:00
|
|
|
|
2015-09-22 19:07:05 +00:00
|
|
|
// Run the job queue
|
2021-04-28 02:13:58 +00:00
|
|
|
$this->runJobs();
|
2015-09-22 19:07:05 +00:00
|
|
|
|
2012-05-18 16:58:21 +00:00
|
|
|
# ------------------------
|
2017-08-04 18:53:34 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-02-17 09:09:32 +00:00
|
|
|
$res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
|
2012-05-18 16:58:21 +00:00
|
|
|
$n = $res->numRows();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
2019-09-17 14:31:49 +00:00
|
|
|
$this->assertSame( 0, $n, 'pagelinks should contain no more links from the page' );
|
2012-05-18 16:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-09 22:05:47 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
*
|
|
|
|
|
* @return ContentHandler
|
|
|
|
|
*/
|
|
|
|
|
protected function defineMockContentModelForUpdateTesting( $name ) {
|
|
|
|
|
/** @var ContentHandler|MockObject $handler */
|
|
|
|
|
$handler = $this->getMockBuilder( TextContentHandler::class )
|
|
|
|
|
->setConstructorArgs( [ $name ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods(
|
2018-03-09 22:05:47 +00:00
|
|
|
[ 'getSecondaryDataUpdates', 'getDeletionUpdates', 'unserializeContent' ]
|
|
|
|
|
)
|
|
|
|
|
->getMock();
|
|
|
|
|
|
2023-01-07 20:46:13 +00:00
|
|
|
$dataUpdate = new MWCallableUpdate( 'time', "$name data update" );
|
2018-03-09 22:05:47 +00:00
|
|
|
|
2023-01-07 20:46:13 +00:00
|
|
|
$deletionUpdate = new MWCallableUpdate( 'time', "$name deletion update" );
|
2018-03-09 22:05:47 +00:00
|
|
|
|
|
|
|
|
$handler->method( 'getSecondaryDataUpdates' )->willReturn( [ $dataUpdate ] );
|
|
|
|
|
$handler->method( 'getDeletionUpdates' )->willReturn( [ $deletionUpdate ] );
|
|
|
|
|
$handler->method( 'unserializeContent' )->willReturnCallback(
|
|
|
|
|
function ( $text ) use ( $handler ) {
|
|
|
|
|
return $this->createMockContent( $handler, $text );
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->mergeMwGlobalArrayValue(
|
|
|
|
|
'wgContentHandlers', [
|
2021-02-07 13:10:36 +00:00
|
|
|
$name => static function () use ( $handler ){
|
2018-03-09 22:05:47 +00:00
|
|
|
return $handler;
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $handler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ContentHandler $handler
|
|
|
|
|
* @param string $text
|
|
|
|
|
*
|
|
|
|
|
* @return Content
|
|
|
|
|
*/
|
|
|
|
|
protected function createMockContent( ContentHandler $handler, $text ) {
|
|
|
|
|
/** @var Content|MockObject $content */
|
|
|
|
|
$content = $this->getMockBuilder( TextContent::class )
|
|
|
|
|
->setConstructorArgs( [ $text ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'getModel', 'getContentHandler' ] )
|
2018-03-09 22:05:47 +00:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$content->method( 'getModel' )->willReturn( $handler->getModelID() );
|
|
|
|
|
$content->method( 'getContentHandler' )->willReturn( $handler );
|
|
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetDeletionUpdates() {
|
2021-08-23 15:38:52 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::getDeletionUpdates' );
|
2018-03-09 22:05:47 +00:00
|
|
|
$m1 = $this->defineMockContentModelForUpdateTesting( 'M1' );
|
|
|
|
|
|
|
|
|
|
$mainContent1 = $this->createMockContent( $m1, 'main 1' );
|
|
|
|
|
|
|
|
|
|
$page = new WikiPage( Title::newFromText( __METHOD__ ) );
|
|
|
|
|
$page = $this->createPage(
|
|
|
|
|
$page,
|
2023-01-03 15:24:42 +00:00
|
|
|
[ SlotRecord::MAIN => $mainContent1 ]
|
2018-03-09 22:05:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$dataUpdates = $page->getDeletionUpdates( $page->getRevisionRecord() );
|
|
|
|
|
$this->assertNotEmpty( $dataUpdates );
|
|
|
|
|
|
2021-02-06 19:30:20 +00:00
|
|
|
$updateNames = array_map( static function ( $du ) {
|
2023-01-07 20:46:13 +00:00
|
|
|
return $du instanceof MWCallableUpdate ? $du->getOrigin() : get_class( $du );
|
2018-03-09 22:05:47 +00:00
|
|
|
}, $dataUpdates );
|
|
|
|
|
|
|
|
|
|
$this->assertContains( LinksDeletionUpdate::class, $updateNames );
|
|
|
|
|
$this->assertContains( 'M1 deletion update', $updateNames );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::getContent
|
|
|
|
|
*/
|
2012-04-24 16:00:21 +00:00
|
|
|
public function testGetContent() {
|
2017-11-27 13:49:04 +00:00
|
|
|
$page = $this->newPage( __METHOD__ );
|
2012-04-24 16:00:21 +00:00
|
|
|
|
|
|
|
|
$content = $page->getContent();
|
|
|
|
|
$this->assertNull( $content );
|
|
|
|
|
|
|
|
|
|
# -----------------
|
2012-09-19 18:07:56 +00:00
|
|
|
$this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
|
2012-04-24 16:00:21 +00:00
|
|
|
|
|
|
|
|
$content = $page->getContent();
|
2019-02-07 00:14:23 +00:00
|
|
|
$this->assertEquals( "some text", $content->getText() );
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::exists
|
|
|
|
|
*/
|
2012-05-02 17:35:42 +00:00
|
|
|
public function testExists() {
|
2017-11-27 13:49:04 +00:00
|
|
|
$page = $this->newPage( __METHOD__ );
|
2012-05-02 17:35:42 +00:00
|
|
|
$this->assertFalse( $page->exists() );
|
|
|
|
|
|
|
|
|
|
# -----------------
|
2012-09-19 18:07:56 +00:00
|
|
|
$this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
|
2012-05-02 17:35:42 +00:00
|
|
|
$this->assertTrue( $page->exists() );
|
|
|
|
|
|
|
|
|
|
$page = new WikiPage( $page->getTitle() );
|
|
|
|
|
$this->assertTrue( $page->exists() );
|
|
|
|
|
|
|
|
|
|
# -----------------
|
2021-10-30 15:45:49 +00:00
|
|
|
$this->deletePage( $page, "done testing" );
|
2012-05-02 17:35:42 +00:00
|
|
|
$this->assertFalse( $page->exists() );
|
|
|
|
|
|
|
|
|
|
$page = new WikiPage( $page->getTitle() );
|
|
|
|
|
$this->assertFalse( $page->exists() );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideHasViewableContent() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'WikiPageTest_testHasViewableContent', false, true ],
|
|
|
|
|
[ 'MediaWiki:WikiPageTest_testHasViewableContent', false ],
|
|
|
|
|
[ 'MediaWiki:help', true ],
|
|
|
|
|
];
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideHasViewableContent
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers WikiPage::hasViewableContent
|
2012-05-02 17:35:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testHasViewableContent( $title, $viewable, $create = false ) {
|
|
|
|
|
$page = $this->newPage( $title );
|
|
|
|
|
$this->assertEquals( $viewable, $page->hasViewableContent() );
|
|
|
|
|
|
|
|
|
|
if ( $create ) {
|
2012-09-19 18:07:56 +00:00
|
|
|
$this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT );
|
2012-05-02 17:35:42 +00:00
|
|
|
$this->assertTrue( $page->hasViewableContent() );
|
|
|
|
|
|
|
|
|
|
$page = new WikiPage( $page->getTitle() );
|
|
|
|
|
$this->assertTrue( $page->hasViewableContent() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideGetRedirectTarget() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT, "hello world", null ],
|
|
|
|
|
[
|
2014-04-24 12:50:36 +00:00
|
|
|
'WikiPageTest_testGetRedirectTarget_2',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
"#REDIRECT [[hello world]]",
|
|
|
|
|
"Hello world"
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2018-10-09 15:51:04 +00:00
|
|
|
// The below added to protect against Media namespace
|
|
|
|
|
// redirects which throw a fatal: (T203942)
|
|
|
|
|
[
|
|
|
|
|
'WikiPageTest_testGetRedirectTarget_3',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
"#REDIRECT [[Media:hello_world]]",
|
|
|
|
|
"File:Hello world"
|
|
|
|
|
],
|
2018-10-25 00:09:59 +00:00
|
|
|
// Test fragments longer than 255 bytes (T207876)
|
|
|
|
|
[
|
|
|
|
|
'WikiPageTest_testGetRedirectTarget_4',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'#REDIRECT [[Foobar#🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴]]',
|
2023-01-30 03:50:03 +00:00
|
|
|
'Foobar#🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴'
|
2018-10-25 00:09:59 +00:00
|
|
|
]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideGetRedirectTarget
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers WikiPage::getRedirectTarget
|
2023-05-05 20:16:04 +00:00
|
|
|
* @covers \MediaWiki\Page\RedirectLookup::getRedirectTarget
|
2012-05-02 17:35:42 +00:00
|
|
|
*/
|
2012-09-19 18:07:56 +00:00
|
|
|
public function testGetRedirectTarget( $title, $model, $text, $target ) {
|
2022-12-06 22:23:53 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::CapitalLinks => true,
|
|
|
|
|
// The file redirect can trigger http request with UseInstantCommons = true
|
|
|
|
|
MainConfigNames::ForeignFileRepos => [],
|
|
|
|
|
] );
|
2014-07-07 23:21:09 +00:00
|
|
|
|
2012-09-19 18:07:56 +00:00
|
|
|
$page = $this->createPage( $title, $text, $model );
|
2012-04-24 16:00:21 +00:00
|
|
|
|
2021-11-21 16:23:11 +00:00
|
|
|
# double check, because this test seems to fail for no reason for some people.
|
2012-05-02 10:54:27 +00:00
|
|
|
$c = $page->getContent();
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertEquals( WikitextContent::class, get_class( $c ) );
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
# now, test the actual redirect
|
2021-10-20 15:51:22 +00:00
|
|
|
$redirectStore = $this->getServiceContainer()->getRedirectStore();
|
|
|
|
|
$t = $redirectStore->getRedirectTarget( $page );
|
2019-03-11 09:29:20 +00:00
|
|
|
$this->assertEquals( $target, $t ? $t->getFullText() : null );
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideGetRedirectTarget
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers WikiPage::isRedirect
|
2012-05-02 17:35:42 +00:00
|
|
|
*/
|
2012-09-19 18:07:56 +00:00
|
|
|
public function testIsRedirect( $title, $model, $text, $target ) {
|
2022-12-06 22:23:53 +00:00
|
|
|
// The file redirect can trigger http request with UseInstantCommons = true
|
|
|
|
|
$this->overrideConfigValue( MainConfigNames::ForeignFileRepos, [] );
|
|
|
|
|
|
2012-09-19 18:07:56 +00:00
|
|
|
$page = $this->createPage( $title, $text, $model );
|
2020-01-09 23:48:34 +00:00
|
|
|
$this->assertEquals( $target !== null, $page->isRedirect() );
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideIsCountable() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
// any
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'',
|
|
|
|
|
'any',
|
|
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'Foo',
|
|
|
|
|
'any',
|
|
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
// link
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'Foo',
|
|
|
|
|
'link',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'Foo [[bar]]',
|
|
|
|
|
'link',
|
|
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
// redirects
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'#REDIRECT [[bar]]',
|
|
|
|
|
'any',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'#REDIRECT [[bar]]',
|
|
|
|
|
'link',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
// not a content namespace
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'Talk:WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'Foo',
|
|
|
|
|
'any',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'Talk:WikiPageTest_testIsCountable',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
'Foo [[bar]]',
|
|
|
|
|
'link',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
// not a content namespace, different model
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'MediaWiki:WikiPageTest_testIsCountable.js',
|
2013-02-14 11:56:23 +00:00
|
|
|
null,
|
|
|
|
|
'Foo',
|
|
|
|
|
'any',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'MediaWiki:WikiPageTest_testIsCountable.js',
|
2013-02-14 11:56:23 +00:00
|
|
|
null,
|
|
|
|
|
'Foo [[bar]]',
|
|
|
|
|
'link',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideIsCountable
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers WikiPage::isCountable
|
2012-05-02 17:35:42 +00:00
|
|
|
*/
|
2012-09-19 18:07:56 +00:00
|
|
|
public function testIsCountable( $title, $model, $text, $mode, $expected ) {
|
2022-08-01 19:14:41 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::ArticleCountMethod, $mode );
|
2012-11-01 12:48:18 +00:00
|
|
|
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
|
2012-09-19 18:07:56 +00:00
|
|
|
$page = $this->createPage( $title, $text, $model );
|
2012-05-23 06:53:01 +00:00
|
|
|
|
2022-06-03 23:45:17 +00:00
|
|
|
$editInfo = $page->prepareContentForEdit(
|
|
|
|
|
$page->getContent(),
|
|
|
|
|
null,
|
|
|
|
|
$this->getTestUser()->getUser()
|
|
|
|
|
);
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
$v = $page->isCountable();
|
|
|
|
|
$w = $page->isCountable( $editInfo );
|
2012-05-23 06:53:01 +00:00
|
|
|
|
2014-04-24 12:50:36 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected,
|
|
|
|
|
$v,
|
|
|
|
|
"isCountable( null ) returned unexpected value " . var_export( $v, true )
|
|
|
|
|
. " instead of " . var_export( $expected, true )
|
|
|
|
|
. " in mode `$mode` for text \"$text\""
|
|
|
|
|
);
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2014-04-24 12:50:36 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected,
|
|
|
|
|
$w,
|
|
|
|
|
"isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
|
|
|
|
|
. " instead of " . var_export( $expected, true )
|
|
|
|
|
. " in mode `$mode` for text \"$text\""
|
|
|
|
|
);
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:12:03 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMakeParserOptions
|
|
|
|
|
* @covers WikiPage::makeParserOptions
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeParserOptions( int $ns, string $title, string $model, $context, callable $expectation ) {
|
|
|
|
|
// Ensure we're working with the default values during this test.
|
|
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::TextModelsToParse => [
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT,
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
],
|
|
|
|
|
MainConfigNames::DisableLangConversion => false,
|
|
|
|
|
] );
|
|
|
|
|
// Call the context function first, which lets us setup the
|
|
|
|
|
// overall wiki context before invoking the function-under-test
|
|
|
|
|
if ( is_callable( $context ) ) {
|
|
|
|
|
$context = $context( $this );
|
|
|
|
|
}
|
|
|
|
|
$page = $this->createPage(
|
|
|
|
|
Title::makeTitle( $ns, $title ), __METHOD__, $model
|
|
|
|
|
);
|
|
|
|
|
$parserOptions = $page->makeParserOptions( $context );
|
|
|
|
|
$expected = $expectation();
|
|
|
|
|
$this->assertTrue( $expected->matches( $parserOptions ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMakeParserOptions
|
|
|
|
|
* @covers WikiPage::makeParserOptionsFromTitleAndModel
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeParserOptionsFromTitleAndModel( int $ns, string $title, string $model, $context, callable $expectation ) {
|
|
|
|
|
// Ensure we're working with the default values during this test.
|
|
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::TextModelsToParse => [
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT,
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
],
|
|
|
|
|
MainConfigNames::DisableLangConversion => false,
|
|
|
|
|
] );
|
|
|
|
|
// Call the context function first, which lets us setup the
|
|
|
|
|
// overall wiki context before invoking the function-under-test
|
|
|
|
|
if ( is_callable( $context ) ) {
|
|
|
|
|
$context = $context( $this );
|
|
|
|
|
}
|
|
|
|
|
$parserOptions = WikiPage::makeParserOptionsFromTitleAndModel(
|
|
|
|
|
Title::makeTitle( $ns, $title ), $model, $context
|
|
|
|
|
);
|
|
|
|
|
$expected = $expectation();
|
|
|
|
|
$this->assertTrue( $expected->matches( $parserOptions ) );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideMakeParserOptions() {
|
2022-06-16 14:12:03 +00:00
|
|
|
// Default canonical parser options for a normal wikitext page
|
|
|
|
|
yield [
|
|
|
|
|
NS_MAIN, 'Main Page', CONTENT_MODEL_WIKITEXT, 'canonical',
|
|
|
|
|
static function () {
|
|
|
|
|
return ParserOptions::newFromAnon();
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
// JavaScript should have Table Of Contents suppressed
|
|
|
|
|
yield [
|
|
|
|
|
NS_MAIN, 'JavaScript Test', CONTENT_MODEL_JAVASCRIPT, 'canonical',
|
|
|
|
|
static function () {
|
|
|
|
|
$po = ParserOptions::newFromAnon();
|
|
|
|
|
$po->setSuppressTOC();
|
|
|
|
|
return $po;
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
// CSS should have Table Of Contents suppressed
|
|
|
|
|
yield [
|
|
|
|
|
NS_MAIN, 'CSS Test', CONTENT_MODEL_CSS, 'canonical',
|
|
|
|
|
static function () {
|
|
|
|
|
$po = ParserOptions::newFromAnon();
|
|
|
|
|
$po->setSuppressTOC();
|
|
|
|
|
return $po;
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
// Language Conversion tables have content conversion disabled
|
|
|
|
|
yield [
|
|
|
|
|
NS_MEDIAWIKI, 'Conversiontable/Test', CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
static function ( $test ) {
|
|
|
|
|
// Switch wiki to a language where LanguageConverter is enabled
|
|
|
|
|
$test->setContentLang( 'zh' );
|
|
|
|
|
$test->setUserLang( 'en' );
|
|
|
|
|
return 'canonical';
|
|
|
|
|
},
|
|
|
|
|
static function () {
|
|
|
|
|
$po = ParserOptions::newFromAnon();
|
|
|
|
|
$po->disableContentConversion();
|
|
|
|
|
// "Canonical" PO should use content language not user language
|
|
|
|
|
Assert::assertSame( 'zh', $po->getUserLang() );
|
|
|
|
|
return $po;
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
// Test "non-canonical" options: parser option should use user
|
|
|
|
|
// language here, not content language
|
|
|
|
|
$user = null;
|
|
|
|
|
yield [
|
|
|
|
|
NS_MAIN, 'Main Page', CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
static function ( $test ) use ( &$user ) {
|
|
|
|
|
$test->setContentLang( 'qqx' );
|
|
|
|
|
$test->setUserLang( 'fr' );
|
|
|
|
|
$user = $test->getTestUser()->getUser();
|
|
|
|
|
return $user;
|
|
|
|
|
},
|
|
|
|
|
static function () use ( &$user ) {
|
|
|
|
|
$po = ParserOptions::newFromUser( $user );
|
|
|
|
|
Assert::assertSame( 'fr', $po->getUserLang() );
|
|
|
|
|
return $po;
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideGetParserOutput() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2017-04-27 16:58:17 +00:00
|
|
|
[
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
"hello ''world''\n",
|
|
|
|
|
"<div class=\"mw-parser-output\"><p>hello <i>world</i></p></div>"
|
|
|
|
|
],
|
2022-06-16 14:12:03 +00:00
|
|
|
[
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT,
|
|
|
|
|
"var test='<h2>not really a heading</h2>';",
|
|
|
|
|
"<pre class=\"mw-code mw-js\" dir=\"ltr\">\nvar test='<h2>not really a heading</h2>';\n</pre>",
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
"/* Not ''wikitext'' */",
|
|
|
|
|
"<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* Not ''wikitext'' */\n</pre>",
|
|
|
|
|
],
|
2013-05-15 01:12:35 +00:00
|
|
|
// @todo more...?
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideGetParserOutput
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers WikiPage::getParserOutput
|
2012-05-02 17:35:42 +00:00
|
|
|
*/
|
2012-09-19 18:07:56 +00:00
|
|
|
public function testGetParserOutput( $model, $text, $expectedHtml ) {
|
2017-11-27 13:49:04 +00:00
|
|
|
$page = $this->createPage( __METHOD__, $text, $model );
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2012-10-14 19:34:26 +00:00
|
|
|
$opt = $page->makeParserOptions( 'canonical' );
|
2012-05-02 17:35:42 +00:00
|
|
|
$po = $page->getParserOutput( $opt );
|
|
|
|
|
$text = $po->getText();
|
|
|
|
|
|
|
|
|
|
$text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
|
2023-03-24 03:21:20 +00:00
|
|
|
$text = preg_replace( '!\s*(</p>|</div>)!m', '\1', $text ); # don't let tidy confuse us
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedHtml, $text );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::getParserOutput
|
|
|
|
|
*/
|
2013-02-14 11:56:23 +00:00
|
|
|
public function testGetParserOutput_nonexisting() {
|
2017-11-27 13:49:04 +00:00
|
|
|
$page = new WikiPage( Title::newFromText( __METHOD__ ) );
|
2012-10-15 12:36:03 +00:00
|
|
|
|
2020-09-18 15:07:18 +00:00
|
|
|
$opt = ParserOptions::newFromAnon();
|
2012-10-15 12:36:03 +00:00
|
|
|
$po = $page->getParserOutput( $opt );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::getParserOutput
|
|
|
|
|
*/
|
2013-02-14 11:56:23 +00:00
|
|
|
public function testGetParserOutput_badrev() {
|
2017-11-27 13:49:04 +00:00
|
|
|
$page = $this->createPage( __METHOD__, 'dummy', CONTENT_MODEL_WIKITEXT );
|
2012-10-18 12:44:47 +00:00
|
|
|
|
2020-09-18 15:07:18 +00:00
|
|
|
$opt = ParserOptions::newFromAnon();
|
2012-10-18 12:44:47 +00:00
|
|
|
$po = $page->getParserOutput( $opt, $page->getLatest() + 1234 );
|
|
|
|
|
|
2013-05-15 01:12:35 +00:00
|
|
|
// @todo would be neat to also test deleted revision
|
2012-10-18 12:44:47 +00:00
|
|
|
|
|
|
|
|
$this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 12:50:36 +00:00
|
|
|
public static $sections =
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
"Intro
|
|
|
|
|
|
|
|
|
|
== stuff ==
|
|
|
|
|
hello world
|
|
|
|
|
|
|
|
|
|
== test ==
|
|
|
|
|
just a test
|
|
|
|
|
|
|
|
|
|
== foo ==
|
|
|
|
|
more stuff
|
|
|
|
|
";
|
|
|
|
|
|
2012-04-24 16:00:21 +00:00
|
|
|
public function dataReplaceSection() {
|
2015-09-11 13:44:59 +00:00
|
|
|
// NOTE: assume the Help namespace to contain wikitext
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'Help:WikiPageTest_testReplaceSection',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
2017-07-23 01:24:09 +00:00
|
|
|
self::$sections,
|
2013-02-14 11:56:23 +00:00
|
|
|
"0",
|
|
|
|
|
"No more",
|
|
|
|
|
null,
|
2023-03-24 03:21:20 +00:00
|
|
|
trim( preg_replace( '/^Intro/m', 'No more', self::$sections ) )
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'Help:WikiPageTest_testReplaceSection',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
2017-07-23 01:24:09 +00:00
|
|
|
self::$sections,
|
2013-02-14 11:56:23 +00:00
|
|
|
"",
|
|
|
|
|
"No more",
|
|
|
|
|
null,
|
|
|
|
|
"No more"
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'Help:WikiPageTest_testReplaceSection',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
2017-07-23 01:24:09 +00:00
|
|
|
self::$sections,
|
2013-02-14 11:56:23 +00:00
|
|
|
"2",
|
|
|
|
|
"== TEST ==\nmore fun",
|
|
|
|
|
null,
|
|
|
|
|
trim( preg_replace( '/^== test ==.*== foo ==/sm',
|
|
|
|
|
"== TEST ==\nmore fun\n\n== foo ==",
|
2017-07-23 01:24:09 +00:00
|
|
|
self::$sections ) )
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'Help:WikiPageTest_testReplaceSection',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
2017-07-23 01:24:09 +00:00
|
|
|
self::$sections,
|
2013-02-14 11:56:23 +00:00
|
|
|
"8",
|
|
|
|
|
"No more",
|
|
|
|
|
null,
|
2017-07-23 01:24:09 +00:00
|
|
|
trim( self::$sections )
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'Help:WikiPageTest_testReplaceSection',
|
2013-02-14 11:56:23 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT,
|
2017-07-23 01:24:09 +00:00
|
|
|
self::$sections,
|
2013-02-14 11:56:23 +00:00
|
|
|
"new",
|
|
|
|
|
"No more",
|
|
|
|
|
"New",
|
2017-07-23 01:24:09 +00:00
|
|
|
trim( self::$sections ) . "\n\n== New ==\n\nNo more"
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 16:00:21 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataReplaceSection
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers WikiPage::replaceSectionContent
|
2012-04-24 16:00:21 +00:00
|
|
|
*/
|
2014-04-24 12:50:36 +00:00
|
|
|
public function testReplaceSectionContent( $title, $model, $text, $section,
|
|
|
|
|
$with, $sectionTitle, $expected
|
|
|
|
|
) {
|
2012-09-19 18:07:56 +00:00
|
|
|
$page = $this->createPage( $title, $text, $model );
|
2012-04-24 16:00:21 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
|
2019-03-11 09:29:20 +00:00
|
|
|
/** @var TextContent $c */
|
2012-04-24 16:00:21 +00:00
|
|
|
$c = $page->replaceSectionContent( $section, $content, $sectionTitle );
|
|
|
|
|
|
2019-03-11 09:29:20 +00:00
|
|
|
$this->assertEquals( $expected, $c ? trim( $c->getText() ) : null );
|
2012-04-24 16:00:21 +00:00
|
|
|
}
|
2012-09-19 18:07:56 +00:00
|
|
|
|
2014-05-18 21:26:17 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataReplaceSection
|
|
|
|
|
* @covers WikiPage::replaceSectionAtRev
|
|
|
|
|
*/
|
|
|
|
|
public function testReplaceSectionAtRev( $title, $model, $text, $section,
|
|
|
|
|
$with, $sectionTitle, $expected
|
|
|
|
|
) {
|
|
|
|
|
$page = $this->createPage( $title, $text, $model );
|
|
|
|
|
$baseRevId = $page->getLatest();
|
|
|
|
|
|
|
|
|
|
$content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
|
2019-03-11 09:29:20 +00:00
|
|
|
/** @var TextContent $c */
|
2014-05-18 21:26:17 +00:00
|
|
|
$c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
|
|
|
|
|
|
2019-03-11 09:29:20 +00:00
|
|
|
$this->assertEquals( $expected, $c ? trim( $c->getText() ) : null );
|
2014-05-18 21:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideGetAutoDeleteReason() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[],
|
2012-05-02 17:35:42 +00:00
|
|
|
false,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
[ "first edit", null ],
|
|
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
"/first edit.*only contributor/",
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
[ "first edit", null ],
|
|
|
|
|
[ "second edit", null ],
|
|
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
"/second edit.*only contributor/",
|
|
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
[ "first edit", "127.0.2.22" ],
|
|
|
|
|
[ "second edit", "127.0.3.33" ],
|
|
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
"/second edit/",
|
|
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
[
|
2014-04-24 12:50:36 +00:00
|
|
|
"first edit: "
|
|
|
|
|
. "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
|
|
|
|
|
. " nonumy eirmod tempor invidunt ut labore et dolore magna "
|
|
|
|
|
. "aliquyam erat, sed diam voluptua. At vero eos et accusam "
|
|
|
|
|
. "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
|
2019-08-21 23:13:16 +00:00
|
|
|
. "no sea takimata sanctus est Lorem ipsum dolor sit amet. "
|
|
|
|
|
. " this here is some more filler content added to try and "
|
|
|
|
|
. "reach the maximum automatic summary length so that this is"
|
|
|
|
|
. " truncated ipot sodit colrad ut ad olve amit basul dat"
|
|
|
|
|
. "Dorbet romt crobit trop bri. DannyS712 put me here lor pe"
|
|
|
|
|
. " ode quob zot bozro see also T22281 for background pol sup"
|
|
|
|
|
. "Lorem ipsum dolor sit amet'",
|
2014-04-24 12:50:36 +00:00
|
|
|
null
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
'/first edit:.*\.\.\."/',
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
[ "first edit", "127.0.2.22" ],
|
|
|
|
|
[ "", "127.0.3.33" ],
|
|
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
"/before blanking.*first edit/",
|
|
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideGetAutoDeleteReason
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers WikiPage::getAutoDeleteReason
|
2012-05-02 17:35:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
|
2015-09-11 13:44:59 +00:00
|
|
|
// NOTE: assume Help namespace to contain wikitext
|
2012-09-19 18:07:56 +00:00
|
|
|
$page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
$c = 1;
|
|
|
|
|
|
|
|
|
|
foreach ( $edits as $edit ) {
|
|
|
|
|
$user = new User();
|
|
|
|
|
|
2013-02-14 11:56:23 +00:00
|
|
|
if ( !empty( $edit[1] ) ) {
|
|
|
|
|
$user->setName( $edit[1] );
|
|
|
|
|
} else {
|
2020-03-14 21:02:42 +00:00
|
|
|
$user = new User;
|
2013-02-14 11:56:23 +00:00
|
|
|
}
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$content = ContentHandler::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
|
2012-04-24 16:00:21 +00:00
|
|
|
|
2020-06-22 16:19:12 +00:00
|
|
|
$page->doUserEditContent( $content, $user, "test edit $c", $c < 2 ? EDIT_NEW : 0 );
|
2012-05-02 17:35:42 +00:00
|
|
|
|
|
|
|
|
$c += 1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:14:18 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::getAutoDeleteReason:' );
|
|
|
|
|
$this->hideDeprecated( 'ContentHandler::getAutoDeleteReason:' );
|
2012-05-02 17:35:42 +00:00
|
|
|
$reason = $page->getAutoDeleteReason( $hasHistory );
|
|
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( is_bool( $expectedResult ) || $expectedResult === null ) {
|
2013-02-14 11:56:23 +00:00
|
|
|
$this->assertEquals( $expectedResult, $reason );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
|
|
|
|
|
"Autosummary didn't match expected pattern $expectedResult: $reason" );
|
|
|
|
|
}
|
2012-05-02 17:35:42 +00:00
|
|
|
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertEquals( $expectedHistory, $hasHistory,
|
2013-02-14 11:56:23 +00:00
|
|
|
"expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function providePreSaveTransform() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'hello this is ~~~',
|
2013-02-14 11:56:23 +00:00
|
|
|
"hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
2013-02-14 11:56:23 +00:00
|
|
|
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 10:54:02 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::factory
|
|
|
|
|
*/
|
|
|
|
|
public function testWikiPageFactory() {
|
2022-10-23 20:28:26 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::factory' );
|
2013-10-24 10:54:02 +00:00
|
|
|
$title = Title::makeTitle( NS_FILE, 'Someimage.png' );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertEquals( WikiFilePage::class, get_class( $page ) );
|
2013-10-24 10:54:02 +00:00
|
|
|
|
|
|
|
|
$title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertEquals( WikiCategoryPage::class, get_class( $page ) );
|
2021-01-18 15:25:52 +00:00
|
|
|
|
|
|
|
|
$title = Title::makeTitle( NS_MAIN, 'SomePage' );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$this->assertEquals( WikiPage::class, get_class( $page ) );
|
|
|
|
|
$this->assertSame( $page, WikiPage::factory( $page ) );
|
|
|
|
|
|
|
|
|
|
$title = new PageIdentityValue( 0, NS_MAIN, 'SomePage', PageIdentity::LOCAL );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$this->assertEquals( WikiPage::class, get_class( $page ) );
|
2013-10-24 10:54:02 +00:00
|
|
|
}
|
2017-06-06 17:39:14 +00:00
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::loadPageData
|
|
|
|
|
* @covers WikiPage::wasLoadedFrom
|
|
|
|
|
*/
|
|
|
|
|
public function testLoadPageData() {
|
|
|
|
|
$title = Title::makeTitle( NS_MAIN, 'SomePage' );
|
2022-09-01 21:18:41 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_NORMAL ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_LATEST ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_LOCKING ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_EXCLUSIVE ) );
|
|
|
|
|
|
|
|
|
|
$page->loadPageData( IDBAccessObject::READ_NORMAL );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_NORMAL ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_LATEST ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_LOCKING ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_EXCLUSIVE ) );
|
|
|
|
|
|
|
|
|
|
$page->loadPageData( IDBAccessObject::READ_LATEST );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_NORMAL ) );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_LATEST ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_LOCKING ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_EXCLUSIVE ) );
|
|
|
|
|
|
|
|
|
|
$page->loadPageData( IDBAccessObject::READ_LOCKING );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_NORMAL ) );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_LATEST ) );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_LOCKING ) );
|
|
|
|
|
$this->assertFalse( $page->wasLoadedFrom( IDBAccessObject::READ_EXCLUSIVE ) );
|
|
|
|
|
|
|
|
|
|
$page->loadPageData( IDBAccessObject::READ_EXCLUSIVE );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_NORMAL ) );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_LATEST ) );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_LOCKING ) );
|
|
|
|
|
$this->assertTrue( $page->wasLoadedFrom( IDBAccessObject::READ_EXCLUSIVE ) );
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 18:23:01 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::updateCategoryCounts
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateCategoryCounts() {
|
|
|
|
|
$page = new WikiPage( Title::newFromText( __METHOD__ ) );
|
|
|
|
|
|
|
|
|
|
// Add an initial category
|
|
|
|
|
$page->updateCategoryCounts( [ 'A' ], [], 0 );
|
|
|
|
|
|
2022-01-14 19:39:06 +00:00
|
|
|
$this->assertSame( 1, Category::newFromName( 'A' )->getMemberCount() );
|
|
|
|
|
$this->assertSame( 0, Category::newFromName( 'B' )->getMemberCount() );
|
|
|
|
|
$this->assertSame( 0, Category::newFromName( 'C' )->getMemberCount() );
|
2017-11-30 18:23:01 +00:00
|
|
|
|
|
|
|
|
// Add a new category
|
|
|
|
|
$page->updateCategoryCounts( [ 'B' ], [], 0 );
|
|
|
|
|
|
2022-01-14 19:39:06 +00:00
|
|
|
$this->assertSame( 1, Category::newFromName( 'A' )->getMemberCount() );
|
|
|
|
|
$this->assertSame( 1, Category::newFromName( 'B' )->getMemberCount() );
|
|
|
|
|
$this->assertSame( 0, Category::newFromName( 'C' )->getMemberCount() );
|
2017-11-30 18:23:01 +00:00
|
|
|
|
|
|
|
|
// Add and remove a category
|
|
|
|
|
$page->updateCategoryCounts( [ 'C' ], [ 'A' ], 0 );
|
|
|
|
|
|
2022-01-14 19:39:06 +00:00
|
|
|
$this->assertSame( 0, Category::newFromName( 'A' )->getMemberCount() );
|
|
|
|
|
$this->assertSame( 1, Category::newFromName( 'B' )->getMemberCount() );
|
|
|
|
|
$this->assertSame( 1, Category::newFromName( 'C' )->getMemberCount() );
|
2017-11-30 18:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideUpdateRedirectOn() {
|
2022-01-21 21:51:20 +00:00
|
|
|
yield [ '#REDIRECT [[Foo]]', true, null, true, true, [] ];
|
|
|
|
|
yield [ '#REDIRECT [[Foo]]', true, 'Foo', true, true, [ [ NS_MAIN, 'Foo' ] ] ];
|
|
|
|
|
yield [ 'SomeText', false, null, false, true, [] ];
|
|
|
|
|
yield [ 'SomeText', false, 'Foo', false, true, [ [ NS_MAIN, 'Foo' ] ] ];
|
2017-12-04 12:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideUpdateRedirectOn
|
|
|
|
|
* @covers WikiPage::updateRedirectOn
|
|
|
|
|
*
|
|
|
|
|
* @param string $initialText
|
|
|
|
|
* @param bool $initialRedirectState
|
|
|
|
|
* @param string|null $redirectTitle
|
|
|
|
|
* @param bool|null $lastRevIsRedirect
|
|
|
|
|
* @param bool $expectedSuccess
|
2022-01-21 21:51:20 +00:00
|
|
|
* @param array $expectedRows
|
2017-12-04 12:11:26 +00:00
|
|
|
*/
|
|
|
|
|
public function testUpdateRedirectOn(
|
|
|
|
|
$initialText,
|
|
|
|
|
$initialRedirectState,
|
|
|
|
|
$redirectTitle,
|
|
|
|
|
$lastRevIsRedirect,
|
|
|
|
|
$expectedSuccess,
|
2022-01-21 21:51:20 +00:00
|
|
|
$expectedRows
|
2017-12-04 12:11:26 +00:00
|
|
|
) {
|
|
|
|
|
static $pageCounter = 0;
|
|
|
|
|
$pageCounter++;
|
|
|
|
|
|
|
|
|
|
$page = $this->createPage( Title::newFromText( __METHOD__ . $pageCounter ), $initialText );
|
|
|
|
|
$this->assertSame( $initialRedirectState, $page->isRedirect() );
|
|
|
|
|
|
|
|
|
|
$redirectTitle = is_string( $redirectTitle )
|
|
|
|
|
? Title::newFromText( $redirectTitle )
|
|
|
|
|
: $redirectTitle;
|
|
|
|
|
|
|
|
|
|
$success = $page->updateRedirectOn( $this->db, $redirectTitle, $lastRevIsRedirect );
|
|
|
|
|
$this->assertSame( $expectedSuccess, $success, 'Success assertion' );
|
|
|
|
|
/**
|
|
|
|
|
* updateRedirectOn explicitly updates the redirect table (and not the page table).
|
|
|
|
|
* Most of core checks the page table for redirect status, so we have to be ugly and
|
|
|
|
|
* assert a select from the table here.
|
|
|
|
|
*/
|
2022-01-21 21:51:20 +00:00
|
|
|
$this->assertRedirectTableCountForPageId( $page->getId(), $expectedRows );
|
2017-12-04 12:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 21:51:20 +00:00
|
|
|
private function assertRedirectTableCountForPageId( $pageId, $expectedRows ) {
|
2017-12-04 12:11:26 +00:00
|
|
|
$this->assertSelect(
|
|
|
|
|
'redirect',
|
2022-01-21 21:51:20 +00:00
|
|
|
[ 'rd_namespace', 'rd_title' ],
|
2017-12-04 12:59:15 +00:00
|
|
|
[ 'rd_from' => $pageId ],
|
2022-01-21 21:51:20 +00:00
|
|
|
$expectedRows
|
2017-12-04 12:59:15 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::insertRedirectEntry
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertRedirectEntry_insertsRedirectEntry() {
|
|
|
|
|
$page = $this->createPage( Title::newFromText( __METHOD__ ), 'A' );
|
2022-01-21 21:51:20 +00:00
|
|
|
$this->assertRedirectTableCountForPageId( $page->getId(), [] );
|
2017-12-04 12:59:15 +00:00
|
|
|
|
|
|
|
|
$targetTitle = Title::newFromText( 'SomeTarget#Frag' );
|
2021-11-17 15:20:38 +00:00
|
|
|
$reflectedTitle = TestingAccessWrapper::newFromObject( $targetTitle );
|
|
|
|
|
$reflectedTitle->mInterwiki = 'eninter';
|
2017-12-04 12:59:15 +00:00
|
|
|
$page->insertRedirectEntry( $targetTitle, null );
|
|
|
|
|
|
|
|
|
|
$this->assertSelect(
|
|
|
|
|
'redirect',
|
|
|
|
|
[ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
|
2017-12-04 12:11:26 +00:00
|
|
|
[ 'rd_from' => $page->getId() ],
|
2017-12-04 12:59:15 +00:00
|
|
|
[ [
|
|
|
|
|
strval( $page->getId() ),
|
|
|
|
|
strval( $targetTitle->getNamespace() ),
|
|
|
|
|
strval( $targetTitle->getDBkey() ),
|
|
|
|
|
strval( $targetTitle->getFragment() ),
|
|
|
|
|
strval( $targetTitle->getInterwiki() ),
|
|
|
|
|
] ]
|
2017-12-04 12:11:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 12:59:15 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::insertRedirectEntry
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertRedirectEntry_insertsRedirectEntryWithPageLatest() {
|
|
|
|
|
$page = $this->createPage( Title::newFromText( __METHOD__ ), 'A' );
|
2022-01-21 21:51:20 +00:00
|
|
|
$this->assertRedirectTableCountForPageId( $page->getId(), [] );
|
2017-12-04 12:59:15 +00:00
|
|
|
|
|
|
|
|
$targetTitle = Title::newFromText( 'SomeTarget#Frag' );
|
2021-11-17 15:20:38 +00:00
|
|
|
$reflectedTitle = TestingAccessWrapper::newFromObject( $targetTitle );
|
|
|
|
|
$reflectedTitle->mInterwiki = 'eninter';
|
2017-12-04 12:59:15 +00:00
|
|
|
$page->insertRedirectEntry( $targetTitle, $page->getLatest() );
|
|
|
|
|
|
|
|
|
|
$this->assertSelect(
|
|
|
|
|
'redirect',
|
|
|
|
|
[ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
|
|
|
|
|
[ 'rd_from' => $page->getId() ],
|
|
|
|
|
[ [
|
|
|
|
|
strval( $page->getId() ),
|
|
|
|
|
strval( $targetTitle->getNamespace() ),
|
|
|
|
|
strval( $targetTitle->getDBkey() ),
|
|
|
|
|
strval( $targetTitle->getFragment() ),
|
|
|
|
|
strval( $targetTitle->getInterwiki() ),
|
|
|
|
|
] ]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::insertRedirectEntry
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertRedirectEntry_doesNotInsertIfPageLatestIncorrect() {
|
|
|
|
|
$page = $this->createPage( Title::newFromText( __METHOD__ ), 'A' );
|
2022-01-21 21:51:20 +00:00
|
|
|
$this->assertRedirectTableCountForPageId( $page->getId(), [] );
|
2017-12-04 12:59:15 +00:00
|
|
|
|
|
|
|
|
$targetTitle = Title::newFromText( 'SomeTarget#Frag' );
|
2021-11-17 15:20:38 +00:00
|
|
|
$reflectedTitle = TestingAccessWrapper::newFromObject( $targetTitle );
|
|
|
|
|
$reflectedTitle->mInterwiki = 'eninter';
|
2017-12-04 12:59:15 +00:00
|
|
|
$page->insertRedirectEntry( $targetTitle, 215251 );
|
|
|
|
|
|
2022-01-21 21:51:20 +00:00
|
|
|
$this->assertRedirectTableCountForPageId( $page->getId(), [] );
|
2017-12-04 12:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-24 21:29:49 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::insertRedirectEntry
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertRedirectEntry_T278367() {
|
|
|
|
|
$page = $this->createPage( Title::newFromText( __METHOD__ ), 'A' );
|
2022-01-21 21:51:20 +00:00
|
|
|
$this->assertRedirectTableCountForPageId( $page->getId(), [] );
|
2021-03-24 21:29:49 +00:00
|
|
|
|
|
|
|
|
$targetTitle = Title::newFromText( '#Frag' );
|
|
|
|
|
$ok = $page->insertRedirectEntry( $targetTitle );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $ok );
|
2022-01-21 21:51:20 +00:00
|
|
|
$this->assertRedirectTableCountForPageId( $page->getId(), [] );
|
2021-03-24 21:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 14:03:41 +00:00
|
|
|
private function getRow( array $overrides = [] ) {
|
|
|
|
|
$row = [
|
|
|
|
|
'page_id' => '44',
|
|
|
|
|
'page_len' => '76',
|
|
|
|
|
'page_is_redirect' => '1',
|
2020-04-16 16:39:15 +00:00
|
|
|
'page_is_new' => '1',
|
2017-12-04 14:03:41 +00:00
|
|
|
'page_latest' => '99',
|
|
|
|
|
'page_namespace' => '3',
|
|
|
|
|
'page_title' => 'JaJaTitle',
|
|
|
|
|
'page_touched' => '20120101020202',
|
|
|
|
|
'page_links_updated' => '20140101020202',
|
2020-04-16 16:39:15 +00:00
|
|
|
'page_lang' => 'it',
|
2021-06-01 20:14:36 +00:00
|
|
|
'page_content_model' => CONTENT_MODEL_WIKITEXT,
|
2017-12-04 14:03:41 +00:00
|
|
|
];
|
|
|
|
|
foreach ( $overrides as $key => $value ) {
|
|
|
|
|
$row[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
return (object)$row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideNewFromRowSuccess() {
|
|
|
|
|
yield 'basic row' => [
|
|
|
|
|
$this->getRow(),
|
2021-02-10 22:31:02 +00:00
|
|
|
static function ( WikiPage $wikiPage, self $test ) {
|
2017-12-04 14:03:41 +00:00
|
|
|
$test->assertSame( 44, $wikiPage->getId() );
|
|
|
|
|
$test->assertSame( 76, $wikiPage->getTitle()->getLength() );
|
2021-02-24 00:44:38 +00:00
|
|
|
$test->assertTrue( $wikiPage->getPageIsRedirectField() );
|
2017-12-04 14:03:41 +00:00
|
|
|
$test->assertSame( 99, $wikiPage->getLatest() );
|
2020-04-16 16:39:15 +00:00
|
|
|
$test->assertSame( true, $wikiPage->isNew() );
|
|
|
|
|
$test->assertSame( 'it', $wikiPage->getLanguage() );
|
2017-12-04 14:03:41 +00:00
|
|
|
$test->assertSame( 3, $wikiPage->getTitle()->getNamespace() );
|
|
|
|
|
$test->assertSame( 'JaJaTitle', $wikiPage->getTitle()->getDBkey() );
|
|
|
|
|
$test->assertSame( '20120101020202', $wikiPage->getTouched() );
|
|
|
|
|
$test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
yield 'different timestamp formats' => [
|
|
|
|
|
$this->getRow( [
|
|
|
|
|
'page_touched' => '2012-01-01 02:02:02',
|
|
|
|
|
'page_links_updated' => '2014-01-01 02:02:02',
|
|
|
|
|
] ),
|
2021-02-10 22:31:02 +00:00
|
|
|
static function ( WikiPage $wikiPage, self $test ) {
|
2017-12-04 14:03:41 +00:00
|
|
|
$test->assertSame( '20120101020202', $wikiPage->getTouched() );
|
|
|
|
|
$test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
|
|
|
|
|
}
|
|
|
|
|
];
|
2020-04-16 16:39:15 +00:00
|
|
|
yield 'no language' => [
|
|
|
|
|
$this->getRow( [
|
|
|
|
|
'page_lang' => null,
|
|
|
|
|
] ),
|
2021-04-29 16:24:12 +00:00
|
|
|
static function ( WikiPage $wikiPage, self $test ) {
|
2021-04-07 09:59:28 +00:00
|
|
|
$test->assertNull(
|
2020-04-16 16:39:15 +00:00
|
|
|
$wikiPage->getLanguage()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
];
|
2017-12-04 14:03:41 +00:00
|
|
|
yield 'not redirect' => [
|
|
|
|
|
$this->getRow( [
|
|
|
|
|
'page_is_redirect' => '0',
|
|
|
|
|
] ),
|
2021-02-10 22:31:02 +00:00
|
|
|
static function ( WikiPage $wikiPage, self $test ) {
|
2017-12-04 14:03:41 +00:00
|
|
|
$test->assertFalse( $wikiPage->isRedirect() );
|
|
|
|
|
}
|
|
|
|
|
];
|
2020-04-16 16:39:15 +00:00
|
|
|
yield 'not new' => [
|
|
|
|
|
$this->getRow( [
|
|
|
|
|
'page_is_new' => '0',
|
|
|
|
|
] ),
|
2021-04-29 16:24:12 +00:00
|
|
|
static function ( WikiPage $wikiPage, self $test ) {
|
2020-04-16 16:39:15 +00:00
|
|
|
$test->assertFalse( $wikiPage->isNew() );
|
|
|
|
|
}
|
|
|
|
|
];
|
2017-12-04 14:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::newFromRow
|
|
|
|
|
* @covers WikiPage::loadFromRow
|
|
|
|
|
* @dataProvider provideNewFromRowSuccess
|
|
|
|
|
*
|
2020-11-12 22:22:22 +00:00
|
|
|
* @param stdClass $row
|
2017-12-04 14:03:41 +00:00
|
|
|
* @param callable $assertions
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromRow( $row, $assertions ) {
|
2022-10-23 20:28:26 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::newFromRow' );
|
2021-09-26 18:52:30 +00:00
|
|
|
$page = WikiPage::newFromRow( $row, WikiPage::READ_NORMAL );
|
2017-12-04 14:03:41 +00:00
|
|
|
$assertions( $page, $this );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideTestNewFromId_returnsNullOnBadPageId() {
|
2021-03-26 22:55:58 +00:00
|
|
|
yield [ 0 ];
|
|
|
|
|
yield [ -11 ];
|
2017-12-04 14:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::newFromID
|
|
|
|
|
* @dataProvider provideTestNewFromId_returnsNullOnBadPageId
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromId_returnsNullOnBadPageId( $pageId ) {
|
2022-10-23 20:28:26 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::newFromID' );
|
2017-12-04 14:14:12 +00:00
|
|
|
$this->assertNull( WikiPage::newFromID( $pageId ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::newFromID
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromId_appearsToFetchCorrectRow() {
|
2022-10-23 20:28:26 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::newFromID' );
|
2017-12-04 14:14:12 +00:00
|
|
|
$createdPage = $this->createPage( __METHOD__, 'Xsfaij09' );
|
|
|
|
|
$fetchedPage = WikiPage::newFromID( $createdPage->getId() );
|
|
|
|
|
$this->assertSame( $createdPage->getId(), $fetchedPage->getId() );
|
|
|
|
|
$this->assertEquals(
|
2019-02-07 00:14:23 +00:00
|
|
|
$createdPage->getContent()->getText(),
|
|
|
|
|
$fetchedPage->getContent()->getText()
|
2017-12-04 14:14:12 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::newFromID
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromId_returnsNullOnNonExistingId() {
|
2022-10-23 20:28:26 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::newFromID' );
|
2018-03-18 02:02:13 +00:00
|
|
|
$this->assertNull( WikiPage::newFromID( 2147483647 ) );
|
2017-12-04 14:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 15:31:57 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::updateRevisionOn
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateRevisionOn_existingPage() {
|
|
|
|
|
$user = $this->getTestSysop()->getUser();
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'StartText' );
|
|
|
|
|
|
2021-04-21 19:33:04 +00:00
|
|
|
$revisionRecord = new MutableRevisionRecord( $page );
|
|
|
|
|
$revisionRecord->setContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
new WikitextContent( __METHOD__ . '-text' )
|
2017-12-04 15:31:57 +00:00
|
|
|
);
|
2021-04-21 19:33:04 +00:00
|
|
|
$revisionRecord->setUser( $user );
|
|
|
|
|
$revisionRecord->setTimestamp( '20170707040404' );
|
|
|
|
|
$revisionRecord->setPageId( $page->getId() );
|
|
|
|
|
$revisionRecord->setId( 9989 );
|
|
|
|
|
$revisionRecord->setSize( strlen( __METHOD__ . '-text' ) );
|
|
|
|
|
$revisionRecord->setMinorEdit( true );
|
|
|
|
|
$revisionRecord->setComment( CommentStoreComment::newUnsavedComment( __METHOD__ ) );
|
|
|
|
|
|
|
|
|
|
$result = $page->updateRevisionOn( $this->db, $revisionRecord );
|
2017-12-04 15:31:57 +00:00
|
|
|
$this->assertTrue( $result );
|
|
|
|
|
$this->assertSame( 9989, $page->getLatest() );
|
2021-04-21 19:33:04 +00:00
|
|
|
$this->assertEquals( $revisionRecord, $page->getRevisionRecord() );
|
2017-12-04 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::updateRevisionOn
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateRevisionOn_NonExistingPage() {
|
|
|
|
|
$user = $this->getTestSysop()->getUser();
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'StartText' );
|
2021-10-30 15:45:49 +00:00
|
|
|
$this->deletePage( $page, '', $user );
|
2017-12-04 15:31:57 +00:00
|
|
|
|
2021-04-21 19:33:04 +00:00
|
|
|
$revisionRecord = new MutableRevisionRecord( $page );
|
|
|
|
|
$revisionRecord->setContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
new WikitextContent( __METHOD__ . '-text' )
|
2017-12-04 15:39:49 +00:00
|
|
|
);
|
2021-04-21 19:33:04 +00:00
|
|
|
$revisionRecord->setUser( $user );
|
|
|
|
|
$revisionRecord->setTimestamp( '20170707040404' );
|
|
|
|
|
$revisionRecord->setPageId( $page->getId() );
|
|
|
|
|
$revisionRecord->setId( 9989 );
|
|
|
|
|
$revisionRecord->setSize( strlen( __METHOD__ . '-text' ) );
|
|
|
|
|
$revisionRecord->setMinorEdit( true );
|
|
|
|
|
$revisionRecord->setComment( CommentStoreComment::newUnsavedComment( __METHOD__ ) );
|
|
|
|
|
|
|
|
|
|
$result = $page->updateRevisionOn( $this->db, $revisionRecord );
|
2017-12-04 15:39:49 +00:00
|
|
|
$this->assertFalse( $result );
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 16:09:54 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::insertOn
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertOn() {
|
|
|
|
|
$title = Title::newFromText( __METHOD__ );
|
|
|
|
|
$page = new WikiPage( $title );
|
|
|
|
|
|
|
|
|
|
$startTimeStamp = wfTimestampNow();
|
|
|
|
|
$result = $page->insertOn( $this->db );
|
|
|
|
|
$endTimeStamp = wfTimestampNow();
|
|
|
|
|
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsInt( $result );
|
2017-12-04 16:09:54 +00:00
|
|
|
$this->assertTrue( $result > 0 );
|
|
|
|
|
|
|
|
|
|
$condition = [ 'page_id' => $result ];
|
|
|
|
|
|
|
|
|
|
// Check the default fields have been filled
|
|
|
|
|
$this->assertSelect(
|
|
|
|
|
'page',
|
|
|
|
|
[
|
|
|
|
|
'page_namespace',
|
|
|
|
|
'page_title',
|
|
|
|
|
'page_is_redirect',
|
|
|
|
|
'page_is_new',
|
|
|
|
|
'page_latest',
|
|
|
|
|
'page_len',
|
|
|
|
|
],
|
|
|
|
|
$condition,
|
|
|
|
|
[ [
|
|
|
|
|
'0',
|
|
|
|
|
__METHOD__,
|
|
|
|
|
'0',
|
|
|
|
|
'1',
|
|
|
|
|
'0',
|
|
|
|
|
'0',
|
|
|
|
|
] ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Check the page_random field has been filled
|
|
|
|
|
$pageRandom = $this->db->selectField( 'page', 'page_random', $condition );
|
|
|
|
|
$this->assertTrue( (float)$pageRandom < 1 && (float)$pageRandom > 0 );
|
|
|
|
|
|
|
|
|
|
// Assert the touched timestamp in the DB is roughly when we inserted the page
|
|
|
|
|
$pageTouched = $this->db->selectField( 'page', 'page_touched', $condition );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
wfTimestamp( TS_UNIX, $startTimeStamp )
|
|
|
|
|
<= wfTimestamp( TS_UNIX, $pageTouched )
|
|
|
|
|
);
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
wfTimestamp( TS_UNIX, $endTimeStamp )
|
|
|
|
|
>= wfTimestamp( TS_UNIX, $pageTouched )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Try inserting the same page again and checking the result is false (no change)
|
|
|
|
|
$result = $page->insertOn( $this->db );
|
|
|
|
|
$this->assertFalse( $result );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::insertOn
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertOn_idSpecified() {
|
|
|
|
|
$title = Title::newFromText( __METHOD__ );
|
|
|
|
|
$page = new WikiPage( $title );
|
2017-12-15 21:03:07 +00:00
|
|
|
$id = 1478952189;
|
2017-12-04 16:09:54 +00:00
|
|
|
|
|
|
|
|
$result = $page->insertOn( $this->db, $id );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $id, $result );
|
|
|
|
|
|
|
|
|
|
$condition = [ 'page_id' => $result ];
|
|
|
|
|
|
|
|
|
|
// Check there is actually a row in the db
|
|
|
|
|
$this->assertSelect(
|
|
|
|
|
'page',
|
|
|
|
|
[ 'page_title' ],
|
|
|
|
|
$condition,
|
|
|
|
|
[ [ __METHOD__ ] ]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideTestDoUpdateRestrictions_setBasicRestrictions() {
|
2017-12-04 18:23:17 +00:00
|
|
|
// Note: Once the current dates passes the date in these tests they will fail.
|
|
|
|
|
yield 'move something' => [
|
|
|
|
|
true,
|
|
|
|
|
[ 'move' => 'something' ],
|
|
|
|
|
[],
|
|
|
|
|
[ 'edit' => [], 'move' => [ 'something' ] ],
|
|
|
|
|
[],
|
|
|
|
|
];
|
|
|
|
|
yield 'move something, edit blank' => [
|
|
|
|
|
true,
|
|
|
|
|
[ 'move' => 'something', 'edit' => '' ],
|
|
|
|
|
[],
|
|
|
|
|
[ 'edit' => [], 'move' => [ 'something' ] ],
|
|
|
|
|
[],
|
|
|
|
|
];
|
|
|
|
|
yield 'edit sysop, with expiry' => [
|
|
|
|
|
true,
|
|
|
|
|
[ 'edit' => 'sysop' ],
|
|
|
|
|
[ 'edit' => '21330101020202' ],
|
|
|
|
|
[ 'edit' => [ 'sysop' ], 'move' => [] ],
|
|
|
|
|
[ 'edit' => '21330101020202' ],
|
|
|
|
|
];
|
|
|
|
|
yield 'move and edit, move with expiry' => [
|
|
|
|
|
true,
|
|
|
|
|
[ 'move' => 'something', 'edit' => 'another' ],
|
|
|
|
|
[ 'move' => '22220202010101' ],
|
|
|
|
|
[ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
|
|
|
|
|
[ 'move' => '22220202010101' ],
|
|
|
|
|
];
|
|
|
|
|
yield 'move and edit, edit with infinity expiry' => [
|
|
|
|
|
true,
|
|
|
|
|
[ 'move' => 'something', 'edit' => 'another' ],
|
|
|
|
|
[ 'edit' => 'infinity' ],
|
|
|
|
|
[ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
|
|
|
|
|
[ 'edit' => 'infinity' ],
|
|
|
|
|
];
|
|
|
|
|
yield 'non existing, create something' => [
|
|
|
|
|
false,
|
|
|
|
|
[ 'create' => 'something' ],
|
|
|
|
|
[],
|
|
|
|
|
[ 'create' => [ 'something' ] ],
|
|
|
|
|
[],
|
|
|
|
|
];
|
|
|
|
|
yield 'non existing, create something with expiry' => [
|
|
|
|
|
false,
|
|
|
|
|
[ 'create' => 'something' ],
|
|
|
|
|
[ 'create' => '23451212112233' ],
|
|
|
|
|
[ 'create' => [ 'something' ] ],
|
|
|
|
|
[ 'create' => '23451212112233' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideTestDoUpdateRestrictions_setBasicRestrictions
|
|
|
|
|
* @covers WikiPage::doUpdateRestrictions
|
|
|
|
|
*/
|
|
|
|
|
public function testDoUpdateRestrictions_setBasicRestrictions(
|
|
|
|
|
$pageExists,
|
|
|
|
|
array $limit,
|
|
|
|
|
array $expiry,
|
|
|
|
|
array $expectedRestrictions,
|
|
|
|
|
array $expectedRestrictionExpiries
|
|
|
|
|
) {
|
|
|
|
|
if ( $pageExists ) {
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'ABC' );
|
|
|
|
|
} else {
|
|
|
|
|
$page = new WikiPage( Title::newFromText( __METHOD__ . '-nonexist' ) );
|
|
|
|
|
}
|
2021-04-19 00:58:38 +00:00
|
|
|
$user = $this->getTestSysop()->getUser();
|
|
|
|
|
$userIdentity = $this->getTestSysop()->getUserIdentity();
|
|
|
|
|
|
2017-12-04 18:23:17 +00:00
|
|
|
$cascade = false;
|
|
|
|
|
|
2021-04-19 00:58:38 +00:00
|
|
|
$status = $page->doUpdateRestrictions( $limit, $expiry, $cascade, 'aReason', $userIdentity, [] );
|
2017-12-04 18:23:17 +00:00
|
|
|
|
|
|
|
|
$logId = $status->getValue();
|
2022-04-13 20:58:13 +00:00
|
|
|
$restrictionStore = $this->getServiceContainer()->getRestrictionStore();
|
|
|
|
|
$allRestrictions = $restrictionStore->getAllRestrictions( $page->getTitle() );
|
2017-12-04 18:23:17 +00:00
|
|
|
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusGood( $status );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsInt( $logId );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->assertSame( $expectedRestrictions, $allRestrictions );
|
|
|
|
|
foreach ( $expectedRestrictionExpiries as $key => $value ) {
|
2022-04-13 20:58:13 +00:00
|
|
|
$this->assertSame( $value, $restrictionStore->getRestrictionExpiry( $page->getTitle(), $key ) );
|
2017-12-04 18:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the log entry looks good
|
|
|
|
|
// log_params is not checked here
|
2022-01-12 20:13:39 +00:00
|
|
|
$commentQuery = $this->getServiceContainer()->getCommentStore()->getJoin( 'log_comment' );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->assertSelect(
|
2021-04-19 00:58:38 +00:00
|
|
|
[ 'logging' ] + $commentQuery['tables'],
|
2017-12-04 18:23:17 +00:00
|
|
|
[
|
2018-11-07 19:50:27 +00:00
|
|
|
'log_comment' => $commentQuery['fields']['log_comment_text'],
|
2021-04-19 00:58:38 +00:00
|
|
|
'log_actor',
|
2017-12-04 18:23:17 +00:00
|
|
|
'log_namespace',
|
|
|
|
|
'log_title',
|
|
|
|
|
],
|
|
|
|
|
[ 'log_id' => $logId ],
|
|
|
|
|
[ [
|
|
|
|
|
'aReason',
|
2021-04-19 00:58:38 +00:00
|
|
|
(string)$user->getActorId(),
|
2017-12-04 18:23:17 +00:00
|
|
|
(string)$page->getTitle()->getNamespace(),
|
|
|
|
|
$page->getTitle()->getDBkey(),
|
2017-09-12 17:12:29 +00:00
|
|
|
] ],
|
|
|
|
|
[],
|
2021-04-19 00:58:38 +00:00
|
|
|
$commentQuery['joins']
|
2017-12-04 18:23:17 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::doUpdateRestrictions
|
|
|
|
|
*/
|
|
|
|
|
public function testDoUpdateRestrictions_failsOnReadOnly() {
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'ABC' );
|
|
|
|
|
$user = $this->getTestSysop()->getUser();
|
|
|
|
|
$cascade = false;
|
|
|
|
|
|
|
|
|
|
// Set read only
|
2021-05-26 03:35:05 +00:00
|
|
|
$readOnly = $this->getDummyReadOnlyMode( true );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->setService( 'ReadOnlyMode', $readOnly );
|
|
|
|
|
|
|
|
|
|
$status = $page->doUpdateRestrictions( [], [], $cascade, 'aReason', $user, [] );
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusNotOK( $status );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->assertSame( 'readonlytext', $status->getMessage()->getKey() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::doUpdateRestrictions
|
|
|
|
|
*/
|
|
|
|
|
public function testDoUpdateRestrictions_returnsGoodIfNothingChanged() {
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'ABC' );
|
|
|
|
|
$user = $this->getTestSysop()->getUser();
|
|
|
|
|
$cascade = false;
|
|
|
|
|
$limit = [ 'edit' => 'sysop' ];
|
|
|
|
|
|
|
|
|
|
$status = $page->doUpdateRestrictions(
|
|
|
|
|
$limit,
|
|
|
|
|
[],
|
|
|
|
|
$cascade,
|
|
|
|
|
'aReason',
|
|
|
|
|
$user,
|
|
|
|
|
[]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// The first entry should have a logId as it did something
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusGood( $status );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsInt( $status->getValue() );
|
2017-12-04 18:23:17 +00:00
|
|
|
|
|
|
|
|
$status = $page->doUpdateRestrictions(
|
|
|
|
|
$limit,
|
|
|
|
|
[],
|
|
|
|
|
$cascade,
|
|
|
|
|
'aReason',
|
|
|
|
|
$user,
|
|
|
|
|
[]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// The second entry should not have a logId as nothing changed
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusGood( $status );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->assertNull( $status->getValue() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::doUpdateRestrictions
|
|
|
|
|
*/
|
|
|
|
|
public function testDoUpdateRestrictions_logEntryTypeAndAction() {
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'ABC' );
|
|
|
|
|
$user = $this->getTestSysop()->getUser();
|
|
|
|
|
$cascade = false;
|
|
|
|
|
|
|
|
|
|
// Protect the page
|
|
|
|
|
$status = $page->doUpdateRestrictions(
|
|
|
|
|
[ 'edit' => 'sysop' ],
|
|
|
|
|
[],
|
|
|
|
|
$cascade,
|
|
|
|
|
'aReason',
|
|
|
|
|
$user,
|
|
|
|
|
[]
|
|
|
|
|
);
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusGood( $status );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsInt( $status->getValue() );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->assertSelect(
|
|
|
|
|
'logging',
|
|
|
|
|
[ 'log_type', 'log_action' ],
|
|
|
|
|
[ 'log_id' => $status->getValue() ],
|
|
|
|
|
[ [ 'protect', 'protect' ] ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Modify the protection
|
|
|
|
|
$status = $page->doUpdateRestrictions(
|
|
|
|
|
[ 'edit' => 'somethingElse' ],
|
|
|
|
|
[],
|
|
|
|
|
$cascade,
|
|
|
|
|
'aReason',
|
|
|
|
|
$user,
|
|
|
|
|
[]
|
|
|
|
|
);
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusGood( $status );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsInt( $status->getValue() );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->assertSelect(
|
|
|
|
|
'logging',
|
|
|
|
|
[ 'log_type', 'log_action' ],
|
|
|
|
|
[ 'log_id' => $status->getValue() ],
|
|
|
|
|
[ [ 'protect', 'modify' ] ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Remove the protection
|
|
|
|
|
$status = $page->doUpdateRestrictions(
|
|
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
$cascade,
|
|
|
|
|
'aReason',
|
|
|
|
|
$user,
|
|
|
|
|
[]
|
|
|
|
|
);
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusGood( $status );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsInt( $status->getValue() );
|
2017-12-04 18:23:17 +00:00
|
|
|
$this->assertSelect(
|
|
|
|
|
'logging',
|
|
|
|
|
[ 'log_type', 'log_action' ],
|
|
|
|
|
[ 'log_id' => $status->getValue() ],
|
|
|
|
|
[ [ 'protect', 'unprotect' ] ]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::newPageUpdater
|
|
|
|
|
* @covers WikiPage::getDerivedDataUpdater
|
|
|
|
|
*/
|
|
|
|
|
public function testNewPageUpdater() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$page = $this->newPage( __METHOD__, __METHOD__ );
|
2021-10-21 12:04:01 +00:00
|
|
|
$content = new WikitextContent( 'Hello World' );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2021-10-21 12:04:01 +00:00
|
|
|
/** @var ContentRenderer $contentRenderer */
|
|
|
|
|
$contentRenderer = $this->getMockBuilder( ContentRenderer::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'getParserOutput' ] )
|
2021-10-21 12:04:01 +00:00
|
|
|
->disableOriginalConstructor()
|
2018-01-27 01:48:19 +00:00
|
|
|
->getMock();
|
2021-10-21 12:04:01 +00:00
|
|
|
$contentRenderer->expects( $this->once() )
|
2018-01-27 01:48:19 +00:00
|
|
|
->method( 'getParserOutput' )
|
|
|
|
|
->willReturn( new ParserOutput( 'HTML' ) );
|
|
|
|
|
|
2021-10-21 12:04:01 +00:00
|
|
|
$this->setService( 'ContentRenderer', $contentRenderer );
|
|
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
$preparedEditBefore = $page->prepareContentForEdit( $content, null, $user );
|
2021-06-23 10:43:46 +00:00
|
|
|
$preparedUpdateBefore = $page->getCurrentUpdate();
|
2018-07-08 19:01:32 +00:00
|
|
|
|
|
|
|
|
// provide context, so the cache can be kept in place
|
|
|
|
|
$slotsUpdate = new revisionSlotsUpdate();
|
2018-09-24 21:10:08 +00:00
|
|
|
$slotsUpdate->modifyContent( SlotRecord::MAIN, $content );
|
2018-07-08 19:01:32 +00:00
|
|
|
|
2021-10-04 17:10:37 +00:00
|
|
|
$revision = $page->newPageUpdater( $user, $slotsUpdate )
|
|
|
|
|
->setContent( SlotRecord::MAIN, $content )
|
|
|
|
|
->saveRevision( CommentStoreComment::newUnsavedComment( 'test' ), EDIT_NEW );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
$preparedEditAfter = $page->prepareContentForEdit( $content, $revision, $user );
|
2021-06-23 10:43:46 +00:00
|
|
|
$preparedUpdateAfter = $page->getCurrentUpdate();
|
2018-07-08 19:01:32 +00:00
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertSame( $revision->getId(), $page->getLatest() );
|
2018-07-08 19:01:32 +00:00
|
|
|
|
|
|
|
|
// Parsed output must remain cached throughout.
|
2021-06-23 10:43:46 +00:00
|
|
|
$this->assertSame(
|
|
|
|
|
$preparedEditBefore->output,
|
|
|
|
|
$preparedEditAfter->output
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$preparedEditBefore->output,
|
|
|
|
|
$preparedUpdateBefore->getCanonicalParserOutput()
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$preparedEditBefore->output,
|
|
|
|
|
$preparedUpdateAfter->getCanonicalParserOutput()
|
|
|
|
|
);
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::newPageUpdater
|
|
|
|
|
* @covers WikiPage::getDerivedDataUpdater
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDerivedDataUpdater() {
|
|
|
|
|
$admin = $this->getTestSysop()->getUser();
|
|
|
|
|
|
|
|
|
|
/** @var object $page */
|
|
|
|
|
$page = $this->createPage( __METHOD__, __METHOD__ );
|
|
|
|
|
$page = TestingAccessWrapper::newFromObject( $page );
|
|
|
|
|
|
2021-04-21 04:35:50 +00:00
|
|
|
$revision = $page->getRevisionRecord();
|
2018-01-27 01:48:19 +00:00
|
|
|
$user = $revision->getUser();
|
|
|
|
|
|
|
|
|
|
$slotsUpdate = new RevisionSlotsUpdate();
|
2018-09-24 21:10:08 +00:00
|
|
|
$slotsUpdate->modifyContent( SlotRecord::MAIN, new WikitextContent( 'Hello World' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// get a virgin updater
|
|
|
|
|
$updater1 = $page->getDerivedDataUpdater( $user );
|
|
|
|
|
$this->assertFalse( $updater1->isUpdatePrepared() );
|
|
|
|
|
|
|
|
|
|
$updater1->prepareUpdate( $revision );
|
|
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
// Re-use updater with same revision or content, even if base changed
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, $revision ) );
|
|
|
|
|
|
|
|
|
|
$slotsUpdate = RevisionSlotsUpdate::newFromContent(
|
2018-09-24 21:10:08 +00:00
|
|
|
[ SlotRecord::MAIN => $revision->getContent( SlotRecord::MAIN ) ]
|
2018-01-27 01:48:19 +00:00
|
|
|
);
|
|
|
|
|
$this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, null, $slotsUpdate ) );
|
|
|
|
|
|
2018-07-08 19:01:32 +00:00
|
|
|
// Don't re-use for edit if base revision ID changed
|
|
|
|
|
$this->assertNotSame(
|
|
|
|
|
$updater1,
|
|
|
|
|
$page->getDerivedDataUpdater( $user, null, $slotsUpdate, true )
|
|
|
|
|
);
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
// Don't re-use with different user
|
|
|
|
|
$updater2a = $page->getDerivedDataUpdater( $admin, null, $slotsUpdate );
|
|
|
|
|
$updater2a->prepareContent( $admin, $slotsUpdate, false );
|
|
|
|
|
|
|
|
|
|
$updater2b = $page->getDerivedDataUpdater( $user, null, $slotsUpdate );
|
|
|
|
|
$updater2b->prepareContent( $user, $slotsUpdate, false );
|
|
|
|
|
$this->assertNotSame( $updater2a, $updater2b );
|
|
|
|
|
|
|
|
|
|
// Don't re-use with different content
|
|
|
|
|
$updater3 = $page->getDerivedDataUpdater( $admin, null, $slotsUpdate );
|
|
|
|
|
$updater3->prepareUpdate( $revision );
|
|
|
|
|
$this->assertNotSame( $updater2b, $updater3 );
|
|
|
|
|
|
|
|
|
|
// Don't re-use if no context given
|
|
|
|
|
$updater4 = $page->getDerivedDataUpdater( $admin );
|
|
|
|
|
$updater4->prepareUpdate( $revision );
|
|
|
|
|
$this->assertNotSame( $updater3, $updater4 );
|
|
|
|
|
|
|
|
|
|
// Don't re-use if AGAIN no context given
|
|
|
|
|
$updater5 = $page->getDerivedDataUpdater( $admin );
|
|
|
|
|
$this->assertNotSame( $updater4, $updater5 );
|
|
|
|
|
|
|
|
|
|
// Don't re-use cached "virgin" unprepared updater
|
|
|
|
|
$updater6 = $page->getDerivedDataUpdater( $admin, $revision );
|
|
|
|
|
$this->assertNotSame( $updater5, $updater6 );
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-28 15:34:25 +00:00
|
|
|
protected function assertPreparedEditEquals(
|
|
|
|
|
PreparedEdit $edit, PreparedEdit $edit2, $message = ''
|
|
|
|
|
) {
|
|
|
|
|
// suppress differences caused by a clock tick between generating the two PreparedEdits
|
2021-02-02 22:53:39 +00:00
|
|
|
$editTimestamp = $edit->timestamp;
|
|
|
|
|
$edit2Timetamp = $edit2->timestamp;
|
|
|
|
|
if ( abs( $editTimestamp - $edit2Timetamp ) < 3 ) {
|
|
|
|
|
$edit2Timetamp = $editTimestamp;
|
2018-08-28 15:34:25 +00:00
|
|
|
}
|
|
|
|
|
$this->assertEquals( $edit, $edit2, $message );
|
2021-02-02 22:53:39 +00:00
|
|
|
$this->assertEquals( $editTimestamp, $edit2Timetamp, $message );
|
2018-08-28 15:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function assertPreparedEditNotEquals(
|
|
|
|
|
PreparedEdit $edit, PreparedEdit $edit2, $message = ''
|
|
|
|
|
) {
|
|
|
|
|
if ( abs( $edit->timestamp - $edit2->timestamp ) < 3 ) {
|
|
|
|
|
$edit2 = clone $edit2;
|
|
|
|
|
$edit2->timestamp = $edit->timestamp;
|
|
|
|
|
}
|
|
|
|
|
$this->assertNotEquals( $edit, $edit2, $message );
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 22:27:07 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::factory
|
|
|
|
|
*
|
|
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
|
|
|
|
public function testWikiPageFactoryHookValid() {
|
2022-10-23 20:28:26 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::factory' );
|
2020-04-30 22:27:07 +00:00
|
|
|
$isCalled = false;
|
|
|
|
|
$expectedWikiPage = $this->createMock( WikiPage::class );
|
|
|
|
|
|
|
|
|
|
$this->setTemporaryHook(
|
|
|
|
|
'WikiPageFactory',
|
2021-02-07 13:10:36 +00:00
|
|
|
static function ( $title, &$page ) use ( &$isCalled, $expectedWikiPage ) {
|
2020-04-30 22:27:07 +00:00
|
|
|
$page = $expectedWikiPage;
|
|
|
|
|
$isCalled = true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
|
|
|
|
|
$wikiPage = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $isCalled );
|
|
|
|
|
$this->assertSame( $expectedWikiPage, $wikiPage );
|
|
|
|
|
}
|
2021-01-19 19:57:24 +00:00
|
|
|
|
2021-02-24 00:44:38 +00:00
|
|
|
/**
|
2021-06-22 15:16:56 +00:00
|
|
|
* This is just to confirm that WikiPage::updateRevisionOn() updates the
|
|
|
|
|
* Title and LinkCache with the correct redirect value. Failing to do so
|
|
|
|
|
* causes subtle test failures in extensions, such as Cognate (T283654)
|
|
|
|
|
* and Echo (no task, but see code review of I12542fc899).
|
2021-02-24 00:44:38 +00:00
|
|
|
*
|
|
|
|
|
* @covers WikiPage
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateSetsTitleRedirectCache() {
|
|
|
|
|
// Get a title object without using the title cache
|
|
|
|
|
$title = Title::makeTitleSafe( NS_MAIN, 'A new redirect' );
|
|
|
|
|
$this->assertFalse( $title->isRedirect() );
|
|
|
|
|
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2022-01-12 20:13:39 +00:00
|
|
|
$store = $this->getServiceContainer()->getRevisionStore();
|
2021-02-24 00:44:38 +00:00
|
|
|
$page = $this->newPage( $title );
|
|
|
|
|
$page->insertOn( $dbw );
|
|
|
|
|
|
|
|
|
|
$revision = new MutableRevisionRecord( $page );
|
|
|
|
|
$revision->setContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
new WikitextContent( '#REDIRECT [[Target]]' )
|
|
|
|
|
);
|
|
|
|
|
$revision->setTimestamp( wfTimestampNow() );
|
|
|
|
|
$revision->setComment( CommentStoreComment::newUnsavedComment( '' ) );
|
|
|
|
|
$revision->setUser( $this->getTestUser()->getUser() );
|
|
|
|
|
|
|
|
|
|
$revision = $store->insertRevisionOn( $revision, $dbw );
|
|
|
|
|
|
|
|
|
|
$page->updateRevisionOn( $dbw, $revision );
|
2021-06-22 15:16:56 +00:00
|
|
|
// check the title cache
|
|
|
|
|
$this->assertTrue( $title->isRedirect() );
|
|
|
|
|
// check the link cache with a fresh title
|
2021-02-24 00:44:38 +00:00
|
|
|
$title = Title::makeTitleSafe( NS_MAIN, 'A new redirect' );
|
|
|
|
|
$this->assertTrue( $title->isRedirect() );
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 16:39:15 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::getTitle
|
|
|
|
|
* @covers WikiPage::getId
|
|
|
|
|
* @covers WikiPage::getNamespace
|
|
|
|
|
* @covers WikiPage::getDBkey
|
|
|
|
|
* @covers WikiPage::getWikiId
|
|
|
|
|
* @covers WikiPage::canExist
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTitle() {
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'whatever' );
|
|
|
|
|
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
$this->assertSame( __METHOD__, $title->getText() );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $page->getId(), $title->getId() );
|
|
|
|
|
$this->assertSame( $page->getNamespace(), $title->getNamespace() );
|
|
|
|
|
$this->assertSame( $page->getDBkey(), $title->getDBkey() );
|
|
|
|
|
$this->assertSame( $page->getWikiId(), $title->getWikiId() );
|
|
|
|
|
$this->assertSame( $page->canExist(), $title->canExist() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::toPageRecord
|
|
|
|
|
* @covers WikiPage::getLatest
|
|
|
|
|
* @covers WikiPage::getTouched
|
|
|
|
|
* @covers WikiPage::isNew
|
|
|
|
|
* @covers WikiPage::isRedirect
|
|
|
|
|
*/
|
|
|
|
|
public function testToPageRecord() {
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'whatever' );
|
|
|
|
|
$record = $page->toPageRecord();
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $page->getId(), $record->getId() );
|
|
|
|
|
$this->assertSame( $page->getNamespace(), $record->getNamespace() );
|
|
|
|
|
$this->assertSame( $page->getDBkey(), $record->getDBkey() );
|
|
|
|
|
$this->assertSame( $page->getWikiId(), $record->getWikiId() );
|
|
|
|
|
$this->assertSame( $page->canExist(), $record->canExist() );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $page->getLatest(), $record->getLatest() );
|
|
|
|
|
$this->assertSame( $page->getTouched(), $record->getTouched() );
|
|
|
|
|
$this->assertSame( $page->isNew(), $record->isNew() );
|
|
|
|
|
$this->assertSame( $page->isRedirect(), $record->isRedirect() );
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 22:11:46 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiPage::setLastEdit
|
|
|
|
|
* @covers WikiPage::getTouched
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTouched() {
|
|
|
|
|
$page = $this->createPage( __METHOD__, 'whatever' );
|
|
|
|
|
|
|
|
|
|
$touched = $this->db->selectField( 'page', 'page_touched', [ 'page_id' => $page->getId() ] );
|
|
|
|
|
$touched = MWTimestamp::convert( TS_MW, $touched );
|
|
|
|
|
|
|
|
|
|
// Internal cache of the touched time was set after the page was created
|
|
|
|
|
$this->assertSame( $touched, $page->getTouched() );
|
|
|
|
|
|
|
|
|
|
$touched = MWTimestamp::convert( TS_MW, MWTimestamp::convert( TS_UNIX, $touched ) + 100 );
|
|
|
|
|
$page->getTitle()->invalidateCache( $touched );
|
|
|
|
|
|
|
|
|
|
// Re-load touched time
|
|
|
|
|
$page = $this->newPage( $page->getTitle() );
|
|
|
|
|
$this->assertSame( $touched, $page->getTouched() );
|
|
|
|
|
|
|
|
|
|
// Cause the latest revision to be loaded
|
|
|
|
|
$page->getRevisionRecord();
|
|
|
|
|
|
|
|
|
|
// Make sure the internal cache of the touched time was not overwritten
|
|
|
|
|
$this->assertSame( $touched, $page->getTouched() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-02 17:35:42 +00:00
|
|
|
}
|