Page MenuHomePhabricator

Refactor WatchedItemQueryService::getWatchedItemsWithRecentChangeInfo and ApiQueryRecentChanges
Open, Needs TriagePublic

Description

WatchedItemQueryService::getWatchedItemsWithRecentChangeInfo() is a helper for ApiQueryWatchlist. Its interface is very specific to the API in a way that limits its applicability elsewhere. It is essentially a duplicate implementation of the queries done by ChangesListSpecialPage. Extensions like ORES that wish to extend ChangesListSpecialPage must also extend WatchedItemQueryService.

My idea is to integrate it with ChangesListQuery, thus removing the code duplication. This will make it easier to implement watchlist labels (T406843 etc.).

Also ApiQueryRecentChanges.

Event Timeline

tstarling renamed this task from Refactor WatchedItemQueryService::getWatchedItemsWithRecentChangeInfo to Refactor WatchedItemQueryService::getWatchedItemsWithRecentChangeInfo and ApiQueryRecentChanges.Mon, Oct 13, 3:39 AM
tstarling updated the task description. (Show Details)

Change #1195974 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/core@master] recentchanges: Migrate ApiQueryRecentChanges to ChangesListQuery

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

Change #1196623 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/core@master] Migrate ApiQueryWatchlist to ChangesListQuery

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

Change #1196783 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/extensions/ORES@master] Allow API query hooks to work on watchlist

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

Test wiki created on Patch demo by KGraessle-WMF using patch(es) linked to this task:
https://cc00d9a8ed.catalyst.wmcloud.org/w/

Test wiki created on Patch demo by KGraessle-WMF using patch(es) linked to this task:
https://aea8a2d39a.catalyst.wmcloud.org/w/

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

https://aea8a2d39a.catalyst.wmcloud.org/w/

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

https://cc00d9a8ed.catalyst.wmcloud.org/w/

Test wiki created on Patch demo by KGraessle-WMF using patch(es) linked to this task:
https://5cdf630a59.catalyst.wmcloud.org/w/

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

https://5cdf630a59.catalyst.wmcloud.org/w/

Change #1196783 merged by jenkins-bot:

[mediawiki/extensions/ORES@master] Allow API query hooks to work on watchlist

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

Hi @tstarling

I was testing the API endpoint locally and I did find one minor issue where bot edits were coming back from the API even with the !bot flag set:

Screenshot 2025-10-23 at 10.33.28 AM.png (894×2 px, 252 KB)

Everything else looked great; I will re-test on patch demo when it's working again to validate it's not a local issue.

I was testing the API endpoint locally and I did find one minor issue where bot edits were coming back from the API even with the !bot flag set:

I can't reproduce that. Can you check that the edit is shown as a bot edit in Special:RecentChanges, or enable rcprop=flags so that the bot flag is shown in the API output? It looks like you used AutoModeratorRollback::updateRecentChange(), since the edit is shown as reverted, but $this->bot is always false, nothing assigns to it, so if $useRCPatrol is true then the edit won't be marked as a bot edit. In RollbackPage there is markAsBot() which sets $this->bot but you don't have that in AutoModeratorRollback.

I was testing the API endpoint locally and I did find one minor issue where bot edits were coming back from the API even with the !bot flag set:

I can't reproduce that. Can you check that the edit is shown as a bot edit in Special:RecentChanges, or enable rcprop=flags so that the bot flag is shown in the API output? It looks like you used AutoModeratorRollback::updateRecentChange(), since the edit is shown as reverted, but $this->bot is always false, nothing assigns to it, so if $useRCPatrol is true then the edit won't be marked as a bot edit. In RollbackPage there is markAsBot() which sets $this->bot but you don't have that in AutoModeratorRollback.

Sure enough, they aren't marked as bot edits. (this is configurable behavior, so it can be expected).
Thanks!

Test wiki created on Patch demo by KGraessle-WMF using patch(es) linked to this task:
https://49a7dfb296.catalyst.wmcloud.org/w/

Test wiki created on Patch demo by KGraessle-WMF using patch(es) linked to this task:
https://feb9e42340.catalyst.wmcloud.org/w/

Hi @tstarling

I found two issues in testing https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1196623 on patch demo.

The first is when you have negative namespace values, I'm not seeing the results being filtered by that namespace and I'm seeing a warning returned:

Screenshot 2025-10-27 at 11.15.18 AM.png (908×2 px, 235 KB)

This happens for both Special and Media namespaces.

The second issue is when I was filtering by the anon param in the wlshow it was returning the correct user entries, but the anon flag was coming back as false:

Screenshot 2025-10-27 at 11.16.38 AM.png (1×2 px, 285 KB)

The first is when you have negative namespace values, I'm not seeing the results being filtered by that namespace and I'm seeing a warning returned:

Screenshot 2025-10-27 at 11.15.18 AM.png (908×2 px, 235 KB)

This happens for both Special and Media namespaces.

This is reproducible against master. It's not related to this commit.

The second issue is when I was filtering by the anon param in the wlshow it was returning the correct user entries, but the anon flag was coming back as false:

Screenshot 2025-10-27 at 11.16.38 AM.png (1×2 px, 285 KB)

This is also reproducible against master. I see in your screenshot that the user's name is "~2025-2". Temporary users are treated as anonymous by wlshow=anon but are treated as non-anonymous for the "anon" flag in the result. There is an existing comment apologising for this behaviour:

				// Whether the user is a logged-out user (IP user). This does
				// not include temporary users, though they are grouped with IP
				// users for FILTER_NOT_ANON and FILTER_ANON, to match the
				// recent changes filters (T343322).
				$vals['anon'] = !$recentChangeInfo['rc_user'];

Change #1195974 merged by jenkins-bot:

[mediawiki/core@master] recentchanges: Migrate ApiQueryRecentChanges to ChangesListQuery

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

Change #1196623 merged by jenkins-bot:

[mediawiki/core@master] recentchanges: Migrate ApiQueryWatchlist to ChangesListQuery

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

Change #1200750 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/extensions/ORES@master] Remove unused WatchedItemQueryService hooks

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

Still some cleanup to do

Change #1201320 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/core@master] watchlist: Remove WatchedItemQueryService::getWatchedItemsWithRecentChangeInfo

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