Page MenuHomePhabricator

[Share Highlights] Text fragment URL generation
Closed, ResolvedPublic1 Estimated Story Points

Description

Include text fragment in URL generation so that anyone using the link to come back to the article lands in that relevant section

Things to address:

Additional tweaks:

  • selection may have boundaries in the middle of words
    • these will not highlight properly!
    • eg http://localhost:8080/w/index.php/Paris#:~:text=ity%20of%20France. doesn't match "city of France." because it breaks a word
    • must either clip or expand those
      • textFragment.js is the wrong place to fix this, it doesn't know it's in the middle of a word. have to do it where we're extracting the text from the selection.

Event Timeline

We have basic working code for this in the textFragment.js file currently. This works but we will want to test against edge cases and languages with non-Latin scripts (@bvibber already filed T417067).

HSwan-WMF set the point value for this task to 1.Mar 12 2026, 4:32 PM

Change #1259248 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/ReaderExperiments@master] WIP fragment cleanup for ShareHighlight experiment

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

Happy with current state of tests and fixes in

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ReaderExperiments/+/1259248

ready for code review.

Breaking out a follow-up task of additional things I noticed about how the fragment URLs work that affects how we should be extracting the text -- worth fixing but out of scope for this task: T421160

Change #1259248 merged by jenkins-bot:

[mediawiki/extensions/ReaderExperiments@master] [ShareHighlight] Text fragment generation tests and fixes

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

Etonkovidova subscribed.

Checked on enwiki beta:

Test summary:

  • When a shared link is followed, the last portion of highlighted text will be displayed as a part of url address

E.g. If the following shared url is clicked,
https://en.wikipedia.beta.wmcloud.org/wiki/Carnivore#:~:text=The%20first%20vertebrate%20carnivores%20were,larger%20than%20itself.%22%5B8%5D
the url in the browser address will have the last portion of highlighted text:
https://en.wikipedia.beta.wmcloud.org/wiki/Carnivore#:~:text=The first vertebrate carnivores were,larger than itself."[8]

Screenshot 2026-03-26 at 5.27.08 PM.png (828×981 px, 184 KB)

  • tested the case when highlighted text includes images/templates

https://en.wikipedia.beta.wmcloud.org/wiki/Paris#:~:text=Flag%20of%20Paris%20Flag%20Coat%20of%20arms%20of%20Paris%20Coat%20of%20arms

Screenshot 2026-03-26 at 6.43.00 PM.png (888×421 px, 197 KB)
Screenshot 2026-03-26 at 5.50.57 PM.png (772×1,578 px, 104 KB)

Following the link above, a user won't see any highlight and will be redirected to the top of an article.