jenkins-bot has submitted this change and it was merged.

Change subject: Add CognateStore to MediawikiServices
......................................................................


Add CognateStore to MediawikiServices

Change-Id: I05001f16a56a1cc6af66b3d4f70cde9c0d2ae210
---
M extension.json
M src/CognateHooks.php
A src/ServiceWiring.php
A tests/phpunit/ServiceWiringTest.php
4 files changed, 52 insertions(+), 4 deletions(-)

Approvals:
  jenkins-bot: Verified
  Gabriel Birke: Looks good to me, approved



diff --git a/extension.json b/extension.json
index c563b37..de00abd 100644
--- a/extension.json
+++ b/extension.json
@@ -16,6 +16,9 @@
     "CognateWiki": false,
     "CognateNamespaces": [ 0 ]
   },
+  "ServiceWiringFiles": [
+    "src/ServiceWiring.php"
+  ],
   "Hooks": {
     "PageContentSaveComplete": [ "CognateHooks::onPageContentSaveComplete" ],
     "LanguageLinks": [ "CognateHooks::onLanguageLinks" ],
diff --git a/src/CognateHooks.php b/src/CognateHooks.php
index 419743d..7405172 100644
--- a/src/CognateHooks.php
+++ b/src/CognateHooks.php
@@ -2,6 +2,8 @@
 
 // TODO Make this class testable by creating non-static public methods for 
each hook and using an instance in the static methods, see 
https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FWikibase/master/client%2FWikibaseClient.hooks.php
 // TODO Split into two hook handler classes, one handling page-related stuff, 
the other handling database update and tests
+use MediaWiki\MediaWikiServices;
+
 class CognateHooks {
 
        /**
@@ -35,13 +37,13 @@
                Status $status,
                $baseRevId
        ) {
-               global $wgCognateWiki, $wgCognateNamespaces, $wgLanguageCode;
+               global $wgCognateNamespaces, $wgLanguageCode;
 
                $title = $article->getTitle();
                if ( !in_array( $title->getNamespace(), $wgCognateNamespaces ) 
) {
                        return true;
                }
-               $interlanguage = new CognateStore( wfGetLB(), $wgCognateWiki );
+               $interlanguage = MediaWikiServices::getInstance()->getService( 
'CognateStore' );
                $interlanguage->savePage( $wgLanguageCode, 
$article->getTitle()->getDBkey() );
 
                return true;
@@ -65,13 +67,13 @@
         * @return bool
         */
        public static function onLanguageLinks( $title, &$links, &$linkFlags ) {
-               global $wgCognateWiki, $wgCognateNamespaces, $wgLanguageCode;
+               global $wgCognateNamespaces, $wgLanguageCode;
 
                if ( !in_array( $title->getNamespace(), $wgCognateNamespaces ) 
) {
                        return true;
                }
 
-               $interlanguage = new CognateStore( wfGetLB(), $wgCognateWiki );
+               $interlanguage = MediaWikiServices::getInstance()->getService( 
'CognateStore' );
                $dbKey = $title->getDBkey();
                $languages = $interlanguage->getTranslationsForPage( 
$wgLanguageCode, $dbKey );
 
diff --git a/src/ServiceWiring.php b/src/ServiceWiring.php
new file mode 100644
index 0000000..694a3ad
--- /dev/null
+++ b/src/ServiceWiring.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Cognate wiring for MediaWiki services.
+ */
+
+use MediaWiki\MediaWikiServices;
+
+return [
+       'CognateStore' => function( MediaWikiServices $services ) {
+               return new CognateStore(
+                       $services->getDBLoadBalancer(),
+                       $services->getMainConfig()->get( 'CognateWiki' )
+               );
+       },
+];
diff --git a/tests/phpunit/ServiceWiringTest.php 
b/tests/phpunit/ServiceWiringTest.php
new file mode 100644
index 0000000..afbe911
--- /dev/null
+++ b/tests/phpunit/ServiceWiringTest.php
@@ -0,0 +1,28 @@
+<?php
+use MediaWiki\MediaWikiServices;
+
+/**
+ * @license GNU GPL v2+
+ * @author Addshore
+ */
+class ServiceWiringTest extends MediaWikiTestCase {
+
+       public function provideServices() {
+               return [
+                       [ 'CognateStore', CognateStore::class ]
+               ];
+       }
+
+       /**
+        * @dataProvider provideServices
+        */
+       public function testServiceWiring( $serviceName, $expectedClass ) {
+               $service1 = MediaWikiServices::getInstance()->getService( 
$serviceName );
+               $service2 = MediaWikiServices::getInstance()->getService( 
$serviceName );
+
+               $this->assertInstanceOf( $expectedClass, $service1 );
+               $this->assertInstanceOf( $expectedClass, $service2 );
+               $this->assertSame( $service1, $service2 );
+       }
+
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I05001f16a56a1cc6af66b3d4f70cde9c0d2ae210
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Cognate
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Gabriel Birke <gabriel.bi...@wikimedia.de>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to