AnotherLadsgroup has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364623 )

Change subject: Add props parameter to SearchEntities API module
......................................................................

Add props parameter to SearchEntities API module

It's not a breaking change but we can easily turn off url now

Bug: T103875
Change-Id: I4f1f546042a03b578f4b6736060fca40c70f13fe
---
M repo/i18n/en.json
M repo/i18n/qqq.json
M repo/includes/Api/SearchEntities.php
M repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
4 files changed, 38 insertions(+), 5 deletions(-)


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

diff --git a/repo/i18n/en.json b/repo/i18n/en.json
index 60aaaec..cddcac8 100644
--- a/repo/i18n/en.json
+++ b/repo/i18n/en.json
@@ -569,12 +569,14 @@
        "apihelp-wbsearchentities-param-language": "Search in this language.",
        "apihelp-wbsearchentities-param-strictlanguage": "Whether to disable 
language fallback",
        "apihelp-wbsearchentities-param-type": "Search for this type of 
entity.",
+       "apihelp-wbsearchentities-param-props": "Return these properties for 
each entity.",
        "apihelp-wbsearchentities-param-limit": "Maximal number of results",
        "apihelp-wbsearchentities-param-continue": "Offset where to continue a 
search",
        "apihelp-wbsearchentities-example-1": "Search for \"abc\" in English 
language, with defaults for type and limit",
        "apihelp-wbsearchentities-example-2": "Search for \"abc\" in English 
language with a limit of 50",
        "apihelp-wbsearchentities-example-3": "Search for \"alphabet\" in 
English language for type property",
        "apihelp-wbsearchentities-example-4": "Search for \"abc\" in English 
language with a limit of 2 and an offset of 2",
+       "apihelp-wbsearchentities-example-5": "Search for \"alphabet\" in 
English language omitting url parameter",
        "apihelp-query+wbsearch-description": "Searches for entities using 
labels and aliases.\nThis can be used as a generator for other 
queries.\nReturns the matched term that should be displayed.",
        "apihelp-query+wbsearch-summary": "Searches for entities using labels 
and aliases.",
        "apihelp-query+wbsearch-extended-description": "This can be used as a 
generator for other queries.\nReturns the matched term that should be 
displayed.",
diff --git a/repo/i18n/qqq.json b/repo/i18n/qqq.json
index f5d9889..0eabbdf 100644
--- a/repo/i18n/qqq.json
+++ b/repo/i18n/qqq.json
@@ -602,12 +602,14 @@
        "apihelp-wbsearchentities-param-language": 
"{{doc-apihelp-param|wbsearchentities|language}}",
        "apihelp-wbsearchentities-param-strictlanguage": 
"{{doc-apihelp-param|wbsearchentities|strictlanguage|info = This message is 
used [https://www.wikidata.org/wiki/Special:ApiSandbox#action=wbsearchentities 
here] at param 3. If enabled only matches in the current language are shown}}",
        "apihelp-wbsearchentities-param-type": 
"{{doc-apihelp-param|wbsearchentities|type}}",
+       "apihelp-wbsearchentities-param-props": 
"{{doc-apihelp-param|wbsearchentities|props}}",
        "apihelp-wbsearchentities-param-limit": 
"{{doc-apihelp-param|wbsearchentities|limit}}",
        "apihelp-wbsearchentities-param-continue": 
"{{doc-apihelp-param|wbsearchentities|continue}}",
        "apihelp-wbsearchentities-example-1": 
"{{doc-apihelp-example|wbsearchentities}}",
        "apihelp-wbsearchentities-example-2": 
"{{doc-apihelp-example|wbsearchentities}}",
        "apihelp-wbsearchentities-example-3": 
"{{doc-apihelp-example|wbsearchentities}}",
        "apihelp-wbsearchentities-example-4": 
"{{doc-apihelp-example|wbsearchentities}}",
+       "apihelp-wbsearchentities-example-5": 
"{{doc-apihelp-example|wbsearchentities}}",
        "apihelp-query+wbsearch-description": 
"{{doc-apihelp-description|query+wbsearch}}",
        "apihelp-query+wbsearch-summary": 
"{{doc-apihelp-summary|query+wbsearch}}",
        "apihelp-query+wbsearch-extended-description": 
