GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Edit Task
  • Edit Related Tasks...
  • Create Subtask
  • Edit Parent Tasks
  • Edit Subtasks
  • Merge Duplicates In
  • Close As Duplicate
  • Edit Commits
  • Edit Mocks
  • Mute Notifications
  • Protect as security issue
  • MediaWiki-Parser
  • (Backlog)
  • MediaWiki-Action-API

This view

  • Original page
  • New address

GeezerVison is showing phabricator.wikimedia.org — T355493 Add more information to MediaWiki parse tree

Page MenuHomePhabricator
Log In
Create Task
Maniphest T355493

Add more information to MediaWiki parse tree
Open, Needs TriagePublic
Actions

  • Edit Task
  • Edit Related Tasks...
  • Create Subtask
  • Edit Parent Tasks
  • Edit Subtasks
  • Merge Duplicates In
  • Close As Duplicate
  • Edit Related Objects...
  • Edit Commits
  • Edit Mocks
  • Mute Notifications
  • Protect as security issue
Assigned To
None
Authored By
Tgr
Jan 21 2024, 10:37 PM2024-01-21 22:37:59 (UTC+0)
Project Tags
  • MediaWiki-Parser (Backlog)
  • MediaWiki-Action-API (Unsorted)
Referenced Files
None
Subscribers
Aklapper
Dogu
Tgr

Description

The action=parse&prop=parsetree API returns an XML representation of how the MediaWiki preprocessor splits up the wikitext into template names, parameters, extension tags etc. Unfortunately this representation doesn't include the template markup itself, making it hard to reconstruct the wikitext from the parse tree, which would be very useful for template manipulations (e.g. remove or change a certain parameter of a certain template). Parsoid can't do that because it can't introspect nested templates ({{outer| {{inner| param }} }} which is common in e.g. infoboxes), regexes are brittle, and writing a client-side parser is more effort than what we should force clients to do. (In Python, mwparserfromhell can do it, but there is no similar JS parser.)

Related Objects

  • Mentions
Mentioned Here
T4700: Pre-save transform skips extensions using wikitext (gallery, references, footnotes, Cite, status indicators, pipe trick, subst, signatures)
T51353: Support Parser::PTD_FOR_INCLUSION mode in action=expandtemplates

Event Timeline

Tgr created this task.Jan 21 2024, 10:37 PM2024-01-21 22:37:59 (UTC+0)
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJan 21 2024, 10:38 PM2024-01-21 22:38:00 (UTC+0)
Tgr added a comment.Jan 21 2024, 10:43 PM2024-01-21 22:43:48 (UTC+0)
Comment Actions

For example {{SomeTemplate|some-param}} is represented in the parse tree as

<template><title>SomeTemplate</title><part><name index=\"1\"/><value>some-param</value></part></template>

Instead, it could be something like

<template><markup>{{</markup><title>SomeTemplate</title><part><markup>|</markup><name index=\"1\"/><value>some-param</value></part><markup>}}</markup></template>

so that loading the parse tree into a DOM model and getting the textContent of the root element would return the original wikitext.

This is a breaking change so we'd need a version parameter and support for both versions, which seems straightforward.

Dogu subscribed.Jan 21 2024, 10:45 PM2024-01-21 22:45:20 (UTC+0)
Umherirrender subscribed.Jan 22 2024, 5:46 PM2024-01-22 17:46:39 (UTC+0)
Comment Actions

The parsetree preserves whitespaces and the markup is represented by the tags, it is already possible to remap the wikitext from the parsetree, not that complex, but also not easy as with textContent.

Some hints:

  • <template> => {{ ... }} possible with lineStart= attribute
  • <tplarg> => {{{ ... }}}
    • both contains <title> and optional <part> with <name>, <equals> and <value> each, for each part a pipe is needed.
  • <ext> => < ... > with <name>, <attr>, <inner> and <close>, when close is missing it is represented as short tag with />

The wikitext in <inner> is not expanded, same reason as T4700.

For a deep dive into templates you would need the inclusion parsetree, that needs T51353.

Umherirrender unsubscribed.Feb 11 2024, 12:06 AM2024-02-11 00:06:27 (UTC+0)
Log In to Comment
Content licensed under Creative Commons Attribution-ShareAlike (CC BY-SA) 4.0 unless otherwise noted; code licensed under GNU General Public License (GPL) 2.0 or later and other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL · Credits
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.