Merge "Turn ApiPrefixUniquenessTest into a structure test"
[lhc/web/wiklou.git] / includes / Storage / DerivedPageDataUpdater.php
index 73463b5..a00766f 100644 (file)
@@ -110,7 +110,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
        /**
         * @var Language
         */
-       private $contentLanguage;
+       private $contLang;
 
        /**
         * @var LoggerInterface
@@ -152,10 +152,21 @@ class DerivedPageDataUpdater implements IDBAccessObject {
        /**
         * The state of the relevant row in page table before the edit.
         * This is determined by the first call to grabCurrentRevision, prepareContent,
-        * or prepareUpdate.
+        * or prepareUpdate (so it is only accessible in 'knows-current' or a later stage).
         * If pageState was not initialized when prepareUpdate() is called, prepareUpdate() will
         * attempt to emulate the state of the page table before the edit.
         *
+        * Contains the following fields:
+        * - oldRevision (RevisionRecord|null): the revision that was current before the change
+        *   associated with this update. Might not be set, use getOldRevision() instead of direct
+        *   access.
+        * - oldId (int|null): the id of the above revision. 0 if there is no such revision (the change
+        *   was about creating a new page); null if not known (that should not happen).
+        * - oldIsRedirect (bool|null): whether the page was a redirect before the change. Lazy-loaded,
+        *   can be null; use wasRedirect() instead of direct access.
+        * - oldCountable (bool|null): whether the page was countable before the change (or null
+        *   if we don't have that information)
+        *
         * @var array
         */
        private $pageState = null;
@@ -240,7 +251,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
         * @param ParserCache $parserCache
         * @param JobQueueGroup $jobQueueGroup
         * @param MessageCache $messageCache
-        * @param Language $contentLanguage
+        * @param Language $contLang
         * @param LoggerInterface|null $saveParseLogger
         */
        public function __construct(
@@ -249,7 +260,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                ParserCache $parserCache,
                JobQueueGroup $jobQueueGroup,
                MessageCache $messageCache,
-               Language $contentLanguage,
+               Language $contLang,
                LoggerInterface $saveParseLogger = null
        ) {
                $this->wikiPage = $wikiPage;
@@ -258,7 +269,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                $this->revisionStore = $revisionStore;
                $this->jobQueueGroup = $jobQueueGroup;
                $this->messageCache = $messageCache;
-               $this->contentLanguage = $contentLanguage;
+               $this->contLang = $contLang;
 
                // XXX: replace all wfDebug calls with a Logger. Do we nede more than one logger here?
                $this->saveParseLogger = $saveParseLogger ?: new NullLogger();
@@ -309,7 +320,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
 
        /**
         * Checks whether this DerivedPageDataUpdater can be re-used for running updates targeting
-        * the the given revision.
+        * the given revision.
         *
         * @param UserIdentity|null $user The user creating the revision in question
         * @param RevisionRecord|null $revision New revision (after save, if already saved)
@@ -679,11 +690,11 @@ class DerivedPageDataUpdater implements IDBAccessObject {
         *
         * @see docs/pageupdater.txt for more information on when thie method can and should be called.
         *
-        * @note: Calling this method more than once with the same $slotsUpdate
+        * @note Calling this method more than once with the same $slotsUpdate
         * has no effect. Calling this method multiple times with different content will cause
         * an exception.
         *
-        * @note: Calling this method after prepareUpdate() has been called will cause an exception.
+        * @note Calling this method after prepareUpdate() has been called will cause an exception.
         *
         * @param User $user The user to act as context for pre-save transformation (PST).
         *        Type hint should be reduced to UserIdentity at some point.
@@ -751,7 +762,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                        $this->canonicalParserOutput = $output;
                }
 
-               $userPopts = ParserOptions::newFromUserAndLang( $user, $this->contentLanguage );
+               $userPopts = ParserOptions::newFromUserAndLang( $user, $this->contLang );
                Hooks::run( 'ArticlePrepareTextForEdit', [ $wikiPage, $userPopts ] );
 
                $this->user = $user;
@@ -826,7 +837,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
        /**
         * Whether the edit created, or should create, a new revision (that is, it's not a null-edit).
         *
-        * @warning: at present, "null-revisions" that do not change content but do have a revision
+        * @warning at present, "null-revisions" that do not change content but do have a revision
         * record would return false after prepareContent(), but true after prepareUpdate()!
         * This should probably be fixed.
         *
@@ -931,11 +942,11 @@ class DerivedPageDataUpdater implements IDBAccessObject {
         *
         * @see docs/pageupdater.txt for more information on when thie method can and should be called.
         *
-        * @note: Calling this method more than once with the same revision has no effect.
+        * @note Calling this method more than once with the same revision has no effect.
         * $options are only used for the first call. Calling this method multiple times with
         * different revisions will cause an exception.
         *
-        * @note: If grabCurrentRevision() (or prepareContent()) has been called before
+        * @note If grabCurrentRevision() (or prepareContent()) has been called before
         * calling this method, $revision->getParentRevision() has to refer to the revision that
         * was the current revision at the time grabCurrentRevision() was called.
         *
@@ -958,7 +969,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
         *    - null: if created is false, don't update the article count; if created
         *      is true, do update the article count
         *    - 'no-change': don't update the article count, ever
-        *
+        *    When set to null, pageState['oldCountable'] will be used instead if available.
         */
        public function prepareUpdate( RevisionRecord $revision, array $options = [] ) {
                Assert::parameter(
@@ -1469,6 +1480,9 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                } 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;
                }
@@ -1533,7 +1547,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
 
                // TODO: In the wiring, register a listener for this on the new PageEventEmitter
                ResourceLoaderWikiModule::invalidateModuleCache(
-                       $title, $oldLegacyRevision, $legacyRevision, $this->getWikiId()
+                       $title, $oldLegacyRevision, $legacyRevision, $this->getWikiId() ?: wfWikiID()
                );
 
                $this->doTransition( 'done' );