Page MenuHomePhabricator

Return watchlist labels for a page when calling action=query&prop=info
Closed, ResolvedPublic

Assigned To
Authored By
TheresNoTime
Tue, Feb 10, 11:00 PM
Referenced Files
F72134954: 2026-02-16_08-44-02.png
Mon, Feb 16, 6:56 PM
F72134952: 2026-02-16_08-43-49.png
Mon, Feb 16, 6:56 PM
F72134950: 2026-02-16_08-40-58.png
Mon, Feb 16, 6:56 PM
F72134948: 2026-02-16_08-38-51.png
Mon, Feb 16, 6:56 PM
F72134946: 2026-02-16_08-39-02.png
Mon, Feb 16, 6:56 PM
F72134944: 2026-02-16_08-37-35.png
Mon, Feb 16, 6:56 PM
F72134940: 2026-02-16_08-37-44.png
Mon, Feb 16, 6:56 PM
F72134934: 2026-02-16_08-36-28.png
Mon, Feb 16, 6:56 PM

Description

It perhaps makes sense for a call to /w/api.php?action=query&format=json&prop=info&titles=Test&formatversion=2&inprop=watchlistlabels to return an array of watchlist labels (IDs? IDs and names?) for the given page

Relates to T416615: Make watchlist labels usable via API calls


Derived Requirements

  1. The action=query&prop=info API must support a new inprop value: watchlistlabels.
  2. When inprop=watchlistlabels is specified and the page is watched by the current user:
    • The response must include an array of watchlist labels assigned to that page.
    • Each label must include:
      • Label ID
      • Label name
    • The structure must align with the existing watchlist label format used elsewhere in the API (consistent schema and field naming).
  3. If the page has no labels assigned:
    • The API must return an empty array for watchlistlabels (not omit the field).
  4. If the page is not watched:
    • The API must either omit the field or return an empty array (behavior must be consistent and documented).
  5. The response must respect user permissions:
    • Only return labels for the authenticated user making the request.
  6. The feature must work with format=json and formatversion=2.
Test Steps

Test Case 1: API returns labels for a watched page with labels

  1. Watch a page in Beta.
  2. Assign one or more watchlist labels to the page.
  3. Call: https://en.wikipedia.beta.wmcloud.org/w/api.php?action=query&format=json&formatversion=2&inprop=watchlistlabels&prop=info&titles=Banana
  4. Inspect the JSON response.
  5. ✅❓❌⬜ AC1: Response includes a watchlistlabels array under the page object, contains each label entry contains both ID and name, also returned labels match those assigned in the UI .

Test Case 2: API returns empty array when page has no labels

  1. Watch a page in Beta.
  2. Ensure no labels are assigned.
  3. Call the same API endpoint with inprop=watchlistlabels.
  4. Inspect the JSON response.
  5. ✅❓❌⬜ AC2: watchlistlabels is present and is an empty array.

