Page MenuHomePhabricator

vNext: Establish a shared vocabulary for use in API responses [SPIKE]
Open, HighPublic5 Estimated Story Points

Description

Explore: API responses across action and REST API should use have shared standard vocabulary that is used by all domains, modules, and extensions. The vocabulary should cover core concepts:

  • page reference and page identity
  • revision references
  • user identity
  • timestamp and expiry

JSON schema fragments for this vocabulary should be published on schema.wikimedia.org in a single file. They should be accessible from code using a single class.

Note that this is different from the shared error response schemas and also from standard pagination envelopes.

DoD: We have rough agreement on a mechanism to use in PHP, scope of the development work, and schemas for the fragments. This allows us to file tickets that break down the work for putting the mechanism into production. Refining and merging the patches attached to this ticket is not necessary for it to be completed. The patches serve the exploration, we may still decide to do something else.

Draft

Example data, following the event entity schema:

# NOTE: All fields are required, some are nullable.

# page identity
page:   # ProperPageIdentity
	page_id: 1234
	page_namespace: 1
	page_title: Talk:John_Doe # Includes the namespace prefix, uses underscores
nonexisting_page:  # ProperPageIdentity
	page_id: 0
	page_namespace: 0 # NS_MAIN
	page_title: Yadda_Yadda
special_page:  # PageIdentity
	page_id: null        # cannot have a page ID. Separate schema?!
	page_namespace: -1   # That's the actual value of NS_SPECIAL in MediaWiki
	page_title: Special:Search

# page reference (e.g. outgoing links)
page_ref: # PageReference
	page_namespace: 1
	page_title: Talk:John_Doe
nonexisting_page_ref: # PageReference
	page_namespace: 0
	page_title: Yadda_Yadda
special_page_ref: # PageReference
	page_namespace: -1
	page_title: Special:Search

# revision reference
rev_id: 1234
revision: # RevisionReference
	rev_id: 1234 
	page_id: 5678 

# revision reference
user: # UserIdentity
	user_id: 1234
	user_name: "Joan Doe" # Note the space. The event schema uses "user_text".

anon_user: # UserIdentity
	user_id: null # not 0, because it can't exist as a user account
	user_name: "123.123.123.123" 

system_user: # UserIdentity
	user_id: 0
	user_name: "MediaWiki Default"
	
# timespams
timestamp: "2026-11-10T12:13:14Z" # ISO 8601. 
expiry_never: "infinity" # or infinite? indefinite? never?

Example data, with redundant prefixes removed:

# NOTE: All fields are required, some are nullable.

# page identity
page:   # ProperPageIdentity
	id: 1234
	namespace: 1
	title: Talk:John_Doe # Includes the namespace prefix, uses underscores
nonexisting_page:  # ProperPageIdentity
	id: 0
	namespace: 0 # NS_MAIN
	title: Yadda_Yadda
special_page:  # PageIdentity
	id: null        # cannot have a page ID. Separate schema?!
	namespace: -1   # That's the actual value of NS_SPECIAL in MediaWiki
	title: Special:Search

# page reference (e.g. outgoing links)
page_ref: # PageReference
	namespace: 1
	title: Talk:John_Doe
nonexisting_page_ref: # PageReference
	namespace: 0
	title: Yadda_Yadda
special_page_ref: # PageReference
	namespace: -1
	title: Special:Search

# revision reference
rev_id: 1234
revision: # RevisionReference
	id: 1234 
	page_id: 5678 # or just "page"?

# revision reference
user: # UserIdentity
	id: 1234
	name: "Joan Doe" # Note the space. 

anon_user: # UserIdentity
	id: null # not 0, because it can't exist as a user account 
	name: "123.123.123.123" 

system_user: # UserIdentity
	id: 0
	name: "MediaWiki Default"
	
# timespams
timestamp: "2026-11-10T12:13:14Z" # ISO 8601. 
expiry_never: "infinity" # or infinite? indefinite? never?

Action API, for comparison:


# page identity
page:
	pageid: 1234
	ns: 1
	title: Talk:John_Doe # Includes the namespace prefix, uses underscores
nonexisting_page:
	pageid: 0
	ns: 0 # NS_MAIN
	title: Yadda_Yadda
special_page:
	pageid: 0 # Same as non-existing page
	ns: -1   # That's the actual value of NS_SPECIAL in MediaWiki
	title: Special:Search

# page reference (e.g. outgoing links)
page_ref:
	ns: 1
	title: Talk:John_Doe
nonexisting_page_ref:
	ns: 0
	title: Yadda_Yadda
special_page_ref:
	ns: -1
	title: Special:Search

# revision reference
revid: 1234
revision:
	revid: 1234
	pageid: 5678 

# revision reference
user: # UserIdentity
	userid: 1234
	user: "Joan Doe" # Note the space. When listing users, the field is called "name".

anon_user: # UserIdentity
	userid: null
	user: "123.123.123.123" 

system_user: # UserIdentity
	userid: 0
	user: "MediaWiki Default"
	
# timespams
timestamp: "2026-11-10T12:13:14Z" # ISO 8601. 
expiry_never: "infinity" # or infinite or indefinite or never

Event Timeline

Change #1349077 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Add a shared vocabulary for result values

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

Change #1350731 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Pin the output of list=categorymembers in a test

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

Change #1350732 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Use vocabulary terms in list=categorymembers

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

