Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371638 )

Change subject: Add badges suppport to NewItem::withSiteLink and andSiteLink
......................................................................

Add badges suppport to NewItem::withSiteLink and andSiteLink

I wrote this because I wanted to use it in the client directory, but
then realized I should not introduce a dependency between repo and
client. I know we will need this feature for sure so I'm submitting it
now even if it is currently unused.

No tests because this is a test-only class that basically tests itself
when it is used.

Change-Id: I056b21d85231a8e05a2b582267c2bbc6e7a63fc4
---
M repo/tests/phpunit/includes/NewItem.php
1 file changed, 15 insertions(+), 7 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/NewItem.php 
b/repo/tests/phpunit/includes/NewItem.php
index 8364c8f..5cfbcf8 100644
--- a/repo/tests/phpunit/includes/NewItem.php
+++ b/repo/tests/phpunit/includes/NewItem.php
@@ -4,6 +4,7 @@
 
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\SiteLink;
 use Wikibase\DataModel\Snak\Snak;
 use Wikibase\DataModel\Statement\Statement;
 
@@ -33,7 +34,7 @@
        private $aliases = [];
 
        /**
-        * @var string[] Indexed by global site ID
+        * @var SiteLink[]
         */
        private $siteLinks = [];
 
@@ -72,8 +73,8 @@
                foreach ( $this->aliases as $language => $aliases ) {
                        $item->setAliases( $language, $aliases );
                }
-               foreach ( $this->siteLinks as $siteId => $pageName ) {
-                       $item->getSiteLinkList()->addNewSiteLink( $siteId, 
$pageName );
+               foreach ( $this->siteLinks as $siteLink ) {
+                       $item->getSiteLinkList()->addSiteLink( $siteLink );
                }
                foreach ( $this->statements as $statement ) {
                        $item->getStatements()->addStatement( $statement );
@@ -163,19 +164,26 @@
        /**
         * @see andSiteLink
         */
-       public static function withSiteLink( $siteId, $pageName ) {
-               return ( new self() )->andSiteLink( $siteId, $pageName );
+       public static function withSiteLink( $siteId, $pageName, $badges = null 
) {
+               return ( new self() )->andSiteLink( $siteId, $pageName, $badges 
);
        }
 
        /**
         * @param string $siteId
         * @param string $pageName
+        * @param ItemId[]|string[]|ItemId|string|null $badges Zero or more 
item ID references as either
+        *  strings or ItemId objects. Can be an array or a single value.
         *
         * @return self
         */
-       public function andSiteLink( $siteId, $pageName ) {
+       public function andSiteLink( $siteId, $pageName, $badges = null ) {
                $copy = clone $this;
-               $copy->siteLinks[$siteId] = $pageName;
+               if ( $badges !== null ) {
+                       $badges = array_map( function ( $badge ) {
+                               return $badge instanceof ItemId ? $badge : new 
ItemId( $badge );
+                       }, (array)$badges );
+               }
+               $copy->siteLinks[] = new SiteLink( $siteId, $pageName, $badges 
);
                return $copy;
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I056b21d85231a8e05a2b582267c2bbc6e7a63fc4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to