Aude has uploaded a new change for review.

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

Change subject: Split SearchEntities foreach block into separate method
......................................................................

Split SearchEntities foreach block into separate method

Change-Id: I60c4b2a97411ba350bd79fc809b1374c3a90ab64
---
M repo/includes/api/SearchEntities.php
1 file changed, 63 insertions(+), 42 deletions(-)


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

diff --git a/repo/includes/api/SearchEntities.php 
b/repo/includes/api/SearchEntities.php
index 498394e..14ee638 100644
--- a/repo/includes/api/SearchEntities.php
+++ b/repo/includes/api/SearchEntities.php
@@ -122,48 +122,66 @@
                );
 
                $entries = array();
+
                foreach ( $searchResults as $match ) {
-                       //TODO: use EntityInfoBuilder, EntityInfoTermLookup
-                       $title = $this->titleLookup->getTitleForId( 
$match->getEntityId() );
-                       $entry = array(
-                               'id' => 
$match->getEntityId()->getSerialization(),
-                               'concepturi' => $this->conceptBaseUri . 
$match->getEntityId()->getSerialization(),
-                               'url' => $title->getFullUrl(),
-                               'title' => $title->getPrefixedText(),
-                               'pageid' => $title->getArticleID()
-                       );
-                       $displayLabel = $match->getDisplayLabel();
-                       if ( !is_null( $displayLabel ) ) {
-                               $entry['label'] = $displayLabel->getText();
-                       }
-                       $displayDescription = $match->getDisplayDescription();
-                       if ( !is_null( $displayDescription ) ) {
-                               $entry['description'] = 
$displayDescription->getText();
-                       }
-                       $entry['match']['type'] = $match->getMatchedTermType();
-
-                       //Special handling for 'entityId's as these are not 
actually Term objects
-                       if ( $entry['match']['type'] === 'entityId' ) {
-                               $entry['match']['text'] = $entry['id'];
-                               $entry['aliases'] = array( $entry['id'] );
-                       } else {
-                               $matchedTerm = $match->getMatchedTerm();
-                               $matchedTermText = $matchedTerm->getText();
-                               $entry['match']['language'] = 
$matchedTerm->getLanguageCode();
-                               $entry['match']['text'] = $matchedTermText;
-
-                               /**
-                                * Add matched terms to the aliases key in the 
result to give some context for the matched Term
-                                * if the matched term is different to the 
alias.
-                                * XXX: This appears odd but is used in the UI 
/ Entity suggesters
-                                */
-                               if ( !array_key_exists( 'label', $entry ) || 
$matchedTermText != $entry['label'] ) {
-                                       $entry['aliases'] = array( 
$matchedTerm->getText() );
-                               }
-                       }
-                       $entries[] = $entry;
+                       $entries[] = $this->buildTermSearchMatchEntry( $match );
                }
+
                return $entries;
+       }
+
+       /**
+        * @param TermSearchResult $match
+        *
+        * @return array
+        */
+       private function buildTermSearchMatchEntry( $match ) {
+               // TODO: use EntityInfoBuilder, EntityInfoTermLookup
+               $title = $this->titleLookup->getTitleForId( 
$match->getEntityId() );
+
+               $entry = array(
+                       'id' => $match->getEntityId()->getSerialization(),
+                       'concepturi' => $this->conceptBaseUri . 
$match->getEntityId()->getSerialization(),
+                       'url' => $title->getFullUrl(),
+                       'title' => $title->getPrefixedText(),
+                       'pageid' => $title->getArticleID()
+               );
+
+               $displayLabel = $match->getDisplayLabel();
+
+               if ( !is_null( $displayLabel ) ) {
+                       $entry['label'] = $displayLabel->getText();
+               }
+
+               $displayDescription = $match->getDisplayDescription();
+
+               if ( !is_null( $displayDescription ) ) {
+                       $entry['description'] = $displayDescription->getText();
+               }
+
+               $entry['match']['type'] = $match->getMatchedTermType();
+
+               // Special handling for 'entityId's as these are not actually 
Term objects
+               if ( $entry['match']['type'] === 'entityId' ) {
+                       $entry['match']['text'] = $entry['id'];
+                       $entry['aliases'] = array( $entry['id'] );
+               } else {
+                       $matchedTerm = $match->getMatchedTerm();
+                       $matchedTermText = $matchedTerm->getText();
+                       $entry['match']['language'] = 
$matchedTerm->getLanguageCode();
+                       $entry['match']['text'] = $matchedTermText;
+
+                       /**
+                        * Add matched terms to the aliases key in the result 
to give some context
+                        * for the matched Term if the matched term is 
different to the alias.
+                        * XXX: This appears odd but is used in the UI / Entity 
suggesters
+                        */
+                       if ( !array_key_exists( 'label', $entry ) || 
$matchedTermText != $entry['label'] ) {
+                               $entry['aliases'] = array( 
$matchedTerm->getText() );
+                       }
+               }
+
+               return $entry;
        }
 
        /**
@@ -264,9 +282,12 @@
         */
        protected function getExamplesMessages() {
                return array(
-                       'action=wbsearchentities&search=abc&language=en' => 
'apihelp-wbsearchentities-example-1',
-                       
'action=wbsearchentities&search=abc&language=en&limit=50' => 
'apihelp-wbsearchentities-example-2',
-                       
'action=wbsearchentities&search=alphabet&language=en&type=property' => 
'apihelp-wbsearchentities-example-3',
+                       'action=wbsearchentities&search=abc&language=en' =>
+                               'apihelp-wbsearchentities-example-1',
+                       
'action=wbsearchentities&search=abc&language=en&limit=50' =>
+                               'apihelp-wbsearchentities-example-2',
+                       
'action=wbsearchentities&search=alphabet&language=en&type=property' =>
+                               'apihelp-wbsearchentities-example-3',
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I60c4b2a97411ba350bd79fc809b1374c3a90ab64
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