Aude has uploaded a new change for review.

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

Change subject: Remove usage of Wikibase\SiteLink in ItemView
......................................................................

Remove usage of Wikibase\SiteLink in ItemView

Change-Id: I93223fee4c1b7598baa49d3501e77672fbd3476e
---
M repo/includes/ItemView.php
1 file changed, 26 insertions(+), 33 deletions(-)


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

diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php
index 3d9ed9c..137a705 100644
--- a/repo/includes/ItemView.php
+++ b/repo/includes/ItemView.php
@@ -2,7 +2,12 @@
 
 namespace Wikibase;
 
-use Sites;
+use IContextSource;
+use SiteSQLStore;
+use Wikibase\DataModel\SiteLink;
+use Wikibase\Lib\PropertyDataTypeLookup;
+use Wikibase\Lib\Serializers\SerializationOptions;
+use Wikibase\Lib\SnakFormatter;
 use Wikibase\Repo\WikibaseRepo;
 
 /**
@@ -87,6 +92,8 @@
        /**
         * Builds and returns the HTML representing a group of a 
WikibaseEntity's site-links.
         *
+        * @todo: code in this function belongs in its own class!
+        *
         * @since 0.4
         *
         * @param Item $item the entity to render
@@ -95,26 +102,9 @@
         * @return string
         */
        public function getHtmlForSiteLinkGroup( Item $item, $group, $editable 
= true ) {
-               $allSiteLinks = $item->getSiteLinks();
+               $siteLinks = $item->getSiteLinks();
 
                $specialGroups = 
WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( 
"specialSiteLinkGroups" );
-
-               $siteLinks = array(); // site links of the currently handled 
site group
-
-               foreach( $allSiteLinks as $siteLink ) {
-                       // FIXME: depracted method usage
-                       $site = Sites::singleton()->getSite( 
$siteLink->getSiteId() );
-
-                       if ( $site === null ) {
-                               continue;
-                       }
-
-                       $link = new SiteLink( $site, $siteLink->getPageName() );
-
-                       if ( $site->getGroup() === $group ) {
-                               $siteLinks[] = $link;
-                       }
-               }
 
                $html = $thead = $tbody = $tfoot = '';
 
@@ -141,15 +131,12 @@
 
                $i = 0;
 
-               // Batch load the sites we need info about during the building 
of the sitelink list.
-               $sites = Sites::singleton()->getSiteGroup( $group );
-
                // Sort the sitelinks according to their global id
                $safetyCopy = $siteLinks; // keep a shallow copy;
                $sortOk = usort(
                        $siteLinks,
                        function( SiteLink $a, SiteLink $b ) {
-                               return strcmp( $a->getSite()->getGlobalId(), 
$b->getSite()->getGlobalId() );
+                               return strcmp( $a->getSiteId(), $b->getSiteId() 
);
                        }
                );
 
@@ -157,33 +144,39 @@
                        $siteLinks = $safetyCopy;
                }
 
+               // @todo inject into constructor
+               $sites = SiteSQLStore::newInstance()->getSites();
+
                // Link to SpecialPage
                $editLink = $this->getEditUrl( 'SetSiteLink', $item, null );
 
                /* @var SiteLink $link */
-               foreach( $siteLinks as $link ) {
+               foreach( $siteLinks as $siteLink ) {
                        $alternatingClass = ( $i++ % 2 ) ? 'even' : 'uneven';
 
-                       $site = $link->getSite();
+                       $siteId = $siteLink->getSiteId();
+                       $pageName = $siteLink->getPageName();
 
-                       if ( $site->getDomain() === '' ) {
+                       $site = $sites->getSite( $siteId );
+
+                       if ( !$site || $site->getDomain() === '' ) {
                                // the link is pointing to an unknown site.
                                // XXX: hide it? make it red? strike it out?
 
                                $tbody .= wfTemplate( 'wb-sitelink-unknown',
                                        $alternatingClass,
-                                       htmlspecialchars( 
$link->getSite()->getGlobalId() ),
-                                       htmlspecialchars( $link->getPage() ),
+                                       htmlspecialchars( $siteId ),
+                                       htmlspecialchars( 
$siteLink->getPageName() ),
                                        $this->getHtmlForEditSection( 
$editLink, 'td' )
                                );
 
                        } else {
                                $languageCode = $site->getLanguageCode();
-                               $escapedSiteId = htmlspecialchars( 
$site->getGlobalId() );
+                               $escapedSiteId = htmlspecialchars( $siteId );
                                // FIXME: this is a quickfix to allow a custom 
site-name for groups defined in $wgSpecialSiteLinkGroups instead of showing the 
language-name
                                if ( in_array( $group, $specialGroups ) ) {
-                                       $siteNameMsg = wfMessage( 
'wikibase-sitelinks-sitename-' . $site->getGlobalId() );
-                                       $siteName = $siteNameMsg->exists() ? 
$siteNameMsg->parse() : $site->getGlobalId();
+                                       $siteNameMsg = wfMessage( 
'wikibase-sitelinks-sitename-' . $siteId );
+                                       $siteName = $siteNameMsg->exists() ? 
$siteNameMsg->parse() : $siteId;
                                } else {
                                        // TODO: get an actual site name rather 
then just the language
                                        $siteName = htmlspecialchars( 
Utils::fetchLanguageName( $languageCode ) );
@@ -197,8 +190,8 @@
                                        $alternatingClass,
                                        $siteName,
                                        $escapedSiteId, // displayed site ID
-                                       htmlspecialchars( $link->getUrl() ),
-                                       htmlspecialchars( $link->getPage() ),
+                                       htmlspecialchars( $site->getPageUrl( 
$pageName ) ),
+                                       htmlspecialchars( $pageName ),
                                        $this->getHtmlForEditSection( $editLink 
. '/' . $escapedSiteId, 'td' ),
                                        $escapedSiteId // ID used in classes
                                );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I93223fee4c1b7598baa49d3501e77672fbd3476e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

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

Reply via email to