Page MenuHomePhabricator

jquery.highlightText: Add support for matching multiple (non-adjecant) words
Closed, DeclinedPublic

Description

I'm passing this request along:

To the devs and volunteer coders: Please see this snippet that uses mediawiki functions:: https://en.wikipedia.org/wiki/User:Dank/wishywashy.js

If you add that to your .js file on en.wp, then every occurrence of wishy or washy will appear in bold for you ... and if you hover over the bolded word, you'll get some helpful advice. People would like for me to automate some of my copyediting advice using this script, but highlightText, as coded in Mediawiki, won't even let me search for a two-word phrase. Ideally, I'd like to have arguments that are regex searches (or the lua equivalent), but at a minimum, I need to search for letters, numbers, spaces and punctuation, if I'm going to be using highlightText. (If your solution allows something like regex, I only need highlighting for the initial phrase that appears before any special regex functions.)

Being able to highlight two words seems like a very useful feature. I've already got ideas about how I might use this if it were possible.


Version: 1.24rc
Severity: enhancement

Details

Reference
bz67784

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 3:33 AM
bzimport set Reference to bz67784.
bzimport added a subscriber: Unknown Object (MLST).

Clarification: highlightText can handle all the punctuation I'm likely to need (,."?!/:;)
but it can't handle spaces.

A (possibly older) version of highlightText is at https://git.wikimedia.org/blob/mediawiki%2Fcore/596a2584b0ea7ca5de24e871e015a9ac03122c3e/resources%2Fjquery%2Fjquery.highlightText.js.

I need a function (in or outside of Mediawiki) identical to highlightText, with (I'm guessing) the space in pat.split(" ") in line 12 replaced ... a tab character would work. (Or, getting rid of the parsing entirely so I can pass an array of strings would be fine.)

Dan

Whatamidoing-WMF changed the task status from Open to Stalled.Mar 23 2015, 6:26 PM
Krinkle renamed this task from jquery.highlightText.js needs to be able to highlight more than one word, numbers, spaces, and punctuation to jquery.highlightText: Add support for matching multiple (non-adjecant) words.Mar 23 2015, 11:17 PM
Krinkle set Security to None.
Krinkle removed a subscriber: Unknown Object (MLST).

jquery.highlightText is intended to highlight a fixed phrase. This is used by, for example, jquery.suggestions; which powers the main search field on Wikipedia with the search results in a list below the input field. It is working fine there, and as such this is unlikely to get prioritised as it's requesting a feature that would not link back to the core product.

It already supports multiple words. It is not limited to a single word. However, it is limited to one phrase (which can happily contain multiple words). This is by design. If you need to highlight multiple unrelated, adjacent phrases, words or parts of words, simply invoke highlightText or splitAndHighlight multiple times.

Please let me know if this does not work for you.

If this were a bug or new feature I'd say, patches welcome from any volunteers who feel like resolving it. However as it stands (unless I misunderstood the request) I'd say supporting multiple sequences should be done by the caller. Adding this to the highlightText plugin would not improve it.

Sorry, let me correct that. It seems the utility method splitAndHighlight in fact even does this already. It takes a list of separate words and searches/highlights them independently using the lower-level highlightText.

To search for two words that explicitly are adjacent, you can call highlightText.innerHighlight directly with a phrase that will be searched for without splitting up into separate search queries.

As for accepting a regex, I think that'd be a welcome addition. It's not needed by anything in MediaWiki core, but it'd be a fine addition. Write a patch adding support for pat being a RegExp instead of a String in jquery.highlightText.js, and a unit test, and I'll make sure it gets merged and released.

Aklapper changed the task status from Stalled to Open.May 24 2020, 7:33 PM
Aklapper subscribed.

The previous comments don't explain what/who exactly this task is stalled on ("If a report is waiting for further input (e.g. from its reporter or a third party) and can currently not be acted on"). Hence resetting task status.

(Smallprint, as general orientation for task management: If you wanted to express that nobody is currently working on this task, then the assignee should be removed and/or priority could be lowered instead. If work on this task is blocked by another task, then that other task should be added via Edit Related Tasks...Edit Subtasks. If this task is stalled on an upstream project, then the Upstream tag should be added. If this task requires info from the task reporter, then there should be instructions which info is needed. If this task is out of scope and nobody should ever work on this, then task status should have the "Declined" status.)

This jQuery plugin primarily exists for the highlighting of text in short and prefix-based search suggestions. If it happens to work for other purposes, that's great, but no elaborate features will be developed in this purely for the use by a gadget.

If have a custom version for this for your gadget, and/or know someone that can work with you on that, I suggest to use that directly in the gadget.