summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmir Sarabadani <ladsgroup@gmail.com>2022-05-12 11:12:38 +0200
committerLadsgroup <Ladsgroup@gmail.com>2022-05-16 10:10:41 +0000
commita6d9b8199f82a3372f4434768e0fadeab2c768ea (patch)
tree05e8444ba1476ac5e61e91d8de475dfe5b6eea09
parent752d3c0fe05b528cb952d56d652ebcfa87f1ef7a (diff)
RestrictionStore: Add support for templatelinks migrationwmf/1.39.0-wmf.11
For checking cascade protection. Bug: T308207 Change-Id: Ia7a3ec84e8de11a77f3addc05e3de0bab2cb51a6 (cherry picked from commit 244127fc5df60db6330a80f145b48eb2f5f55fe8)
-rw-r--r--includes/Permissions/RestrictionStore.php20
-rw-r--r--includes/ServiceWiring.php1
-rw-r--r--tests/phpunit/integration/includes/Permissions/RestrictionStoreTest.php5
-rw-r--r--tests/phpunit/unit/includes/Permissions/RestrictionStoreTest.php2
4 files changed, 22 insertions, 6 deletions
diff --git a/includes/Permissions/RestrictionStore.php b/includes/Permissions/RestrictionStore.php
index b44f1cc1ac50..dc5bd0a91420 100644
--- a/includes/Permissions/RestrictionStore.php
+++ b/includes/Permissions/RestrictionStore.php
@@ -10,12 +10,14 @@ use MediaWiki\Cache\CacheKeyHelper;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\HookContainer\HookRunner;
+use MediaWiki\Linker\LinksMigration;
use MediaWiki\MainConfigNames;
use MediaWiki\Page\PageIdentity;
use MediaWiki\Page\PageIdentityValue;
use MediaWiki\Page\PageStore;
use stdClass;
use Title;
+use TitleValue;
use WANObjectCache;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;
@@ -48,6 +50,9 @@ class RestrictionStore {
/** @var LinkCache */
private $linkCache;
+ /** @var LinksMigration */
+ private $linksMigration;
+
/** @var CommentStore */
private $commentStore;
@@ -79,6 +84,7 @@ class RestrictionStore {
* @param WANObjectCache $wanCache
* @param ILoadBalancer $loadBalancer
* @param LinkCache $linkCache
+ * @param LinksMigration $linksMigration
* @param CommentStore $commentStore
* @param HookContainer $hookContainer
* @param PageStore $pageStore
@@ -88,6 +94,7 @@ class RestrictionStore {
WANObjectCache $wanCache,
ILoadBalancer $loadBalancer,
LinkCache $linkCache,
+ LinksMigration $linksMigration,
CommentStore $commentStore,
HookContainer $hookContainer,
PageStore $pageStore
@@ -97,6 +104,7 @@ class RestrictionStore {
$this->wanCache = $wanCache;
$this->loadBalancer = $loadBalancer;
$this->linkCache = $linkCache;
+ $this->linksMigration = $linksMigration;
$this->commentStore = $commentStore;
$this->hookContainer = $hookContainer;
$this->hookRunner = new HookRunner( $hookContainer );
@@ -625,12 +633,12 @@ class RestrictionStore {
];
} else {
$tables = [ 'templatelinks', 'page_restrictions' ];
- $where_clauses = [
- 'tl_namespace' => $page->getNamespace(),
- 'tl_title' => $page->getDBkey(),
- 'tl_from=pr_page',
- 'pr_cascade' => 1
- ];
+ $where_clauses = $this->linksMigration->getLinksConditions(
+ 'templatelinks',
+ TitleValue::newFromPage( $page )
+ );
+ $where_clauses[] = 'tl_from=pr_page';
+ $where_clauses['pr_cascade'] = 1;
}
if ( $shortCircuit ) {
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index cfbd5379f6a6..433592625f18 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -1527,6 +1527,7 @@ return [
$services->getMainWANObjectCache(),
$services->getDBLoadBalancer(),
$services->getLinkCache(),
+ $services->getLinksMigration(),
$services->getCommentStore(),
$services->getHookContainer(),
$services->getPageStore()
diff --git a/tests/phpunit/integration/includes/Permissions/RestrictionStoreTest.php b/tests/phpunit/integration/includes/Permissions/RestrictionStoreTest.php
index 571bda079bd3..4327ee07a20f 100644
--- a/tests/phpunit/integration/includes/Permissions/RestrictionStoreTest.php
+++ b/tests/phpunit/integration/includes/Permissions/RestrictionStoreTest.php
@@ -31,6 +31,9 @@ class RestrictionStoreTest extends MediaWikiIntegrationTestCase {
/** @var LinkCache */
private $linkCache;
+ /** @var \MediaWiki\Linker\LinksMigration */
+ private $linksMigration;
+
/** @var HookContainer */
private $hookContainer;
@@ -50,6 +53,7 @@ class RestrictionStoreTest extends MediaWikiIntegrationTestCase {
$this->wanCache = $services->getMainWANObjectCache();
$this->loadBalancer = $services->getDBLoadBalancer();
$this->linkCache = $services->getLinkCache();
+ $this->linksMigration = $services->getLinksMigration();
$this->commentStore = $services->getCommentStore();
$this->hookContainer = $services->getHookContainer();
$this->pageStore = $services->getPageStore();
@@ -77,6 +81,7 @@ class RestrictionStoreTest extends MediaWikiIntegrationTestCase {
$this->wanCache,
$this->loadBalancer,
$this->linkCache,
+ $this->linksMigration,
$this->commentStore,
$this->hookContainer,
$this->pageStore
diff --git a/tests/phpunit/unit/includes/Permissions/RestrictionStoreTest.php b/tests/phpunit/unit/includes/Permissions/RestrictionStoreTest.php
index 16763e200c5b..7d3463e5851b 100644
--- a/tests/phpunit/unit/includes/Permissions/RestrictionStoreTest.php
+++ b/tests/phpunit/unit/includes/Permissions/RestrictionStoreTest.php
@@ -5,6 +5,7 @@ namespace MediaWiki\Tests\Unit\Permissions;
use DatabaseTestHelper;
use LinkCache;
use MediaWiki\Config\ServiceOptions;
+use MediaWiki\Linker\LinksMigration;
use MediaWiki\Page\PageIdentity;
use MediaWiki\Page\PageIdentityValue;
use MediaWiki\Page\PageReferenceValue;
@@ -88,6 +89,7 @@ class RestrictionStoreTest extends MediaWikiUnitTestCase {
$this->newMockLoadBalancer( $options['db'] ?? [] ),
// @todo test that these calls work correctly
$this->createNoOpMock( LinkCache::class, [ 'addLinkObj', 'getGoodLinkFieldObj' ] ),
+ $this->createNoOpMock( LinksMigration::class, [ 'getLinksConditions' ] ),
$this->getDummyCommentStore(),
$this->createHookContainer( isset( $options['hookFn'] )
? [ 'TitleGetRestrictionTypes' => $options['hookFn'] ]