| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Api\Query; |
| 4 |
|
| 5 |
use MediaWiki\Linker\LinkTarget; |
| 6 |
use MediaWiki\Permissions\Authority; |
| 7 |
use MediaWiki\Tests\Api\ApiTestCase; |
| 8 |
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait; |
| 9 |
use MediaWiki\Tests\User\TempUser\TempUserTestTrait; |
| 10 |
use MediaWiki\Title\TitleValue; |
| 11 |
use MediaWiki\User\User; |
| 12 |
use MediaWiki\Watchlist\WatchedItemQueryService; |
| 13 |
use RecentChange; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
class ApiQueryRecentChangesIntegrationTest extends ApiTestCase { |
| 23 |
use MockAuthorityTrait; |
| 24 |
use TempUserTestTrait; |
| 25 |
|
| 26 |
private function getLoggedInTestUser() { |
| 27 |
return $this->getTestUser()->getUser(); |
| 28 |
} |
| 29 |
|
| 30 |
private function doPageEdit( Authority $performer, $target, $summary ) { |
| 31 |
static $i = 0; |
| 32 |
|
| 33 |
$this->editPage( |
| 34 |
$target, |
| 35 |
__CLASS__ . $i++, |
| 36 |
$summary, |
| 37 |
NS_MAIN, |
| 38 |
$performer |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
private function doMinorPageEdit( User $user, LinkTarget $target, $summary ) { |
| 43 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target ); |
| 44 |
$page->doUserEditContent( |
| 45 |
$page->getContentHandler()->unserializeContent( __CLASS__ ), |
| 46 |
$user, |
| 47 |
$summary, |
| 48 |
EDIT_MINOR |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
private function doBotPageEdit( User $user, LinkTarget $target, $summary ) { |
| 53 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target ); |
| 54 |
$page->doUserEditContent( |
| 55 |
$page->getContentHandler()->unserializeContent( __CLASS__ ), |
| 56 |
$user, |
| 57 |
$summary, |
| 58 |
EDIT_FORCE_BOT |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
private function doAnonPageEdit( LinkTarget $target, $summary ) { |
| 63 |
$this->disableAutoCreateTempUser(); |
| 64 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target ); |
| 65 |
$page->doUserEditContent( |
| 66 |
$page->getContentHandler()->unserializeContent( __CLASS__ ), |
| 67 |
$this->getServiceContainer()->getUserFactory()->newAnonymous(), |
| 68 |
$summary |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
private function doTempPageEdit( LinkTarget $target, $summary ) { |
| 73 |
|
| 74 |
$this->enableAutoCreateTempUser(); |
| 75 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target ); |
| 76 |
$page->doUserEditContent( |
| 77 |
$page->getContentHandler()->unserializeContent( __CLASS__ ), |
| 78 |
$this->mockTempUltimateAuthority(), |
| 79 |
$summary |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
private function doPageEdits( User $user, array $editData ) { |
| 93 |
foreach ( $editData as $singleEditData ) { |
| 94 |
if ( array_key_exists( 'minorEdit', $singleEditData ) && $singleEditData['minorEdit'] ) { |
| 95 |
$this->doMinorPageEdit( |
| 96 |
$user, |
| 97 |
$singleEditData['target'], |
| 98 |
$singleEditData['summary'] |
| 99 |
); |
| 100 |
continue; |
| 101 |
} |
| 102 |
if ( array_key_exists( 'botEdit', $singleEditData ) && $singleEditData['botEdit'] ) { |
| 103 |
$this->doBotPageEdit( |
| 104 |
$user, |
| 105 |
$singleEditData['target'], |
| 106 |
$singleEditData['summary'] |
| 107 |
); |
| 108 |
continue; |
| 109 |
} |
| 110 |
$this->doPageEdit( |
| 111 |
$user, |
| 112 |
$singleEditData['target'], |
| 113 |
$singleEditData['summary'] |
| 114 |
); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
private function doListRecentChangesRequest( array $params = [] ) { |
| 119 |
return $this->doApiRequest( |
| 120 |
array_merge( |
| 121 |
[ 'action' => 'query', 'list' => 'recentchanges' ], |
| 122 |
$params |
| 123 |
), |
| 124 |
null, |
| 125 |
false, |
| 126 |
$this->getLoggedInTestUser() |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
private function doGeneratorRecentChangesRequest( array $params = [] ) { |
| 131 |
return $this->doApiRequest( |
| 132 |
array_merge( |
| 133 |
[ 'action' => 'query', 'generator' => 'recentchanges' ], |
| 134 |
$params |
| 135 |
), |
| 136 |
null, |
| 137 |
false, |
| 138 |
$this->getLoggedInTestUser() |
| 139 |
); |
| 140 |
} |
| 141 |
|
| 142 |
private function getItemsFromRecentChangesResult( array $result ) { |
| 143 |
return $result[0]['query']['recentchanges']; |
| 144 |
} |
| 145 |
|
| 146 |
public function testListRecentChanges_returnsRCInfo() { |
| 147 |
$target = new TitleValue( NS_MAIN, 'ApiQueryRecentChangesIntegrationTestPage' ); |
| 148 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' ); |
| 149 |
|
| 150 |
$result = $this->doListRecentChangesRequest(); |
| 151 |
$items = $this->getItemsFromRecentChangesResult( $result ); |
| 152 |
|
| 153 |
|
| 154 |
$this->assertCount( 1, $items ); |
| 155 |
$item = $items[0]; |
| 156 |
foreach ( [ |
| 157 |
'pageid', |
| 158 |
'revid', |
| 159 |
'old_revid', |
| 160 |
'rcid', |
| 161 |
'timestamp', |
| 162 |
] as $key ) { |
| 163 |
|
| 164 |
$this->assertArrayHasKey( $key, $item ); |
| 165 |
unset( $item[ $key ] ); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
$this->assertEquals( |
| 170 |
[ |
| 171 |
'type' => 'new', |
| 172 |
'ns' => NS_MAIN, |
| 173 |
'title' => 'ApiQueryRecentChangesIntegrationTestPage', |
| 174 |
], |
| 175 |
$item |
| 176 |
); |
| 177 |
} |
| 178 |
|
| 179 |
public function testIdsPropParameter() { |
| 180 |
$target = new TitleValue( NS_MAIN, 'ApiQueryRecentChangesIntegrationTestPage' ); |
| 181 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' ); |
| 182 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'ids' ] ); |
| 183 |
$items = $this->getItemsFromRecentChangesResult( $result ); |
| 184 |
|
| 185 |
$this->assertCount( 1, $items ); |
| 186 |
$item = $items[0]; |
| 187 |
foreach ( [ |
| 188 |
'pageid', |
| 189 |
'revid', |
| 190 |
'old_revid', |
| 191 |
'rcid', |
| 192 |
] as $key ) { |
| 193 |
|
| 194 |
$this->assertArrayHasKey( $key, $item ); |
| 195 |
unset( $item[ $key ] ); |
| 196 |
} |
| 197 |
|
| 198 |
$this->assertEquals( |
| 199 |
[ |
| 200 |
'type' => 'new', |
| 201 |
], |
| 202 |
$item |
| 203 |
); |
| 204 |
} |
| 205 |
|
| 206 |
public function testTitlePropParameter() { |
| 207 |
$this->doPageEdits( |
| 208 |
$this->getLoggedInTestUser(), |
| 209 |
[ |
| 210 |
[ |
| 211 |
'target' => new TitleValue( NS_MAIN, 'Thing' ), |
| 212 |
'summary' => 'Create the page', |
| 213 |
], |
| 214 |
[ |
| 215 |
'target' => new TitleValue( NS_TALK, 'Thing' ), |
| 216 |
'summary' => 'Create Talk page', |
| 217 |
], |
| 218 |
] |
| 219 |
); |
| 220 |
|
| 221 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] ); |
| 222 |
|
| 223 |
$this->assertEquals( |
| 224 |
[ |
| 225 |
[ |
| 226 |
'type' => 'new', |
| 227 |
'ns' => NS_TALK, |
| 228 |
'title' => 'Talk:Thing', |
| 229 |
], |
| 230 |
[ |
| 231 |
'type' => 'new', |
| 232 |
'ns' => NS_MAIN, |
| 233 |
'title' => 'Thing', |
| 234 |
], |
| 235 |
], |
| 236 |
$this->getItemsFromRecentChangesResult( $result ) |
| 237 |
); |
| 238 |
} |
| 239 |
|
| 240 |
public function testFlagsPropParameter() { |
| 241 |
$this->doPageEdits( |
| 242 |
$this->getLoggedInTestUser(), |
| 243 |
[ |
| 244 |
[ |
| 245 |
'summary' => 'Create the page', |
| 246 |
'target' => new TitleValue( NS_MAIN, 'Regularpage' ), |
| 247 |
], |
| 248 |
[ |
| 249 |
'summary' => 'Create the page for minor change', |
| 250 |
'target' => new TitleValue( NS_MAIN, 'Minorpage' ), |
| 251 |
], |
| 252 |
[ |
| 253 |
'summary' => 'Make minor content', |
| 254 |
'target' => new TitleValue( NS_MAIN, 'Minorpage' ), |
| 255 |
'minorEdit' => true, |
| 256 |
], |
| 257 |
[ |
| 258 |
'summary' => 'Create the page as a bot', |
| 259 |
'target' => new TitleValue( NS_MAIN, 'Botpage' ), |
| 260 |
'botEdit' => true, |
| 261 |
], |
| 262 |
] |
| 263 |
); |
| 264 |
|
| 265 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'flags' ] ); |
| 266 |
|
| 267 |
$this->assertEquals( |
| 268 |
[ |
| 269 |
[ |
| 270 |
'type' => 'new', |
| 271 |
'new' => true, |
| 272 |
'minor' => false, |
| 273 |
'bot' => true, |
| 274 |
], |
| 275 |
[ |
| 276 |
'type' => 'edit', |
| 277 |
'new' => false, |
| 278 |
'minor' => true, |
| 279 |
'bot' => false, |
| 280 |
], |
| 281 |
[ |
| 282 |
'type' => 'new', |
| 283 |
'new' => true, |
| 284 |
'minor' => false, |
| 285 |
'bot' => false, |
| 286 |
], |
| 287 |
[ |
| 288 |
'type' => 'new', |
| 289 |
'new' => true, |
| 290 |
'minor' => false, |
| 291 |
'bot' => false, |
| 292 |
], |
| 293 |
], |
| 294 |
$this->getItemsFromRecentChangesResult( $result ) |
| 295 |
); |
| 296 |
} |
| 297 |
|
| 298 |
public function testUserPropParameter() { |
| 299 |
$userEditTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 300 |
$anonEditTarget = new TitleValue( NS_MAIN, 'Bar' ); |
| 301 |
$tempEditTarget = new TitleValue( NS_MAIN, 'Baz' ); |
| 302 |
$this->doPageEdit( $this->getLoggedInTestUser(), $userEditTarget, 'Create the page' ); |
| 303 |
$this->doAnonPageEdit( $anonEditTarget, 'Create the page' ); |
| 304 |
|
| 305 |
|
| 306 |
$this->disableAutoCreateTempUser(); |
| 307 |
$result = $this->doListRecentChangesRequest( [ |
| 308 |
'rcprop' => 'user', |
| 309 |
'rcshow' => WatchedItemQueryService::FILTER_NOT_ANON, |
| 310 |
] ); |
| 311 |
$this->assertEquals( |
| 312 |
[ |
| 313 |
[ |
| 314 |
'type' => 'new', |
| 315 |
'user' => $this->getLoggedInTestUser()->getName(), |
| 316 |
], |
| 317 |
], |
| 318 |
$this->getItemsFromRecentChangesResult( $result ) |
| 319 |
); |
| 320 |
|
| 321 |
|
| 322 |
$this->doTempPageEdit( $tempEditTarget, 'Create the page' ); |
| 323 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'user' ] ); |
| 324 |
$this->assertEquals( |
| 325 |
[ |
| 326 |
[ |
| 327 |
'type' => 'new', |
| 328 |
'temp' => true, |
| 329 |
'user' => '~2024-1', |
| 330 |
], |
| 331 |
[ |
| 332 |
'type' => 'new', |
| 333 |
'anon' => true, |
| 334 |
'user' => '127.0.0.1', |
| 335 |
], |
| 336 |
[ |
| 337 |
'type' => 'new', |
| 338 |
'user' => $this->getLoggedInTestUser()->getName(), |
| 339 |
], |
| 340 |
], |
| 341 |
$this->getItemsFromRecentChangesResult( $result ) |
| 342 |
); |
| 343 |
} |
| 344 |
|
| 345 |
public function testUserIdPropParameter() { |
| 346 |
$user = $this->getLoggedInTestUser(); |
| 347 |
$userEditTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 348 |
$anonEditTarget = new TitleValue( NS_MAIN, 'Bar' ); |
| 349 |
$this->doPageEdit( $user, $userEditTarget, 'Create the page' ); |
| 350 |
$this->doAnonPageEdit( $anonEditTarget, 'Create the page' ); |
| 351 |
|
| 352 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'userid' ] ); |
| 353 |
|
| 354 |
$this->assertEquals( |
| 355 |
[ |
| 356 |
[ |
| 357 |
'type' => 'new', |
| 358 |
'anon' => true, |
| 359 |
'userid' => 0, |
| 360 |
], |
| 361 |
[ |
| 362 |
'type' => 'new', |
| 363 |
'userid' => $user->getId(), |
| 364 |
], |
| 365 |
], |
| 366 |
$this->getItemsFromRecentChangesResult( $result ) |
| 367 |
); |
| 368 |
} |
| 369 |
|
| 370 |
public function testCommentPropParameter() { |
| 371 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 372 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the <b>page</b>' ); |
| 373 |
|
| 374 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'comment' ] ); |
| 375 |
|
| 376 |
$this->assertEquals( |
| 377 |
[ |
| 378 |
[ |
| 379 |
'type' => 'new', |
| 380 |
'comment' => 'Create the <b>page</b>', |
| 381 |
], |
| 382 |
], |
| 383 |
$this->getItemsFromRecentChangesResult( $result ) |
| 384 |
); |
| 385 |
} |
| 386 |
|
| 387 |
public function testParsedCommentPropParameter() { |
| 388 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 389 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the <b>page</b>' ); |
| 390 |
|
| 391 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'parsedcomment' ] ); |
| 392 |
|
| 393 |
$this->assertEquals( |
| 394 |
[ |
| 395 |
[ |
| 396 |
'type' => 'new', |
| 397 |
'parsedcomment' => 'Create the <b>page</b>', |
| 398 |
], |
| 399 |
], |
| 400 |
$this->getItemsFromRecentChangesResult( $result ) |
| 401 |
); |
| 402 |
} |
| 403 |
|
| 404 |
public function testTimestampPropParameter() { |
| 405 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 406 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' ); |
| 407 |
|
| 408 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'timestamp' ] ); |
| 409 |
$items = $this->getItemsFromRecentChangesResult( $result ); |
| 410 |
|
| 411 |
$this->assertCount( 1, $items ); |
| 412 |
$this->assertIsString( $items[0]['timestamp'] ); |
| 413 |
} |
| 414 |
|
| 415 |
public function testSizesPropParameter() { |
| 416 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 417 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' ); |
| 418 |
|
| 419 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'sizes' ] ); |
| 420 |
|
| 421 |
$this->assertEquals( |
| 422 |
[ |
| 423 |
[ |
| 424 |
'type' => 'new', |
| 425 |
'oldlen' => 0, |
| 426 |
|
| 427 |
'newlen' => 64, |
| 428 |
], |
| 429 |
], |
| 430 |
$this->getItemsFromRecentChangesResult( $result ) |
| 431 |
); |
| 432 |
} |
| 433 |
|
| 434 |
private function createPageAndDeleteIt( LinkTarget $target ) { |
| 435 |
$wikiPage = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target ); |
| 436 |
$this->doPageEdit( $this->getLoggedInTestUser(), |
| 437 |
$wikiPage, |
| 438 |
'Create the page that will be deleted' |
| 439 |
); |
| 440 |
$this->deletePage( $wikiPage, 'Important Reason' ); |
| 441 |
} |
| 442 |
|
| 443 |
public function testLoginfoPropParameter() { |
| 444 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 445 |
$this->createPageAndDeleteIt( $target ); |
| 446 |
|
| 447 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'loginfo' ] ); |
| 448 |
$items = $this->getItemsFromRecentChangesResult( $result ); |
| 449 |
|
| 450 |
$this->assertCount( 1, $items ); |
| 451 |
foreach ( [ |
| 452 |
'logid', |
| 453 |
] as $key ) { |
| 454 |
|
| 455 |
$this->assertArrayHasKey( $key, $items[0] ); |
| 456 |
unset( $items[0][ $key ] ); |
| 457 |
} |
| 458 |
$this->assertEquals( |
| 459 |
[ |
| 460 |
'type' => 'log', |
| 461 |
'logtype' => 'delete', |
| 462 |
'logaction' => 'delete', |
| 463 |
'logparams' => [], |
| 464 |
], |
| 465 |
$items[0] |
| 466 |
); |
| 467 |
} |
| 468 |
|
| 469 |
public function testEmptyPropParameter() { |
| 470 |
$user = $this->getLoggedInTestUser(); |
| 471 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 472 |
$this->doPageEdit( $user, $target, 'Create the page' ); |
| 473 |
|
| 474 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => '' ] ); |
| 475 |
|
| 476 |
$this->assertEquals( |
| 477 |
[ |
| 478 |
[ |
| 479 |
'type' => 'new', |
| 480 |
] |
| 481 |
], |
| 482 |
$this->getItemsFromRecentChangesResult( $result ) |
| 483 |
); |
| 484 |
} |
| 485 |
|
| 486 |
public function testNamespaceParam() { |
| 487 |
$subjectTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 488 |
$talkTarget = new TitleValue( NS_TALK, 'Foo' ); |
| 489 |
$this->doPageEdits( |
| 490 |
$this->getLoggedInTestUser(), |
| 491 |
[ |
| 492 |
[ |
| 493 |
'target' => $subjectTarget, |
| 494 |
'summary' => 'Create the page', |
| 495 |
], |
| 496 |
[ |
| 497 |
'target' => $talkTarget, |
| 498 |
'summary' => 'Create the talk page', |
| 499 |
], |
| 500 |
] |
| 501 |
); |
| 502 |
|
| 503 |
$result = $this->doListRecentChangesRequest( [ 'rcnamespace' => '0', 'rcprop' => 'title' ] ); |
| 504 |
$items = $this->getItemsFromRecentChangesResult( $result ); |
| 505 |
|
| 506 |
$this->assertCount( 1, $items ); |
| 507 |
$this->assertEquals( |
| 508 |
[ |
| 509 |
'type' => 'new', |
| 510 |
'ns' => NS_MAIN, |
| 511 |
'title' => 'Foo', |
| 512 |
], |
| 513 |
$items[0] |
| 514 |
); |
| 515 |
} |
| 516 |
|
| 517 |
public function testShowAnonParams() { |
| 518 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 519 |
$this->doAnonPageEdit( $target, 'Create the page' ); |
| 520 |
|
| 521 |
$tempEditTarget = new TitleValue( NS_MAIN, 'Baz' ); |
| 522 |
$this->doTempPageEdit( $tempEditTarget, 'Create the page' ); |
| 523 |
|
| 524 |
$resultAnon = $this->doListRecentChangesRequest( [ |
| 525 |
'rcprop' => 'user', |
| 526 |
'rcshow' => WatchedItemQueryService::FILTER_ANON |
| 527 |
] ); |
| 528 |
$resultNotAnon = $this->doListRecentChangesRequest( [ |
| 529 |
'rcprop' => 'user', |
| 530 |
'rcshow' => WatchedItemQueryService::FILTER_NOT_ANON |
| 531 |
] ); |
| 532 |
|
| 533 |
$items = $this->getItemsFromRecentChangesResult( $resultAnon ); |
| 534 |
$this->assertCount( 2, $items ); |
| 535 |
$this->assertEquals( |
| 536 |
[ |
| 537 |
[ |
| 538 |
'type' => 'new', |
| 539 |
'temp' => true, |
| 540 |
'user' => '~2024-1', |
| 541 |
], |
| 542 |
[ |
| 543 |
'type' => 'new', |
| 544 |
'anon' => true, |
| 545 |
'user' => '127.0.0.1', |
| 546 |
], |
| 547 |
], |
| 548 |
$items |
| 549 |
); |
| 550 |
$this->assertSame( [], $this->getItemsFromRecentChangesResult( $resultNotAnon ) ); |
| 551 |
} |
| 552 |
|
| 553 |
public function testNewAndEditTypeParameters() { |
| 554 |
$subjectTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 555 |
$talkTarget = new TitleValue( NS_TALK, 'Foo' ); |
| 556 |
$this->doPageEdits( |
| 557 |
$this->getLoggedInTestUser(), |
| 558 |
[ |
| 559 |
[ |
| 560 |
'target' => $subjectTarget, |
| 561 |
'summary' => 'Create the page', |
| 562 |
], |
| 563 |
[ |
| 564 |
'target' => $subjectTarget, |
| 565 |
'summary' => 'Change the content', |
| 566 |
], |
| 567 |
[ |
| 568 |
'target' => $talkTarget, |
| 569 |
'summary' => 'Create Talk page', |
| 570 |
], |
| 571 |
] |
| 572 |
); |
| 573 |
|
| 574 |
$resultNew = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'new' ] ); |
| 575 |
$resultEdit = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'edit' ] ); |
| 576 |
|
| 577 |
$this->assertEquals( |
| 578 |
[ |
| 579 |
[ |
| 580 |
'type' => 'new', |
| 581 |
'ns' => NS_TALK, |
| 582 |
'title' => 'Talk:Foo', |
| 583 |
], |
| 584 |
[ |
| 585 |
'type' => 'new', |
| 586 |
'ns' => NS_MAIN, |
| 587 |
'title' => 'Foo', |
| 588 |
], |
| 589 |
], |
| 590 |
$this->getItemsFromRecentChangesResult( $resultNew ) |
| 591 |
); |
| 592 |
$this->assertEquals( |
| 593 |
[ |
| 594 |
[ |
| 595 |
'type' => 'edit', |
| 596 |
'ns' => NS_MAIN, |
| 597 |
'title' => 'Foo', |
| 598 |
], |
| 599 |
], |
| 600 |
$this->getItemsFromRecentChangesResult( $resultEdit ) |
| 601 |
); |
| 602 |
} |
| 603 |
|
| 604 |
public function testLogTypeParameters() { |
| 605 |
$subjectTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 606 |
$talkTarget = new TitleValue( NS_TALK, 'Foo' ); |
| 607 |
$this->createPageAndDeleteIt( $subjectTarget ); |
| 608 |
$this->doPageEdit( $this->getLoggedInTestUser(), $talkTarget, 'Create Talk page' ); |
| 609 |
|
| 610 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'log' ] ); |
| 611 |
|
| 612 |
$this->assertEquals( |
| 613 |
[ |
| 614 |
[ |
| 615 |
'type' => 'log', |
| 616 |
'ns' => NS_MAIN, |
| 617 |
'title' => 'Foo', |
| 618 |
], |
| 619 |
], |
| 620 |
$this->getItemsFromRecentChangesResult( $result ) |
| 621 |
); |
| 622 |
} |
| 623 |
|
| 624 |
private function getExternalRC( LinkTarget $target ) { |
| 625 |
$title = $this->getServiceContainer()->getTitleFactory()->newFromLinkTarget( $target ); |
| 626 |
|
| 627 |
$rc = new RecentChange; |
| 628 |
$rc->mAttribs = [ |
| 629 |
'rc_timestamp' => wfTimestamp( TS_MW ), |
| 630 |
'rc_namespace' => $title->getNamespace(), |
| 631 |
'rc_title' => $title->getDBkey(), |
| 632 |
'rc_type' => RC_EXTERNAL, |
| 633 |
'rc_source' => 'foo', |
| 634 |
'rc_minor' => 0, |
| 635 |
'rc_cur_id' => $title->getArticleID(), |
| 636 |
'rc_user' => 0, |
| 637 |
'rc_user_text' => 'm>External User', |
| 638 |
'rc_comment' => '', |
| 639 |
'rc_comment_text' => '', |
| 640 |
'rc_comment_data' => null, |
| 641 |
'rc_this_oldid' => $title->getLatestRevID(), |
| 642 |
'rc_last_oldid' => $title->getLatestRevID(), |
| 643 |
'rc_bot' => 0, |
| 644 |
'rc_ip' => '', |
| 645 |
'rc_patrolled' => 0, |
| 646 |
'rc_new' => 0, |
| 647 |
'rc_old_len' => $title->getLength(), |
| 648 |
'rc_new_len' => $title->getLength(), |
| 649 |
'rc_deleted' => 0, |
| 650 |
'rc_logid' => 0, |
| 651 |
'rc_log_type' => null, |
| 652 |
'rc_log_action' => '', |
| 653 |
'rc_params' => '', |
| 654 |
]; |
| 655 |
$rc->mExtra = [ |
| 656 |
'prefixedDBkey' => $title->getPrefixedDBkey(), |
| 657 |
'lastTimestamp' => 0, |
| 658 |
'oldSize' => $title->getLength(), |
| 659 |
'newSize' => $title->getLength(), |
| 660 |
'pageStatus' => 'changed' |
| 661 |
]; |
| 662 |
|
| 663 |
return $rc; |
| 664 |
} |
| 665 |
|
| 666 |
public function testExternalTypeParameters() { |
| 667 |
$user = $this->getLoggedInTestUser(); |
| 668 |
$subjectTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 669 |
$talkTarget = new TitleValue( NS_TALK, 'Foo' ); |
| 670 |
$this->doPageEdit( $user, $subjectTarget, 'Create the page' ); |
| 671 |
$this->doPageEdit( $user, $talkTarget, 'Create Talk page' ); |
| 672 |
$rc = $this->getExternalRC( $subjectTarget ); |
| 673 |
$rc->save(); |
| 674 |
|
| 675 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'external' ] ); |
| 676 |
|
| 677 |
$this->assertEquals( |
| 678 |
[ |
| 679 |
[ |
| 680 |
'type' => 'external', |
| 681 |
'ns' => NS_MAIN, |
| 682 |
'title' => 'Foo', |
| 683 |
], |
| 684 |
], |
| 685 |
$this->getItemsFromRecentChangesResult( $result ) |
| 686 |
); |
| 687 |
} |
| 688 |
|
| 689 |
public function testCategorizeTypeParameter() { |
| 690 |
$user = $this->getLoggedInTestUser(); |
| 691 |
$subjectTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 692 |
$categoryTarget = new TitleValue( NS_CATEGORY, 'Bar' ); |
| 693 |
$this->doPageEdits( |
| 694 |
$user, |
| 695 |
[ |
| 696 |
[ |
| 697 |
'target' => $categoryTarget, |
| 698 |
'summary' => 'Create the category', |
| 699 |
], |
| 700 |
[ |
| 701 |
'target' => $subjectTarget, |
| 702 |
'summary' => 'Create the page and add it to the category', |
| 703 |
], |
| 704 |
] |
| 705 |
); |
| 706 |
$titleFactory = $this->getServiceContainer()->getTitleFactory(); |
| 707 |
$title = $titleFactory->newFromLinkTarget( $subjectTarget ); |
| 708 |
$revision = $this->getServiceContainer() |
| 709 |
->getRevisionLookup() |
| 710 |
->getRevisionByTitle( $title ); |
| 711 |
|
| 712 |
$comment = $revision->getComment(); |
| 713 |
$rc = RecentChange::newForCategorization( |
| 714 |
$revision->getTimestamp(), |
| 715 |
$titleFactory->newFromLinkTarget( $categoryTarget ), |
| 716 |
$user, |
| 717 |
$comment ? $comment->text : '', |
| 718 |
$title, |
| 719 |
0, |
| 720 |
$revision->getId(), |
| 721 |
null, |
| 722 |
false |
| 723 |
); |
| 724 |
$rc->save(); |
| 725 |
|
| 726 |
$result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'categorize' ] ); |
| 727 |
|
| 728 |
$this->assertEquals( |
| 729 |
[ |
| 730 |
[ |
| 731 |
'type' => 'categorize', |
| 732 |
'ns' => NS_CATEGORY, |
| 733 |
'title' => 'Category:Bar', |
| 734 |
], |
| 735 |
], |
| 736 |
$this->getItemsFromRecentChangesResult( $result ) |
| 737 |
); |
| 738 |
} |
| 739 |
|
| 740 |
public function testLimitParam() { |
| 741 |
$this->doPageEdits( |
| 742 |
$this->getLoggedInTestUser(), |
| 743 |
[ |
| 744 |
[ |
| 745 |
'target' => new TitleValue( NS_MAIN, 'Foo' ), |
| 746 |
'summary' => 'Create the page', |
| 747 |
], |
| 748 |
[ |
| 749 |
'target' => new TitleValue( NS_TALK, 'Foo' ), |
| 750 |
'summary' => 'Create Talk page', |
| 751 |
], |
| 752 |
[ |
| 753 |
'target' => new TitleValue( NS_MAIN, 'Bar' ), |
| 754 |
'summary' => 'Create another page', |
| 755 |
], |
| 756 |
] |
| 757 |
); |
| 758 |
|
| 759 |
$resultWithoutLimit = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] ); |
| 760 |
$resultWithLimit = $this->doListRecentChangesRequest( [ 'rclimit' => 2, 'rcprop' => 'title' ] ); |
| 761 |
|
| 762 |
$this->assertEquals( |
| 763 |
[ |
| 764 |
[ |
| 765 |
'type' => 'new', |
| 766 |
'ns' => NS_MAIN, |
| 767 |
'title' => 'Bar' |
| 768 |
], |
| 769 |
[ |
| 770 |
'type' => 'new', |
| 771 |
'ns' => NS_TALK, |
| 772 |
'title' => 'Talk:Foo' |
| 773 |
], |
| 774 |
[ |
| 775 |
'type' => 'new', |
| 776 |
'ns' => NS_MAIN, |
| 777 |
'title' => 'Foo' |
| 778 |
], |
| 779 |
], |
| 780 |
$this->getItemsFromRecentChangesResult( $resultWithoutLimit ) |
| 781 |
); |
| 782 |
$this->assertEquals( |
| 783 |
[ |
| 784 |
[ |
| 785 |
'type' => 'new', |
| 786 |
'ns' => NS_MAIN, |
| 787 |
'title' => 'Bar' |
| 788 |
], |
| 789 |
[ |
| 790 |
'type' => 'new', |
| 791 |
'ns' => NS_TALK, |
| 792 |
'title' => 'Talk:Foo' |
| 793 |
], |
| 794 |
], |
| 795 |
$this->getItemsFromRecentChangesResult( $resultWithLimit ) |
| 796 |
); |
| 797 |
$this->assertArrayHasKey( 'rccontinue', $resultWithLimit[0]['continue'] ); |
| 798 |
} |
| 799 |
|
| 800 |
public function testAllRevParam() { |
| 801 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 802 |
$this->doPageEdits( |
| 803 |
$this->getLoggedInTestUser(), |
| 804 |
[ |
| 805 |
[ |
| 806 |
'target' => $target, |
| 807 |
'summary' => 'Create the page', |
| 808 |
], |
| 809 |
[ |
| 810 |
'target' => $target, |
| 811 |
'summary' => 'Change the content', |
| 812 |
], |
| 813 |
] |
| 814 |
); |
| 815 |
|
| 816 |
$resultAllRev = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rcallrev' => '' ] ); |
| 817 |
$resultNoAllRev = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] ); |
| 818 |
|
| 819 |
$this->assertEquals( |
| 820 |
[ |
| 821 |
[ |
| 822 |
'type' => 'edit', |
| 823 |
'ns' => NS_MAIN, |
| 824 |
'title' => 'Thing', |
| 825 |
], |
| 826 |
[ |
| 827 |
'type' => 'new', |
| 828 |
'ns' => NS_MAIN, |
| 829 |
'title' => 'Thing', |
| 830 |
], |
| 831 |
], |
| 832 |
$this->getItemsFromRecentChangesResult( $resultNoAllRev ) |
| 833 |
); |
| 834 |
$this->assertEquals( |
| 835 |
[ |
| 836 |
[ |
| 837 |
'type' => 'edit', |
| 838 |
'ns' => NS_MAIN, |
| 839 |
'title' => 'Thing', |
| 840 |
], |
| 841 |
[ |
| 842 |
'type' => 'new', |
| 843 |
'ns' => NS_MAIN, |
| 844 |
'title' => 'Thing', |
| 845 |
], |
| 846 |
], |
| 847 |
$this->getItemsFromRecentChangesResult( $resultAllRev ) |
| 848 |
); |
| 849 |
} |
| 850 |
|
| 851 |
public function testDirParams() { |
| 852 |
$subjectTarget = new TitleValue( NS_MAIN, 'Foo' ); |
| 853 |
$talkTarget = new TitleValue( NS_TALK, 'Foo' ); |
| 854 |
$this->doPageEdits( |
| 855 |
$this->getLoggedInTestUser(), |
| 856 |
[ |
| 857 |
[ |
| 858 |
'target' => $subjectTarget, |
| 859 |
'summary' => 'Create the page', |
| 860 |
], |
| 861 |
[ |
| 862 |
'target' => $talkTarget, |
| 863 |
'summary' => 'Create Talk page', |
| 864 |
], |
| 865 |
] |
| 866 |
); |
| 867 |
|
| 868 |
$resultDirOlder = $this->doListRecentChangesRequest( |
| 869 |
[ 'rcdir' => 'older', 'rcprop' => 'title' ] |
| 870 |
); |
| 871 |
$resultDirNewer = $this->doListRecentChangesRequest( |
| 872 |
[ 'rcdir' => 'newer', 'rcprop' => 'title' ] |
| 873 |
); |
| 874 |
|
| 875 |
$this->assertEquals( |
| 876 |
[ |
| 877 |
[ |
| 878 |
'type' => 'new', |
| 879 |
'ns' => NS_TALK, |
| 880 |
'title' => 'Talk:Foo' |
| 881 |
], |
| 882 |
[ |
| 883 |
'type' => 'new', |
| 884 |
'ns' => NS_MAIN, |
| 885 |
'title' => 'Foo' |
| 886 |
], |
| 887 |
], |
| 888 |
$this->getItemsFromRecentChangesResult( $resultDirOlder ) |
| 889 |
); |
| 890 |
$this->assertEquals( |
| 891 |
[ |
| 892 |
[ |
| 893 |
'type' => 'new', |
| 894 |
'ns' => NS_MAIN, |
| 895 |
'title' => 'Foo' |
| 896 |
], |
| 897 |
[ |
| 898 |
'type' => 'new', |
| 899 |
'ns' => NS_TALK, |
| 900 |
'title' => 'Talk:Foo' |
| 901 |
], |
| 902 |
], |
| 903 |
$this->getItemsFromRecentChangesResult( $resultDirNewer ) |
| 904 |
); |
| 905 |
} |
| 906 |
|
| 907 |
public function testTitleParams() { |
| 908 |
$this->doPageEdits( |
| 909 |
$this->getLoggedInTestUser(), |
| 910 |
[ |
| 911 |
[ |
| 912 |
'target' => new TitleValue( NS_MAIN, 'Foo' ), |
| 913 |
'summary' => 'Create the page', |
| 914 |
], |
| 915 |
[ |
| 916 |
'target' => new TitleValue( NS_TALK, 'Bar' ), |
| 917 |
'summary' => 'Create the page', |
| 918 |
], |
| 919 |
[ |
| 920 |
'target' => new TitleValue( NS_MAIN, 'Quux' ), |
| 921 |
'summary' => 'Create the page', |
| 922 |
], |
| 923 |
] |
| 924 |
); |
| 925 |
|
| 926 |
$result1 = $this->doListRecentChangesRequest( |
| 927 |
[ |
| 928 |
'rctitle' => 'Foo', |
| 929 |
'rcprop' => 'title' |
| 930 |
] |
| 931 |
); |
| 932 |
$result2 = $this->doListRecentChangesRequest( |
| 933 |
[ |
| 934 |
'rctitle' => 'Talk:Bar', |
| 935 |
'rcprop' => 'title' |
| 936 |
] |
| 937 |
); |
| 938 |
|
| 939 |
$this->assertEquals( |
| 940 |
[ |
| 941 |
[ |
| 942 |
'type' => 'new', |
| 943 |
'ns' => NS_MAIN, |
| 944 |
'title' => 'Foo' |
| 945 |
], |
| 946 |
], |
| 947 |
$this->getItemsFromRecentChangesResult( $result1 ) |
| 948 |
); |
| 949 |
$this->assertEquals( |
| 950 |
[ |
| 951 |
[ |
| 952 |
'type' => 'new', |
| 953 |
'ns' => NS_TALK, |
| 954 |
'title' => 'Talk:Bar' |
| 955 |
], |
| 956 |
], |
| 957 |
$this->getItemsFromRecentChangesResult( $result2 ) |
| 958 |
); |
| 959 |
} |
| 960 |
|
| 961 |
public function testStartEndParams() { |
| 962 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 963 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' ); |
| 964 |
|
| 965 |
$resultStart = $this->doListRecentChangesRequest( [ |
| 966 |
'rcstart' => '20010115000000', |
| 967 |
'rcdir' => 'newer', |
| 968 |
'rcprop' => 'title', |
| 969 |
] ); |
| 970 |
$resultEnd = $this->doListRecentChangesRequest( [ |
| 971 |
'rcend' => '20010115000000', |
| 972 |
'rcdir' => 'newer', |
| 973 |
'rcprop' => 'title', |
| 974 |
] ); |
| 975 |
|
| 976 |
$this->assertEquals( |
| 977 |
[ |
| 978 |
[ |
| 979 |
'type' => 'new', |
| 980 |
'ns' => NS_MAIN, |
| 981 |
'title' => 'Thing', |
| 982 |
] |
| 983 |
], |
| 984 |
$this->getItemsFromRecentChangesResult( $resultStart ) |
| 985 |
); |
| 986 |
$this->assertSame( [], $this->getItemsFromRecentChangesResult( $resultEnd ) ); |
| 987 |
} |
| 988 |
|
| 989 |
public function testContinueParam() { |
| 990 |
$this->doPageEdits( |
| 991 |
$this->getLoggedInTestUser(), |
| 992 |
[ |
| 993 |
[ |
| 994 |
'target' => new TitleValue( NS_MAIN, 'Foo' ), |
| 995 |
'summary' => 'Create the page', |
| 996 |
], |
| 997 |
[ |
| 998 |
'target' => new TitleValue( NS_TALK, 'Foo' ), |
| 999 |
'summary' => 'Create Talk page', |
| 1000 |
], |
| 1001 |
[ |
| 1002 |
'target' => new TitleValue( NS_MAIN, 'Bar' ), |
| 1003 |
'summary' => 'Create the page', |
| 1004 |
], |
| 1005 |
] |
| 1006 |
); |
| 1007 |
|
| 1008 |
$firstResult = $this->doListRecentChangesRequest( [ 'rclimit' => 2, 'rcprop' => 'title' ] ); |
| 1009 |
|
| 1010 |
$continuationParam = $firstResult[0]['continue']['rccontinue']; |
| 1011 |
|
| 1012 |
$continuedResult = $this->doListRecentChangesRequest( |
| 1013 |
[ 'rccontinue' => $continuationParam, 'rcprop' => 'title' ] |
| 1014 |
); |
| 1015 |
|
| 1016 |
$this->assertEquals( |
| 1017 |
[ |
| 1018 |
[ |
| 1019 |
'type' => 'new', |
| 1020 |
'ns' => NS_MAIN, |
| 1021 |
'title' => 'Bar', |
| 1022 |
], |
| 1023 |
[ |
| 1024 |
'type' => 'new', |
| 1025 |
'ns' => NS_TALK, |
| 1026 |
'title' => 'Talk:Foo', |
| 1027 |
], |
| 1028 |
], |
| 1029 |
$this->getItemsFromRecentChangesResult( $firstResult ) |
| 1030 |
); |
| 1031 |
$this->assertEquals( |
| 1032 |
[ |
| 1033 |
[ |
| 1034 |
'type' => 'new', |
| 1035 |
'ns' => NS_MAIN, |
| 1036 |
'title' => 'Foo', |
| 1037 |
] |
| 1038 |
], |
| 1039 |
$this->getItemsFromRecentChangesResult( $continuedResult ) |
| 1040 |
); |
| 1041 |
} |
| 1042 |
|
| 1043 |
public function testGeneratorRecentChangesPropInfo_returnsRCPages() { |
| 1044 |
$target = new TitleValue( NS_MAIN, 'Thing' ); |
| 1045 |
$this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' ); |
| 1046 |
|
| 1047 |
$result = $this->doGeneratorRecentChangesRequest( [ 'prop' => 'info' ] ); |
| 1048 |
|
| 1049 |
|
| 1050 |
$pages = array_values( $result[0]['query']['pages'] ); |
| 1051 |
$this->assertCount( 1, $pages ); |
| 1052 |
|
| 1053 |
$page = $pages[0]; |
| 1054 |
foreach ( [ |
| 1055 |
'pageid', |
| 1056 |
'touched', |
| 1057 |
'lastrevid', |
| 1058 |
'length', |
| 1059 |
] as $key ) { |
| 1060 |
|
| 1061 |
$this->assertArrayHasKey( $key, $page ); |
| 1062 |
unset( $page[ $key ] ); |
| 1063 |
} |
| 1064 |
|
| 1065 |
$this->assertEquals( |
| 1066 |
[ |
| 1067 |
'ns' => NS_MAIN, |
| 1068 |
'title' => 'Thing', |
| 1069 |
'new' => true, |
| 1070 |
'contentmodel' => 'wikitext', |
| 1071 |
'pagelanguage' => 'en', |
| 1072 |
'pagelanguagehtmlcode' => 'en', |
| 1073 |
'pagelanguagedir' => 'ltr', |
| 1074 |
], |
| 1075 |
$page |
| 1076 |
); |
| 1077 |
} |
| 1078 |
|
| 1079 |
} |