2018-09-27 15:04:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
2022-07-19 10:57:01 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2021-02-13 02:54:05 +00:00
|
|
|
use Wikimedia\Timestamp\ConvertibleTimestamp;
|
2019-05-13 14:18:07 +00:00
|
|
|
|
2018-09-27 15:04:24 +00:00
|
|
|
/**
|
|
|
|
|
* @group API
|
|
|
|
|
* @group medium
|
|
|
|
|
* @group Database
|
|
|
|
|
*
|
2023-09-02 23:16:24 +00:00
|
|
|
* @covers ApiQueryInfo
|
2018-09-27 15:04:24 +00:00
|
|
|
*/
|
|
|
|
|
class ApiQueryInfoTest extends ApiTestCase {
|
|
|
|
|
|
2020-12-14 22:29:18 +00:00
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
2021-02-06 18:53:58 +00:00
|
|
|
|
2022-07-19 10:57:01 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
|
MainConfigNames::WatchlistExpiry => true,
|
|
|
|
|
MainConfigNames::WatchlistExpiryMaxDuration => '6 months',
|
2020-12-14 22:29:18 +00:00
|
|
|
] );
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 15:04:24 +00:00
|
|
|
public function testExecute() {
|
2023-09-02 23:16:24 +00:00
|
|
|
// Mock time for a deterministic result, without cut off from dynamic "max duration"
|
2021-02-13 02:54:05 +00:00
|
|
|
ConvertibleTimestamp::setFakeTime( '2011-01-01T00:00:00Z' );
|
|
|
|
|
|
2018-09-27 15:04:24 +00:00
|
|
|
$page = $this->getExistingTestPage( 'Pluto' );
|
|
|
|
|
$title = $page->getTitle();
|
2020-12-14 22:29:18 +00:00
|
|
|
$user = $this->getTestUser()->getUser();
|
2021-01-11 15:26:02 +00:00
|
|
|
RequestContext::getMain()->setUser( $user );
|
2021-04-13 03:28:23 +00:00
|
|
|
$this->getServiceContainer()->getWatchlistManager()->addWatch(
|
2020-12-14 22:29:18 +00:00
|
|
|
$user,
|
2021-04-13 03:28:23 +00:00
|
|
|
$title,
|
2021-02-13 02:54:05 +00:00
|
|
|
// 3 months later
|
|
|
|
|
'2011-04-01T00:00:00Z'
|
2020-12-14 22:29:18 +00:00
|
|
|
);
|
2018-09-27 15:04:24 +00:00
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $data ] = $this->doApiRequest( [
|
2018-09-27 15:04:24 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
2021-01-12 14:16:35 +00:00
|
|
|
'inprop' => 'watched|notificationtimestamp',
|
|
|
|
|
'titles' => $title->getText() . '|' . 'NonExistingPage_lkasdoiewlmasdoiwem7483',
|
2020-12-14 22:29:18 +00:00
|
|
|
], null, false, $user );
|
2018-09-27 15:04:24 +00:00
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data['query'] );
|
|
|
|
|
$this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][$page->getId()];
|
|
|
|
|
$this->assertSame( $page->getId(), $info['pageid'] );
|
2021-02-13 02:54:05 +00:00
|
|
|
$this->assertSame( NS_MAIN, $info['ns'] );
|
|
|
|
|
$this->assertSame( 'Pluto', $info['title'] );
|
|
|
|
|
$this->assertSame( 'wikitext', $info['contentmodel'] );
|
|
|
|
|
$this->assertSame( 'en', $info['pagelanguage'] );
|
|
|
|
|
$this->assertSame( 'en', $info['pagelanguagehtmlcode'] );
|
|
|
|
|
$this->assertSame( 'ltr', $info['pagelanguagedir'] );
|
|
|
|
|
$this->assertSame( '2011-01-01T00:00:00Z', $info['touched'] );
|
2018-09-27 15:04:24 +00:00
|
|
|
$this->assertSame( $title->getLatestRevID(), $info['lastrevid'] );
|
|
|
|
|
$this->assertSame( $title->getLength(), $info['length'] );
|
2021-02-13 02:54:05 +00:00
|
|
|
$this->assertSame( true, $info['new'] );
|
|
|
|
|
$this->assertSame( true, $info['watched'] );
|
|
|
|
|
$this->assertSame( '2011-04-01T00:00:00Z', $info['watchlistexpiry'] );
|
2018-09-27 15:04:24 +00:00
|
|
|
$this->assertArrayNotHasKey( 'actions', $info );
|
2020-12-10 23:39:12 +00:00
|
|
|
$this->assertArrayNotHasKey( 'linkclasses', $info );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExecuteLinkClasses() {
|
|
|
|
|
$page = $this->getExistingTestPage( 'Pluto' );
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $data ] = $this->doApiRequest( [
|
2020-12-10 23:39:12 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'inprop' => 'linkclasses',
|
|
|
|
|
'inlinkcontext' => $title->getText(),
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data['query'] );
|
|
|
|
|
$this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][$page->getId()];
|
|
|
|
|
$this->assertArrayHasKey( 'linkclasses', $info );
|
|
|
|
|
$this->assertEquals( [], $info['linkclasses'] );
|
2018-09-27 15:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExecuteEditActions() {
|
|
|
|
|
$page = $this->getExistingTestPage( 'Pluto' );
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $data ] = $this->doApiRequest( [
|
2018-09-27 15:04:24 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'edit'
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data['query'] );
|
|
|
|
|
$this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][$page->getId()];
|
|
|
|
|
$this->assertArrayHasKey( 'actions', $info );
|
|
|
|
|
$this->assertArrayHasKey( 'edit', $info['actions'] );
|
|
|
|
|
$this->assertTrue( $info['actions']['edit'] );
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-27 19:22:02 +00:00
|
|
|
public function testExecuteEditActionsAutoCreate() {
|
|
|
|
|
$page = $this->getExistingTestPage( 'Pluto' );
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
|
|
|
|
|
// Disabled
|
|
|
|
|
$this->overrideConfigValue( MainConfigNames::AutoCreateTempUser, [
|
|
|
|
|
'enabled' => false,
|
|
|
|
|
] );
|
|
|
|
|
[ $data ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'edit',
|
|
|
|
|
'intestactionsautocreate' => true,
|
|
|
|
|
], null, false, new User() );
|
|
|
|
|
$result = $data['query']['pages'][$page->getId()]['wouldautocreate']['edit'];
|
|
|
|
|
$this->assertFalse( $result );
|
|
|
|
|
|
|
|
|
|
// Enabled
|
|
|
|
|
$this->setGroupPermissions( '*', 'createaccount', true );
|
|
|
|
|
$this->overrideConfigValue( MainConfigNames::AutoCreateTempUser, [
|
|
|
|
|
'enabled' => true,
|
2023-08-23 12:06:00 +00:00
|
|
|
'expireAfterDays' => null,
|
2023-04-27 19:22:02 +00:00
|
|
|
'actions' => [ 'edit' ],
|
|
|
|
|
'genPattern' => 'Unregistered $1',
|
|
|
|
|
'serialProvider' => [],
|
|
|
|
|
'serialMapping' => [],
|
|
|
|
|
] );
|
|
|
|
|
[ $data ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'edit',
|
|
|
|
|
'intestactionsautocreate' => true,
|
|
|
|
|
], null, false, new User() );
|
|
|
|
|
$result = $data['query']['pages'][$page->getId()]['wouldautocreate']['edit'];
|
|
|
|
|
$this->assertTrue( $result );
|
|
|
|
|
|
|
|
|
|
[ $data ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'create',
|
|
|
|
|
'intestactionsautocreate' => true,
|
|
|
|
|
], null, false, new User() );
|
|
|
|
|
$result = $data['query']['pages'][$page->getId()]['wouldautocreate']['create'];
|
|
|
|
|
$this->assertTrue( $result );
|
|
|
|
|
|
|
|
|
|
// Enabled - 'read' is not an autocreate action
|
|
|
|
|
[ $data ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'read',
|
|
|
|
|
'intestactionsautocreate' => true,
|
|
|
|
|
], null, false, new User() );
|
|
|
|
|
$result = $data['query']['pages'][$page->getId()]['wouldautocreate']['read'];
|
|
|
|
|
$this->assertFalse( $result );
|
|
|
|
|
|
|
|
|
|
// Enabled - but the user is logged in
|
|
|
|
|
[ $data ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'edit',
|
|
|
|
|
'intestactionsautocreate' => true,
|
|
|
|
|
], null, false, static::getTestSysop()->getAuthority() );
|
|
|
|
|
$result = $data['query']['pages'][$page->getId()]['wouldautocreate']['edit'];
|
|
|
|
|
$this->assertFalse( $result );
|
|
|
|
|
|
|
|
|
|
// Enabled - but the user isn't allowed to create accounts
|
|
|
|
|
$this->setGroupPermissions( '*', 'createaccount', false );
|
|
|
|
|
[ $data ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'edit',
|
|
|
|
|
'intestactionsautocreate' => true,
|
|
|
|
|
], null, false, new User() );
|
|
|
|
|
$result = $data['query']['pages'][$page->getId()]['wouldautocreate']['edit'];
|
|
|
|
|
$this->assertFalse( $result );
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 15:04:24 +00:00
|
|
|
public function testExecuteEditActionsFull() {
|
|
|
|
|
$page = $this->getExistingTestPage( 'Pluto' );
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $data ] = $this->doApiRequest( [
|
2018-09-27 15:04:24 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'edit',
|
|
|
|
|
'intestactionsdetail' => 'full',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data['query'] );
|
|
|
|
|
$this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][$page->getId()];
|
|
|
|
|
$this->assertArrayHasKey( 'actions', $info );
|
|
|
|
|
$this->assertArrayHasKey( 'edit', $info['actions'] );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsArray( $info['actions']['edit'] );
|
2018-09-27 15:04:24 +00:00
|
|
|
$this->assertSame( [], $info['actions']['edit'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExecuteEditActionsFullBlock() {
|
|
|
|
|
$badActor = $this->getTestUser()->getUser();
|
|
|
|
|
$sysop = $this->getTestSysop()->getUser();
|
|
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
$block = new DatabaseBlock( [
|
2023-11-05 23:53:56 +00:00
|
|
|
'address' => $badActor,
|
2021-06-02 09:44:38 +00:00
|
|
|
'by' => $sysop,
|
2018-09-27 15:04:24 +00:00
|
|
|
'expiry' => 'infinity',
|
2018-08-27 01:45:18 +00:00
|
|
|
'sitewide' => 1,
|
2018-09-27 15:04:24 +00:00
|
|
|
'enableAutoblock' => true,
|
|
|
|
|
] );
|
|
|
|
|
|
2022-01-12 20:13:39 +00:00
|
|
|
$blockStore = $this->getServiceContainer()->getDatabaseBlockStore();
|
2020-08-27 09:27:10 +00:00
|
|
|
$blockStore->insertBlock( $block );
|
2018-09-27 15:04:24 +00:00
|
|
|
|
|
|
|
|
$page = $this->getExistingTestPage( 'Pluto' );
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $data ] = $this->doApiRequest( [
|
2018-09-27 15:04:24 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getText(),
|
|
|
|
|
'intestactions' => 'edit',
|
|
|
|
|
'intestactionsdetail' => 'full',
|
|
|
|
|
], null, false, $badActor );
|
|
|
|
|
|
2020-08-27 09:27:10 +00:00
|
|
|
$blockStore->deleteBlock( $block );
|
2018-09-27 15:04:24 +00:00
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data['query'] );
|
|
|
|
|
$this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][$page->getId()];
|
|
|
|
|
$this->assertArrayHasKey( 'actions', $info );
|
|
|
|
|
$this->assertArrayHasKey( 'edit', $info['actions'] );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsArray( $info['actions']['edit'] );
|
2018-09-27 15:04:24 +00:00
|
|
|
$this->assertArrayHasKey( 0, $info['actions']['edit'] );
|
|
|
|
|
$this->assertArrayHasKey( 'code', $info['actions']['edit'][0] );
|
|
|
|
|
$this->assertSame( 'blocked', $info['actions']['edit'][0]['code'] );
|
|
|
|
|
$this->assertArrayHasKey( 'data', $info['actions']['edit'][0] );
|
|
|
|
|
$this->assertArrayHasKey( 'blockinfo', $info['actions']['edit'][0]['data'] );
|
|
|
|
|
$this->assertArrayHasKey( 'blockid', $info['actions']['edit'][0]['data']['blockinfo'] );
|
|
|
|
|
$this->assertSame( $block->getId(), $info['actions']['edit'][0]['data']['blockinfo']['blockid'] );
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 05:16:45 +00:00
|
|
|
public function testAssociatedPage() {
|
|
|
|
|
$page = $this->getExistingTestPage( 'Demo' );
|
|
|
|
|
$title = $page->getTitle();
|
|
|
|
|
|
|
|
|
|
$title2 = Title::makeTitle( NS_TALK, 'Page does not exist' );
|
|
|
|
|
// Make sure it doesn't exist
|
|
|
|
|
$this->getNonexistingTestPage( $title2 );
|
|
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $data ] = $this->doApiRequest( [
|
2021-06-08 05:16:45 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'titles' => $title->getPrefixedText() . '|' . $title2->getPrefixedText(),
|
|
|
|
|
'inprop' => 'associatedpage',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data['query'] );
|
|
|
|
|
$this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][$page->getId()];
|
|
|
|
|
$this->assertArrayHasKey( 'associatedpage', $info );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'Talk:Demo',
|
|
|
|
|
$info['associatedpage']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// For the non-existing page
|
|
|
|
|
$this->assertArrayHasKey( -1, $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][ -1 ];
|
|
|
|
|
$this->assertArrayHasKey( 'associatedpage', $info );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'Page does not exist',
|
|
|
|
|
$info['associatedpage']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 18:47:20 +00:00
|
|
|
public function testDisplayTitle() {
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $data ] = $this->doApiRequest( [
|
2021-09-28 18:47:20 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'info',
|
|
|
|
|
'inprop' => 'displaytitle',
|
|
|
|
|
'titles' => 'Art©',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data['query'] );
|
|
|
|
|
|
|
|
|
|
// For the non-existing page
|
|
|
|
|
$this->assertArrayHasKey( -1, $data['query']['pages'] );
|
|
|
|
|
|
|
|
|
|
$info = $data['query']['pages'][ -1 ];
|
|
|
|
|
$this->assertArrayHasKey( 'displaytitle', $info );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'Art&copy',
|
|
|
|
|
$info['displaytitle']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 15:04:24 +00:00
|
|
|
}
|