Test Case 3: API behavior for unwatched page

  1. Ensure a page is not on the watchlist in Beta.
  2. Call the API with inprop=watchlistlabels.
  3. Inspect the JSON response.
  4. ✅❓❌⬜ AC3: watchlistlabels` is present and is an empty array.

Test Case 4: API without inprop parameter

  1. Call: https://en.wikipedia.beta.wmcloud.org/w/api.php?action=query&format=json&formatversion=2&prop=info&titles=Banana
  2. Inspect the JSON response.
  3. ✅❓❌⬜ AC4: No watchlistlabels field is present when inprop=watchlistlabels is not specified.

Test Case 5: Permission check

  1. Log out or use a user without the page on their watchlist.
  2. Call the API with inprop=watchlistlabels.
  3. ✅❓❌⬜ AC5: Labels are not returned for another user’s watchlist.

QA Results -Beta

Details

Related Changes in Gerrit:

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change #1238448 had a related patch set uploaded (by Samtar; author: Samtar):

[mediawiki/core@master] ApiQueryInfo: Add inprop=watchlistlabels

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

nb. I've opted to return both the label ID and label name, e.g.

{
   "pageid": 1,
   "ns": 0,
   "title": "Main Page",
   "contentmodel": "wikitext",
   "pagelanguage": "en",
   "pagelanguagehtmlcode": "en",
   "pagelanguagedir": "ltr",
   "touched": "2025-07-29T08:59:44Z",
   "lastrevid": 160,
   "length": 8,
   "watched": true,
   "watchlistlabels": [
      {
         "id": 1,
         "name": "test"
      }
   ]
},
Samwilson changed the task status from Open to In Progress.Wed, Feb 11, 2:53 AM

Change #1238448 merged by Samtar:

[mediawiki/core@master] ApiQueryInfo: Add inprop=watchlistlabels

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

@TheresNoTime Confirmed return watchlist labels for a page when calling action=query&prop=info, as seen from the screenshots below. I will mark this as Resolved. Thanks for all your work!

Test Result - Beta

Status: ✅ PASS
Environment: Beta
OS: macOS Tahoe 26.2
Browser: Chrome 143
Device: MBA
Emulated Device: NA

Test Artifact(s):
https://en.wikipedia.beta.wmcloud.org/w/api.php?action=query&format=json&formatversion=2&inprop=watchlistlabels&prop=info&titles=Banana
https://en.wikipedia.beta.wmcloud.org/w/api.php?action=query&format=json&formatversion=2&prop=info&titles=Banana
https://en.wikipedia.beta.wmcloud.org/wiki/Special:EditWatchlist

Test Steps

Test Case 1: API returns labels for a watched page with labels

  1. Watch a page in Beta.
  2. Assign one or more watchlist labels to the page.
  3. Call: https://en.wikipedia.beta.wmcloud.org/w/api.php?action=query&format=json&formatversion=2&inprop=watchlistlabels&prop=info&titles=Banana
  4. Inspect the JSON response.
  5. AC1: Response includes a watchlistlabels array under the page object, contains each label entry contains both ID and name, also returned labels match those assigned in the UI .
WatchlistJson
2026-02-16_08-36-11.png (960×1 px, 158 KB)
2026-02-16_08-36-28.png (664×1 px, 82 KB)

Test Case 2: API returns empty array when page has no labels

  1. Watch a page in Beta.
  2. Ensure no labels are assigned.
  3. Call the same API endpoint with inprop=watchlistlabels.
  4. Inspect the JSON response.
  5. AC2: watchlistlabels is present and is an empty array.
WatchlistJson
2026-02-16_08-37-44.png (834×1 px, 142 KB)
2026-02-16_08-37-35.png (445×1 px, 60 KB)

Test Case 3: API behavior for unwatched page

  1. Ensure a page is not on the watchlist in Beta.
  2. Call the API with inprop=watchlistlabels.
  3. Inspect the JSON response.

4.✅ AC3: watchlistlabels` is present and is an empty array.

WatchlistJson
2026-02-16_08-39-02.png (939×1 px, 157 KB)
2026-02-16_08-38-51.png (451×1 px, 62 KB)

Test Case 4: API without inprop parameter

  1. Call: https://en.wikipedia.beta.wmcloud.org/w/api.php?action=query&format=json&formatversion=2&prop=info&titles=Banana
  2. Inspect the JSON response.
  3. AC4: No watchlistlabels field is present when inprop=watchlistlabels is not specified.
WatchlistJson
2026-02-16_08-37-44.png (834×1 px, 142 KB)
2026-02-16_08-40-58.png (522×1 px, 59 KB)

Test Case 5: Permission check

  1. Log out or use a user without the page on their watchlist.
  2. Call the API with inprop=watchlistlabels.
  3. AC5: Labels are not returned for another user’s watchlist.
WatchlistJson
2026-02-16_08-43-49.png (793×1 px, 134 KB)
2026-02-16_08-44-02.png (451×1 px, 62 KB)
GMikesell-WMF updated Other Assignee, removed: GMikesell-WMF.
GMikesell-WMF updated the task description. (Show Details)