Page MenuHomePhabricator

Incomplete <head> using MediaWiki API "headhtml"
Open, Needs TriagePublic

Description

When getting the <head> of a page with prop = headhtml in the MediaWiki API (using action=parse), a large part of styles and scripts are then not loaded.

This is because headhtml from API is incomplete as you can see when you compare for instance the source code of https://www.mediawiki.org/wiki/API:Parsing_wikitext and the corresponding headhtml from API : https://www.mediawiki.org/w/api.php?action=parse&format=json&page=API%3AParsing%20wikitext&prop=headhtml

Notice that <title>API:Parsing wikitext - MediaWiki</title> in the source code becomes <title> - MediaWiki</title> using headhtml

Then, within first <script> tags, scripts disappear:

RLSTATE={"ext.gadget.site-styles":"ready","ext.globalCssJs.user.styles":"ready","site.styles":"ready","noscript":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":
"loading","ext.translate":"ready","ext.translate.tag.languages":"ready","mediawiki.hlist":"ready","mediawiki.apipretty":"ready","ext.pygments":"ready","skins.vector.styles":"ready","mediawiki.ui.icon":"ready","jquery.makeCollapsible.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.echo.styles.badge":"ready","oojs-ui.styles.icons-alerts":"ready","ext.uls.pt":"ready","ext.wikimediaBadges":"ready","wikibase.client.init":"ready"};RLPAGEMODULES=["site","mediawiki.page.ready","jquery.makeCollapsible","mediawiki.toc","skins.vector.js","mediawiki.page.watch.ajax","ext.gadget.site","ext.gadget.collapsibleTables","ext.gadget.tabbedwindow","ext.gadget.logo-voting","ext.gadget.Edittools","ext.centralauth.centralautologin.clearcookie","mmv.head","mmv.bootstrap.autostart","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.init","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.compactlinks","ext.uls.interface","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.translate.pagetranslation.uls","wikibase.client.linkitem.init"];

becomes:

RLSTATE={"site.styles":"ready","noscript":"ready","user.styles":"ready","user":"ready","user.options":"loading","ext.translate":"ready","ext.translate.tag.languages":"ready","mediawiki.hlist":"ready","mediawiki.apipretty":"ready","ext.pygments":"ready"};

Same for stylesheets:

<link rel="stylesheet" href="/w/load.php?lang=en&amp;amp;modules=ext.echo.styles.badge%7Cext.pygments%2Ctranslate%2CwikimediaBadges%7Cext.translate.tag.languages%7Cext.uls.pt%7Cext.visualEditor.desktopArticleTarget.noscript%7Cjquery.makeCollapsible.styles%7Cmediawiki.apipretty%2Chlist%7Cmediawiki.ui.icon%7Coojs-ui.styles.icons-alerts%7Cskins.vector.styles%7Cwikibase.client.init&amp;amp;only=styles&amp;amp;skin=vector"/>

becomes:

<link rel="stylesheet" href="/w/load.php?lang=en&amp;amp;modules=ext.pygments%2Ctranslate%7Cext.translate.tag.languages%7Cmediawiki.apipretty%2Chlist&amp;amp;only=styles&amp;amp;skin=vector"/>

Context: For my project, I want to be able to dynamically load (on demand) other local pages of my wiki in a page using iframes. As I only need the content of the pages (no header, footer etc.), I wanted to use the MediaWiki API instead of the src attribute for performance issue. Thus I also need to load the head as it may be different from the head of the hosting page. Am I missing something? How would you dyamically load a local page in another one? If using the API is not the proper way, how would proceed to get <head> and page content only?

Event Timeline

Indeed, it seems to me it is a bug related to the Mediawiki API so I also reported it here after nobody answered in the support desk. Did I do anything wrong?