Sferg
Sferg

Reputation: 31

Semantic Mediawiki and properties in template

I have the following construction in the template to check whether attributes are full

{{#if:{{{typeip|}}}|'''Type IP:'''{{{typeip}}}|<big>'''Type IP:'''</big><span style="color: red">not filled in</span>}}

I want the typyap attribute to be a property so that I can find it by semantic search or by using a query via the #ask function.

I tried the following construction

{{#if:[[typeip::{{{typeip|}}}]]|'''Type IP:'''{{{typeip}}}|<big>'''Type IP:'''</big><span style="color: red">not filled in</span>}}

But it doesn't work. The #asc function returns an empty request and the type ip property page is empty. Can you tell me what I'm doing wrong? I performed reindexing using a service script rebuildData.php But that doesn't help either. I tried to insert the property in various other places in the template, but it doesn't work either. The template is filled in using the form.

Thank you in advance!

Upvotes: 1

Views: 502

Answers (1)

Alexander Mashin
Alexander Mashin

Reputation: 4539

Of course, it doesn't work. You invoke the {{#if:}} parser function incorrectly.

Its parametres are:

  1. the condition,
  2. the value returned if the first parametre does not evaluate to an empty string or whitespace,
  3. the value returned if the first parametre is empty.

Therefore the semantic annotation should be in the second parametre, not the first:

{{#if:{{{typeip|}}}
| '''Type IP:''' [[typeip::{{{typeip}}}]]
| <big>'''Type IP:'''</big><span style="color: red">not filled in</span>
}}

{{{typeip}}} should be bare text without any wiki formatting. If you must pass wikitext to it to convert wikilinks into semantic annotations setting properties of the type Page, the simplest way will be as follows:

  • Install Scribunto,
  • create Module:Inject with the following content:
return {
    property = function (frame)
        local wikitext, property = frame.args[1], frame.args[2]
        local annotation = mw.ustring.gsub (
            wikitext,
            '%[%[([^|%]]+)(|[^%]]*)?%]%]',
            '[[' .. property .. '::%1%2]]'
        )
        return annotation
    end
}
  • put the following in your template:
{{#invoke:Inject|property|{{{typeip|}}}|typeip}}

The template will convert any wikilinks in {{{typeip}}} like [[A]] or [[B|C]] into semantic annotations like [[typeip::A]] or [[typeip::B|C]].

Upvotes: 1

Related Questions