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

Change subject: Do not expect items in SpecialEntityUsage
......................................................................


Do not expect items in SpecialEntityUsage

See discussion in I4cddb3d. Discussed with Daniel. He confirms this is
correct and the special page should work for all entity types.

Bug: T144923
Change-Id: Ia4c9154a37d7a2f258ca08a75c16f13f855c4627
---
M client/includes/Specials/SpecialEntityUsage.php
M client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
2 files changed, 47 insertions(+), 24 deletions(-)

Approvals:
  Ladsgroup: Looks good to me, but someone else must approve
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/includes/Specials/SpecialEntityUsage.php 
b/client/includes/Specials/SpecialEntityUsage.php
index 9d97ba8..0820dec 100644
--- a/client/includes/Specials/SpecialEntityUsage.php
+++ b/client/includes/Specials/SpecialEntityUsage.php
@@ -4,16 +4,19 @@
 
 use HTMLForm;
 use Html;
-use InvalidArgumentException;
 use Linker;
 use QueryPage;
 use Skin;
 use Title;
 use Wikibase\Client\Usage\EntityUsage;
-use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\Client\WikibaseClient;
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\EntityIdParser;
+use Wikibase\DataModel\Entity\EntityIdParsingException;
 
 /**
- * Get usage of any given entity.
+ * A special page that lists client wiki pages that use a given entity ID from 
the repository, and
+ * which aspects each page uses.
  *
  * @since 0.5
  *
@@ -23,9 +26,14 @@
 class SpecialEntityUsage extends QueryPage {
 
        /**
-        * @var ItemId|null
+        * @var EntityIdParser
         */
-       private $entityId;
+       private $idParser;
+
+       /**
+        * @var EntityId|null
+        */
+       private $entityId = null;
 
        /**
         * @see SpecialPage::__construct
@@ -34,6 +42,9 @@
         */
        public function __construct( $name = 'EntityUsage' ) {
                parent::__construct( $name );
+
+               // TODO: Inject.
+               $this->idParser = 
WikibaseClient::getDefaultInstance()->getEntityIdParser();
        }
 
        /**
@@ -53,13 +64,16 @@
                }
        }
 
+       /**
+        * @param string $subPage
+        */
        private function prepareParams( $subPage ) {
                $entity = $this->getRequest()->getText( 'entity', $subPage );
 
                if ( $entity ) {
                        try {
-                               $this->entityId = new ItemId( $entity );
-                       } catch ( InvalidArgumentException $ex ) {
+                               $this->entityId = $this->idParser->parse( 
$entity );
+                       } catch ( EntityIdParsingException $ex ) {
                                $this->getOutput()->addHTML(
                                        Html::element(
                                                'p',
@@ -76,7 +90,7 @@
        /**
         * @see QueryPage::getPageHeader
         *
-        * @return string
+        * @return string HTML
         */
        public function getPageHeader() {
                $formDescriptor = [
@@ -141,26 +155,36 @@
         * @see QueryPage::formatResult
         *
         * @param Skin $skin
-        * @param object $result
+        * @param object $row
         *
-        * @return string
+        * @return string HTML
         */
        public function formatResult( $skin, $row ) {
                global $wgContLang;
 
                $title = Title::makeTitleSafe( $row->namespace, $row->title );
-               $aspects = $this->formatAspects( $row->aspects );
-               if ( $title instanceof Title ) {
-                       $text = $wgContLang->convert( $title->getPrefixedText() 
);
-                       return Linker::link( $title, htmlspecialchars( $text ) 
) . ': ' . $aspects;
-               } else {
-                       return Html::element( 'span', [ 'class' => 
'mw-invalidtitle' ],
-                               Linker::getInvalidTitleDescription( 
$this->getContext(), $row->namespace, $row->title ) );
+
+               if ( !$title ) {
+                       return Html::element(
+                               'span',
+                               [ 'class' => 'mw-invalidtitle' ],
+                               Linker::getInvalidTitleDescription(
+                                       $this->getContext(),
+                                       $row->namespace,
+                                       $row->title
+                               )
+                       );
                }
+
+               return Linker::link(
+                       $title,
+                       htmlspecialchars( $wgContLang->convert( 
$title->getPrefixedText() ) )
+               ) . ': ' . $this->formatAspects( $row->aspects );
        }
 
        /**
         * @param string $rowAspects
+        *
         * @return string
         */
        public function formatAspects( $rowAspects ) {
@@ -197,7 +221,7 @@
        /**
         * @see QueryPage::linkParameters
         *
-        * @return array
+        * @return string[]
         */
        public function linkParameters() {
                return [ 'entity' => $this->entityId->getSerialization() ];
diff --git a/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php 
b/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
index 7e5d933..e3daa05 100644
--- a/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
+++ b/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
@@ -21,10 +21,6 @@
  */
 class SpecialEntityUsageTest extends SpecialPageTestBase {
 
-       protected function setUp() {
-               parent::setUp();
-       }
-
        public function reallyDoQueryMock() {
                $rows = [
                        (object)[
@@ -36,10 +32,13 @@
                                'eu_entity_id' => 'Q3',
                        ],
                ];
-               $res = new FakeResultWrapper( $rows );
-               return $res;
+
+               return new FakeResultWrapper( $rows );
        }
 
+       /**
+        * @return SpecialEntityUsage
+        */
        protected function newSpecialPage() {
                $specialPage = $this->getMockBuilder( SpecialEntityUsage::class 
)
                        ->setMethods( [ 'reallyDoQuery' ] )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia4c9154a37d7a2f258ca08a75c16f13f855c4627
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchane...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@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