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

Sitelink refactor #26

Merged
merged 3 commits into from
Dec 2, 2024
Merged

Sitelink refactor #26

merged 3 commits into from
Dec 2, 2024

Conversation

malberts
Copy link
Contributor

@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2024

Codecov Report

Attention: Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.

Project coverage is 32.43%. Comparing base (cce74aa) to head (827b243).

Files with missing lines Patch % Lines
src/WikibaseFacetedSearchExtension.php 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #26      +/-   ##
============================================
+ Coverage     28.97%   32.43%   +3.45%     
- Complexity       79       85       +6     
============================================
  Files            12       14       +2     
  Lines           245      259      +14     
============================================
+ Hits             71       84      +13     
- Misses          174      175       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

public function testReturnsNull(): void {
$this->assertNull(
( new NullItemPageLookup() )->getPageTitle( new ItemId( 'Q42' ) )
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone wants their 100% code coverage :D


return new NullItemPageLookup();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What motivated you to put this factory logic into a dedicated class? (I'm not objecting)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it would be slightly more testable than being directly in the extension factory (where we don't typically expect, and test, logic). But then again it's also slightly YAGNI since there are no other Lookups at the moment.


public function getPageTitle( ItemId $itemId ): ?Title {
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.

I wonder if the call to rewriteLinkForNonEntityResult in the hooks file is being skipped over in cases it should not when we always 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.

In which case, this code could go into its own method:

$pageTitle = self::getItemPage( $itemId );

		if ( $pageTitle === null ) {
			return;
		}

		$title = $pageTitle;
		```

Copy link
Contributor Author

@malberts malberts Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewriteLinkForNonEntityResult basically reimplements this: https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/3f636e441cf070234bfcd4f217603d2e2a0be28a/repo/includes/Hooks/HtmlPageLinkRendererEndHookHandler.php#L321-L327

When you override $title without $titleSnippet, MW ends up using $title's text for the link. So to get the original Item link text back, we need to trigger the original link text building and put that into $titleSnippet. I couldn't get it to work by manually triggering the entire hook that calls that code.

In the end if $pageTitle is null, then we shouldn't do anything further, because the original item link would already be correct as per the link building of Wikibase/WikibaseCirrusSearch.

@malberts malberts merged commit 1fd2dd1 into master Dec 2, 2024
16 checks passed
@malberts malberts deleted the sitelink-refactor branch December 2, 2024 14:50
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