Hoo man has uploaded a new change for review.

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


Change subject: Allow (optional) title normalization in wbgetentities
......................................................................

Allow (optional) title normalization in wbgetentities

Change-Id: I1d010e5d5e07209f23c93636163f722d0d247a29
---
M repo/includes/api/GetEntities.php
1 file changed, 23 insertions(+), 2 deletions(-)


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

diff --git a/repo/includes/api/GetEntities.php 
b/repo/includes/api/GetEntities.php
index 9969088..694bd24 100644
--- a/repo/includes/api/GetEntities.php
+++ b/repo/includes/api/GetEntities.php
@@ -13,6 +13,7 @@
 use Wikibase\EntityId;
 use Wikibase\Item;
 use Wikibase\EntityContentFactory;
+use Wikibase\Settings;
 
 /**
  * API module to get the data for one or more Wikibase entities.
@@ -26,6 +27,7 @@
  * @licence GNU GPL v2+
  * @author John Erling Blad < [email protected] >
  * @author Jeroen De Dauw < [email protected] >
+ * @author Marius Hoch < [email protected] >
  */
 class GetEntities extends ApiWikibase {
 
@@ -49,6 +51,7 @@
                        $numSites = count( $params['sites'] );
                        $numTitles = count( $params['titles'] );
                        $max = max( $numSites, $numTitles );
+
                        if ( $numSites === 0 || $numTitles === 0 ) {
                                wfProfileOut( __METHOD__ );
                                $this->dieUsage( $this->msg( 
'wikibase-api-ids-xor-wikititles' )->text(), 'id-xor-wikititle' );
@@ -63,12 +66,23 @@
 
                                        $id = 
StoreFactory::getStore()->newSiteLinkCache()->getItemIdForLink( $siteId, $title 
);
 
+                                       // Try harder by requesting 
normalization on the external site.
+                                       // For performance reasons we only do 
this if the user asked for it and only for one title!
+                                       if ( $id === false && $numSites === 1 
&& $numTitles === 1 && $params['normalize'] === true
+                                               && Settings::get( 
'normalizeItemByTitlePageNames' ) === true )
+                                       {
+                                               $siteObj = 
\SiteSQLStore::newInstance()->getSite( $siteId );
+                                               if ( $siteObj ) {
+                                                       $title = 
$siteObj->normalizePageName( $title );
+                                                       $id = 
StoreFactory::getStore()->newSiteLinkCache()->getItemIdForLink( $siteId, $title 
);
+                                               }
+                                       }
+
                                        if ( $id === false ) {
                                                $this->getResult()->addValue( 
'entities', (string)(--$missing),
                                                        array( 'site' => 
$siteId, 'title' => $title, 'missing' => "" )
                                                );
-                                       }
-                                       else {
+                                       } else {
                                                $id = new EntityId( 
Item::ENTITY_TYPE, $id );
                                                $params['ids'][] = 
$id->getPrefixedId();
                                        }
@@ -247,6 +261,10 @@
                                ApiBase::PARAM_TYPE => 
Utils::getLanguageCodes(),
                                ApiBase::PARAM_ISMULTI => true,
                        ),
+                       'normalize' => array(
+                               ApiBase::PARAM_TYPE => 'boolean',
+                               ApiBase::PARAM_DFLT => false
+                       ),
                ) );
        }
 
@@ -276,6 +294,9 @@
                        'languages' => array( 'By default the internationalized 
values are returned in all available languages.',
                                'This parameter allows filtering these down to 
one or more languages by providing one or more language codes.'
                        ),
+                       'normalize' => array( 'Try to normalize the page title 
against the client site.',
+                               'This only works if exactly one site and one 
page have been given.'
+                       ),
                ) );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1d010e5d5e07209f23c93636163f722d0d247a29
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

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

Reply via email to