Skip to content
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

Merged
merged 1 commit into from
Nov 30, 2024
Merged

Rewrite item link with page sitelink #24

merged 1 commit into from
Nov 30, 2024

Conversation

malberts
Copy link
Contributor

@malberts malberts commented Nov 30, 2024

For #4

The search results behave differently depending on search criteria.

  1. When searching with a mix of namespaces (Item and Main):
    image
    (Item does not get text highlight)

  2. With just Item namespace:
    image
    (Item gets text highlight)

  3. Search for Item ID with mix of namespaces:
    image

  4. Search for Item ID with just Item namespace:
    image

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.

@malberts malberts marked this pull request as ready for review November 30, 2024 01:36
@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2024

Codecov Report

Attention: Patch coverage is 15.87302% with 53 lines in your changes missing coverage. Please review.

Project coverage is 18.91%. Comparing base (30d9a7c) to head (40b092b).

Files with missing lines Patch % Lines
src/EntryPoints/WikibaseFacetedSearchHooks.php 0.00% 48 Missing ⚠️
src/WikibaseFacetedSearchExtension.php 0.00% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@malberts malberts force-pushed the sitelink branch 2 times, most recently from 5780501 to 04cb34d Compare November 30, 2024 01:41
- ../../extensions/Wikibase
- ../../extensions/WikibaseCirrusSearch
bootstrapFiles:
- ../../includes/AutoLoader.php
Copy link
Contributor Author

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().

@malberts malberts marked this pull request as draft November 30, 2024 11:44
@malberts
Copy link
Contributor Author

All 4 scenarios work after rewriting this.

  1. When searching with a mix of namespaces (Item and Main):
    image

  2. With just Item namespace:
    image

  3. Search for Item ID with mix of namespaces:
    image

  4. Search for Item ID with just Item namespace:
    image

The default, additional language text also works:
image

@malberts malberts marked this pull request as ready for review November 30, 2024 12:45
return;
}

// TODO: get item site link and replace $title
$title = $pageTitle;
Copy link
Contributor Author

@malberts malberts Nov 30, 2024

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.

Comment on lines +52 to +61
if ( !( $result instanceof EntityResult ) ) {
self::rewriteLinkForNonEntityResult(
self::newLabelDescriptionLookup( $specialSearch->getContext() ),
self::newLinkFormatter( $specialSearch->getLanguage() ),
$itemId,
$titleSnippet,
$attributes
);
}
}
Copy link
Contributor Author

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().

@malberts malberts force-pushed the sitelink branch 2 times, most recently from 633f757 to 43d72f7 Compare November 30, 2024 15:31
];
}

return null;
Copy link
Member

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

@JeroenDeDauw JeroenDeDauw merged commit 574e5a1 into master Nov 30, 2024
16 checks passed
@JeroenDeDauw JeroenDeDauw deleted the sitelink branch November 30, 2024 16:51
@malberts malberts mentioned this pull request Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants