Ladsgroup has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/405881 )

Change subject: Use external username when building RecentChange entry
......................................................................

Use external username when building RecentChange entry

When it can't find the username locally

Bug: T183019
Change-Id: I4644b249fc3f866419c54eb5f0e5c4c26ef39024
---
M client/includes/RecentChanges/RecentChangeFactory.php
M client/includes/WikibaseClient.php
M client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
M client/tests/phpunit/includes/WikibaseClientTest.php
4 files changed, 50 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/81/405881/1

diff --git a/client/includes/RecentChanges/RecentChangeFactory.php 
b/client/includes/RecentChanges/RecentChangeFactory.php
index 65c694e..b17fabe 100644
--- a/client/includes/RecentChanges/RecentChangeFactory.php
+++ b/client/includes/RecentChanges/RecentChangeFactory.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Client\RecentChanges;
 
 use CentralIdLookup;
+use ExternalUserNames;
 use Language;
 use Message;
 use MWException;
@@ -41,20 +42,28 @@
        private $centralIdLookup;
 
        /**
+        * @var string[]
+        */
+       private $repoInterwikiPrefixes;
+
+       /**
         * @param Language $language Language to format in
         * @param SiteLinkCommentCreator $siteLinkCommentCreator
         * @param CentralIdLookup|null $centralIdLookup CentralIdLookup, or 
null if
         *   this repository is not connected to a central user system (see
         *   Wikibase\Lib\Changes\CentralIdLookupFactory).
+        * @param string[] $repoInterwikiPrefixes
         */
        public function __construct(
                Language $language,
                SiteLinkCommentCreator $siteLinkCommentCreator,
-               CentralIdLookup $centralIdLookup = null
+               CentralIdLookup $centralIdLookup = null,
+               array $repoInterwikiPrefixes
        ) {
                $this->language = $language;
                $this->siteLinkCommentCreator = $siteLinkCommentCreator;
                $this->centralIdLookup = $centralIdLookup;
+               $this->repoInterwikiPrefixes = $repoInterwikiPrefixes;
        }
 
        /**
@@ -132,6 +141,13 @@
 
                $repoUserId = $change->getUserId();
                $clientUserId = $this->getClientUserId( $repoUserId, $metadata 
);
+               if ( $clientUserId === 0 && $this->repoInterwikiPrefixes !== [] 
) {
+                       $externalUsernames = new ExternalUserNames(
+                               $this->repoInterwikiPrefixes[0],
+                               false
+                       );
+                       $userText = $externalUsernames->addPrefix( $userText );
+               }
 
                $attribs = [
                        'rc_user' => $clientUserId,
diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index e28047f..fa6c877 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -1192,6 +1192,11 @@
         * @return RecentChangeFactory
         */
        public function getRecentChangeFactory() {
+               $repoSite = $this->siteLookup->getSite(
+                       
$this->getRepositoryDefinitions()->getDatabaseNames()['']
+               );
+               $interwikiPrefixes = ( $repoSite !== null ) ? 
$repoSite->getInterwikiIds() : [];
+
                return new RecentChangeFactory(
                        $this->getContentLanguage(),
                        new SiteLinkCommentCreator(
@@ -1199,7 +1204,8 @@
                                $this->siteLookup,
                                $this->settings->getSetting( 'siteGlobalID' )
                        ),
-                       ( new CentralIdLookupFactory() )->getCentralIdLookup()
+                       ( new CentralIdLookupFactory() )->getCentralIdLookup(),
+                       $interwikiPrefixes
                );
        }
 
diff --git 
a/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php 
b/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
index affc250..7d23f13 100644
--- a/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
+++ b/client/tests/phpunit/includes/RecentChanges/RecentChangeFactoryTest.php
@@ -40,7 +40,12 @@
 
                $lang = Language::factory( 'qqx' );
                $siteLinkCommentCreator = new SiteLinkCommentCreator( $lang, 
$siteLookup, 'testwiki' );
-               return new RecentChangeFactory( $lang, $siteLinkCommentCreator, 
$centralIdLookup );
+               return new RecentChangeFactory(
+                       $lang,
+                       $siteLinkCommentCreator,
+                       $centralIdLookup,
+                       [ 'repo' ]
+               );
        }
 
        private function newRecentChangeFactory() {
@@ -161,7 +166,7 @@
 
                $changeAttr = [
                        'rc_user' => 0,
-                       'rc_user_text' => 'RecentChangeFactoryTestUser',
+                       'rc_user_text' => 'repo>RecentChangeFactoryTestUser',
                        'rc_type' => RC_EXTERNAL,
                        'rc_minor' => true, // for now, always consider these 
minor
                        'rc_bot' => false,
diff --git a/client/tests/phpunit/includes/WikibaseClientTest.php 
b/client/tests/phpunit/includes/WikibaseClientTest.php
index ca11a58..40cc078 100644
--- a/client/tests/phpunit/includes/WikibaseClientTest.php
+++ b/client/tests/phpunit/includes/WikibaseClientTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Client\Tests;
 
+use Wikibase\Client\RecentChanges\RecentChangeFactory;
 use Wikibase\Lib\DataTypeFactory;
 use Deserializers\Deserializer;
 use HashSiteStore;
@@ -41,6 +42,7 @@
 use Wikibase\Lib\WikibaseValueFormatterBuilders;
 use Wikibase\SettingsArray;
 use Wikibase\StringNormalizer;
+use Wikimedia\TestingAccessWrapper;
 
 /**
  * @covers Wikibase\Client\WikibaseClient
@@ -215,6 +217,13 @@
 
                $siteStore->saveSite( $site );
 
+               $site = new Site();
+               $site->setGlobalId( 'repo' );
+               $site->setGroup( 'wikipedia' );
+               $site->addInterwikiId( 'repointerwiki' );
+
+               $siteStore->saveSite( $site );
+
                return $siteStore;
        }
 
@@ -279,6 +288,14 @@
        public function testGetChangeHandler() {
                $handler = $this->getWikibaseClient()->getChangeHandler();
                $this->assertInstanceOf( ChangeHandler::class, $handler );
+       }
+
+       public function testGetRecentChangeFactory() {
+               $recentChangeFactory = 
$this->getWikibaseClient()->getRecentChangeFactory();
+               $this->assertInstanceOf( RecentChangeFactory::class, 
$recentChangeFactory );
+
+               $recentChangeFactory = TestingAccessWrapper::newFromObject( 
$recentChangeFactory );
+               $this->assertSame( [ 'repointerwiki' ], 
$recentChangeFactory->repoInterwikiPrefixes );
        }
 
        public function testGetParserFunctionRegistrant() {
@@ -358,7 +375,7 @@
                        new DataTypeDefinitions( [] ),
                        new EntityTypeDefinitions( [] ),
                        $this->getRepositoryDefinitions(),
-                       new HashSiteStore()
+                       $this->getSiteLookup()
                );
        }
 
@@ -367,7 +384,7 @@
         */
        private function getRepositoryDefinitions() {
                return new RepositoryDefinitions(
-                       [ '' => [ 'database' => '', 'base-uri' => '', 
'entity-namespaces' => [], 'prefix-mapping' => [] ] ]
+                       [ '' => [ 'database' => 'repo', 'base-uri' => '', 
'entity-namespaces' => [], 'prefix-mapping' => [] ] ]
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4644b249fc3f866419c54eb5f0e5c4c26ef39024
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>

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

Reply via email to