Page MenuHomePhabricator

Auto attach Contest Template to Articles to Wiki Contest
Open, Needs TriagePublic

Description

Summary

Implement automatic template enforcement for Wikimedia/Wikipedia edit-a-thon contests. When users submit articles to a contest, the system should automatically verify and attach the contest's required template to the article if it's missing.

Context

This feature applies to Wikimedia / Wikipedia edit-a-thon contests, where submitted articles are expected to follow a specific contest template (e.g., banner, maintenance template, or contest metadata template). The system should automatically ensure compliance by checking for and attaching templates as needed.


Requirements

1. Contest Creation - Template Link Field

Task: Add template link field to contest model and creation form.

  • Add a new database field/column: template_link
  • This field stores the official wiki template URL associated with the contest
  • Example: https://en.wikipedia.org/wiki/Template:Editathon2025
  • Update contest creation and editing forms to include this field
  • Update database migration to add the new column

Acceptance Criteria:

  • Database schema includes template_link field (nullable initially, required for active contests)
  • Contest creation form includes template link input field
  • Contest editing form allows updating template link
  • Field is displayed in contest details view

2. Template Validation

Task: Implement basic validation for template links during contest creation/update.

Validation Requirements:

  • The link must be a valid URL
  • The page must exist and be reachable
  • The page must correspond to a Wiki template page:
    • Page namespace is Template:
    • OR the page content includes template syntax ({{...}})

Error Handling:

  • If validation fails, block contest creation or activation
  • Display clear error message: *"Invalid or unreachable template link"*
  • Provide user-friendly guidance on what constitutes a valid template link

Acceptance Criteria:

  • URL format validation on frontend
  • Backend validation checks URL reachability
  • Backend validation verifies template namespace or syntax
  • Clear error messages displayed to user
  • Contest cannot be activated with invalid template link

3. Article Submission - Template Check Logic

Task: Implement template presence check when articles are submitted to contests.

Implementation Steps:

  1. Retrieve the contest's template_link when article is submitted
  2. Fetch the template content from the wiki
  3. Check whether the beginning of the submitted article already contains the contest template

Compliance Rules:

  • Article is compliant if it starts with the same template (or its wiki invocation)
  • Allow for:
    • Leading whitespace
    • Minor formatting differences
  • Normalize content before comparison (trim whitespace, normalize line breaks)

Acceptance Criteria:

  • System retrieves template content from provided link
  • System checks article content for template presence
  • Comparison handles whitespace and formatting variations
  • Template detection works with both {{TemplateName}} and {{Template:TemplateName}} formats

4. Automatic Template Attachment

Task: Automatically prepend contest template to articles that don't have it.

Implementation Requirements:

  • If submitted article does not begin with the contest's template:
    • Automatically prepend the contest template to the top of the article
    • Ensure template is added only once (prevent duplicates)
    • Maintain proper spacing between template and article content

Final Article Structure:

{{ContestTemplate}}

Article content starts here…

Technical Implementation:

  • Use MediaWiki API prependtext parameter (not appendtext) to add template at top
  • Use OAuth authentication to edit on behalf of the user
  • Handle edit conflicts gracefully
  • Provide clear edit summary: "Adding [TemplateName] via Contest Tool"

Acceptance Criteria:

  • Template is automatically added if missing
  • Template is added at the top of the article (not bottom)
  • Duplicate insertion is prevented
  • Proper spacing is maintained
  • Edit is performed using user's OAuth credentials
  • Edit summary is clear and descriptive