jenkins-bot has submitted this change and it was merged.
Change subject: Use combobox field in Special:ItemByTitle
......................................................................
Use combobox field in Special:ItemByTitle
Instead of a jQuery-UI-based suggester
Change-Id: Ifcbf53ba69fbf65e05a774a6cf99f3640ff31d79
---
M repo/includes/Specials/SpecialItemByTitle.php
M repo/resources/Resources.php
D repo/resources/wikibase.special/wikibase.special.itemByTitle.js
M repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
4 files changed, 70 insertions(+), 66 deletions(-)
Approvals:
Hoo man: Looks good to me, but someone else must approve
Jonas Kress (WMDE): Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/includes/Specials/SpecialItemByTitle.php
b/repo/includes/Specials/SpecialItemByTitle.php
index 7afabcd..3a4178f 100644
--- a/repo/includes/Specials/SpecialItemByTitle.php
+++ b/repo/includes/Specials/SpecialItemByTitle.php
@@ -6,9 +6,10 @@
use Html;
use Site;
use SiteStore;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\Store\EntityTitleLookup;
use Wikibase\Lib\Store\SiteLinkLookup;
-use Wikibase\Repo\Content\ItemHandler;
+use Wikibase\Repo\SiteLinkTargetProvider;
use Wikibase\Repo\WikibaseRepo;
/**
@@ -29,6 +30,11 @@
private $titleLookup;
/**
+ * @var LanguageNameLookup
+ */
+ private $languageNameLookup;
+
+ /**
* @var SiteStore
*/
private $sites;
@@ -37,6 +43,11 @@
* @var SiteLinkLookup
*/
private $siteLinkLookup;
+
+ /**
+ * @var SiteLinkTargetProvider
+ */
+ private $siteLinkTargetProvider;
/**
* site link groups
@@ -60,10 +71,17 @@
$wikibaseRepo->getSettings()->getSetting(
'siteLinkGroups' )
);
+ $siteLinkTargetProvider = new SiteLinkTargetProvider(
+ $wikibaseRepo->getSiteStore(),
+ $wikibaseRepo->getSettings()->getSetting(
'specialSiteLinkGroups' )
+ );
+
$this->initServices(
$wikibaseRepo->getEntityTitleLookup(),
+ new LanguageNameLookup(),
$wikibaseRepo->getSiteStore(),
- $wikibaseRepo->getStore()->newSiteLinkStore()
+ $wikibaseRepo->getStore()->newSiteLinkStore(),
+ $siteLinkTargetProvider
);
}
@@ -84,17 +102,23 @@
* May be used to inject mock services for testing.
*
* @param EntityTitleLookup $titleLookup
+ * @param LanguageNameLookup $languageNameLookup
* @param SiteStore $siteStore
* @param SiteLinkLookup $siteLinkLookup
+ * @param SiteLinkTargetProvider $siteLinkTargetProvider
*/
public function initServices(
EntityTitleLookup $titleLookup,
+ LanguageNameLookup $languageNameLookup,
SiteStore $siteStore,
- SiteLinkLookup $siteLinkLookup
+ SiteLinkLookup $siteLinkLookup,
+ SiteLinkTargetProvider $siteLinkTargetProvider
) {
$this->titleLookup = $titleLookup;
+ $this->languageNameLookup = $languageNameLookup;
$this->sites = $siteStore;
$this->siteLinkLookup = $siteLinkLookup;
+ $this->siteLinkTargetProvider = $siteLinkTargetProvider;
}
/**
@@ -163,6 +187,21 @@
}
/**
+ * Return options for the site input field.
+ *
+ * @return array
+ */
+ private function getSiteOptions() {
+ $options = array();
+ foreach ( $this->siteLinkTargetProvider->getSiteList(
$this->groups ) as $site ) {
+ $siteId = $site->getGlobalId();
+ $languageName = $this->languageNameLookup->getName(
$site->getLanguageCode() );
+ $options["$languageName ($siteId)"] = $siteId;
+ }
+ return $options;
+ }
+
+ /**
* Output a form to allow searching for a page
*
* @param string $siteId
@@ -178,13 +217,12 @@
wfDebugLog( __CLASS__, __FUNCTION__ . ": Site $siteId exists: "
. var_export( $siteExists, true ) );
- $this->getOutput()->addModules( 'wikibase.special.itemByTitle'
);
-
$formDescriptor = array(
'site' => array(
'name' => 'site',
'default' => $siteId,
- 'type' => 'text',
+ 'type' => 'combobox',
+ 'options' => $this->getSiteOptions(),
'id' => 'wb-itembytitle-sitename',
'size' => 12,
'label-message' =>
'wikibase-itembytitle-lookup-site'
diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php
index 05ca96d..97a10d4 100644
--- a/repo/resources/Resources.php
+++ b/repo/resources/Resources.php
@@ -148,17 +148,6 @@
),
),
- 'wikibase.special.itemByTitle' => $moduleTemplate + array(
- 'scripts' => array(
-
'wikibase.special/wikibase.special.itemByTitle.js'
- ),
- 'dependencies' => array(
- 'wikibase.sites',
- 'jquery.ui.suggester',
- 'oojs-ui'
- )
- ),
-
);
return array_merge(
diff --git a/repo/resources/wikibase.special/wikibase.special.itemByTitle.js
b/repo/resources/wikibase.special/wikibase.special.itemByTitle.js
deleted file mode 100644
index 2d10b95..0000000
--- a/repo/resources/wikibase.special/wikibase.special.itemByTitle.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * JavaScript for 'wikibase' extension special page 'ItemByTitle'
- *
- * @since 0.1
- *
- * @license GPL-2.0+
- * @author Jens Ohlig
- */
-( function( $, mw, OO, wb ) {
- 'use strict';
-
- $( document ).ready( function() {
- if ( ( mw.config.get( 'wgCanonicalSpecialPageName' ) !==
'ItemByTitle' ) ) {
- return; // not the right special page
- }
-
- // this will build a drop-down for the language selection:
- var sites = wb.sites.getSites(),
- siteList = [];
- for ( var siteId in sites ) {
- if ( sites.hasOwnProperty( siteId ) ) {
- siteList.push( sites[ siteId ].getName() + ' ('
+ siteId + ')' );
- }
- }
-
- var $input = OO.ui.infuse( $( '#wb-itembytitle-sitename' )
).$input;
-
- $input
- .attr( 'autocomplete', 'off' )
- .suggester( { source: siteList } );
- // Hackety hack hack...
- // On submit, replace human readable value like "English (en)"
with actual sitename ("enwiki")
- $( '#wb-itembytitle-form1' ).submit( function() {
- var langID = String( $input.val().replace(
/.*\(|\).*/gi, '' ) );
- if ( wb.sites.getSite( langID ).getId() !== undefined )
{
- $input.val( wb.sites.getSite( langID ).getId()
);
- }
- } );
- } );
-
-} )( jQuery, mediaWiki, OO, wikibase );
diff --git a/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
b/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
index 3cdc982..b60c39f 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
@@ -2,7 +2,6 @@
namespace Wikibase\Repo\Tests\Specials;
-use FauxResponse;
use Site;
use SiteList;
use SiteStore;
@@ -10,8 +9,10 @@
use Title;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\Lib\Store\EntityTitleLookup;
use Wikibase\Lib\Store\SiteLinkLookup;
+use Wikibase\Repo\SiteLinkTargetProvider;
use Wikibase\Repo\Specials\SpecialItemByTitle;
/**
@@ -46,6 +47,18 @@
}
/**
+ * @return LanguageNameLookup
+ */
+ private function getMockLanguageNameLookup() {
+ $mock = $this->getMock( LanguageNameLookup::class );
+ $mock->expects( $this->any() )
+ ->method( 'getName' )
+ ->will( $this->returnValue( '<LANG>' ) );
+
+ return $mock;
+ }
+
+ /**
* @return SiteLinkLookup
*/
private function getMockSiteLinkLookup() {
@@ -74,10 +87,9 @@
return $site;
};
- $mockSiteList = $this->getMock( SiteList::class );
- $mockSiteList->expects( $this->any() )
- ->method( 'getSite' )
- ->will( $this->returnCallback( $getSite ) );
+ $siteList = new SiteList();
+ $siteList[] = $getSite( 'dewiki' );
+ $siteList[] = $getSite( 'enwiki' );
$mock = $this->getMock( SiteStore::class );
$mock->expects( $this->any() )
@@ -86,7 +98,7 @@
$mock->expects( $this->any() )
->method( 'getSites' )
- ->will( $this->returnValue( $mockSiteList ) );
+ ->will( $this->returnValue( $siteList ) );
return $mock;
}
@@ -101,10 +113,16 @@
array( 'wikipedia' )
);
+ $siteStore = $this->getMockSiteStore();
+
+ $siteLinkTargetProvider = new SiteLinkTargetProvider(
$siteStore, array() );
+
$page->initServices(
$this->getMockTitleLookup(),
- $this->getMockSiteStore(),
- $this->getMockSiteLinkLookup()
+ $this->getMockLanguageNameLookup(),
+ $siteStore,
+ $this->getMockSiteLinkLookup(),
+ $siteLinkTargetProvider
);
return $page;
--
To view, visit https://gerrit.wikimedia.org/r/281923
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifcbf53ba69fbf65e05a774a6cf99f3640ff31d79
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Adrian Heine <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits