Page MenuHomePhabricator

Store utterances from UI content (DOM-strings) in Wikispeech segmentation storage
Open, Needs TriagePublic16 Estimated Story Points

Description

Once UI strings have been identified and bound to DOM elements, they should be processed similarly to article content and saved in the utterance storage.

This task investigates:

  • How to create utterances for UI-based content
  • How to segment and cache them properly in the storage system

Event Timeline

This work includes developing a separate segmentation flow for UI content, distinct from the article-based segmenter.

Specifically, this could involve:

  • Creating a SegmentUIFactory.php (extends from SegmentFactory.php, see T401173)
  • Implementing a corresponding API module, e.g. ApiWikispeechUISegment.php

These components would handle segmentation of DOM UI strings, enabling them to be stored and reused in the utterance storage (caching system), just like the regular Wikipedia article content.

Change #1195102 had a related patch set uploaded (by Viktoria Hillerud WMSE; author: Viktoria Hillerud WMSE):

[mediawiki/extensions/Wikispeech@master] Store utterances from UI content in Wikispeech segmentation storage

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

I made a patch that is WIP since I will implement API-logic as well. Right now I have only created the SegmentUIfFactory. If you want, your'e welcome to review the changes so far and give some input.

When considering the design of the API, we're currently using a single module (wikispeech-segment). If we want to support both page content and UI string segmentation through it, this avoids code duplication but introduces complexity in parameter handling (e.g. making sure only page or ui-strings is set, not both or neither) in getAllowedParams().

An alternative would be to split it into two dedicated modules (wikispeech-segment-page and wikispeech-segment-ui) for clarity and stricter parameter validation. However, this would add an additional API module to maintain.

I made a patch that is WIP since I will implement API-logic as well. Right now I have only created the SegmentUIfFactory. If you want, your'e welcome to review the changes so far and give some input.

What's the intended input, i.e. uiStrings? Is is multiple strings for a single UI element?

If SegmentUIResponse doesn't add any extra logic, maybe it doesn't have to be it's own class. That is unless you have to distinguish it from other SegmentResponses.

If we want to support both page content and UI string segmentation through it, this avoids code duplication but introduces complexity in parameter handling (e.g. making sure only page or ui-strings is set, not both or neither) in getAllowedParams().

The listen API does something similar. It takes a revision (and segment) or a string (plain or IPA). This sort of thing also exists in other API actions. For instance the much used query action takes input in a bunch of different, mutually exclusive ways.

I made a patch that is WIP since I will implement API-logic as well. Right now I have only created the SegmentUIfFactory. If you want, your'e welcome to review the changes so far and give some input.

What's the intended input, i.e. uiStrings? Is is multiple strings for a single UI element?

If SegmentUIResponse doesn't add any extra logic, maybe it doesn't have to be it's own class. That is unless you have to distinguish it from other SegmentResponses.

The idea is that uiStrings is a flat list, e.g one string per UI element. So even if the string contains nested HTML tags, it’s still treated as a single string in the list.
For example:

$uiStrings = [
	"<b>Hello</b>",
	"<div>Click here to start.</div>",
	"<span>This is a test.</span>"
];

I created SegmentUIResponse just because I don't know If I will need some other logic there further on. But yes for now I can just use SegmentResponse as the return type

After a recent discussion, and since the majority of the identified and mapped UI strings originate from mw.msg() i18n (T402621
), it is more logical and efficient to handle these strings directly in the frontend, without sending them through an API.
Only the DOM-only strings (that don’t have corresponding i18n keys) need to be sent to the backend for segmentation.

Thoughts and how to move forward:

Avoid using ApiWikispeechSegment for mw.msg() strings.
  • These can be segmented either client-side or passed as-is to ApiWikispeechListen.
Keep SegmentUIFactory and ApiWikispeechSegment for handling DOM-only strings.
  • These strings must still be cleaned and segmented server side.
If following this structure, client logic must now decide:
  • If string comes from mw.msg() → segment on client and send directly to ApiWikispeechListen
  • If string comes from raw DOM → send to ApiWikispeechSegment

Possibly clean up or simplify some server logic that assumed everything would be sent through ApiWikispeechSegment, otherwise I think I can keep the logic as it is for now for handling DOM-ui-elements?

Please let me know if this aligns with what we discussed @Sebastian_Berlin-WMSE

That's not what I had in mind. I don't know if I understand you correctly, but here's what I suggested:

If an element gets its text from a message we can pre generate these (T387284). Then we can get the correct utterance via the listen API. This would need expanding that API to accept message keys.

We also need to find the correct message key for an element for the listen API request. This should be possible because the URL parameter uselang=qqx display these.

This way there's no unnecessary processing required in the frontend and the size of the requests shouldn't get out of hand due to long messages (unless there are some keys that are really long). There may be elements where you can't rely on messages, but I think we should add specific logic for them later as needed.

If it's still unclear we should have a meeting to sort this out so we're on the same page.

I think I now understand what you mean, correct me if I still get it wrong:

UI strings coming from mw.msg() should not be passed through ApiWikispeechSegment or segmented in the frontend.
Instead, these message-based strings should be pre-segmented and synthesized using the existing PreSynthesizeMessages maintenance script (T387284), and then referenced by their message key via ApiWikispeechListen (which will need to be extended to support message-based requests).

Given this, what would be the best approach moving forward: should I roll back my current patch and split this into two separate tasks (one for DOM-only UI strings, and one for message-based strings), or is it still reasonable to keep both approaches in this task since they're closely related? I would rather not roll back, since I think the solution I have now could be useful in the future for DOM-strings, so maybe I should rename this task to clarify it's only DOM-strings and then create a new task for message-based strings?

Viktoria_Hillerud_WMSE renamed this task from Store utterances from UI content in Wikispeech segmentation storage to Store utterances from UI content (DOM-strings) in Wikispeech segmentation storage.Oct 16 2025, 8:41 AM

We decided in keeping this task and patch WIP, as it could come in handy later on when handling DOM-based ui strings.
But for now, I'll create a new task that handles the strings that comes from MW:s message system. The new task can be found here: T407474