Merge "Add MessagesBi.php"
[lhc/web/wiklou.git] / includes / Storage / PageUpdater.php
index 838efcd..1621213 100644 (file)
@@ -344,10 +344,6 @@ 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 );
        }
 
@@ -844,7 +840,6 @@ class PageUpdater {
         *
         * @param CommentStoreComment $comment
         * @param User $user
-        * @param string $timestamp
         * @param int $flags
         * @param Status $status
         *
@@ -853,7 +848,6 @@ class PageUpdater {
        private function makeNewRevision(
                CommentStoreComment $comment,
                User $user,
-               $timestamp,
                $flags,
                Status $status
        ) {
@@ -861,7 +855,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 ) {
@@ -873,20 +871,15 @@ class PageUpdater {
 
                $rev->setComment( $comment );
                $rev->setUser( $user );
-               $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 );
                }
@@ -908,9 +901,6 @@ class PageUpdater {
                // Update article, but only if changed.
                $status = Status::newGood( [ 'new' => false, 'revision' => null, 'revision-record' => null ] );
 
-               // Convenience variables
-               $now = $this->getTimestampNow();
-
                $oldRev = $this->grabParentRevision();
                $oldid = $oldRev ? $oldRev->getId() : 0;
 
@@ -924,7 +914,6 @@ class PageUpdater {
                $newRevisionRecord = $this->makeNewRevision(
                        $summary,
                        $user,
-                       $now,
                        $flags,
                        $status
                );
@@ -933,6 +922,8 @@ class PageUpdater {
                        return $status;
                }
 
+               $now = $newRevisionRecord->getTimestamp();
+
                // XXX: we may want a flag that allows a null revision to be forced!
                $changed = $this->derivedDataUpdater->isChange();
 
@@ -1064,12 +1055,9 @@ class PageUpdater {
 
                $status = Status::newGood( [ 'new' => true, 'revision' => null, 'revision-record' => null ] );
 
-               $now = $this->getTimestampNow();
-
                $newRevisionRecord = $this->makeNewRevision(
                        $summary,
                        $user,
-                       $now,
                        $flags,
                        $status
                );
@@ -1078,6 +1066,8 @@ class PageUpdater {
                        return $status;
                }
 
+               $now = $newRevisionRecord->getTimestamp();
+
                $dbw = $this->getDBConnectionRef( DB_MASTER );
                $dbw->startAtomic( __METHOD__ );
 
@@ -1191,6 +1181,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 );