From 10ad65f6c2801ea072a6b3b7a6ad86a01acf2280 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Wed, 1 Aug 2018 14:22:37 +0200 Subject: [PATCH] Fix article counting logic in DerivedPageDataUpdater Use old state of the page if we have it. Bug: T200823 Change-Id: Iff29731a127ef32baec5970dcbc25a0a5c3eb4d9 --- includes/Storage/DerivedPageDataUpdater.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/Storage/DerivedPageDataUpdater.php b/includes/Storage/DerivedPageDataUpdater.php index 6f241bab6b..4c51003def 100644 --- a/includes/Storage/DerivedPageDataUpdater.php +++ b/includes/Storage/DerivedPageDataUpdater.php @@ -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; @@ -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; } -- 2.20.1