-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite item link with page sitelink #24
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #24 +/- ##
=============================================
- Coverage 33.33% 18.91% -14.42%
- Complexity 4 18 +14
=============================================
Files 2 3 +1
Lines 12 74 +62
=============================================
+ Hits 4 14 +10
- Misses 8 60 +52 ☔ View full report in Codecov by Sentry. |
5780501
to
04cb34d
Compare
- ../../extensions/Wikibase | ||
- ../../extensions/WikibaseCirrusSearch | ||
bootstrapFiles: | ||
- ../../includes/AutoLoader.php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for PHPStan to understand class_alias()
.
return; | ||
} | ||
|
||
// TODO: get item site link and replace $title | ||
$title = $pageTitle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set the new target page.
For EntityResult results we just need to point to the new page, since the correct $titleSnippet gets set in CirrusShowSearchHitHandler::onShowSearchHitTitle()
.
For non-EntityResult we also need to rewrite the text below.
if ( !( $result instanceof EntityResult ) ) { | ||
self::rewriteLinkForNonEntityResult( | ||
self::newLabelDescriptionLookup( $specialSearch->getContext() ), | ||
self::newLinkFormatter( $specialSearch->getLanguage() ), | ||
$itemId, | ||
$titleSnippet, | ||
$attributes | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For non-EntityResult there is no $titleSnippet by default, which means the link is going to use the text of the target page title, not the item title.
To get the item title again, this calls a minimal implementation based on HtmlPageLinkRendererEndHookHandler::internalDoHtmlPageLinkRendererEnd()
.
633f757
to
43d72f7
Compare
]; | ||
} | ||
|
||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of static code here. Likely we can move much to one or more classes that do not bind to globals and can be tested easier
For #4
The search results behave differently depending on search criteria.
When searching with a mix of namespaces (Item and Main):
![image](https://private-user-images.githubusercontent.com/1428594/391205628-3e61bd0d-b24f-45aa-94f3-241e097db481.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MjIwNzEsIm5iZiI6MTczODgyMTc3MSwicGF0aCI6Ii8xNDI4NTk0LzM5MTIwNTYyOC0zZTYxYmQwZC1iMjRmLTQ1YWEtOTRmMy0yNDFlMDk3ZGI0ODEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDZUMDYwMjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjZiZDIyMjFmZWZiNmU3ZGEyMGU1YzNmMmEwYTVjY2YwZjY5NTk0ODM5ZmFjZWFlYmQxNDVmYzkyMjViNTM5OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.ILFULQeHFHVY7NumlZM4Pw4_NHSnv3Y35eHSHFIWo5w)
(Item does not get text highlight)
With just Item namespace:
![image](https://private-user-images.githubusercontent.com/1428594/391205652-79814279-e2ea-4153-b8f8-54f7a5ba0965.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MjIwNzEsIm5iZiI6MTczODgyMTc3MSwicGF0aCI6Ii8xNDI4NTk0LzM5MTIwNTY1Mi03OTgxNDI3OS1lMmVhLTQxNTMtYjhmOC01NGY3YTViYTA5NjUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDZUMDYwMjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjE2YjhkMDY4ZmIyMGQ3ZmYzZTBkMTliM2VlNGQxZDJiMGQwMmQyYWFkMjQ2ZGVmZDhjZTMxMjYyNWRkYzZjNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.OclXPdXG4jUwNN56jPk6ejCc9y3M8TVf_TJEnmPzoH8)
(Item gets text highlight)
Search for Item ID with mix of namespaces:
![image](https://private-user-images.githubusercontent.com/1428594/391205700-ce11adcc-c55f-462a-9d24-5192952973d7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MjIwNzEsIm5iZiI6MTczODgyMTc3MSwicGF0aCI6Ii8xNDI4NTk0LzM5MTIwNTcwMC1jZTExYWRjYy1jNTVmLTQ2MmEtOWQyNC01MTkyOTUyOTczZDcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDZUMDYwMjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTdmMGNhODMwM2IwMjc1YTBlM2EzNDhjOWUzMmQxZTBjMjQ0MWFiOTg5YzFiYmQ0ZTM1M2NlYjE3YmFiNWNjNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.iXDxO0QMuEogOxypRv2zCY0hc7ehvXiRQDPXVAuJN7w)
Search for Item ID with just Item namespace:
![image](https://private-user-images.githubusercontent.com/1428594/391205774-46e71029-e8d4-422a-aa5e-9814f5745c45.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MjIwNzEsIm5iZiI6MTczODgyMTc3MSwicGF0aCI6Ii8xNDI4NTk0LzM5MTIwNTc3NC00NmU3MTAyOS1lOGQ0LTQyMmEtYWE1ZS05ODE0ZjU3NDVjNDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDZUMDYwMjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTRlNzM5ZjFhMDVlYzdmYzY4MzAyM2YwZDM5MDBjYzIxNTA5NWYyODA0MmQxNjI4NTE5MmQ5M2MzYWYwNjQ5NyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.IklEBt-U7M3xqWrACEi8vhys5gE7D0J0DSnsYxjI3Rk)
I consider (3) broken, because without this PR it shows the same link title as the other scenarios. I will return to this in a follow-up, so that the initial code here can go in.