Merge "output: Narrow Title type hint to LinkTarget"
[lhc/web/wiklou.git] / includes / Storage / DerivedPageDataUpdater.php
index b4d6f05..b2c003a 100644 (file)
@@ -79,7 +79,7 @@ use WikiPage;
  *
  * DerivedPageDataUpdater instances are designed to be cached inside a WikiPage instance,
  * and re-used by callback code over the course of an update operation. It's a stepping stone
- * one the way to a more complete refactoring of WikiPage.
+ * on the way to a more complete refactoring of WikiPage.
  *
  * When using a DerivedPageDataUpdater, the following life cycle must be observed:
  * grabCurrentRevision (optional), prepareContent (optional), prepareUpdate (required
@@ -343,14 +343,6 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
                }
        }
 
-       /**
-        * @return bool|string
-        */
-       private function getWikiId() {
-               // TODO: get from RevisionStore
-               return false;
-       }
-
        /**
         * Checks whether this DerivedPageDataUpdater can be re-used for running updates targeting
         * the given revision.
@@ -580,7 +572,6 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
         */
        public function isContentDeleted() {
                if ( $this->revision ) {
-                       // XXX: if that revision is the current revision, this should be skipped
                        return $this->revision->isDeleted( RevisionRecord::DELETED_TEXT );
                } else {
                        // If the content has not been saved yet, it cannot have been deleted yet.
@@ -668,7 +659,7 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
                        $hasLinks = (bool)count( $this->getCanonicalParserOutput()->getLinks() );
                }
 
-               foreach ( $this->getModifiedSlotRoles() as $role ) {
+               foreach ( $this->getSlots()->getSlotRoles() as $role ) {
                        $roleHandler = $this->slotRoleRegistry->getRoleHandler( $role );
                        if ( $roleHandler->supportsArticleCount() ) {
                                $content = $this->getRawContent( $role );
@@ -1082,6 +1073,11 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
         *    See DataUpdate::getCauseAction(). (default 'unknown')
         *  - causeAgent: name of the user who caused the update. See DataUpdate::getCauseAgent().
         *    (string, default 'unknown')
+        *  - known-revision-output: a combined canonical ParserOutput for the revision, perhaps
+        *    from some cache. The caller is responsible for ensuring that the ParserOutput indeed
+        *    matched the $rev and $options. This mechanism is intended as a temporary stop-gap,
+        *    for the time until caches have been changed to store RenderedRevision states instead
+        *    of ParserOutput objects. (default: null) (since 1.33)
         */
        public function prepareUpdate( RevisionRecord $revision, array $options = [] ) {
                Assert::parameter(
@@ -1212,7 +1208,8 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
                }
 
                // "created" is forced here
-               $this->options['created'] = ( $this->pageState['oldId'] === 0 );
+               $this->options['created'] = ( $this->options['created'] ||
+                                               ( $this->pageState['oldId'] === 0 ) );
 
                $this->revision = $revision;
 
@@ -1228,14 +1225,17 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
                if ( $this->renderedRevision ) {
                        $this->renderedRevision->updateRevision( $revision );
                } else {
-
                        // NOTE: we want a canonical rendering, so don't pass $this->user or ParserOptions
                        // NOTE: the revision is either new or current, so we can bypass audience checks.
                        $this->renderedRevision = $this->revisionRenderer->getRenderedRevision(
                                $this->revision,
                                null,
                                null,
-                               [ 'use-master' => $this->useMaster(), 'audience' => RevisionRecord::RAW ]
+                               [
+                                       'use-master' => $this->useMaster(),
+                                       'audience' => RevisionRecord::RAW,
+                                       'known-revision-output' => $options['known-revision-output'] ?? null
+                               ]
                        );
 
                        // XXX: Since we presumably are dealing with the current revision,
@@ -1485,7 +1485,6 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
 
                $id = $this->getPageId();
                $title = $this->getTitle();
-               $dbKey = $title->getPrefixedDBkey();
                $shortTitle = $title->getDBkey();
 
                if ( !$title->exists() ) {
@@ -1523,7 +1522,7 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
                // TODO: make search infrastructure aware of slots!
                $mainSlot = $this->revision->getSlot( SlotRecord::MAIN );
                if ( !$mainSlot->isInherited() && !$this->isContentDeleted() ) {
-                       DeferredUpdates::addUpdate( new SearchUpdate( $id, $dbKey, $mainSlot->getContent() ) );
+                       DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $mainSlot->getContent() ) );
                }
 
                // If this is another user's talk page, update newtalk.
@@ -1532,7 +1531,9 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
                if ( $this->options['changed']
                        && $title->getNamespace() == NS_USER_TALK
                        && $shortTitle != $legacyUser->getTitleKey()
-                       && !( $this->revision->isMinor() && $legacyUser->isAllowed( 'nominornewtalk' ) )
+                       && !( $this->revision->isMinor() && MediaWikiServices::getInstance()
+                                       ->getPermissionManager()
+                                       ->userHasRight( $legacyUser, 'nominornewtalk' ) )
                ) {
                        $recipient = User::newFromName( $shortTitle, false );
                        if ( !$recipient ) {
@@ -1574,7 +1575,10 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
 
                // TODO: In the wiring, register a listener for this on the new PageEventEmitter
                ResourceLoaderWikiModule::invalidateModuleCache(
-                       $title, $oldLegacyRevision, $legacyRevision, $this->getWikiId() ?: wfWikiID()
+                       $title,
+                       $oldLegacyRevision,
+                       $legacyRevision,
+                       $this->loadbalancerFactory->getLocalDomainID()
                );
 
                $this->doTransition( 'done' );