Page MenuHomePhabricator

Reroute /v1/transform endpoints to rest gateway
Closed, ResolvedPublic

Description

Currently mediawiki has support for those endpoints and we need to reroute them via rest-gateway

  • Endpoints
    • v1/transform/wikitext/to/html
    • v1/transform/wikitext/to/html/{title}
    • v1/transform/wikitext/to/html/{title}/{revision}
    • v1/transform/html/to/wikitext
    • v1/transform/html/to/wikitext/{title}/{revision}
    • v1/transform/html/to/wikitext/{title}/

transform/wikitext/to/lint is covered by T384216

The paths are the same but instead of RB they need to point to
https://{wiki}/w/rest.php/{path}

Event Timeline

Change #1156811 had a related patch set uploaded (by Hnowlan; author: Hnowlan):

[operations/deployment-charts@master] rest-gateway: route html<->wikitext transforms to mw-api-int

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

Change #1156813 had a related patch set uploaded (by Hnowlan; author: Hnowlan):

[operations/puppet@production] trafficserver: migrate html<->wikitext transforms out of restbase

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

Change #1156811 merged by jenkins-bot:

[operations/deployment-charts@master] rest-gateway: route html<->wikitext transforms to mw-api-int

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

These transforms are live on the rest-gateway:

$ curl -s -H "Host: en.wikipedia.org" -k -X POST -d "wikitext='''hello'''" https://staging.svc.eqiad.wmnet:4113/en.wikipedia.org/v1/transform/wikitext/to/html 
<!DOCTYPE html>
<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/"><head prefix="mwr: https://en.wikipedia.org/wiki/Special:Redirect/"><meta charset="utf-8"/><meta property="mw:pageId" content="15580374"/><meta property="mw:pageNamespace" content="0"/><meta property="mw:revisionSHA1" content="2c0c49dc9af8f5e2e6446ee70550b684fd8325fb"/><meta property="isMainPage" content="true"/><meta property="mw:htmlVersion" content="2.8.0"/><meta property="mw:html:version" content="2.8.0"/><link rel="dc:isVersionOf" href="//en.wikipedia.org/wiki/Main_Page"/><base href="//en.wikipedia.org/wiki/"/><title>Main Page</title><link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=mediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Csite.styles&amp;only=styles&amp;skin=vector"/><meta http-equiv="content-language" content="en"/><meta http-equiv="vary" content="Accept"/></head><body lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr" data-mw-parsoid-version="0.22.0.0-alpha6" data-mw-html-version="2.8.0" id="mwAA" data-parsoid='{"dsr":[0,11,0,0]}'><section data-mw-section-id="0" id="mwAQ" data-parsoid="{}"><p id="mwAg" data-parsoid='{"dsr":[0,11,0,0]}'><b id="mwAw" data-parsoid='{"dsr":[0,11,3,3]}'>hello</b></p></section></body></html>
$ curl -s -H "Host: en.wikipedia.org" -k -X POST -d 'html=<i>hello</i>' https://staging.svc.eqiad.wmnet:4113/en.wikipedia.org/v1/transform/html/to/wikitext 
''hello''
hnowlan changed the task status from Open to In Progress.Jun 16 2025, 11:11 AM
hnowlan added a project: serviceops-deprecated.

I also tried a request with a specific title and looks OK:

curl -k --request POST --url https://10.2.2.82:4113/en.wikipedia.org/v1/transform/wikitext/to/html/Earth --header 'Content-Type: application/json' --header 'Host: en.wikipedia.org' --data '{
  "wikitext": "'\'''\''Emphasize'\'''\'', '\'''\'''\''strongly'\'''\'''\''",
  "stash": true
}'

Output HTML:

<!DOCTYPE html>
<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/">

<head prefix="mwr: https://en.wikipedia.org/wiki/Special:Redirect/">
    <meta charset="utf-8" />
    <meta property="mw:pageId" content="9228" />
    <meta property="mw:pageNamespace" content="0" />
    <meta property="mw:revisionSHA1" content="150845fc10938df6cf38019909db020618b0c1d2" />
    <meta property="mw:htmlVersion" content="2.8.0" />
    <meta property="mw:html:version" content="2.8.0" />
    <link rel="dc:isVersionOf" href="//en.wikipedia.org/wiki/Earth" />
    <base href="//en.wikipedia.org/wiki/" />
    <title>Earth</title>
    <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=mediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Csite.styles&amp;only=styles&amp;skin=vector" />
    <meta http-equiv="content-language" content="en" />
    <meta http-equiv="vary" content="Accept" />
</head>

<body lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr" data-mw-parsoid-version="0.22.0.0-alpha6" data-mw-html-version="2.8.0" id="mwAA" data-parsoid='{"dsr":[0,29,0,0]}'>
    <section data-mw-section-id="0" id="mwAQ" data-parsoid="{}">
        <p id="mwAg" data-parsoid='{"dsr":[0,29,0,0]}'><i id="mwAw" data-parsoid='{"dsr":[0,13,2,2]}'>Emphasize</i>, <b id="mwBA" data-parsoid='{"dsr":[15,29,3,3]}'>strongly</b></p>
    </section>
</body>

</html>

Output preview:

image.png (144×630 px, 9 KB)

Also for html to wikitext with title:

curl -k --request POST --url https://10.2.2.82:4113/en.wikipedia.org/v1/transform/html/to/wikitext/Earth --header 'Content-Type: application/json' --header 'Host: en.wikipedia.org' --data '{
  "html": "<h1>This is a heading</h1> <p>This is a paragraph with <i>italic</i> </p>"
}'

Output:

= This is a heading =
This is a paragraph with ''italic''

Change #1156813 merged by Hnowlan:

[operations/puppet@production] trafficserver: migrate html<->wikitext transforms out of restbase

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

These APIs have been switched from restbase to the rest-gateway.