Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311728

Change subject: DNM WIP Only act on the main namespace
......................................................................

DNM WIP Only act on the main namespace

Prior to this multiple namespaces were configurable.

Although the current DB table only supports a single ns
really as otherwise dbkeys accross namespaces will result in
identical rows..

The usecase of wiktionaries as far as I understand only needs
this functionality for a single namespace and that namespace
is always the main namespace.

Links will also be needed for talk pages, can these simply be
created using the main table or will there indeed need to be
a new col in this table for nsid?

Change-Id: I5576c964cb983d7d45f46533f633ce656be9c80f
---
M extension.json
M src/ServiceWiring.php
M src/hooks/CognatePageHookHandler.php
M tests/phpunit/hooks/CognatePageHookHandlerTest.php
4 files changed, 12 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cognate 
refs/changes/28/311728/1

diff --git a/extension.json b/extension.json
index f544dfb..2892b09 100644
--- a/extension.json
+++ b/extension.json
@@ -15,8 +15,7 @@
   },
   "config": {
     "CognateDb": false,
-    "CognateCluster": false,
-    "CognateNamespaces": [ 0 ]
+    "CognateCluster": false
   },
   "ServiceWiringFiles": [
     "src/ServiceWiring.php"
diff --git a/src/ServiceWiring.php b/src/ServiceWiring.php
index d4c2ba2..8bf2c14 100644
--- a/src/ServiceWiring.php
+++ b/src/ServiceWiring.php
@@ -20,7 +20,6 @@
 
        'CognatePageHookHandler' => function( MediaWikiServices $services ) {
                return new CognatePageHookHandler(
-                       $services->getMainConfig()->get( 'CognateNamespaces' ),
                        $services->getMainConfig()->get( 'LanguageCode' )
                );
        },
diff --git a/src/hooks/CognatePageHookHandler.php 
b/src/hooks/CognatePageHookHandler.php
index 1fb288f..323a493 100644
--- a/src/hooks/CognatePageHookHandler.php
+++ b/src/hooks/CognatePageHookHandler.php
@@ -15,18 +15,11 @@
        private $languageCode;
 
        /**
-        * @var int[]
-        */
-       private $namespaces;
-
-       /**
         * CognatePageHookHandler constructor.
         *
-        * @param int[] $namespaces array of namespace ids the hooks should 
operate on
         * @param string $languageCode the language code of the current site
         */
-       public function __construct( array $namespaces, $languageCode ) {
-               $this->namespaces = $namespaces;
+       public function __construct( $languageCode ) {
                $this->languageCode = $languageCode;
        }
 
@@ -59,7 +52,7 @@
                Status $status,
                $baseRevId
        ) {
-               if ( $article->getTitle()->inNamespaces( $this->namespaces ) ) {
+               if ( $article->getTitle()->inNamespace( NS_MAIN ) ) {
                        $store = MediaWikiServices::getInstance()->getService( 
'CognateStore' );
                        $store->savePage( $this->languageCode, 
$article->getTitle()->getDBkey() );
                }
@@ -80,7 +73,7 @@
        ) {
                $title = $page->getTitle();
                $language = $this->languageCode;
-               if ( $title->inNamespaces( $this->namespaces ) ) {
+               if ( $title->inNamespace( NS_MAIN ) ) {
                        $updates[] = new MWCallableUpdate(
                                function () use ( $title, $language ){
                                        $store = 
MediaWikiServices::getInstance()->getService( 'CognateStore' );
@@ -106,7 +99,7 @@
                $comment,
                $oldPageId
        ) {
-               if ( $title->inNamespaces( $this->namespaces ) ) {
+               if ( $title->inNamespace( NS_MAIN ) ) {
                        $store = MediaWikiServices::getInstance()->getService( 
'CognateStore' );
                        $store->savePage( $this->languageCode, 
$title->getDBkey() );
                }
diff --git a/tests/phpunit/hooks/CognatePageHookHandlerTest.php 
b/tests/phpunit/hooks/CognatePageHookHandlerTest.php
index 3834b01..4fa26f4 100644
--- a/tests/phpunit/hooks/CognatePageHookHandlerTest.php
+++ b/tests/phpunit/hooks/CognatePageHookHandlerTest.php
@@ -36,7 +36,7 @@
                        ->method( 'savePage' )
                        ->with( 'abc2', 'ArticleDbKey' );
 
-               $this->call_onPageContentSaveComplete( [ 0 ], 'abc2', new 
TitleValue( 0, 'ArticleDbKey' ) );
+               $this->call_onPageContentSaveComplete( 'abc2', new TitleValue( 
0, 'ArticleDbKey' ) );
        }
 
        public function test_onPageContentSaveComplete_noNamespaceMatch() {
@@ -45,16 +45,14 @@
                $this->store->expects( $this->never() )
                        ->method( 'savePage' );
 
-               $this->call_onPageContentSaveComplete( [ 120 ], 'abc2', new 
TitleValue( 0, 'ArticleDbKey' ) );
+               $this->call_onPageContentSaveComplete( 'abc2', new TitleValue( 
120, 'ArticleDbKey' ) );
        }
 
        /**
-        * @param int[] $namespaces
         * @param string $language
         * @param LinkTarget $linkTarget
         */
        private function call_onPageContentSaveComplete(
-               array $namespaces,
                $language,
                LinkTarget $linkTarget
        ) {
@@ -66,7 +64,7 @@
                        ->method( 'getTitle' )
                        ->willReturn( Title::newFromLinkTarget( $linkTarget ) );
 
-               $handler = new CognatePageHookHandler( $namespaces, $language );
+               $handler = new CognatePageHookHandler( $language );
                $handler->onPageContentSaveComplete(
                        $mockWikiPage,
                        User::newFromId( 0 ),
@@ -85,7 +83,6 @@
                        ->method( 'savePage' );
 
                $updates = $this->call_onWikiPageDeletionUpdates(
-                       [ 0 ],
                        'abc2',
                        new TitleValue( 0, 'ArticleDbKey' )
                );
@@ -101,23 +98,20 @@
                        ->method( 'savePage' );
 
                $updates = $this->call_onWikiPageDeletionUpdates(
-                       [ 120 ],
                        'abc2',
-                       new TitleValue( 0, 'ArticleDbKey' )
+                       new TitleValue( 120, 'ArticleDbKey' )
                );
 
                $this->assertCount( 0, $updates );
        }
 
        /**
-        * @param int[] $namespaces
         * @param string $language
         * @param LinkTarget $linkTarget
         *
         * @return DeferrableUpdate[]
         */
        private function call_onWikiPageDeletionUpdates(
-               array $namespaces,
                $language,
                LinkTarget $linkTarget
        ) {
@@ -131,7 +125,7 @@
                        ->method( 'getTitle' )
                        ->willReturn( Title::newFromLinkTarget( $linkTarget ) );
 
-               $handler = new CognatePageHookHandler( $namespaces, $language );
+               $handler = new CognatePageHookHandler( $language );
                $handler->onWikiPageDeletionUpdates(
                        $mockWikiPage,
                        null,
@@ -149,7 +143,6 @@
                        ->with( 'abc2', 'ArticleDbKey' );
 
                $this->call_onArticleUndelete(
-                       [ 0 ],
                        'abc2',
                        new TitleValue( 0, 'ArticleDbKey' )
                );
@@ -162,23 +155,20 @@
                        ->method( 'savePage' );
 
                $this->call_onArticleUndelete(
-                       [ 120 ],
                        'abc2',
-                       new TitleValue( 0, 'ArticleDbKey' )
+                       new TitleValue( 120, 'ArticleDbKey' )
                );
        }
 
        /**
-        * @param int[] $namespaces
         * @param string $language
         * @param LinkTarget $linkTarget
         */
        private function call_onArticleUndelete(
-               array $namespaces,
                $language,
                LinkTarget $linkTarget
        ) {
-               $handler = new CognatePageHookHandler( $namespaces, $language );
+               $handler = new CognatePageHookHandler( $language );
                $handler->onArticleUndelete(
                        Title::newFromLinkTarget( $linkTarget ),
                        null, null, null

-- 
To view, visit https://gerrit.wikimedia.org/r/311728
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5576c964cb983d7d45f46533f633ce656be9c80f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cognate
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to