"{{doc-apihelp-extended-description|query+wbsearch}}",
diff --git a/repo/includes/Api/SearchEntities.php 
b/repo/includes/Api/SearchEntities.php
index afdbc6a..0131b72 100644
--- a/repo/includes/Api/SearchEntities.php
+++ b/repo/includes/Api/SearchEntities.php
@@ -103,7 +103,7 @@
                $entries = [];
 
                foreach ( $searchResults as $match ) {
-                       $entries[] = $this->buildTermSearchMatchEntry( $match );
+                       $entries[] = $this->buildTermSearchMatchEntry( $match, 
$params['props'] );
                }
 
                return $entries;
@@ -111,10 +111,11 @@
 
        /**
         * @param TermSearchResult $match
+        * @param string[] $props
         *
         * @return array
         */
-       private function buildTermSearchMatchEntry( TermSearchResult $match ) {
+       private function buildTermSearchMatchEntry( TermSearchResult $match, 
array $props = null ) {
                // TODO: use EntityInfoBuilder, EntityInfoTermLookup
                $entityId = $match->getEntityId();
                $title = $this->titleLookup->getTitleForId( $entityId );
@@ -123,11 +124,13 @@
                        'repository' => $entityId->getRepositoryName(),
                        'id' => $entityId->getSerialization(),
                        'concepturi' => $this->getConceptUri( $entityId ),
-                       'url' => $title->getFullURL(),
                        'title' => $title->getPrefixedText(),
                        'pageid' => $title->getArticleID()
                ];
 
+               if ( $props !== null && in_array( 'url', $props ) ) {
+                       $entry['url'] = $title->getFullUrl();
+               }
                if ( $entityId instanceof PropertyId ) {
                        $entry['datatype'] = $this->propertyDataTypeLookup
                                ->getDataTypeIdForProperty( $entityId );
@@ -290,6 +293,11 @@
                                self::PARAM_REQUIRED => false,
                                self::PARAM_DFLT => 0
                        ],
+                       'props' => [
+                               self::PARAM_TYPE => [ 'url' ],
+                               ApiBase::PARAM_ISMULTI => true,
+                               self::PARAM_DFLT => 'url',
+                   ]
                ];
        }
 
@@ -306,6 +314,8 @@
                                'apihelp-wbsearchentities-example-4',
                        
'action=wbsearchentities&search=alphabet&language=en&type=property' =>
                                'apihelp-wbsearchentities-example-3',
+                       
'action=wbsearchentities&search=alphabet&language=en&props=' =>
+                               'apihelp-wbsearchentities-example-5',
                ];
        }
 
diff --git a/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php 
b/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
index 9716691..f374666 100644
--- a/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
+++ b/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
@@ -291,6 +291,21 @@
                        ],
                ];
 
+               $q333ResultWithoutUrl = [
+                       'repository' => '',
+                       'id' => 'Q333',
+                       'concepturi' => 'http://acme.test/concept/Q333',
+                       'title' => 'Prefixed:Title',
+                       'pageid' => 42,
+                       'label' => 'ADisplayLabel',
+                       'aliases' => [ 'AMatchedTerm' ],
+                       'match' => [
+                               'type' => 'alias',
+                               'language' => 'de',
+                               'text' => 'AMatchedTerm',
+                       ],
+               ];
+
                return [
                        'No exact match' => [
                                [ 'search' => 'Q999' ],
@@ -326,7 +341,12 @@
                                [ 'search' => 'PropertyLabel', 'type' => 
'property' ],
                                [ $propertyMatch ],
                                [ $propertyResult ],
-                       ]
+                       ],
+                       'URL is omitted' => [
+                               [ 'search' => 'Q333', 'props' => '' ],
+                               [ $q333Match ],
+                               [ $q333ResultWithoutUrl ],
+                       ],
                ];
        }
 
@@ -359,7 +379,6 @@
                        $this->assertArrayHasKey( 'repository', $searchresult );
                        $this->assertArrayHasKey( 'id', $searchresult );
                        $this->assertArrayHasKey( 'concepturi', $searchresult );
-                       $this->assertArrayHasKey( 'url', $searchresult );
                        $this->assertArrayHasKey( 'title', $searchresult );
                        $this->assertArrayHasKey( 'pageid', $searchresult );
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f1f546042a03b578f4b6736060fca40c70f13fe
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: AnotherLadsgroup <ladsgr...@gmail.com>

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

Reply via email to