[MCR] Move getSecondaryDataUpdates to the page level
[lhc/web/wiklou.git] / includes / Storage / PageUpdater.php
index 67928f9..ec1f6e2 100644 (file)
@@ -344,13 +344,18 @@ class PageUpdater {
                // TODO: MCR: check the role and the content's model against the list of supported
                // roles, see T194046.
 
-               if ( $role !== 'main' ) {
-                       throw new InvalidArgumentException( 'Only the main slot is presently supported' );
-               }
-
                $this->slotsUpdate->modifyContent( $role, $content );
        }
 
+       /**
+        * Set the new slot for the given slot role
+        *
+        * @param SlotRecord $slot
+        */
+       public function setSlot( SlotRecord $slot ) {
+               $this->slotsUpdate->modifySlot( $slot );
+       }
+
        /**
         * Explicitly inherit a slot from some earlier revision.
         *
@@ -615,7 +620,6 @@ class PageUpdater {
                // Defend against mistakes caused by differences with the
                // signature of WikiPage::doEditContent.
                Assert::parameterType( 'integer', $flags, '$flags' );
-               Assert::parameterType( 'CommentStoreComment', $summary, '$summary' );
 
                if ( $this->wasCommitted() ) {
                        throw new RuntimeException( 'saveRevision() has already been called on this PageUpdater!' );
@@ -853,7 +857,11 @@ class PageUpdater {
                $title = $this->getTitle();
                $parent = $this->grabParentRevision();
 
-               $rev = new MutableRevisionRecord( $title, $this->getWikiId() );
+               // XXX: we expect to get a MutableRevisionRecord here, but that's a bit brittle!
+               // TODO: introduce something like an UnsavedRevisionFactory service instead!
+               /** @var MutableRevisionRecord $rev */
+               $rev = $this->derivedDataUpdater->getRevision();
+
                $rev->setPageId( $title->getArticleID() );
 
                if ( $parent ) {
@@ -868,17 +876,13 @@ class PageUpdater {
                $rev->setTimestamp( $timestamp );
                $rev->setMinorEdit( ( $flags & EDIT_MINOR ) > 0 );
 
-               foreach ( $this->derivedDataUpdater->getSlots()->getSlots() as $slot ) {
+               foreach ( $rev->getSlots()->getSlots() as $slot ) {
                        $content = $slot->getContent();
 
                        // XXX: We may push this up to the "edit controller" level, see T192777.
                        // TODO: change the signature of PrepareSave to not take a WikiPage!
                        $prepStatus = $content->prepareSave( $wikiPage, $flags, $oldid, $user );
 
-                       if ( $prepStatus->isOK() ) {
-                               $rev->setSlot( $slot );
-                       }
-
                        // TODO: MCR: record which problem arose in which slot.
                        $status->merge( $prepStatus );
                }
@@ -1183,6 +1187,10 @@ class PageUpdater {
                                $wikiPage, $newRevisionRecord, $user,
                                $summary, $flags, $status, $hints
                        ) {
+                               // set debug data
+                               $hints['causeAction'] = 'edit-page';
+                               $hints['causeAgent'] = $user->getName();
+
                                $newLegacyRevision = new Revision( $newRevisionRecord );
                                $mainContent = $newRevisionRecord->getContent( 'main', RevisionRecord::RAW );