Page MenuHomePhabricator

Add mechanism to add a namespace prefix attribute to <html> or <head>, to use an RDFa schema (such as Open Graph or Dublin Core)
Open, Needs TriagePublic

Description

In order to properly* use an RDFa schema (such as Open Graph or Dublin Core) on a web page it is necessary to use a namespace prefix attribute; this is normally done in the <html> or <head> element so as to avoid having to repeat the prefix attribute in every element it applies to. Example:

<html prefix="og: https://ogp.me/ns#">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="https://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="https://ia.media-imdb.com/images/rock.jpg" />
...
</head>
...
</html>

However, per this Support desk discussion there doesn't seem to be any easy way of adding attributes to <html> or <head>. It is possible to write a new skin and use getHtmlElementAttributes() but this is not really scalable. (If all you want to do is add RDF metadata to your wiki, it shouldn't have to be necessary to fork and manually patch all the available skins and then keep those forks in sync with future official releases.)

Please consider adding some mechanism for adding attributes to <html> or <head> which can be invoked from an extension and from LocalSettings.php, the same way that functions like addMeta() can be invoked.

*There do exist MediaWiki extensions which purport to add RDFa metadata schemas, though as far as I can tell none of them do this in a manner that conforms to the RDFa specification, since none of them add the requisite prefix attribute to the metadata tags or to their <html> or <head> (grand)parent.

Event Timeline

Aklapper renamed this task from Add mechanism to add attributes to <html> or <head> to Add mechanism to add a namespace prefix attribute to <html> or <head>, to use an RDFa schema (such as Open Graph or Dublin Core).Jul 28 2020, 1:37 PM
Aklapper added a project: MediaWiki-General.

This should probably be implemented in Html::htmlHeader().

Actually, that method allows you to define custom namespaces using $wgXhtmlNamespaces already, which apparently can be used instead of the 'prefix' attribute (it's deprecated though). https://www.w3.org/TR/rdfa-core/#PS-IRI-mappings

@Psychonaut did you find any solution to add those tags? I am also facing the same issue on my site.

As I understand it, the only real solution is for this functionality to be added to the MediaWiki codebase. I'm not aware of any workarounds other than manually creating/modifying skins, or declaring the namespace directly in the elements, though neither of these workarounds are ideal.