Background: Endpoint to add an article to an event's worklist. Called by the add-article
form (task-TBD). Only organizers and registered participants may add articles. The backend must
validate that the article exists on the specified wiki before adding it.
Type of story
- Backend
Acceptance criteria
- Only organizers and registered participants of the event may call this endpoint; all others receive 403.
- The wiki_id must be a recognised wiki in the CampaignEvents configuration; unrecognised values return 400.
- The page_title must be syntactically valid (non-empty, no illegal characters); invalid values return 400.
- The page must actually exist on the specified wiki; non-existent pages return 400 with the localised error message campaignevents-worklist-invalid-article-error.
- If the article is already in the worklist for this event, the endpoint returns 400 or 422 (TBD) with the localised error message campaignevents-worklist-article-already-exists.
- On success the endpoint returns 201 with { "id": <integer> } and a Location header pointing to the worklist resource.
- If the event registration ID does not exist, the endpoint returns 404.
Error messages and copy included
- For happy path: NOT NEEDED
- For unhappy path:
- Message key: campaignevents-worklist-invalid-article-error
- Message text: TBD
- Message suggestion: "The article \"$1\" could not be found on $2. Please check the title and wiki and try again."
- Context: returned in the API 400 response body when the article does not exist on the specified wiki; also displayed inline below the article input field in task-8. Parameters: $1 = page title, $2 = wiki identifier.
- Message key: campaignevents-worklist-article-already-exists
- Message text: TBD
- Message suggestion: "The article \"$1\" is already in this event's worklist on $2."
- Context: returned in the API 400 or 422 (TBD) response body when a duplicate article is submitted. Parameters: $1 = page title, $2 = wiki identifier.
- Message key: campaignevents-worklist-add-forbidden
- Message text: TBD
- Message suggestion: "You are not allowed to add articles to this event's worklist."
- Context: returned in the API 403 response body when the performer is neither organizer nor registered participant.
- Message key: campaignevents-worklist-event-not-found
- Message text: TBD
- Message suggestion: "There is no event registration with this ID."
- Context: returned in the API 404 response body when the path id does not correspond to an existing event registration.
- Message key: campaignevents-worklist-invalid-article-error
Are there dependencies (on someone else or learning something new)?
- Check cross-wiki validation for articles added -Investigation task TBD
Depends on
- T423332 ( DB layer for ce_worklist_articles — addArticle() and isArticleInWorklist())
- T423606 (Worklist feature flag)
Testing required?
- Yes
- Minimum testing to pass QA: unit tests covering happy path (201), 400 invalid article, 400 non-existent page, 403 forbidden, 404 event not found, 409 duplicate.
- Tested end-to-end in: task-8 (Worklist tab — add article form)
Technical details
- Follow the existing POST handler pattern in src/Rest/ (e.g. RegisterForEventHandler.php).
- Permission check: reuse the existing organizer/participant permission check pattern.
Split patches suggestion
- Branch 1: POST handler + route registration + permission check + validation + unit tests + i18n messages for invalid article, duplicate article, forbidden, and event not found.
API documentation
- The endpoint must be documented at: Extension:CampaignEvents/Api
== Add article to worklist ==
Route: `/campaignevents/v0/event_registration/{id}/worklist`
Content type: `application/json`
Method: POST
Returns: `{ "id": "<ID of the newly added worklist article (integer)>" }`
Adds an article to the worklist of a given event registration. The article is validated before
being added: the wiki_id must be a supported wiki and the page must exist on that wiki. Only
organizers and registered participants of the event may add articles.
=== Parameters ===
`id`
required | path
ID of the event registration.
=== Request schema ===
`page_title`
required | title
Title of the article to add. Must be a valid, existing page title on the specified wiki.
`wiki_id`
required | string
Wiki identifier (e.g. "enwiki", "frwiki"). Must be a supported wiki in the CampaignEvents configuration.
=== Responses ===
201
Success. The article was added to the worklist. The Location header points to the worklist resource.
400
The request data is invalid: unrecognised wiki_id, malformed page_title, or the page does not
exist on the specified wiki. The response body contains a localised error message
(campaignevents-worklist-invalid-article-error).
403
The performer is not an organizer or registered participant of the event.
404
The given event registration ID does not exist.
400 or 422 (TBD)
The article is already in the worklist for this event.Gherkin scenarios
Feature: Add article to event worklist via REST API
- Scenario: Organizer adds a valid article successfully
- Given an event registration exists with ID 1
- And the user is an organizer of the event
- And the article "Fermat's Last Theorem" exists on "enwiki"
- When the user sends POST /campaignevents/v0/event_registration/1/worklist with page_title "Fermat's Last Theorem" and wiki_id "enwiki"
- Then the response status is 201
- And the response body contains the new article ID
- Scenario: Registered participant adds a valid article successfully
- Given an event registration exists with ID 1
- And the user is a registered participant of the event
- And the article "Python (programming language)" exists on "enwiki"
- When the user sends POST /campaignevents/v0/event_registration/1/worklist with page_title "Python (programming language)" and wiki_id "enwiki"
- Then the response status is 201
- Scenario: Article does not exist on the specified wiki
- Given an event registration exists with ID 1
- And the user is an organizer of the event
- And the article "NonExistentArticleXYZ" does not exist on "enwiki"
- When the user sends POST /campaignevents/v0/event_registration/1/worklist with page_title "NonExistentArticleXYZ" and wiki_id "enwiki"
- Then the response status is 400
- And the response body contains the localised error message for campaignevents-worklist-invalid-article-error
- Scenario: Article is already in the worklist
- Given an event registration exists with ID 1
- And the user is an organizer of the event
- And the article "Python (programming language)" is already in the worklist for event 1
- When the user sends POST /campaignevents/v0/event_registration/1/worklist with page_title "Python (programming language)" and wiki_id "enwiki"
- Then the response status is 409
- And the response body contains the localised error message for campaignevents-worklist-article-already-exists
- Scenario: Non-participant tries to add an article
- Given an event registration exists with ID 1
- And the user is not an organizer or registered participant of the event
- When the user sends POST /campaignevents/v0/event_registration/1/worklist
- Then the response status is 403
- And the response body contains the localised error message for campaignevents-worklist-add-forbidden
- Scenario: Event registration does not exist
- Given no event registration exists with ID 999
- When the user sends POST /campaignevents/v0/event_registration/999/worklist
- Then the response status is 404
- And the response body contains the localised error message for campaignevents-worklist-event-not-found