Addshore has submitted this change and it was merged.

Change subject: Fix search result display for title matches
......................................................................


Fix search result display for title matches

CirrusSearch wraps title matches in a span tag, which
does not work with our LinkBegin hook handler.

The span tag is normally used to provide bold highlighting
of matches.

Perhaps in the future, we can improve the entity link formatting
to provide highlighting of both Q## titles and labels.

Bug: 62348
Change-Id: I1a4e9cb622d00c72177a415c39ac627c88536b0a
---
M repo/Wikibase.hooks.php
M repo/Wikibase.php
2 files changed, 22 insertions(+), 0 deletions(-)

Approvals:
  WikidataJenkins: Verified
  Addshore: Looks good to me, approved
  jenkins-bot: Checked



diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 4c5f1bd..6c7c0c6 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -937,6 +937,27 @@
        }
 
        /**
+        * Remove span tag (added by Cirrus) placed around title search hit for 
entity titles
+        * to highlight matches in bold.
+        *
+        * @todo highlight the Q## part of the entity link formatting and 
highlight label matches
+        *
+        * @param string &$link_t
+        * @param string &$titleSnippet
+        * @param SearchResult $result
+        */
+       public static function onShowSearchHitTitle( &$link_t, &$titleSnippet, 
SearchResult $result ) {
+               $title = $result->getTitle();
+               $entityNamespaces = NamespaceUtils::getEntityNamespaces();
+
+               if ( in_array( $title->getNamespace(), $entityNamespaces ) ) {
+                       $titleSnippet = $title->getPrefixedText();
+               }
+
+               return true;
+       }
+
+       /**
         * Handler for the TitleGetRestrictionTypes hook.
         *
         * Implemented to prevent people from protecting pages from being
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index a8bc1a1..d7d3d80 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -180,6 +180,7 @@
        $wgHooks['ApiCheckCanExecute'][]                                        
= 'Wikibase\RepoHooks::onApiCheckCanExecute';
        $wgHooks['SetupAfterCache'][]                                           
= 'Wikibase\RepoHooks::onSetupAfterCache';
        $wgHooks['ShowSearchHit'][]                                             
= 'Wikibase\RepoHooks::onShowSearchHit';
+       $wgHooks['ShowSearchHitTitle'][]                                        
= 'Wikibase\RepoHooks::onShowSearchHitTitle';
        $wgHooks['TitleGetRestrictionTypes'][]                          = 
'Wikibase\RepoHooks::onTitleGetRestrictionTypes';
        $wgHooks['AbuseFilter-contentToString'][]                       = 
'Wikibase\RepoHooks::onAbuseFilterContentToString';
        $wgHooks['SpecialPage_reorderPages'][]                          = 
'Wikibase\RepoHooks::onSpecialPage_reorderPages';

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1a4e9cb622d00c72177a415c39ac627c88536b0a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to