[MediaWiki-commits] [Gerrit] (Bug 43066) Replace search box with item selector - change (mediawiki...Wikibase)
Daniel Kinzler has submitted this change and it was merged. Change subject: (Bug 43066) Replace search box with item selector .. (Bug 43066) Replace search box with item selector - patch set 5: Improved removing native suggestion context, added some doc - patch set 6: Further improvement of suggestion context removal - patch set 7: rebase - patch set 8: Set correct file group Change-Id: Ic70e323c118ed066c7846de57651076865106b2d --- M repo/Wikibase.hooks.php M repo/Wikibase.php M repo/resources/Resources.php A repo/resources/wikibase.ui.entitysearch.js 4 files changed, 72 insertions(+), 0 deletions(-) Approvals: Daniel Kinzler: Verified; Looks good to me, approved diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php index 6ad7768..8b1c5e6 100644 --- a/repo/Wikibase.hooks.php +++ b/repo/Wikibase.hooks.php @@ -32,8 +32,20 @@ * @author Nikola Smolenski * @author Daniel Werner * @author Michał Łazowik + * @author Jens Ohlig */ final class RepoHooks { + /** +* Handler for the BeforePageDisplay hook, simply injects wikibase.ui.entitysearch module +* +* @since 0.4 +* +* @return boolean +*/ + public static function onBeforePageDisplay( \OutputPage &$out, \Skin &$skin ) { + $out->addModules( 'wikibase.ui.entitysearch' ); + return true; + } /** * Handler for the SetupAfterCache hook, completing setup of diff --git a/repo/Wikibase.php b/repo/Wikibase.php index bd04822..d02b327 100644 --- a/repo/Wikibase.php +++ b/repo/Wikibase.php @@ -247,6 +247,7 @@ // Hooks +$wgHooks['BeforePageDisplay'][] = 'Wikibase\RepoHooks::onBeforePageDisplay'; $wgHooks['LoadExtensionSchemaUpdates'][] = 'Wikibase\RepoHooks::onSchemaUpdate'; $wgHooks['UnitTestsList'][]= 'Wikibase\RepoHooks::registerUnitTests'; $wgHooks['NamespaceIsMovable'][] = 'Wikibase\RepoHooks::onNamespaceIsMovable'; diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php index b230b1f..147ed5f 100644 --- a/repo/resources/Resources.php +++ b/repo/resources/Resources.php @@ -56,6 +56,15 @@ ) ), + 'wikibase.ui.entitysearch' => $moduleTemplate + array( + 'scripts' => array( + 'wikibase.ui.entitysearch.js', + ), + 'dependencies' => array( + 'jquery.ui.entityselector', + ), + ), + /* Wikibase special pages */ 'wikibase.special' => $moduleTemplate + array( diff --git a/repo/resources/wikibase.ui.entitysearch.js b/repo/resources/wikibase.ui.entitysearch.js new file mode 100644 index 000..702f662 --- /dev/null +++ b/repo/resources/wikibase.ui.entitysearch.js @@ -0,0 +1,50 @@ +/** + * Replacing the native MediaWiki search suggestions with Wikibase's entity selector widget. + * + * @file + * @ingroup WikibaseRepo + * + * @license GNU GPL v2+ + * @author Jens Ohlig + * @author H. Snater < mediaw...@snater.com > + */ +( function( $, mw ) { + 'use strict'; + + $( document ).ready( function() { + + /** +* Removes the native search box suggestion list. +* +* @param {Object} input Search box node +*/ + function removeSuggestionContext( input ) { + // Native fetch() updates/re-sets the data attribute with the suggestion context. + $.data( input, 'suggestionsContext' ).config.fetch = function() {}; + $.removeData( input, 'suggestionsContext' ); + } + + $( '#searchInput' ) + .one( 'focus', function( event ) { + if ( $.data( this, 'suggestionsContext' ) ) { + removeSuggestionContext( this ); + } else { + // Suggestion context might not be initialized when focusing the search box while + // the page is still rendered. + var $input = $( this ); + $input.on( 'keypress.entitysearch', function( event ) { + if ( $.data( this, 'suggestionsContext' ) ) { + removeSuggestionContext( this ); + $input.off( '.entitysearch' ); + } + } ); + } + } ) + .entityselector( { + url: mw.config.get( 'wgServer'
[MediaWiki-commits] [Gerrit] (Bug 43066) Replace search box with item selector - change (mediawiki...Wikibase)
Jens Ohlig has uploaded a new change for review. https://gerrit.wikimedia.org/r/49263 Change subject: (Bug 43066) Replace search box with item selector .. (Bug 43066) Replace search box with item selector Change-Id: Ic70e323c118ed066c7846de57651076865106b2d --- M repo/Wikibase.hooks.php M repo/Wikibase.php M repo/resources/Resources.php A repo/resources/wikibase.ui.entityselector.js 4 files changed, 22 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/63/49263/1 diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php index 6ad7768..a056272 100644 --- a/repo/Wikibase.hooks.php +++ b/repo/Wikibase.hooks.php @@ -961,4 +961,9 @@ return false; } +public static function onBeforePageDisplay( \OutputPage &$out, \Skin &$skin ) { +$out->addModules( 'wikibase.ui.entityselector' ); +return true; +} + } diff --git a/repo/Wikibase.php b/repo/Wikibase.php index 9657c0d..7b534dd 100644 --- a/repo/Wikibase.php +++ b/repo/Wikibase.php @@ -268,7 +268,7 @@ $wgHooks['ShowSearchHit'][]= 'Wikibase\RepoHooks::onShowSearchHit'; $wgHooks['TitleGetRestrictionTypes'][] = 'Wikibase\RepoHooks::onTitleGetRestrictionTypes'; $wgHooks['AbuseFilter-contentToString'][] = 'Wikibase\RepoHooks::onAbuseFilterContentToString'; - +$wgHooks['BeforePageDisplay'][] = 'Wikibase\RepoHooks::onBeforePageDisplay'; // Resource Loader Modules: $wgResourceModules = array_merge( $wgResourceModules, include( "$dir/resources/Resources.php" ) ); diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php index b230b1f..fb1f729 100644 --- a/repo/resources/Resources.php +++ b/repo/resources/Resources.php @@ -39,7 +39,8 @@ return array( 'wikibase.ui.entityViewInit' => $moduleTemplate + array( 'scripts' => array( - 'wikibase.ui.entityViewInit.js' // should probably be adjusted for more modularity +'wikibase.ui.entityViewInit.js', + 'wikibase.ui.entityselector.js' ), 'dependencies' => array( 'mediawiki.user', @@ -48,12 +49,13 @@ 'wikibase.datamodel', 'jquery.json', 'jquery.cookie', + 'jquery.ui.entityselector', ), 'messages' => array( 'wikibase-sitelinks', 'wikibase-statements', 'wikibase-copyrighttooltip-acknowledge', - ) +), ), /* Wikibase special pages */ diff --git a/repo/resources/wikibase.ui.entityselector.js b/repo/resources/wikibase.ui.entityselector.js new file mode 100644 index 000..90554db --- /dev/null +++ b/repo/resources/wikibase.ui.entityselector.js @@ -0,0 +1,12 @@ +( function( $, mw ) { + 'use strict'; + $( document ).ready( function() { +$( '#searchInput' ).removeData( 'suggestionsContext' ) +mw.loader.using( ['jquery.ui.entityselector'], function () { + $( '#searchInput' ).entityselector( { +url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php', +language: mw.config.get( 'wgUserLanguage' ) + } ) +} ); + } ) +}( jQuery, mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/49263 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic70e323c118ed066c7846de57651076865106b2d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jens Ohlig ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits