Merge "Simplify HTMLTitleTextField::validate"
[lhc/web/wiklou.git] / includes / Storage / PageUpdater.php
index 9d2f209..29ce710 100644 (file)
@@ -388,7 +388,7 @@ class PageUpdater {
         * @param string $role A slot role name (but not "main")
         */
        public function removeSlot( $role ) {
-               if ( $role === 'main' ) {
+               if ( $role === SlotRecord::MAIN ) {
                        throw new InvalidArgumentException( 'Cannot remove the main slot!' );
                }
 
@@ -635,7 +635,7 @@ class PageUpdater {
 
                // Make sure the given content type is allowed for this page
                // TODO: decide: Extend check to other slots? Consider the role in check? [PageType]
-               $mainContentHandler = $this->getContentHandler( 'main' );
+               $mainContentHandler = $this->getContentHandler( SlotRecord::MAIN );
                if ( !$mainContentHandler->canBeUsedOn( $this->getTitle() ) ) {
                        $this->status = Status::newFatal( 'content-not-allowed-here',
                                ContentHandler::getLocalizedName( $mainContentHandler->getModelID() ),
@@ -701,7 +701,7 @@ class PageUpdater {
                 */
                $this->derivedDataUpdater->getCanonicalParserOutput();
 
-               $mainContent = $this->derivedDataUpdater->getSlots()->getContent( 'main' );
+               $mainContent = $this->derivedDataUpdater->getSlots()->getContent( SlotRecord::MAIN );
 
                // Trigger pre-save hook (using provided edit summary)
                $hookStatus = Status::newGood( [] );
@@ -840,7 +840,6 @@ class PageUpdater {
         *
         * @param CommentStoreComment $comment
         * @param User $user
-        * @param string $timestamp
         * @param int $flags
         * @param Status $status
         *
@@ -849,7 +848,6 @@ class PageUpdater {
        private function makeNewRevision(
                CommentStoreComment $comment,
                User $user,
-               $timestamp,
                $flags,
                Status $status
        ) {
@@ -873,7 +871,6 @@ class PageUpdater {
 
                $rev->setComment( $comment );
                $rev->setUser( $user );
-               $rev->setTimestamp( $timestamp );
                $rev->setMinorEdit( ( $flags & EDIT_MINOR ) > 0 );
 
                foreach ( $rev->getSlots()->getSlots() as $slot ) {
@@ -904,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;
 
@@ -920,7 +914,6 @@ class PageUpdater {
                $newRevisionRecord = $this->makeNewRevision(
                        $summary,
                        $user,
-                       $now,
                        $flags,
                        $status
                );
@@ -929,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();
 
@@ -1054,18 +1049,15 @@ class PageUpdater {
        private function doCreate( CommentStoreComment $summary, User $user, $flags ) {
                $wikiPage = $this->getWikiPage(); // TODO: use for legacy hooks only!
 
-               if ( !$this->derivedDataUpdater->getSlots()->hasSlot( 'main' ) ) {
+               if ( !$this->derivedDataUpdater->getSlots()->hasSlot( SlotRecord::MAIN ) ) {
                        throw new PageUpdateException( 'Must provide a main slot when creating a page!' );
                }
 
                $status = Status::newGood( [ 'new' => true, 'revision' => null, 'revision-record' => null ] );
 
-               $now = $this->getTimestampNow();
-
                $newRevisionRecord = $this->makeNewRevision(
                        $summary,
                        $user,
-                       $now,
                        $flags,
                        $status
                );
@@ -1074,6 +1066,8 @@ class PageUpdater {
                        return $status;
                }
 
+               $now = $newRevisionRecord->getTimestamp();
+
                $dbw = $this->getDBConnectionRef( DB_MASTER );
                $dbw->startAtomic( __METHOD__ );
 
@@ -1187,8 +1181,12 @@ 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 );
+                               $mainContent = $newRevisionRecord->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
 
                                // Update links tables, site stats, etc.
                                $this->derivedDataUpdater->prepareUpdate( $newRevisionRecord, $hints );