Permissions: Exit early from RestrictionStore::loadRestrictions if no rev id

When a new page is created, MW checks if the page is "protected"
from autopatrolling in the middle of its creation
(WikiPage::doUserEditContent). At this point, there is no latest rev,
but $page->getId() still returns something.

This causes a warning in php8, along with some caching behaviour that's
almost certainly wrong. Exit early when this happens.

Bug: T313663
Change-Id: Iebaa536b1281588bf3db12d724f3d17f3d3b20e1
This commit is contained in:
Brian Wolff 2022-09-11 10:43:06 -07:00 committed by Krinkle
parent 56105077fb
commit 4f89380816

View file

@ -389,6 +389,12 @@ class RestrictionStore {
} else {
$this->linkCache->addLinkObj( $page );
$latestRev = $this->linkCache->getGoodLinkFieldObj( $page, 'revision' );
if ( !$latestRev ) {
// This method can get called in the middle of page creation
// (WikiPage::doUserEditContent) where a page might have an
// id but no revisions, while checking the "autopatrol" permission.
$rows = [];
} else {
$rows = $this->wanCache->getWithSetCallback(
// Page protections always leave a new null revision
$this->wanCache->makeKey( 'page-restrictions', 'v1', $id, $latestRev ),
@ -405,6 +411,7 @@ class RestrictionStore {
}
);
}
}
$this->loadRestrictionsFromRows( $page, $rows );
} else {