Search code examples
mediawikisemantic-mediawiki

Using SMW subobjects without having to duplicate the content


Example for what I want to achieve

I have many patch pages ("Patch 1.4", "Patch 1.5" etc.) that list the changes that were made to a project, where the affected/changed things are linked to their corresponding pages ("confirmation dialog", "foo", etc.):

Patch 1.4

  • Fixed spelling in the [[confirmation dialog]]

Patch 1.5

  • Added two options: [[foo]], [[bar]]

On the pages about the things that were changed ("confirmation dialog", "foo", …), I want to automatically show all corresponding changes:

Foo

  • [[Patch 1.5]]: Added two options: [[foo]], [[bar]]

Semantic MediaWiki’s subobjects can do this

#subobject allows me to create an (anonymous) object for each change on the patch pages:

{{#subobject:|
|Changes=Added two options: [[foo]], [[bar]]
|Affects=Foo|Bar
}}

And on each page ("foo" etc.) I can include an #ask subobject query to list all the matching subobjects:

{{#ask: [[Affects::{{FULLPAGENAME}}]]
 |? Changes
}}

Great.

Problem: I have to duplicate the change entry.

On the patch pages, a change entry looks like this:

* Added two options: [[foo]], [[bar]] {{#subobject:|
|Changes=Added two options: [[foo]], [[bar]]
|Affects=Foo|Bar
}}

So I have to specify "Added two options: [[foo]], [[bar]]" two times: one time for the visible content, one time for the invisible subobject.

Is there a way in (Semantic) MediaWiki to do this without having to duplicate the content?

The ideal solution would just require me to enclose the change entry and specify the affected pages next to it, e.g.:

* {{ Added two options: [[foo]], [[bar]] }}((foo|bar))

As each patch page can list hundreds of changes, I don’t want to have to create a separate page for each change.


Solution

  • If I understand your question clearly, it seems you just need a simple query:

    {{#ask: [[-Has subobject::{{FULLPAGENAME}}]] 
    | ?Changes
    | format = ul
    | headers = hide
    | mainlabel = -
    }}
    

    Since using SMW markup may be tedious and error-prone, you might also use MediaWiki templates. You can simplify adding patch changes:

    Template:Change

    <includeonly><!--
    -->{{#subobject:|
       | Changes = {{{1|}}}
       | Affects = {{{2|}}}|+sep=;
       }}<!--
    --></includeonly><nowiki/>
    

    {{{1}}} and {{{2}}} are positional parameter,s and the Affects subobject property uses the ; separator (as a pipe | is ambiguous and may break templates, parser functions, etc). The <nowiki/> is a sort of a hack saving from whitespace bloating at the call-site pages.

    You can also add a special template that would encapsulate the changes query:

    Template:Patch changes

    <includeonly><!--
    -->{{#ask: [[-Has subobject::{{{1|{{FULLPAGENAME}}}}}]] 
       | ?Changes
       | format = ul
       | headers = hide
       | mainlabel = -
       }}<!--
    --></includeonly><nowiki/>
    

    By default, the template asks for the changes list for the current page (if the positional parameter #1 argument is empty), or you can explicitly override it at the call-site later (say, {{Patch changes|Patch 1.5}}).

    Patch 1.4

    {{Change | Fixed spelling in the [[confirmation dialog]] | Confirmation dialog}}
    
    {{Patch changes}}
    

    Patch 1.5

    {{Change | Added two options: [[foo]], [[bar]] | Foo; Bar}}
    
    {{Patch changes}}
    

    respectively.

    These links might be useful later: