Merge "Add checkDependencies.php"
[lhc/web/wiklou.git] / includes / Storage / DerivedPageDataUpdater.php
index 3dbe0a8..ff5541d 100644 (file)
@@ -22,7 +22,6 @@
 
 namespace MediaWiki\Storage;
 
-use ApiStashEdit;
 use CategoryMembershipChangeJob;
 use Content;
 use ContentHandler;
@@ -38,6 +37,7 @@ use LinksDeletionUpdate;
 use LinksUpdate;
 use LogicException;
 use MediaWiki\Edit\PreparedEdit;
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Revision\MutableRevisionRecord;
 use MediaWiki\Revision\RenderedRevision;
 use MediaWiki\Revision\RevisionRecord;
@@ -755,9 +755,12 @@ class DerivedPageDataUpdater implements IDBAccessObject {
 
                // TODO: MCR: allow output for all slots to be stashed.
                if ( $useStash && $slotsUpdate->isModifiedSlot( SlotRecord::MAIN ) ) {
-                       $mainContent = $slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent();
-                       $legacyUser = User::newFromIdentity( $user );
-                       $stashedEdit = ApiStashEdit::checkCache( $title, $mainContent, $legacyUser );
+                       $editStash = MediaWikiServices::getInstance()->getPageEditStash();
+                       $stashedEdit = $editStash->checkCache(
+                               $title,
+                               $slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent(),
+                               User::newFromIdentity( $user )
+                       );
                }
 
                $userPopts = ParserOptions::newFromUserAndLang( $user, $this->contLang );
@@ -1471,27 +1474,30 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                        return;
                }
 
-               if ( $this->options['oldcountable'] === 'no-change' ||
-                       ( !$this->options['changed'] && !$this->options['moved'] )
-               ) {
-                       $good = 0;
-               } elseif ( $this->options['created'] ) {
-                       $good = (int)$this->isCountable();
-               } elseif ( $this->options['oldcountable'] !== null ) {
-                       $good = (int)$this->isCountable()
-                               - (int)$this->options['oldcountable'];
-               } elseif ( isset( $this->pageState['oldCountable'] ) ) {
-                       $good = (int)$this->isCountable()
-                               - (int)$this->pageState['oldCountable'];
-               } else {
-                       $good = 0;
-               }
-               $edits = $this->options['changed'] ? 1 : 0;
-               $pages = $this->options['created'] ? 1 : 0;
+               DeferredUpdates::addCallableUpdate( function () {
+                       if (
+                               $this->options['oldcountable'] === 'no-change' ||
+                               ( !$this->options['changed'] && !$this->options['moved'] )
+                       ) {
+                               $good = 0;
+                       } elseif ( $this->options['created'] ) {
+                               $good = (int)$this->isCountable();
+                       } elseif ( $this->options['oldcountable'] !== null ) {
+                               $good = (int)$this->isCountable()
+                                       - (int)$this->options['oldcountable'];
+                       } elseif ( isset( $this->pageState['oldCountable'] ) ) {
+                               $good = (int)$this->isCountable()
+                                       - (int)$this->pageState['oldCountable'];
+                       } else {
+                               $good = 0;
+                       }
+                       $edits = $this->options['changed'] ? 1 : 0;
+                       $pages = $this->options['created'] ? 1 : 0;
 
-               DeferredUpdates::addUpdate( SiteStatsUpdate::factory(
-                       [ 'edits' => $edits, 'articles' => $good, 'pages' => $pages ]
-               ) );
+                       DeferredUpdates::addUpdate( SiteStatsUpdate::factory(
+                               [ 'edits' => $edits, 'articles' => $good, 'pages' => $pages ]
+                       ) );
+               } );
 
                // TODO: make search infrastructure aware of slots!
                $mainSlot = $this->revision->getSlot( SlotRecord::MAIN );
@@ -1576,10 +1582,10 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                ];
                $deferValues = [ false, DeferredUpdates::PRESEND, DeferredUpdates::POSTSEND ];
                if ( !in_array( $options['defer'], $deferValues, true ) ) {
-                       throw new InvalidArgumentException( 'invalid value for defer: ' . $options['defer'] );
+                       throw new InvalidArgumentException( 'Invalid value for defer: ' . $options['defer'] );
                }
-               Assert::parameterType( 'integer|null', $options['transactionTicket'],
-                       '$options[\'transactionTicket\']' );
+               Assert::parameterType(
+                       'integer|null', $options['transactionTicket'], '$options[\'transactionTicket\']' );
 
                $updates = $this->getSecondaryDataUpdates( $options['recursive'] );
 
@@ -1590,14 +1596,13 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                $causeAction = $this->options['causeAction'] ?? 'unknown';
                $causeAgent = $this->options['causeAgent'] ?? 'unknown';
                $legacyRevision = new Revision( $this->revision );
+               $ticket = $options['transactionTicket'];
 
-               if ( $options['defer'] === false && $options['transactionTicket'] !== null ) {
+               if ( $options['defer'] === false && $ticket !== null ) {
                        // For legacy hook handlers doing updates via LinksUpdateConstructed, make sure
                        // any pending writes they made get flushed before the doUpdate() calls below.
                        // This avoids snapshot-clearing errors in LinksUpdate::acquirePageLock().
-                       $this->loadbalancerFactory->commitAndWaitForReplication(
-                               __METHOD__, $options['transactionTicket']
-                       );
+                       $this->loadbalancerFactory->commitAndWaitForReplication( __METHOD__, $ticket );
                }
 
                foreach ( $updates as $update ) {
@@ -1610,8 +1615,8 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                        }
 
                        if ( $options['defer'] === false ) {
-                               if ( $update instanceof DataUpdate && $options['transactionTicket'] !== null ) {
-                                       $update->setTransactionTicket( $options['transactionTicket'] );
+                               if ( $update instanceof DataUpdate && $ticket !== null ) {
+                                       $update->setTransactionTicket( $ticket );
                                }
                                $update->doUpdate();
                        } else {