Ricordisamoa has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234966
Change subject: [WIP] Add suggestions for page field to Special:ItemByTitle
......................................................................
[WIP] Add suggestions for page field to Special:ItemByTitle
Bug: T68744
Change-Id: I6ca612e15151e1263ff2e3888feb5993abd35d30
---
M repo/resources/wikibase.special/wikibase.special.itemByTitle.js
1 file changed, 48 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/66/234966/1
diff --git a/repo/resources/wikibase.special/wikibase.special.itemByTitle.js
b/repo/resources/wikibase.special/wikibase.special.itemByTitle.js
index 5ea4d7b..b8833db 100644
--- a/repo/resources/wikibase.special/wikibase.special.itemByTitle.js
+++ b/repo/resources/wikibase.special/wikibase.special.itemByTitle.js
@@ -14,24 +14,63 @@
return; // not the right special page
}
- // this will build a drop-down for the language selection:
- var sites = wb.sites.getSites(),
- siteList = [];
+ function getSite( input ) {
+ return wb.sites.getSite( input.replace( /.*\(|\).*/gi,
'' ) );
+ }
+
+ // this will build a drop-down for the site selection:
+ var api,
+ sites = wb.sites.getSites(),
+ siteList = [],
+ $input = $( '#wb-itembytitle-sitename' );
for( var siteId in sites ) {
if( sites.hasOwnProperty( siteId ) ) {
siteList.push( sites[ siteId ].getName() + ' ('
+ siteId + ')' );
}
}
- $( '#wb-itembytitle-sitename' )
+ $input
.attr( 'autocomplete', 'off' )
- .suggester( { source: siteList } );
+ .suggester( { source: siteList } )
+ .on( 'change', function () {
+ var site = getSite( $input.val() );
+ if ( site ) {
+ var apiUrl = site.getApi();
+ if ( !api || apiUrl !== api.apiUrl ) {
+ api = new mw.Api( {
+ ajax: {
+ url: apiUrl,
+ dataType: 'jsonp'
+ }
+ } );
+ }
+ } else {
+ api = null;
+ }
+ } );
+ $( '#pagename' )
+ .attr( 'autocomplete', 'off' )
+ .on( 'input', function () {
+ if ( api ) {
+ var $pagename = $( this );
+ api.get( {
+ action: 'query',
+ list: 'allpages',
+ apprefix: $pagename.val()
+ } ).done( function ( data ) {
+ $pagename.suggester( {
+ source: $.map(
data.query.allpages, function ( item ) {
+ return item.title;
+ } )
+ } );
+ } );
+ }
+ } );
// Hackety hack hack...
// On submit, replace human readable value like "English (en)"
with actual sitename ("enwiki")
$( '#wb-itembytitle-form1' ).submit( function() {
- var $input = $( '#wb-itembytitle-sitename' );
- var langID = String( $input.val().replace(
/.*\(|\).*/gi, '' ) );
- if ( wb.sites.getSite( langID ).getId() !== undefined )
{
- $input.val( wb.sites.getSite( langID ).getId()
);
+ var site = getSite( $input.val() );
+ if ( site ) {
+ $input.val( site.getId() );
}
} );
} );
--
To view, visit https://gerrit.wikimedia.org/r/234966
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ca612e15151e1263ff2e3888feb5993abd35d30
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits