jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/348110 )

Change subject: Show supported data formats in Special:EntityData
......................................................................


Show supported data formats in Special:EntityData

Bug: T162870
Change-Id: I1d1124611f0a95cc24473ed0d84fd8e7ebd2effe
---
M repo/i18n/en.json
M repo/i18n/qqq.json
M repo/includes/Specials/SpecialEntityData.php
M repo/tests/phpunit/includes/Specials/SpecialEntityDataTest.php
4 files changed, 52 insertions(+), 11 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/i18n/en.json b/repo/i18n/en.json
index eb628bc..39aa9d9 100644
--- a/repo/i18n/en.json
+++ b/repo/i18n/en.json
@@ -300,7 +300,7 @@
        "wikibase-entitydata-unsupported-format": "The data format $1 is not 
supported by this interface.",
        "wikibase-entitydata-storage-error": "Failed to load entity $1.",
        "wikibase-entitydata-title": "Entity Data",
-       "wikibase-entitydata-text": "This page provides a linked data interface 
to entity values. Please provide the entity ID in the URL, using subpage 
syntax.\n* Content negotiation applies based on you client's Accept header. 
This means that the entity data will be provided in the format preferred by 
your client. For a web browser, this will be HTML, causing your browser to be 
redirected to the regular entity page.\n* You can explicitly request a specific 
data format by adding the appropriate file extension to the entity ID: Q23.json 
will return data in the JSON format, Q23.ttl will return RDF/Turtle, and so 
on.",
+       "wikibase-entitydata-text": "This page provides a linked data interface 
to entity values. Please provide the entity ID in the URL, using subpage 
syntax.\n* Content negotiation applies based on you client's Accept header. 
This means that the entity data will be provided in the format preferred by 
your client. For a web browser, this will be HTML, causing your browser to be 
redirected to the regular entity page.\n* You can explicitly request a specific 
data format by adding the appropriate file extension to the entity ID: Q23.json 
will return data in the JSON format, Q23.ttl will return RDF/Turtle, and so on. 
Supported formats are: $1.",
        "special-entitypage": "Entity page",
        "wikibase-entitypage-title": "Entity Page",
        "wikibase-entitypage-text": "This page redirects to the entity page on 
the repository it belongs to. Please provide the entity ID in the URL, using 
subpage syntax.",
diff --git a/repo/i18n/qqq.json b/repo/i18n/qqq.json
index 8fb3d5c..308cc4e 100644
--- a/repo/i18n/qqq.json
+++ b/repo/i18n/qqq.json
@@ -332,7 +332,7 @@
        "wikibase-entitydata-unsupported-format": "Error shown when the 
requested output format is not supported for entity data (HTTP error 
415).\n\nParameters:\n* $1 - the specified data format name",
        "wikibase-entitydata-storage-error": "Error shown when the requested 
entity could not be loaded.\n\nParameters:\n* $1 - entity ID\n* $2 - (Unused) 
revision ID\nSee also:\n* {{msg-mw|Wikibase-entitydata-bad-revision}}",
        "wikibase-entitydata-title": "Title shown on the special page when a 
form or text is presented",
-       "wikibase-entitydata-text": "Explanatory text shown on the special 
page.",
+       "wikibase-entitydata-text": "Explanatory text shown on the special 
page.\n* $1: List of supported formats",
        "special-entitypage": "{{doc-special|EntityPage}}\nThis special page 
redirects to the actual entity page on the repository the entity belongs to.",
        "wikibase-entitypage-title": "Title shown on Special:EntityPage when 
the explanatory text is presented",
        "wikibase-entitypage-text": "Explanatory text shown on 
Special:EntityPage when no ID has been provided.",
diff --git a/repo/includes/Specials/SpecialEntityData.php 
b/repo/includes/Specials/SpecialEntityData.php
index 82f680e..fa2cdaf 100644
--- a/repo/includes/Specials/SpecialEntityData.php
+++ b/repo/includes/Specials/SpecialEntityData.php
@@ -30,8 +30,15 @@
         */
        private $requestHandler = null;
 
+       /**
+        * @var EntityDataFormatProvider|null
+        */
+       private $entityDataFormatProvider = null;
+
        public function __construct() {
                parent::__construct( 'EntityData' );
+
+               $this->entityDataFormatProvider = new 
EntityDataFormatProvider();
        }
 
        /**
@@ -75,8 +82,6 @@
                $titleLookup = $wikibaseRepo->getEntityTitleLookup();
                $entityIdParser = $wikibaseRepo->getEntityIdParser();
 
-               $entityDataFormatProvider = new EntityDataFormatProvider();
-
                $serializerFactoryOptions = 
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH +
                        
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH;
 
@@ -91,7 +96,7 @@
                        $wikibaseRepo->getValueSnakRdfBuilderFactory(),
                        $wikibaseRepo->getEntityRdfBuilderFactory(),
                        $wikibaseRepo->getSiteLookup()->getSites(),
-                       $entityDataFormatProvider,
+                       $this->entityDataFormatProvider,
                        $serializerFactory,
                        $wikibaseRepo->getEntitySerializer( 
$serializerFactoryOptions ),
                        $wikibaseRepo->getSiteLookup(),
@@ -100,15 +105,15 @@
 
                $maxAge = $wikibaseRepo->getSettings()->getSetting( 
'dataSquidMaxage' );
                $formats = $wikibaseRepo->getSettings()->getSetting( 
'entityDataFormats' );
-               $entityDataFormatProvider->setFormatWhiteList( $formats );
+               $this->entityDataFormatProvider->setFormatWhiteList( $formats );
 
                $defaultFormat = empty( $formats ) ? 'html' : $formats[0];
 
                // build a mapping of formats to file extensions and include 
HTML
                $supportedExtensions = array();
                $supportedExtensions['html'] = 'html';
-               foreach ( $entityDataFormatProvider->getSupportedFormats() as 
$format ) {
-                       $ext = $entityDataFormatProvider->getExtension( $format 
);
+               foreach ( 
$this->entityDataFormatProvider->getSupportedFormats() as $format ) {
+                       $ext = $this->entityDataFormatProvider->getExtension( 
$format );
 
                        if ( $ext !== null ) {
                                $supportedExtensions[$format] = $ext;
@@ -128,7 +133,7 @@
                        $entityRevisionLookup,
                        $entityRedirectLookup,
                        $serializationService,
-                       $entityDataFormatProvider,
+                       $this->entityDataFormatProvider,
                        $defaultFormat,
                        $maxAge,
                        $wgUseSquid,
@@ -162,7 +167,24 @@
        public function showForm() {
                //TODO: show input form with selector for format and field for 
ID. Add some explanation,
                //      point to meta-info like schema and license, and 
generally be a helpful data endpoint.
-               $this->getOutput()->showErrorPage( 'wikibase-entitydata-title', 
'wikibase-entitydata-text' );
+               $supportedFormats = 
$this->entityDataFormatProvider->getSupportedExtensions();
+               $supportedFormats[] = 'html';
+               $this->getOutput()->showErrorPage(
+                       'wikibase-entitydata-title',
+                       'wikibase-entitydata-text',
+                       [ $this->getOutput()->getLanguage()->commaList( 
$supportedFormats ) ]
+               );
+       }
+
+       /**
+        * @param EntityDataFormatProvider $entityDataFormatProvider
+        *
+        * TODO: Inject them
+        */
+       public function setEntityDataFormatProvider(
+               EntityDataFormatProvider $entityDataFormatProvider
+       ) {
+               $this->entityDataFormatProvider = $entityDataFormatProvider;
        }
 
 }
diff --git a/repo/tests/phpunit/includes/Specials/SpecialEntityDataTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialEntityDataTest.php
index fbee6da..20823c3 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialEntityDataTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialEntityDataTest.php
@@ -5,6 +5,7 @@
 use DataValues\Serializers\DataValueSerializer;
 use FauxRequest;
 use FauxResponse;
+use Language;
 use HashSiteStore;
 use HttpError;
 use OutputPage;
@@ -52,6 +53,7 @@
                $page->getContext()->setOutput( new OutputPage( 
$page->getContext() ) );
 
                $page->setRequestHandler( $this->newRequestHandler() );
+               $page->setEntityDataFormatProvider( 
$this->newEntityDataFormatProvider() );
 
                return $page;
        }
@@ -141,7 +143,6 @@
                                $cases[$n][5] = array(); // response headers
                        }
                }
-
                return $cases;
        }
 
@@ -189,4 +190,22 @@
                }
        }
 
+       private function newEntityDataFormatProvider() {
+               $entityDataFormatProvider = new EntityDataFormatProvider();
+               $entityDataFormatProvider->setFormatWhiteList( [ 'json', 
'rdfxml', 'ntriples' ] );
+
+               return $entityDataFormatProvider;
+       }
+
+       public function testEntityDataFormatProvider() {
+               $this->setContentLang( Language::factory( 'en' ) );
+               $request = new FauxRequest();
+               $request->response()->header( 'Status: 200 OK', true, 200 ); // 
init/reset
+
+               list( $output, ) = $this->executeSpecialPage( '', $request );
+
+               $this->assertRegExp( '/Supported formats are: json, nt, rdf, 
html/', $output, "output" );
+
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1d1124611f0a95cc24473ed0d84fd8e7ebd2effe
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to