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

Change subject: Expose identifiers on Special:ListProperties
......................................................................


Expose identifiers on Special:ListProperties

Bug: T107882
Change-Id: I72416188d3d3545ff985d23b48ae15ae65f30627
---
M repo/includes/specials/SpecialListProperties.php
M repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
2 files changed, 71 insertions(+), 9 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/specials/SpecialListProperties.php 
b/repo/includes/specials/SpecialListProperties.php
index 4ee3492..d459176 100644
--- a/repo/includes/specials/SpecialListProperties.php
+++ b/repo/includes/specials/SpecialListProperties.php
@@ -4,9 +4,14 @@
 
 use DataTypes\DataTypeFactory;
 use Html;
+use OutOfBoundsException;
+use Title;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
 use Wikibase\DataTypeSelector;
+use Wikibase\Lib\Store\EntityTitleLookup;
+use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookup;
 use Wikibase\PropertyInfoStore;
 use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
 use Wikibase\Repo\WikibaseRepo;
@@ -18,6 +23,7 @@
  * @since 0.5
  * @licence GNU GPL v2+
  * @author Bene* < [email protected] >
+ * @author Adam Shorland
  */
 class SpecialListProperties extends SpecialWikibaseQueryPage {
 
@@ -49,6 +55,11 @@
        private $labelDescriptionLookupFactory;
 
        /**
+        * @var LanguageFallbackLabelDescriptionLookup
+        */
+       private $labelDescriptionLookup;
+
+       /**
         * @var string
         */
        private $dataType;
@@ -63,6 +74,11 @@
         */
        private $entityIdFormatter;
 
+       /**
+        * @var EntityTitleLookup
+        */
+       private $titleLookup;
+
        public function __construct() {
                parent::__construct( 'ListProperties' );
 
@@ -72,7 +88,8 @@
                        $wikibaseRepo->getDataTypeFactory(),
                        $wikibaseRepo->getStore()->getPropertyInfoStore(),
                        $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory(),
-                       
$wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()
+                       
$wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory(),
+                       $wikibaseRepo->getEntityTitleLookup()
                );
        }
 
@@ -84,12 +101,14 @@
                DataTypeFactory $dataTypeFactory,
                PropertyInfoStore $propertyInfoStore,
                EntityIdFormatterFactory $entityIdFormatterFactory,
-               LanguageFallbackLabelDescriptionLookupFactory 
$labelDescriptionLookupFactory
+               LanguageFallbackLabelDescriptionLookupFactory 
$labelDescriptionLookupFactory,
+               EntityTitleLookup $titleLookup
        ) {
                $this->dataTypeFactory = $dataTypeFactory;
                $this->propertyInfoStore = $propertyInfoStore;
                $this->entityIdFormatterFactory = $entityIdFormatterFactory;
                $this->labelDescriptionLookupFactory = 
$labelDescriptionLookupFactory;
+               $this->titleLookup = $titleLookup;
        }
 
        /**
@@ -192,18 +211,60 @@
         * @return string
         */
        protected function formatRow( $propertyId ) {
-               $entityIdFormatter = $this->getEntityIdFormatter();
-               return $entityIdFormatter->formatEntityId( $propertyId );
+               $labelDescriptionLookup = $this->getLabelDescriptionLookup();
+
+               $title = $this->titleLookup->getTitleForId( $propertyId );
+               if ( !$title->exists() ) {
+                       return $this->getEntityIdFormater()->formatEntityId( 
$propertyId );
+               }
+
+               $row = $this->getIdHtml( $propertyId, $title );
+               try {
+                       $label = $labelDescriptionLookup->getLabel( $propertyId 
)->getText();
+                       $row .= wfMessage( 'colon-separator' )->escaped() . 
$label;
+               } catch ( OutOfBoundsException $e ) {
+                       // If there is no label do not add it
+               }
+
+               return $row;
        }
 
-       private function getEntityIdFormatter() {
-               if ( !isset( $this->entityIdFormatter ) ) {
-                       $labelDescriptionLookup = 
$this->labelDescriptionLookupFactory->newLabelDescriptionLookup(
+       /**
+        * Returns HTML representing the label in the display language (or an 
appropriate fallback).
+        *
+        * @param EntityId|null $entityId
+        * @param Title|null $title
+        *
+        * @return string HTML
+        */
+       private function getIdHtml( EntityId $entityId = null, $title ) {
+               $idElement =  Html::element(
+                       'a',
+                       array(
+                               'title' => $title ? $title->getPrefixedText() : 
$entityId->getSerialization(),
+                               'href' => $title ? $title->getLocalURL() : '',
+                               'class' => 'wb-itemlink-id'
+                       ),
+                       $entityId->getSerialization()
+               );
+
+               return $idElement;
+       }
+
+       private function getLabelDescriptionLookup() {
+               if ( !isset( $this->labelDescriptionLookup ) ) {
+                       $this->labelDescriptionLookup = 
$this->labelDescriptionLookupFactory->newLabelDescriptionLookup(
                                $this->getLanguage(),
                                $this->propertyIds
                        );
+               }
+               return $this->labelDescriptionLookup;
+       }
+
+       private function getEntityIdFormater() {
+               if ( !isset( $this->entityIdFormatter ) ) {
                        $this->entityIdFormatter = 
$this->entityIdFormatterFactory->getEntityIdFormater(
-                               $labelDescriptionLookup
+                               $this->getLabelDescriptionLookup()
                        );
                }
                return $this->entityIdFormatter;
diff --git a/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php 
b/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
index af68701..06d72e2 100644
--- a/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
@@ -119,7 +119,8 @@
                                new LanguageFallbackChainFactory(),
                                $this->getTermLookup(),
                                $this->getTermBuffer()
-                       )
+                       ),
+                       $this->getEntityTitleLookup()
                );
 
                return $specialPage;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I72416188d3d3545ff985d23b48ae15ae65f30627
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Bene <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to