Page MenuHomePhabricator

API: Include redirects to sections or anchors (with fragment)
Closed, ResolvedPublicBUG REPORT

Description

With T296671, redirects are resolved in search results.
With T303013, UI will notice when a result comes from a redirect.

However, that would not solve the following issue with redirects-to-anchor results:

A few additional pieces of information that might be of use, to perhas consider not using the destination title, or at least not as the link target.

  1. Wikipedians spend much time establishing and maintaining in great detail redirects to specific sections.

For example, where the subject doesn't have its own article, and is covered within a larger one. Such as:

  • TRANSIENT to ECHELON#Confirmation_(2015).
  • recdns to Name_server#Recursive_query.
  • Mirall to Allen_Institute.
  • .work to List_of_Internet_top-level_domains#W.

As such, it may be important for the destination URL to either be the original unchanged redirect, or the fully formed destination URL. I don't know the REST API code well, but from a quick glance it seemed as if maybe it is resolving to a page identity, and not a link target. Which means these sections would be lost.

  • Bush TwinsGeorge W. Bush. Unless you know that this is a redirect to a section of the former president's article this is confusing and implies that George is a twin (he isn't).

QA steps

  • Search for "recdns"
  • Click link

Currently: Navigate to Name_server (incorrect behaviour)
Expected: Navigate to Name_server#Recursive_query

Requirement

Scope: Desktop and mobile web search. Redirects that include anchors or section fragments must preserve the fragment in API responses and resulting links:

  • Clicking a search suggestion or result that is a redirect to a section navigates to the fully resolved URL with fragment (e.g., Name_server#Recursive_query).
  • Users should not be dropped at the top of the destination page when the redirect target is a section anchor.

BDD

Feature: Preserve section fragments in redirects from search results

  Scenario: Redirect to section from search
    Given a search result corresponds to a redirect that points to a section (with a fragment)
    When I click the search result link
    Then I am navigated to the destination page including the correct section fragment
    And the viewport is scrolled to the section

Test Steps

Test Case 1: Redirect with fragment navigates correctly

  1. Go to search input and type "recdns".
  2. Select the "recdns" result from the suggestions or search results.
  3. AC1: The destination link points to Name_server#Recursive_query (contains the fragment).
  4. AC2: Browser navigation loads Name_server and scrolls to the "Recursive query" section.
  5. AC3: No navigation occurs to just Name_server without the fragment.

QA Results - Prod

ACStatusDetails
1T306150#11154855
2T306150#11154855
3T306150#11154855

Event Timeline

T296671 introduced an issue with redirects. T303013 partially solved it, but the redirect-to-section issue remains.
Both tasks are complementary.

There is a similar discussion about this issue here on enwiki.

ovasileva triaged this task as Medium priority.Mar 20 2023, 3:54 PM
ovasileva raised the priority of this task from Medium to High.Apr 11 2023, 5:52 PM
ovasileva moved this task from Groomed to Current Fiscal Year on the Web-Team-Backlog-Archived board.
ovasileva lowered the priority of this task from High to Medium.Dec 4 2023, 7:01 PM

Change #1060908 had a related patch set uploaded (by Jayden Bailey; author: Jayden Bailey):

[mediawiki/core@master] Rest: Return fragments in SearchHandler

https://gerrit.wikimedia.org/r/1060908

Change #1062114 had a related patch set uploaded (by Jayden Bailey; author: Jayden Bailey):

[mediawiki/skins/Vector@master] Append fragment to search suggestion URLs, if one is provided

https://gerrit.wikimedia.org/r/1062114

HCoplin-WMF changed the task status from Open to In Progress.Dec 4 2024, 2:16 PM
HCoplin-WMF moved this task from Backlog to In Progress on the MW-Interfaces-Team board.

I think this is just blocked on someone (tm) approving the name of the new field in the response. This is an addition to the response schema which cannot easily be undone. It's not clear to me who "owns" that schema...

I think this is just blocked on someone (tm) approving the name of the new field in the response. This is an addition to the response schema which cannot easily be undone. It's not clear to me who "owns" that schema...

Under what circumstances might it need to be undone? This seems like a problem out of scope for this ticket. If an API can be versioned, the name should be easy to change.

Can we nominate someone to make a decision here? Maybe Moriel?

Under what circumstances might it need to be undone? This seems like a problem out of scope for this ticket.

For example when the proposed name turns out to be misleading, inconsistent, or conflicting with some other aspect we want to expose later. Inutively, I would have expected "section" rather than "fragment".

If an API can be versioned, the name should be easy to change.

Yes, Really Soon Now: T366835

Can we nominate someone to make a decision here? Maybe Moriel?

I'd prefer Discovery-Search to chime in.

Change #1060908 merged by jenkins-bot:

[mediawiki/core@master] Rest: Return fragments in SearchHandler

https://gerrit.wikimedia.org/r/1060908

@daniel @BPirkle testing this I see an issue:
For https://en.wikipedia.org/w/rest.php/v1/search/title?q=TRANSIENT&limit=10 anchor is Confirmation of ECHELON (2015) but it should be Confirmation_of_ECHELON_(2015). Encoding to headings is not always a simple case of replacing spaces with underscores...

Jdlrobson-WMF renamed this task from New Vector Search should show redirects to sections or anchors (with fragment) to API: Include redirects to sections or anchors (with fragment).May 7 2025, 9:12 PM

The UI portion of this fix is now fully captured in T303013.

Change #1062114 abandoned by Jayden Bailey:

[mediawiki/skins/Vector@master] Append fragment to search suggestion URLs, if one is provided

Reason:

Relevant code was moved to MediaWiki core in T380507. Will remake the patch.

https://gerrit.wikimedia.org/r/1062114

Change #1155750 had a related patch set uploaded (by Jayden Bailey; author: Jayden Bailey):

[mediawiki/core@master] Append anchor to search suggestion URLs, if one is provided

https://gerrit.wikimedia.org/r/1155750

Test wiki created on Patch demo by Jdlrobson using patch(es) linked to this task:
https://1c7b90cc8f.catalyst.wmcloud.org/w/

Change #1155750 merged by jenkins-bot:

[mediawiki/core@master] Append anchor to search suggestion URLs, if one is provided

https://gerrit.wikimedia.org/r/1155750

Jdlrobson-WMF claimed this task.

Fix will roll out on this week's train.

Test Result - Prod

Status: ✅ PASS
Environment: enwiki
OS: macOS Sequoia 15.5
Browser: Chrome Canary (latest as of test date)
Device: MS
Emulated Device: NA

Test Case 1: Redirect with fragment navigates correctly

  1. Go to search input and type "recdns".
  2. Select the "recdns" result from the suggestions or search results.
  3. AC1: The destination link points to Name_server#Recursive_query (contains the fragment).
  4. AC2: Browser navigation loads Name_server and scrolls to the "Recursive query" section.
  5. AC3: No navigation occurs to just Name_server without the fragment.

screenshot 19.mov.gif (944×1 px, 1 MB)

Test wiki on Patch demo by Jdlrobson using patch(es) linked to this task was deleted:

https://1c7b90cc8f.catalyst.wmcloud.org/w/

Test wiki on Patch demo by Jdlrobson using patch(es) linked to this task was deleted:

https://1c7b90cc8f.catalyst.wmcloud.org/w/