Meta tags in skin from MediaWiki template

100 Views Asked by At

Let's say i have a template in my MediaWiki like

<includeonly>

<div id="custom-person">

* <span>Birthday:</span> {{#if: {{{birth date|}}} | <b>{{#ol-time:|{{{birth date}}}}}</b> | — }}
{{#if: {{{full name|}}} | * <span>full name:</span> <b>{{{full name}}}</b>}}
{{#if: {{{birth place|}}} | * <span>birth place:</span> <b>{{{birth place}}}</b>}}
{{#if: {{{age|}}} | * <span> age:</span> <b>{{{age}}}</b>}}
{{#if: {{{nationality|}}} | * <span> nationality:</span> <b>{{{nationality}}}</b>}}

<div class="clear"></div>

</div>

[[Category:Person]]

__NOTOC__

</includeonly>

All these pages are in one Namespace (0).

I need to generate head meta tags with data from this template.

I figured out how to filter such a pages and add title tags in my SkinPerson.php

if ( $out->getTitle()->getNamespace() == 0 ) {
    $out->addMeta( "description", $out->getPageTitle());
    $out->addHeadItem( 'og:description', '<meta property="og:description" content="' . $out->getPageTitle() . '">');
}

But I'm really stuck on how can I insert in, say, 'og:description' tag something like {{{full name}}} + {{{age}}} ?

1

There are 1 best solutions below

1
On

That's simply not possible, and I would wonder what your use case here would be, why you want to do that. First some explanation, why this is not possible in the way you want to achieve that:

The template is evaluated by a piece of software we call the Parser. The parser is generating a html representation of your wikitext, including all the templates and so on. The result of that is then saved in the ParserOutput and probably cached in ParserCache (so that not every time it needs to be parsed again).

However, the skin, where you want to add the head item, is using the output of the parser directly, so it does not really know about the wikitext (including template parameters) anymore, and really shouldn't.

One possible solution for what you want to achieve is probably to extend the wikitext markup language by providing a tag extension, parsing that during the parsing of the wikitext, and save the values for the head items in the database. During the output of the page you can then retrieve these values from the database again and add them into the head items like you want. See more information about that in the documentation.

There might be other ways, apart from the database, to get information from the parsing time into the output time, which I'm not aware of.