| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Storage; |
| 22 |
|
| 23 |
use CategoryMembershipChangeJob; |
| 24 |
use InvalidArgumentException; |
| 25 |
use JobQueueGroup; |
| 26 |
use LogicException; |
| 27 |
use MediaWiki\Config\ServiceOptions; |
| 28 |
use MediaWiki\Content\Content; |
| 29 |
use MediaWiki\Content\ContentHandler; |
| 30 |
use MediaWiki\Content\IContentHandlerFactory; |
| 31 |
use MediaWiki\Content\Transform\ContentTransformer; |
| 32 |
use MediaWiki\Deferred\DeferrableUpdate; |
| 33 |
use MediaWiki\Deferred\DeferredUpdates; |
| 34 |
use MediaWiki\Deferred\LinksUpdate\LinksUpdate; |
| 35 |
use MediaWiki\Deferred\RefreshSecondaryDataUpdate; |
| 36 |
use MediaWiki\Deferred\SearchUpdate; |
| 37 |
use MediaWiki\Deferred\SiteStatsUpdate; |
| 38 |
use MediaWiki\Edit\PreparedEdit; |
| 39 |
use MediaWiki\HookContainer\HookContainer; |
| 40 |
use MediaWiki\HookContainer\HookRunner; |
| 41 |
use MediaWiki\Language\Language; |
| 42 |
use MediaWiki\MainConfigNames; |
| 43 |
use MediaWiki\Page\PageIdentity; |
| 44 |
use MediaWiki\Page\ParserOutputAccess; |
| 45 |
use MediaWiki\Page\WikiPageFactory; |
| 46 |
use MediaWiki\Parser\ParserCache; |
| 47 |
use MediaWiki\Parser\ParserOptions; |
| 48 |
use MediaWiki\Parser\ParserOutput; |
| 49 |
use MediaWiki\Permissions\PermissionManager; |
| 50 |
use MediaWiki\ResourceLoader as RL; |
| 51 |
use MediaWiki\Revision\MutableRevisionRecord; |
| 52 |
use MediaWiki\Revision\RenderedRevision; |
| 53 |
use MediaWiki\Revision\RevisionRecord; |
| 54 |
use MediaWiki\Revision\RevisionRenderer; |
| 55 |
use MediaWiki\Revision\RevisionSlots; |
| 56 |
use MediaWiki\Revision\RevisionStore; |
| 57 |
use MediaWiki\Revision\SlotRecord; |
| 58 |
use MediaWiki\Revision\SlotRoleRegistry; |
| 59 |
use MediaWiki\Title\Title; |
| 60 |
use MediaWiki\User\TalkPageNotificationManager; |
| 61 |
use MediaWiki\User\User; |
| 62 |
use MediaWiki\User\UserIdentity; |
| 63 |
use MediaWiki\User\UserNameUtils; |
| 64 |
use MediaWiki\Utils\MWTimestamp; |
| 65 |
use MessageCache; |
| 66 |
use MWUnknownContentModelException; |
| 67 |
use ParsoidCachePrewarmJob; |
| 68 |
use Psr\Log\LoggerAwareInterface; |
| 69 |
use Psr\Log\LoggerInterface; |
| 70 |
use Psr\Log\NullLogger; |
| 71 |
use RevertedTagUpdateJob; |
| 72 |
use Wikimedia\Assert\Assert; |
| 73 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 74 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 75 |
use Wikimedia\Rdbms\ILBFactory; |
| 76 |
use WikiPage; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
class DerivedPageDataUpdater implements LoggerAwareInterface, PreparedUpdate { |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
private $user = null; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
private $wikiPage; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
private $parserCache; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
private $revisionStore; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
private $contLang; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
private $jobQueueGroup; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
private $messageCache; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
private $loadbalancerFactory; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
private $hookRunner; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
private $logger; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
private $articleCountMethod; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
private $rcWatchCategoryMembership = false; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
private $options = [ |
| 179 |
'changed' => true, |
| 180 |
|
| 181 |
|
| 182 |
'newrev' => false, |
| 183 |
'created' => false, |
| 184 |
'moved' => false, |
| 185 |
'oldtitle' => null, |
| 186 |
'restored' => false, |
| 187 |
'oldrevision' => null, |
| 188 |
'oldcountable' => null, |
| 189 |
'oldredirect' => null, |
| 190 |
'triggeringUser' => null, |
| 191 |
|
| 192 |
|
| 193 |
'causeAction' => null, |
| 194 |
'causeAgent' => null, |
| 195 |
'editResult' => null, |
| 196 |
'approved' => false |
| 197 |
]; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
private $pageState = null; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
private $slotsUpdate = null; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
private $parentRevision = null; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
private $revision = null; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
private $renderedRevision = null; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
private $revisionRenderer; |
| 244 |
|
| 245 |
|
| 246 |
private $slotRoleRegistry; |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
private $forceEmptyRevision = false; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
private $stage = 'new'; |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
private const TRANSITIONS = [ |
| 272 |
'new' => [ |
| 273 |
'new' => true, |
| 274 |
'knows-current' => true, |
| 275 |
'has-content' => true, |
| 276 |
'has-revision' => true, |
| 277 |
], |
| 278 |
'knows-current' => [ |
| 279 |
'knows-current' => true, |
| 280 |
'has-content' => true, |
| 281 |
'has-revision' => true, |
| 282 |
], |
| 283 |
'has-content' => [ |
| 284 |
'has-content' => true, |
| 285 |
'has-revision' => true, |
| 286 |
], |
| 287 |
'has-revision' => [ |
| 288 |
'has-revision' => true, |
| 289 |
'done' => true, |
| 290 |
], |
| 291 |
]; |
| 292 |
|
| 293 |
|
| 294 |
private $contentHandlerFactory; |
| 295 |
|
| 296 |
|
| 297 |
private $editResultCache; |
| 298 |
|
| 299 |
|
| 300 |
private $userNameUtils; |
| 301 |
|
| 302 |
|
| 303 |
private $contentTransformer; |
| 304 |
|
| 305 |
|
| 306 |
private $pageEditStash; |
| 307 |
|
| 308 |
|
| 309 |
private $talkPageNotificationManager; |
| 310 |
|
| 311 |
|
| 312 |
private $mainWANObjectCache; |
| 313 |
|
| 314 |
|
| 315 |
private $permissionManager; |
| 316 |
|
| 317 |
|
| 318 |
private $warmParsoidParserCache; |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
public function __construct( |
| 343 |
ServiceOptions $options, |
| 344 |
PageIdentity $page, |
| 345 |
RevisionStore $revisionStore, |
| 346 |
RevisionRenderer $revisionRenderer, |
| 347 |
SlotRoleRegistry $slotRoleRegistry, |
| 348 |
ParserCache $parserCache, |
| 349 |
JobQueueGroup $jobQueueGroup, |
| 350 |
MessageCache $messageCache, |
| 351 |
Language $contLang, |
| 352 |
ILBFactory $loadbalancerFactory, |
| 353 |
IContentHandlerFactory $contentHandlerFactory, |
| 354 |
HookContainer $hookContainer, |
| 355 |
EditResultCache $editResultCache, |
| 356 |
UserNameUtils $userNameUtils, |
| 357 |
ContentTransformer $contentTransformer, |
| 358 |
PageEditStash $pageEditStash, |
| 359 |
TalkPageNotificationManager $talkPageNotificationManager, |
| 360 |
WANObjectCache $mainWANObjectCache, |
| 361 |
PermissionManager $permissionManager, |
| 362 |
WikiPageFactory $wikiPageFactory |
| 363 |
) { |
| 364 |
|
| 365 |
$this->wikiPage = $wikiPageFactory->newFromTitle( $page ); |
| 366 |
|
| 367 |
$this->parserCache = $parserCache; |
| 368 |
$this->revisionStore = $revisionStore; |
| 369 |
$this->revisionRenderer = $revisionRenderer; |
| 370 |
$this->slotRoleRegistry = $slotRoleRegistry; |
| 371 |
$this->jobQueueGroup = $jobQueueGroup; |
| 372 |
$this->messageCache = $messageCache; |
| 373 |
$this->contLang = $contLang; |
| 374 |
|
| 375 |
|
| 376 |
$this->loadbalancerFactory = $loadbalancerFactory; |
| 377 |
$this->contentHandlerFactory = $contentHandlerFactory; |
| 378 |
$this->hookRunner = new HookRunner( $hookContainer ); |
| 379 |
$this->editResultCache = $editResultCache; |
| 380 |
$this->userNameUtils = $userNameUtils; |
| 381 |
$this->contentTransformer = $contentTransformer; |
| 382 |
$this->pageEditStash = $pageEditStash; |
| 383 |
$this->talkPageNotificationManager = $talkPageNotificationManager; |
| 384 |
$this->mainWANObjectCache = $mainWANObjectCache; |
| 385 |
$this->permissionManager = $permissionManager; |
| 386 |
|
| 387 |
$this->logger = new NullLogger(); |
| 388 |
$this->warmParsoidParserCache = $options |
| 389 |
->get( MainConfigNames::ParsoidCacheConfig )['WarmParsoidParserCache']; |
| 390 |
} |
| 391 |
|
| 392 |
public function setLogger( LoggerInterface $logger ) { |
| 393 |
$this->logger = $logger; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public function setCause( ?string $causeAction, ?string $causeAgent ) { |
| 406 |
if ( $causeAction ) { |
| 407 |
$this->options['causeAction'] = $causeAction; |
| 408 |
} |
| 409 |
|
| 410 |
if ( $causeAgent ) { |
| 411 |
$this->options['causeAgent'] = $causeAgent; |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
private function getCause(): array { |
| 419 |
return [ |
| 420 |
$this->options['causeAction'] ?? 'unknown', |
| 421 |
$this->options['causeAgent'] ?? 'unknown', |
| 422 |
]; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
private function doTransition( $newStage ) { |
| 434 |
$this->assertTransition( $newStage ); |
| 435 |
|
| 436 |
$oldStage = $this->stage; |
| 437 |
$this->stage = $newStage; |
| 438 |
|
| 439 |
return $oldStage; |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
private function assertTransition( $newStage ) { |
| 450 |
if ( empty( self::TRANSITIONS[$this->stage][$newStage] ) ) { |
| 451 |
throw new LogicException( "Cannot transition from {$this->stage} to $newStage" ); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
public function isReusableFor( |
| 467 |
?UserIdentity $user = null, |
| 468 |
?RevisionRecord $revision = null, |
| 469 |
?RevisionSlotsUpdate $slotsUpdate = null, |
| 470 |
$parentId = null |
| 471 |
) { |
| 472 |
if ( $revision |
| 473 |
&& $parentId |
| 474 |
&& $revision->getParentId() !== $parentId |
| 475 |
) { |
| 476 |
throw new InvalidArgumentException( '$parentId should match the parent of $revision' ); |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
if ( $user && $this->user && $user->getName() !== $this->user->getName() ) { |
| 483 |
return false; |
| 484 |
} |
| 485 |
|
| 486 |
if ( $revision && $this->revision && $this->revision->getId() |
| 487 |
&& $this->revision->getId() !== $revision->getId() |
| 488 |
) { |
| 489 |
return false; |
| 490 |
} |
| 491 |
|
| 492 |
if ( $this->pageState |
| 493 |
&& $revision |
| 494 |
&& $revision->getParentId() !== null |
| 495 |
&& $this->pageState['oldId'] !== $revision->getParentId() |
| 496 |
) { |
| 497 |
return false; |
| 498 |
} |
| 499 |
|
| 500 |
if ( $this->pageState |
| 501 |
&& $parentId !== null |
| 502 |
&& $this->pageState['oldId'] !== $parentId |
| 503 |
) { |
| 504 |
return false; |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
if ( $this->slotsUpdate |
| 509 |
&& $slotsUpdate |
| 510 |
&& !$this->slotsUpdate->hasSameUpdates( $slotsUpdate ) |
| 511 |
) { |
| 512 |
return false; |
| 513 |
} |
| 514 |
|
| 515 |
if ( $revision |
| 516 |
&& $this->revision |
| 517 |
&& !$this->revision->getSlots()->hasSameContent( $revision->getSlots() ) |
| 518 |
) { |
| 519 |
return false; |
| 520 |
} |
| 521 |
|
| 522 |
return true; |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
public function setForceEmptyRevision( bool $forceEmptyRevision ) { |
| 537 |
if ( $this->revision ) { |
| 538 |
throw new LogicException( 'prepareContent() or prepareUpdate() was already called.' ); |
| 539 |
} |
| 540 |
|
| 541 |
$this->forceEmptyRevision = $forceEmptyRevision; |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
public function setArticleCountMethod( $articleCountMethod ) { |
| 549 |
$this->articleCountMethod = $articleCountMethod; |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
public function setRcWatchCategoryMembership( $rcWatchCategoryMembership ) { |
| 557 |
$this->rcWatchCategoryMembership = $rcWatchCategoryMembership; |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
private function getTitle() { |
| 564 |
|
| 565 |
return $this->wikiPage->getTitle(); |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
private function getWikiPage() { |
| 572 |
|
| 573 |
return $this->wikiPage; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
public function getPage(): PageIdentity { |
| 582 |
return $this->wikiPage; |
| 583 |
} |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
public function pageExisted() { |
| 593 |
$this->assertHasPageState( __METHOD__ ); |
| 594 |
|
| 595 |
return $this->pageState['oldId'] > 0; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
private function getParentRevision() { |
| 608 |
$this->assertPrepared( __METHOD__ ); |
| 609 |
|
| 610 |
if ( $this->parentRevision ) { |
| 611 |
return $this->parentRevision; |
| 612 |
} |
| 613 |
|
| 614 |
if ( !$this->pageState['oldId'] ) { |
| 615 |
|
| 616 |
|
| 617 |
return null; |
| 618 |
} |
| 619 |
|
| 620 |
$oldId = $this->revision->getParentId(); |
| 621 |
$flags = $this->usePrimary() ? IDBAccessObject::READ_LATEST : 0; |
| 622 |
$this->parentRevision = $oldId |
| 623 |
? $this->revisionStore->getRevisionById( $oldId, $flags ) |
| 624 |
: null; |
| 625 |
|
| 626 |
return $this->parentRevision; |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public function grabCurrentRevision() { |
| 650 |
if ( $this->pageState ) { |
| 651 |
return $this->pageState['oldRevision']; |
| 652 |
} |
| 653 |
|
| 654 |
$this->assertTransition( 'knows-current' ); |
| 655 |
|
| 656 |
|
| 657 |
$wikiPage = $this->getWikiPage(); |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
$wikiPage->loadPageData( IDBAccessObject::READ_LATEST ); |
| 662 |
$current = $wikiPage->getRevisionRecord(); |
| 663 |
|
| 664 |
$this->pageState = [ |
| 665 |
'oldRevision' => $current, |
| 666 |
'oldId' => $current ? $current->getId() : 0, |
| 667 |
'oldIsRedirect' => $wikiPage->isRedirect(), |
| 668 |
'oldCountable' => $wikiPage->isCountable(), |
| 669 |
]; |
| 670 |
|
| 671 |
$this->doTransition( 'knows-current' ); |
| 672 |
|
| 673 |
return $this->pageState['oldRevision']; |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
public function isContentPrepared() { |
| 682 |
return $this->revision !== null; |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
public function isUpdatePrepared() { |
| 693 |
return $this->revision !== null && $this->revision->getId() !== null; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
private function getPageId() { |
| 700 |
|
| 701 |
return $this->wikiPage->getId(); |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
public function isContentDeleted() { |
| 710 |
if ( $this->revision ) { |
| 711 |
return $this->revision->isDeleted( RevisionRecord::DELETED_TEXT ); |
| 712 |
} else { |
| 713 |
|
| 714 |
return false; |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
public function getRawSlot( $role ) { |
| 728 |
return $this->getSlots()->getSlot( $role ); |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
public function getRawContent( string $role ): Content { |
| 740 |
return $this->getRawSlot( $role )->getContent(); |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
private function getContentHandler( $role ): ContentHandler { |
| 749 |
return $this->contentHandlerFactory |
| 750 |
->getContentHandler( $this->getRawSlot( $role )->getModel() ); |
| 751 |
} |
| 752 |
|
| 753 |
private function usePrimary() { |
| 754 |
|
| 755 |
return $this->wikiPage->wasLoadedFrom( IDBAccessObject::READ_LATEST ); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
public function isCountable(): bool { |
| 762 |
|
| 763 |
|
| 764 |
if ( !$this->getTitle()->isContentPage() ) { |
| 765 |
return false; |
| 766 |
} |
| 767 |
|
| 768 |
if ( $this->isContentDeleted() ) { |
| 769 |
|
| 770 |
|
| 771 |
return false; |
| 772 |
} |
| 773 |
|
| 774 |
if ( $this->isRedirect() ) { |
| 775 |
return false; |
| 776 |
} |
| 777 |
|
| 778 |
$hasLinks = null; |
| 779 |
|
| 780 |
if ( $this->articleCountMethod === 'link' ) { |
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
$hasLinks = (bool)count( $this->getParserOutputForMetaData()->getLinks() ); |
| 787 |
} |
| 788 |
|
| 789 |
foreach ( $this->getSlots()->getSlotRoles() as $role ) { |
| 790 |
$roleHandler = $this->slotRoleRegistry->getRoleHandler( $role ); |
| 791 |
if ( $roleHandler->supportsArticleCount() ) { |
| 792 |
$content = $this->getRawContent( $role ); |
| 793 |
|
| 794 |
if ( $content->isCountable( $hasLinks ) ) { |
| 795 |
return true; |
| 796 |
} |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
return false; |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
public function isRedirect(): bool { |
| 807 |
|
| 808 |
|
| 809 |
$mainContent = $this->getRawContent( SlotRecord::MAIN ); |
| 810 |
|
| 811 |
return $mainContent->isRedirect(); |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
private function revisionIsRedirect( RevisionRecord $rev ) { |
| 820 |
|
| 821 |
$mainContent = $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW ); |
| 822 |
|
| 823 |
return $mainContent->isRedirect(); |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
public function prepareContent( |
| 850 |
UserIdentity $user, |
| 851 |
RevisionSlotsUpdate $slotsUpdate, |
| 852 |
$useStash = true |
| 853 |
) { |
| 854 |
if ( $this->slotsUpdate ) { |
| 855 |
if ( !$this->user ) { |
| 856 |
throw new LogicException( |
| 857 |
'Unexpected state: $this->slotsUpdate was initialized, ' |
| 858 |
. 'but $this->user was not.' |
| 859 |
); |
| 860 |
} |
| 861 |
|
| 862 |
if ( $this->user->getName() !== $user->getName() ) { |
| 863 |
throw new LogicException( 'Can\'t call prepareContent() again for different user! ' |
| 864 |
. 'Expected ' . $this->user->getName() . ', got ' . $user->getName() |
| 865 |
); |
| 866 |
} |
| 867 |
|
| 868 |
if ( !$this->slotsUpdate->hasSameUpdates( $slotsUpdate ) ) { |
| 869 |
throw new LogicException( |
| 870 |
'Can\'t call prepareContent() again with different slot content!' |
| 871 |
); |
| 872 |
} |
| 873 |
|
| 874 |
return; |
| 875 |
} |
| 876 |
|
| 877 |
$this->assertTransition( 'has-content' ); |
| 878 |
|
| 879 |
$wikiPage = $this->getWikiPage(); |
| 880 |
$title = $this->getTitle(); |
| 881 |
|
| 882 |
$parentRevision = $this->grabCurrentRevision(); |
| 883 |
|
| 884 |
|
| 885 |
$stashedEdit = false; |
| 886 |
|
| 887 |
|
| 888 |
if ( $useStash && $slotsUpdate->isModifiedSlot( SlotRecord::MAIN ) ) { |
| 889 |
$stashedEdit = $this->pageEditStash->checkCache( |
| 890 |
$title, |
| 891 |
$slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent(), |
| 892 |
$user |
| 893 |
); |
| 894 |
} |
| 895 |
|
| 896 |
$userPopts = ParserOptions::newFromUserAndLang( $user, $this->contLang ); |
| 897 |
$userPopts->setRenderReason( $this->options['causeAgent'] ?? 'unknown' ); |
| 898 |
|
| 899 |
$this->hookRunner->onArticlePrepareTextForEdit( $wikiPage, $userPopts ); |
| 900 |
|
| 901 |
$this->user = $user; |
| 902 |
$this->slotsUpdate = $slotsUpdate; |
| 903 |
|
| 904 |
if ( $parentRevision ) { |
| 905 |
$this->revision = MutableRevisionRecord::newFromParentRevision( $parentRevision ); |
| 906 |
} else { |
| 907 |
$this->revision = new MutableRevisionRecord( $title ); |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
$this->revision->setTimestamp( MWTimestamp::now( TS_MW ) ); |
| 913 |
$this->revision->setUser( $user ); |
| 914 |
|
| 915 |
|
| 916 |
$oldCallback = $userPopts->getCurrentRevisionRecordCallback(); |
| 917 |
$userPopts->setCurrentRevisionRecordCallback( |
| 918 |
function ( Title $parserTitle, $parser = null ) use ( $title, $oldCallback ) { |
| 919 |
if ( $parserTitle->equals( $title ) ) { |
| 920 |
return $this->revision; |
| 921 |
} else { |
| 922 |
return call_user_func( $oldCallback, $parserTitle, $parser ); |
| 923 |
} |
| 924 |
} |
| 925 |
); |
| 926 |
|
| 927 |
$pstContentSlots = $this->revision->getSlots(); |
| 928 |
|
| 929 |
foreach ( $slotsUpdate->getModifiedRoles() as $role ) { |
| 930 |
$slot = $slotsUpdate->getModifiedSlot( $role ); |
| 931 |
|
| 932 |
if ( $slot->isInherited() ) { |
| 933 |
|
| 934 |
|
| 935 |
$pstSlot = $slot; |
| 936 |
} elseif ( $role === SlotRecord::MAIN && $stashedEdit ) { |
| 937 |
|
| 938 |
$pstSlot = SlotRecord::newUnsaved( $role, $stashedEdit->pstContent ); |
| 939 |
} else { |
| 940 |
$pstContent = $this->contentTransformer->preSaveTransform( |
| 941 |
$slot->getContent(), |
| 942 |
$title, |
| 943 |
$user, |
| 944 |
$userPopts |
| 945 |
); |
| 946 |
|
| 947 |
$pstSlot = SlotRecord::newUnsaved( $role, $pstContent ); |
| 948 |
} |
| 949 |
|
| 950 |
$pstContentSlots->setSlot( $pstSlot ); |
| 951 |
} |
| 952 |
|
| 953 |
foreach ( $slotsUpdate->getRemovedRoles() as $role ) { |
| 954 |
$pstContentSlots->removeSlot( $role ); |
| 955 |
} |
| 956 |
|
| 957 |
$this->options['created'] = ( $parentRevision === null ); |
| 958 |
$this->options['changed'] = ( $parentRevision === null |
| 959 |
|| !$pstContentSlots->hasSameContent( $parentRevision->getSlots() ) ); |
| 960 |
|
| 961 |
$this->doTransition( 'has-content' ); |
| 962 |
|
| 963 |
if ( !$this->options['changed'] ) { |
| 964 |
if ( $this->forceEmptyRevision ) { |
| 965 |
|
| 966 |
foreach ( $parentRevision->getSlotRoles() as $role ) { |
| 967 |
$this->revision->inheritSlot( $parentRevision->getSlot( $role ) ); |
| 968 |
} |
| 969 |
} else { |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
$this->revision->setId( $parentRevision->getId() ); |
| 974 |
$this->revision->setTimestamp( $parentRevision->getTimestamp() ); |
| 975 |
$this->revision->setPageId( $parentRevision->getPageId() ); |
| 976 |
$this->revision->setParentId( $parentRevision->getParentId() ); |
| 977 |
$this->revision->setUser( $parentRevision->getUser( RevisionRecord::RAW ) ); |
| 978 |
$this->revision->setComment( $parentRevision->getComment( RevisionRecord::RAW ) ); |
| 979 |
$this->revision->setMinorEdit( $parentRevision->isMinor() ); |
| 980 |
$this->revision->setVisibility( $parentRevision->getVisibility() ); |
| 981 |
|
| 982 |
|
| 983 |
$this->doTransition( 'has-revision' ); |
| 984 |
} |
| 985 |
} else { |
| 986 |
$this->parentRevision = $parentRevision; |
| 987 |
} |
| 988 |
|
| 989 |
$renderHints = [ 'use-master' => $this->usePrimary(), 'audience' => RevisionRecord::RAW ]; |
| 990 |
|
| 991 |
if ( $stashedEdit ) { |
| 992 |
|
| 993 |
$output = $stashedEdit->output; |
| 994 |
|
| 995 |
$output->setCacheTime( $stashedEdit->timestamp ); |
| 996 |
|
| 997 |
$renderHints['known-revision-output'] = $output; |
| 998 |
|
| 999 |
$this->logger->debug( __METHOD__ . ': using stashed edit output...' ); |
| 1000 |
} |
| 1001 |
|
| 1002 |
$renderHints['generate-html'] = $this->shouldGenerateHTMLOnEdit(); |
| 1003 |
|
| 1004 |
[ $causeAction, ] = $this->getCause(); |
| 1005 |
$renderHints['causeAction'] = $causeAction; |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
$this->renderedRevision = $this->revisionRenderer->getRenderedRevision( |
| 1010 |
$this->revision, |
| 1011 |
null, |
| 1012 |
null, |
| 1013 |
$renderHints |
| 1014 |
); |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
public function getRevision(): RevisionRecord { |
| 1033 |
$this->assertPrepared( __METHOD__ ); |
| 1034 |
return $this->revision; |
| 1035 |
} |
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
public function getRenderedRevision(): RenderedRevision { |
| 1041 |
$this->assertPrepared( __METHOD__ ); |
| 1042 |
|
| 1043 |
return $this->renderedRevision; |
| 1044 |
} |
| 1045 |
|
| 1046 |
private function assertHasPageState( $method ) { |
| 1047 |
if ( !$this->pageState ) { |
| 1048 |
throw new LogicException( |
| 1049 |
'Must call grabCurrentRevision() or prepareContent() ' |
| 1050 |
. 'or prepareUpdate() before calling ' . $method |
| 1051 |
); |
| 1052 |
} |
| 1053 |
} |
| 1054 |
|
| 1055 |
private function assertPrepared( $method ) { |
| 1056 |
if ( !$this->revision ) { |
| 1057 |
throw new LogicException( |
| 1058 |
'Must call prepareContent() or prepareUpdate() before calling ' . $method |
| 1059 |
); |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
private function assertHasRevision( $method ) { |
| 1064 |
if ( !$this->revision->getId() ) { |
| 1065 |
throw new LogicException( |
| 1066 |
'Must call prepareUpdate() before calling ' . $method |
| 1067 |
); |
| 1068 |
} |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
public function isCreation() { |
| 1077 |
$this->assertPrepared( __METHOD__ ); |
| 1078 |
return $this->options['created']; |
| 1079 |
} |
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
public function isChange() { |
| 1094 |
$this->assertPrepared( __METHOD__ ); |
| 1095 |
return $this->options['changed']; |
| 1096 |
} |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
public function wasRedirect() { |
| 1104 |
$this->assertHasPageState( __METHOD__ ); |
| 1105 |
|
| 1106 |
if ( $this->pageState['oldIsRedirect'] === null ) { |
| 1107 |
|
| 1108 |
$rev = $this->pageState['oldRevision']; |
| 1109 |
if ( $rev ) { |
| 1110 |
$this->pageState['oldIsRedirect'] = $this->revisionIsRedirect( $rev ); |
| 1111 |
} else { |
| 1112 |
$this->pageState['oldIsRedirect'] = false; |
| 1113 |
} |
| 1114 |
} |
| 1115 |
|
| 1116 |
return $this->pageState['oldIsRedirect']; |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
public function getSlots() { |
| 1128 |
$this->assertPrepared( __METHOD__ ); |
| 1129 |
return $this->revision->getSlots(); |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
private function getRevisionSlotsUpdate() { |
| 1138 |
$this->assertPrepared( __METHOD__ ); |
| 1139 |
|
| 1140 |
if ( !$this->slotsUpdate ) { |
| 1141 |
$old = $this->getParentRevision(); |
| 1142 |
$this->slotsUpdate = RevisionSlotsUpdate::newFromRevisionSlots( |
| 1143 |
$this->revision->getSlots(), |
| 1144 |
$old ? $old->getSlots() : null |
| 1145 |
); |
| 1146 |
} |
| 1147 |
return $this->slotsUpdate; |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
public function getTouchedSlotRoles() { |
| 1157 |
return $this->getRevisionSlotsUpdate()->getTouchedRoles(); |
| 1158 |
} |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
public function getModifiedSlotRoles(): array { |
| 1167 |
return $this->getRevisionSlotsUpdate()->getModifiedRoles(); |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
public function getRemovedSlotRoles(): array { |
| 1176 |
return $this->getRevisionSlotsUpdate()->getRemovedRoles(); |
| 1177 |
} |
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
public function prepareUpdate( RevisionRecord $revision, array $options = [] ) { |
| 1234 |
Assert::parameter( |
| 1235 |
!isset( $options['oldrevision'] ) |
| 1236 |
|| $options['oldrevision'] instanceof RevisionRecord, |
| 1237 |
'$options["oldrevision"]', |
| 1238 |
'must be a RevisionRecord' |
| 1239 |
); |
| 1240 |
Assert::parameter( |
| 1241 |
!isset( $options['triggeringUser'] ) |
| 1242 |
|| $options['triggeringUser'] instanceof UserIdentity, |
| 1243 |
'$options["triggeringUser"]', |
| 1244 |
'must be a UserIdentity' |
| 1245 |
); |
| 1246 |
Assert::parameter( |
| 1247 |
!isset( $options['editResult'] ) |
| 1248 |
|| $options['editResult'] instanceof EditResult, |
| 1249 |
'$options["editResult"]', |
| 1250 |
'must be an EditResult' |
| 1251 |
); |
| 1252 |
|
| 1253 |
if ( !$revision->getId() ) { |
| 1254 |
throw new InvalidArgumentException( |
| 1255 |
'Revision must have an ID set for it to be used with prepareUpdate()!' |
| 1256 |
); |
| 1257 |
} |
| 1258 |
|
| 1259 |
if ( $this->revision && $this->revision->getId() ) { |
| 1260 |
if ( $this->revision->getId() === $revision->getId() ) { |
| 1261 |
return; |
| 1262 |
} else { |
| 1263 |
throw new LogicException( |
| 1264 |
'Trying to re-use DerivedPageDataUpdater with revision ' |
| 1265 |
. $revision->getId() |
| 1266 |
. ', but it\'s already bound to revision ' |
| 1267 |
. $this->revision->getId() |
| 1268 |
); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
if ( $this->revision |
| 1273 |
&& !$this->revision->getSlots()->hasSameContent( $revision->getSlots() ) |
| 1274 |
) { |
| 1275 |
throw new LogicException( |
| 1276 |
'The revision provided has mismatching content!' |
| 1277 |
); |
| 1278 |
} |
| 1279 |
|
| 1280 |
|
| 1281 |
$this->options = array_intersect_key( $options, $this->options ) + $this->options; |
| 1282 |
|
| 1283 |
if ( $this->revision ) { |
| 1284 |
$oldId = $this->pageState['oldId'] ?? 0; |
| 1285 |
$this->options['newrev'] = ( $revision->getId() !== $oldId ); |
| 1286 |
} elseif ( isset( $this->options['oldrevision'] ) ) { |
| 1287 |
|
| 1288 |
$oldRev = $this->options['oldrevision']; |
| 1289 |
$oldId = $oldRev->getId(); |
| 1290 |
$this->options['newrev'] = ( $revision->getId() !== $oldId ); |
| 1291 |
} else { |
| 1292 |
$oldId = $revision->getParentId(); |
| 1293 |
} |
| 1294 |
|
| 1295 |
if ( $oldId !== null ) { |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
if ( $oldId === $revision->getParentId() ) { |
| 1302 |
|
| 1303 |
|
| 1304 |
$this->options['changed'] = true; |
| 1305 |
} elseif ( $oldId === $revision->getId() ) { |
| 1306 |
|
| 1307 |
$this->options['changed'] = false; |
| 1308 |
} else { |
| 1309 |
|
| 1310 |
throw new LogicException( |
| 1311 |
'The RevisionRecord mismatches old revision ID: ' |
| 1312 |
. 'Old ID is ' . $oldId |
| 1313 |
. ', parent ID is ' . $revision->getParentId() |
| 1314 |
. ', revision ID is ' . $revision->getId() |
| 1315 |
); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
if ( $this->user !== null && $this->options['changed'] && $this->slotsUpdate ) { |
| 1324 |
$user = $revision->getUser(); |
| 1325 |
if ( !$this->user->equals( $user ) ) { |
| 1326 |
throw new LogicException( |
| 1327 |
'The RevisionRecord provided has a mismatching actor: expected ' |
| 1328 |
. $this->user->getName() |
| 1329 |
. ', got ' |
| 1330 |
. $user->getName() |
| 1331 |
); |
| 1332 |
} |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
if ( !$this->pageState ) { |
| 1338 |
$this->pageState = [ |
| 1339 |
'oldIsRedirect' => isset( $this->options['oldredirect'] ) |
| 1340 |
&& is_bool( $this->options['oldredirect'] ) |
| 1341 |
? $this->options['oldredirect'] |
| 1342 |
: null, |
| 1343 |
'oldCountable' => isset( $this->options['oldcountable'] ) |
| 1344 |
&& is_bool( $this->options['oldcountable'] ) |
| 1345 |
? $this->options['oldcountable'] |
| 1346 |
: null, |
| 1347 |
]; |
| 1348 |
|
| 1349 |
if ( $this->options['changed'] ) { |
| 1350 |
|
| 1351 |
$this->pageState['oldId'] = $revision->getParentId(); |
| 1352 |
|
| 1353 |
$this->pageState['oldRevision'] = $this->options['oldrevision'] ?? null; |
| 1354 |
} else { |
| 1355 |
|
| 1356 |
$this->pageState['oldId'] = $revision->getId(); |
| 1357 |
$this->pageState['oldRevision'] = $revision; |
| 1358 |
} |
| 1359 |
} |
| 1360 |
|
| 1361 |
|
| 1362 |
$this->options['created'] = ( $this->options['created'] || |
| 1363 |
( $this->pageState['oldId'] === 0 ) ); |
| 1364 |
|
| 1365 |
$this->revision = $revision; |
| 1366 |
|
| 1367 |
$this->doTransition( 'has-revision' ); |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
if ( !$this->user ) { |
| 1372 |
$this->user = $revision->getUser( RevisionRecord::RAW ); |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
if ( $this->renderedRevision ) { |
| 1377 |
$this->renderedRevision->updateRevision( $revision ); |
| 1378 |
} else { |
| 1379 |
[ $causeAction, ] = $this->getCause(); |
| 1380 |
|
| 1381 |
|
| 1382 |
$this->renderedRevision = $this->revisionRenderer->getRenderedRevision( |
| 1383 |
$this->revision, |
| 1384 |
null, |
| 1385 |
null, |
| 1386 |
[ |
| 1387 |
'use-master' => $this->usePrimary(), |
| 1388 |
'audience' => RevisionRecord::RAW, |
| 1389 |
'known-revision-output' => $options['known-revision-output'] ?? null, |
| 1390 |
'causeAction' => $causeAction |
| 1391 |
] |
| 1392 |
); |
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
} |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
} |
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
public function getPreparedEdit() { |
| 1407 |
$this->assertPrepared( __METHOD__ ); |
| 1408 |
|
| 1409 |
$slotsUpdate = $this->getRevisionSlotsUpdate(); |
| 1410 |
$preparedEdit = new PreparedEdit(); |
| 1411 |
|
| 1412 |
$preparedEdit->popts = $this->getCanonicalParserOptions(); |
| 1413 |
$preparedEdit->parserOutputCallback = [ $this, 'getCanonicalParserOutput' ]; |
| 1414 |
$preparedEdit->pstContent = $this->revision->getContent( SlotRecord::MAIN ); |
| 1415 |
$preparedEdit->newContent = |
| 1416 |
$slotsUpdate->isModifiedSlot( SlotRecord::MAIN ) |
| 1417 |
? $slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent() |
| 1418 |
: $this->revision->getContent( SlotRecord::MAIN ); |
| 1419 |
$preparedEdit->oldContent = null; |
| 1420 |
$preparedEdit->revid = $this->revision ? $this->revision->getId() : null; |
| 1421 |
$preparedEdit->format = $preparedEdit->pstContent->getDefaultFormat(); |
| 1422 |
|
| 1423 |
return $preparedEdit; |
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
public function getSlotParserOutput( $role, $generateHtml = true ) { |
| 1432 |
return $this->getRenderedRevision()->getSlotParserOutput( |
| 1433 |
$role, |
| 1434 |
[ 'generate-html' => $generateHtml ] |
| 1435 |
); |
| 1436 |
} |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
public function getParserOutputForMetaData(): ParserOutput { |
| 1443 |
return $this->getRenderedRevision()->getRevisionParserOutput( [ 'generate-html' => false ] ); |
| 1444 |
} |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
public function getCanonicalParserOutput(): ParserOutput { |
| 1451 |
return $this->getRenderedRevision()->getRevisionParserOutput(); |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
public function getCanonicalParserOptions(): ParserOptions { |
| 1458 |
return $this->getRenderedRevision()->getOptions(); |
| 1459 |
} |
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
public function getSecondaryDataUpdates( $recursive = false ) { |
| 1467 |
if ( $this->isContentDeleted() ) { |
| 1468 |
|
| 1469 |
|
| 1470 |
return []; |
| 1471 |
} |
| 1472 |
|
| 1473 |
$wikiPage = $this->getWikiPage(); |
| 1474 |
$wikiPage->loadPageData( IDBAccessObject::READ_LATEST ); |
| 1475 |
if ( !$wikiPage->exists() ) { |
| 1476 |
|
| 1477 |
return []; |
| 1478 |
} |
| 1479 |
|
| 1480 |
$title = $wikiPage->getTitle(); |
| 1481 |
$allUpdates = []; |
| 1482 |
$parserOutput = $this->shouldGenerateHTMLOnEdit() ? |
| 1483 |
$this->getCanonicalParserOutput() : $this->getParserOutputForMetaData(); |
| 1484 |
|
| 1485 |
|
| 1486 |
$linksUpdate = new LinksUpdate( |
| 1487 |
$title, |
| 1488 |
$parserOutput, |
| 1489 |
$recursive, |
| 1490 |
|
| 1491 |
|
| 1492 |
$this->isRedirect() || $this->wasRedirect() |
| 1493 |
); |
| 1494 |
if ( $this->options['moved'] ) { |
| 1495 |
|
| 1496 |
$linksUpdate->setMoveDetails( $this->options['oldtitle'] ); |
| 1497 |
} |
| 1498 |
|
| 1499 |
$allUpdates[] = $linksUpdate; |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
$renderedRevision = $this->getRenderedRevision(); |
| 1504 |
|
| 1505 |
foreach ( $this->getSlots()->getSlotRoles() as $role ) { |
| 1506 |
$slot = $this->getRawSlot( $role ); |
| 1507 |
$content = $slot->getContent(); |
| 1508 |
$handler = $content->getContentHandler(); |
| 1509 |
|
| 1510 |
$updates = $handler->getSecondaryDataUpdates( |
| 1511 |
$title, |
| 1512 |
$content, |
| 1513 |
$role, |
| 1514 |
$renderedRevision |
| 1515 |
); |
| 1516 |
|
| 1517 |
$allUpdates = array_merge( $allUpdates, $updates ); |
| 1518 |
} |
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
$parentRevision = $this->getParentRevision(); |
| 1529 |
foreach ( $this->getRemovedSlotRoles() as $role ) { |
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
$parentSlot = $parentRevision->getSlot( $role, RevisionRecord::RAW ); |
| 1534 |
$content = $parentSlot->getContent(); |
| 1535 |
$handler = $content->getContentHandler(); |
| 1536 |
|
| 1537 |
$updates = $handler->getDeletionUpdates( |
| 1538 |
$title, |
| 1539 |
$role |
| 1540 |
); |
| 1541 |
|
| 1542 |
$allUpdates = array_merge( $allUpdates, $updates ); |
| 1543 |
} |
| 1544 |
|
| 1545 |
|
| 1546 |
$this->hookRunner->onRevisionDataUpdates( $title, $renderedRevision, $allUpdates ); |
| 1547 |
|
| 1548 |
return $allUpdates; |
| 1549 |
} |
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
private function shouldGenerateHTMLOnEdit(): bool { |
| 1556 |
foreach ( $this->getSlots()->getSlotRoles() as $role ) { |
| 1557 |
$slot = $this->getRawSlot( $role ); |
| 1558 |
$contentHandler = $this->contentHandlerFactory->getContentHandler( $slot->getModel() ); |
| 1559 |
if ( $contentHandler->generateHTMLOnEdit() ) { |
| 1560 |
return true; |
| 1561 |
} |
| 1562 |
} |
| 1563 |
return false; |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
public function doUpdates() { |
| 1577 |
$this->assertTransition( 'done' ); |
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
$wikiPage = $this->getWikiPage(); |
| 1582 |
|
| 1583 |
if ( $this->shouldGenerateHTMLOnEdit() ) { |
| 1584 |
$this->triggerParserCacheUpdate(); |
| 1585 |
} |
| 1586 |
|
| 1587 |
$this->doSecondaryDataUpdates( [ |
| 1588 |
|
| 1589 |
'recursive' => $this->options['changed'], |
| 1590 |
|
| 1591 |
'defer' => DeferredUpdates::POSTSEND |
| 1592 |
] ); |
| 1593 |
|
| 1594 |
|
| 1595 |
if ( $this->rcWatchCategoryMembership |
| 1596 |
&& $this->getContentHandler( SlotRecord::MAIN )->supportsCategories() === true |
| 1597 |
&& ( $this->options['changed'] || $this->options['created'] ) |
| 1598 |
&& !$this->options['restored'] |
| 1599 |
) { |
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
$this->jobQueueGroup->lazyPush( |
| 1604 |
CategoryMembershipChangeJob::newSpec( |
| 1605 |
$this->getTitle(), |
| 1606 |
$this->revision->getTimestamp(), |
| 1607 |
$this->options['causeAction'] === 'import-page' |
| 1608 |
) |
| 1609 |
); |
| 1610 |
} |
| 1611 |
|
| 1612 |
$id = $this->getPageId(); |
| 1613 |
$title = $this->getTitle(); |
| 1614 |
$shortTitle = $title->getDBkey(); |
| 1615 |
|
| 1616 |
if ( !$title->exists() ) { |
| 1617 |
wfDebug( __METHOD__ . ": Page doesn't exist any more, bailing out" ); |
| 1618 |
|
| 1619 |
$this->doTransition( 'done' ); |
| 1620 |
return; |
| 1621 |
} |
| 1622 |
|
| 1623 |
DeferredUpdates::addCallableUpdate( function () { |
| 1624 |
if ( |
| 1625 |
$this->options['oldcountable'] === 'no-change' || |
| 1626 |
( !$this->options['changed'] && !$this->options['moved'] ) |
| 1627 |
) { |
| 1628 |
$good = 0; |
| 1629 |
} elseif ( $this->options['created'] ) { |
| 1630 |
$good = (int)$this->isCountable(); |
| 1631 |
} elseif ( $this->options['oldcountable'] !== null ) { |
| 1632 |
$good = (int)$this->isCountable() |
| 1633 |
- (int)$this->options['oldcountable']; |
| 1634 |
} elseif ( isset( $this->pageState['oldCountable'] ) ) { |
| 1635 |
$good = (int)$this->isCountable() |
| 1636 |
- (int)$this->pageState['oldCountable']; |
| 1637 |
} else { |
| 1638 |
$good = 0; |
| 1639 |
} |
| 1640 |
$edits = $this->options['changed'] ? 1 : 0; |
| 1641 |
$pages = $this->options['created'] ? 1 : 0; |
| 1642 |
|
| 1643 |
DeferredUpdates::addUpdate( SiteStatsUpdate::factory( |
| 1644 |
[ 'edits' => $edits, 'articles' => $good, 'pages' => $pages ] |
| 1645 |
) ); |
| 1646 |
} ); |
| 1647 |
|
| 1648 |
|
| 1649 |
$mainSlot = $this->revision->getSlot( SlotRecord::MAIN ); |
| 1650 |
if ( !$mainSlot->isInherited() && !$this->isContentDeleted() ) { |
| 1651 |
DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $mainSlot->getContent() ) ); |
| 1652 |
} |
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
if ( $this->options['changed'] |
| 1659 |
&& $title->getNamespace() === NS_USER_TALK |
| 1660 |
&& $title->getText() != $this->user->getName() |
| 1661 |
&& !( $this->revision->isMinor() && $this->permissionManager |
| 1662 |
->userHasRight( $this->user, 'nominornewtalk' ) |
| 1663 |
) |
| 1664 |
) { |
| 1665 |
$recipient = User::newFromName( $shortTitle, false ); |
| 1666 |
if ( !$recipient ) { |
| 1667 |
wfDebug( __METHOD__ . ": invalid username" ); |
| 1668 |
} else { |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
if ( $this->hookRunner->onArticleEditUpdateNewTalk( $wikiPage, $recipient ) ) { |
| 1673 |
$revRecord = $this->revision; |
| 1674 |
if ( $this->userNameUtils->isIP( $shortTitle ) ) { |
| 1675 |
|
| 1676 |
$this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord ); |
| 1677 |
} elseif ( $recipient->isRegistered() ) { |
| 1678 |
$this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord ); |
| 1679 |
} else { |
| 1680 |
wfDebug( __METHOD__ . ": don't need to notify a nonexistent user" ); |
| 1681 |
} |
| 1682 |
} |
| 1683 |
} |
| 1684 |
} |
| 1685 |
|
| 1686 |
if ( $title->getNamespace() === NS_MEDIAWIKI |
| 1687 |
&& $this->getRevisionSlotsUpdate()->isModifiedSlot( SlotRecord::MAIN ) |
| 1688 |
) { |
| 1689 |
$mainContent = $this->isContentDeleted() ? null : $this->getRawContent( SlotRecord::MAIN ); |
| 1690 |
|
| 1691 |
$this->messageCache->updateMessageOverride( $title, $mainContent ); |
| 1692 |
} |
| 1693 |
|
| 1694 |
|
| 1695 |
if ( $this->options['created'] ) { |
| 1696 |
WikiPage::onArticleCreate( $title, $this->isRedirect() ); |
| 1697 |
} elseif ( $this->options['changed'] ) { |
| 1698 |
WikiPage::onArticleEdit( |
| 1699 |
$title, |
| 1700 |
$this->revision, |
| 1701 |
$this->getTouchedSlotRoles(), |
| 1702 |
|
| 1703 |
|
| 1704 |
$this->isRedirect() || $this->wasRedirect() |
| 1705 |
); |
| 1706 |
} elseif ( $this->options['restored'] ) { |
| 1707 |
$this->mainWANObjectCache->touchCheckKey( |
| 1708 |
"DerivedPageDataUpdater:restore:page:$id" |
| 1709 |
); |
| 1710 |
} |
| 1711 |
|
| 1712 |
$oldRevisionRecord = $this->getParentRevision(); |
| 1713 |
|
| 1714 |
|
| 1715 |
RL\WikiModule::invalidateModuleCache( |
| 1716 |
$title, |
| 1717 |
$oldRevisionRecord, |
| 1718 |
$this->revision, |
| 1719 |
$this->loadbalancerFactory->getLocalDomainID() |
| 1720 |
); |
| 1721 |
|
| 1722 |
|
| 1723 |
$this->maybeEnqueueRevertedTagUpdateJob(); |
| 1724 |
|
| 1725 |
$this->doTransition( 'done' ); |
| 1726 |
} |
| 1727 |
|
| 1728 |
private function triggerParserCacheUpdate() { |
| 1729 |
$this->assertHasRevision( __METHOD__ ); |
| 1730 |
|
| 1731 |
$userParserOptions = ParserOptions::newFromUser( $this->user ); |
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
if ( $userParserOptions->matchesForCacheKey( $this->getCanonicalParserOptions() ) ) { |
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
$this->doParserCacheUpdate(); |
| 1741 |
} else { |
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
DeferredUpdates::addCallableUpdate( function () { |
| 1746 |
$this->doParserCacheUpdate(); |
| 1747 |
} ); |
| 1748 |
} |
| 1749 |
} |
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
private function maybeEnqueueRevertedTagUpdateJob() { |
| 1757 |
if ( $this->options['editResult'] === null ) { |
| 1758 |
return; |
| 1759 |
} |
| 1760 |
|
| 1761 |
$editResult = $this->options['editResult']; |
| 1762 |
if ( !$editResult->isRevert() ) { |
| 1763 |
return; |
| 1764 |
} |
| 1765 |
|
| 1766 |
if ( $this->options['approved'] ) { |
| 1767 |
|
| 1768 |
$this->jobQueueGroup->lazyPush( |
| 1769 |
RevertedTagUpdateJob::newSpec( |
| 1770 |
$this->revision->getId(), |
| 1771 |
$this->options['editResult'] |
| 1772 |
) |
| 1773 |
); |
| 1774 |
} else { |
| 1775 |
|
| 1776 |
$this->editResultCache->set( |
| 1777 |
$this->revision->getId(), |
| 1778 |
$this->options['editResult'] |
| 1779 |
); |
| 1780 |
} |
| 1781 |
} |
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
public function doSecondaryDataUpdates( array $options = [] ) { |
| 1799 |
$this->assertHasRevision( __METHOD__ ); |
| 1800 |
$options += [ 'recursive' => false, 'defer' => false, 'freshness' => false ]; |
| 1801 |
$deferValues = [ false, DeferredUpdates::PRESEND, DeferredUpdates::POSTSEND ]; |
| 1802 |
if ( !in_array( $options['defer'], $deferValues, true ) ) { |
| 1803 |
throw new InvalidArgumentException( 'Invalid value for defer: ' . $options['defer'] ); |
| 1804 |
} |
| 1805 |
|
| 1806 |
$triggeringUser = $this->options['triggeringUser'] ?? $this->user; |
| 1807 |
[ $causeAction, $causeAgent ] = $this->getCause(); |
| 1808 |
if ( isset( $options['known-revision-output'] ) ) { |
| 1809 |
$this->getRenderedRevision()->setRevisionParserOutput( $options['known-revision-output'] ); |
| 1810 |
} |
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
$update = new RefreshSecondaryDataUpdate( |
| 1817 |
$this->loadbalancerFactory, |
| 1818 |
|
| 1819 |
$triggeringUser, |
| 1820 |
$this->wikiPage, |
| 1821 |
$this->revision, |
| 1822 |
$this, |
| 1823 |
[ 'recursive' => $options['recursive'], 'freshness' => $options['freshness'] ] |
| 1824 |
); |
| 1825 |
$update->setCause( $causeAction, $causeAgent ); |
| 1826 |
|
| 1827 |
if ( $options['defer'] === false ) { |
| 1828 |
DeferredUpdates::attemptUpdate( $update ); |
| 1829 |
} else { |
| 1830 |
DeferredUpdates::addUpdate( $update, $options['defer'] ); |
| 1831 |
} |
| 1832 |
} |
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
public function doParserCacheUpdate() { |
| 1841 |
$this->assertHasRevision( __METHOD__ ); |
| 1842 |
|
| 1843 |
$wikiPage = $this->getWikiPage(); |
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
$output = $this->getCanonicalParserOutput(); |
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
$timestamp = $this->options['newrev'] ? $this->revision->getTimestamp() |
| 1856 |
: $output->getCacheTime(); |
| 1857 |
$this->parserCache->save( |
| 1858 |
$output, $wikiPage, $this->getCanonicalParserOptions(), |
| 1859 |
$timestamp, $this->revision->getId() |
| 1860 |
); |
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
if ( $this->warmParsoidParserCache ) { |
| 1866 |
$cacheWarmingParams = $this->getCause(); |
| 1867 |
$cacheWarmingParams['options'] = ParserOutputAccess::OPT_FORCE_PARSE; |
| 1868 |
|
| 1869 |
$this->jobQueueGroup->lazyPush( |
| 1870 |
ParsoidCachePrewarmJob::newSpec( |
| 1871 |
$this->revision->getId(), |
| 1872 |
$wikiPage->toPageRecord(), |
| 1873 |
$cacheWarmingParams |
| 1874 |
) |
| 1875 |
); |
| 1876 |
} |
| 1877 |
} |
| 1878 |
|
| 1879 |
} |