Change #1350733 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Pin the output of list=recentchanges for pages and users

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

Change #1350734 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Use vocabulary terms in list=recentchanges

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

Change #1350803 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Pin the output of action=move in a test

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

Change #1350804 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] REST: Render vocabulary terms with Rest26 in action module adapters

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

Change #1351198 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Explore a helper for page-related prop values

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

Change #1351478 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Add experimental formatversion=3 with the Rest26 dialect

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

Change #1351504 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: Add a beta formatversion=Rest26

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

daniel renamed this task from vNext: Establish a shared vocabulary for use in API responses to vNext: Establish a shared vocabulary for use in API responses [SPIKE].Oct 9 2026, 2:45 PM
daniel set the point value for this task to 5.

I estimate this at 5 points for the exploration and decision making. Productionizing will need a fresh estimate. The outcome of the spike is to agree on a mechanism and on some details of the modeling/schemas. It is not necessary for the patches to be merged.

Hi, I understand very little about the ResultTerm idea, but FWIW:

event fragment/mediawiki/state common event schemas representing mediawiki state

especially jsonschema/fragment/mediawiki/state/entity, which has resusable data models :

  • page
  • page_link
  • revision
  • revision_rendering
  • revision_rendering_content
  • revision_slots
  • user

All of which have some fields which may overlap with your terms here? Not that we have to align everything, but the more we do the better!

Hi, I understand very little about the ResultTerm idea, but FWIW:

event fragment/mediawiki/state common event schemas representing mediawiki state

especially jsonschema/fragment/mediawiki/state/entity, which has resusable data models :

  • page
  • page_link
  • revision
  • revision_rendering
  • revision_rendering_content
  • revision_slots
  • user

All of which have some fields which may overlap with your terms here? Not that we have to align everything, but the more we do the better!

Nice, thank you! Yes, I agree that we should at least align on property names, so it becomes easier to fractor out the smallest common denominator later, and share it.

@HCoplin-WMF Good news: I was wrong about the page_title in events, it does have the namespace prefix (*). So we can use it with the same semantics in the API.

(*) The schema doesn't say, but the EventBus code does.

Restricted Application added a subscriber: revi. · View Herald TranscriptThu, Nov 5, 1:01 PM

^ Related: T426268: Support new fields: (1) namespace textual prefix and (2) page title without prefix
Request to not put namespace in page_title, or at least provide a field that does not have namespace in page_title.

Nice! Quick thoughts

page_namespace

Suggestion to use _id suffix here, to avoid having to qualify its potential textual name, e.g. page_namespace_name.

user_text

Yeah, this is mostly a leftover from long ago (I think pre actor table?). This is one where it might be better to go with updated concept (user_name?) rather than align with event schemas. See also https://wikitech.wikimedia.org/wiki/Data_Platform/Data_modeling_guidelines#User_text_vs._user_name.

We could consider adding a redundant user_name alongside of user_text in events to accommadate the new name. It probably would be hard to fully remove user_text though.

daniel updated the task description. (Show Details)

timestamp

Fully up to you, but the event guidelines use naming to differentiate whether or not a timestamp is (serialized) as a 'date time string' (ISO8601) or epoch time counter. Date times are dt, and timestamps are ts. Just a convention though.

https://wikitech.wikimedia.org/wiki/Event_Platform/Schemas/Guidelines#Datetimes
https://wikitech.wikimedia.org/wiki/Data_Platform/Data_modeling_guidelines#Timestamps

Datetime fields (also known as timestamps) should be named with the suffix _dt and in UTC. They should should be serialized in JSON as ISO-8601 strings with the suffix "Z". For example, 2015-12-20T09:10:56Z.
[...]
There may be cases where it is necessary to send an integer Unix timestamp instead of an ISO-8601 string. In this case, the data type should be integer, the timestamp should be sent as integer milliseconds, and the field name should be suffixed with _ts_ms. If you must send seconds instead of milliseconds, then the field name should be suffixed with with _ts_s.

at least provide a field that does not have namespace in page_title.

We were actually talking about that yesterday. I sort of agree that it makes sense to have namespace, title, and namespace:title all be available for different use cases. We were concerned about too much duplicative data going through the EventStream though. Are you saying that you also want to provide all 3 as separate fields?

  1. NOTE: All fields are required, some are nullable.

In the example, I only see SpecialPage page ID as null. What else is nullable? Is it also reasonable to assume we would use null instead of the 0's returned by the Action API for missing IDs? Or is the plan to continue that pattern, given the non-existant page example?

though. Are you saying that you also want to provide all 3 as separate fields?

I'm not sure, but IIRC, the main request in that ticket is to have a page_title that does not have namespace in it. We hadn't reached a decision on what to actually do.

NOTE: All fields are required, some are nullable.

Also FWIW, event schemas don't use nullable fields. Instead they use optional fields and events omit them when absent.

https://wikitech.wikimedia.org/wiki/Event_Platform/Schemas/Guidelines#No_union_types_/_No_null_values

For your purposes do what makes the most sense, of course.

Just FYI JSONSchema nulls are a bit useless on their own, and that Union types make the type of the field non deterministic, which is problematic when automating conversions between type systems.

Change #1369496 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] REST: Don't construct ResponseFactory directly in tests

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

Change #1369503 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] REST: Clean up ResponseFactory's constructor

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

Change #1369510 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] REST: Use JsonCodec when building responses

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