MediaWiki: How to display a link only if the page exists - mediawiki

I'd like to display a link (or an image) only if the page exists. What is the mediawiki syntax for doing so?

use the function #ifexist
http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions
{{#ifexist: page title | value if exists | value if doesn't exist }}

Related

how to set in laravel blade the display of a tag p depending on whether the data passed has a value or is empty or null

As already described, I want to display the input in my show depending on whether the data present in the view has a value (so it is shown to me through a p tag) or do not show this p tag if the present data is null or empty.
If it is empty or null do not show anything
This is my code:
<div>
<h4>Code</h4>
<p>{{$client->code}}</p>
</div>
If I understand your question correctly, the simplest way would be to wrap it in an if statement:
<div>
<h4>Code</h4>
#if(!empty($client->code))
<p>{{ $client->code }}</p>
#endif
</div>

Change default page names in Bigcartel Theme (Luna)

I would like to change the name of the "products" page into "artworks".
I changed it manually in the theme layout (Luna), but that doesn't work of course for the main page title displayed on the browser tab. I looked around in theme options but can't find a way. Thanks for your help, Giorgio
Go to Design > Code > Products Custom Code
Search for:
{% assign page_name = 'Products' %}
Change to:
{% assign page_name = 'Artworks' %}
Your page's header will change to Artworks along with the browser tab.
See my example here where I have renamed the products page " C A T A L O G "
If I understand your question correctly you might not need to code this bit. Just change the name of the "Products" category to whatever you like.
Go to Design>Code>Products
Don't go into the code - right at the top of the page where the category is titled Products change it to Artworks.

How to include template's value inside link or table in MediaWiki?

I search the documentation but I didn't know exactly how to call that.
I have a template Index2Name that return a name based on an index.
I'm trying to use that name in a link:
[[Articles/{{Index2Name|0001}}|{{Index2Name|0001}}]]
or
Image:Big-0001.png|link=Articles/{{Index2Name|0001}}|''{{Index2Name|0001}}''
In the last example, the name is printed but the link doesn't work. (In gallery element)
It doesn't work. The value from the template is printed but it is not converted to a link.
How can I make this works? And does this have a name? (For future reference)
EDIT: Index2Name is a simple switch returning a few words depending of the id. Since I'm using subpages I only want the name to appear (Example: MyArticle) but the link is Articles/MyArticle
Could you clarify exactly what you want to happen please. (Where you want to link and how you want it to look).
But for example if you use:
[[Image:Big-0001.png|''{{Index2Name|0001}}'']]
It will link to the page Image:Big-0001.png with the link text being the output of:
''{{Index2Name|0001}}''
Or if you use:
[[Image:Big-001.jpg|link=Articles/{{Index2Name|0001}}]]
The image, when clicked, will redirect you to the output of:
{{Index2Name|0001}}

Conditional categories

I'm using a template {{MyTemplate|foo}} which consists of the following code:
{{#switch: {{{1}}}
| foo = [[Category:Foo]]
| bar = [[Category:Bar]]
| #default = [[Category:Unknown]]
}}
When I'm using it on a page, the categories show up nicely as wished at the bottom of that page. But unfortunately inside of that category-page (Category:Foo for example) the page doesn't show up.
If I add [[Category:Foo]] manually to that page, the page shows up in the Foo-category-page.
Any suggestions why this doesn't work via the template?
Does the template page that contain the previous code appear under Unknown category?. If yes, then any page contain that template must appear in it's category. You may just have to clear cache, and wait few seconds if you have a large wiki.
Make sure that foo & bar categories are not hidden in your wiki. See this: https://www.mediawiki.org/wiki/Help:Categories#Hidden_categories
EDIT
Also, try one of these solutions, which can do the same goal:
{{#switch: {{{1}}}
| foo = [[Category:Foo]]
| bar = [[Category:Bar]]
| #default = [[Category:Unknown]]
}}
OR
{{#ifeq: {{{1}}} | foo | [[Category:Foo]] | {{#ifeq: {{{1}}} | bar | [[Category:Bar]] | [[Category:Unknown]]}} }}
Do you run the jobqueue on your wiki? Linkstables are updated asynchronously and not at page save time.
https://www.mediawiki.org/wiki/Manual:Job_queue
https://www.mediawiki.org/wiki/Manual:RunJobs.php
Cant understand the description to your problem, but anyway, it seems like you could achieve the same goal by:
{{#vardefine: my_category |wow}}
[[Category: {{#ifeq: {{#var:my_category}}| default| unknown| {{#var:my_category}} }} ]]
Which adds this category to the page,
In my opinion, you should use switch when you are adding category in any case but also decide not to add category in another case.
If you are adding category in all cases, you can write as i wrote above, or export the final category to another variable and use it inside the category.
As for your problem, you can use "?action=purge" for this page, if that wont work, write here some more info.

Semantic mediawiki #ask query: Displaying nested properties on the same query

I would like to display in the same query properties of a page which is related to the pages im querying for.
Let's say I would like to query all the pages in the City category, which are located in Germany, and I want to display the title of the page, but also I want to display the surface data of Germany, for example.
Something like this: {{#ask: [[Category:City]] [[location::Germany]] |?mainlabel |?Location.surface }}
I know this wont work, but you can see what I want to achieve.
I'm not sure if there's a way to nest queries directly inside other queries. The normal method of doing it is using a template. So you might define a template (or subpage of the template if this going into a template) called {{tablerow}} that consists of:
<includeonly>
|- valign="top"
| [[{{{1|}}}]]
| {{#show: {{{1|}}} | ?surface }}</includeonly>
The <includeonly> tags are important for reasons I don't really understand, it produces errors sometimes if you leave them out. Then you just run an #ask query with format = template. (You can build the header into the query, but I find it simpler to just put it outside.)
{| class="wikitable smwtable sortable"
|- valign="bottom"
! [[City]]
! [[Surface]]
{{#ask: [[Category:City]] [[location::Germany]]
| format = template
| template = tablerow
| link = none
}}
|}
That will punch each result returned by the query through the template as {{{1}}} and generate a row based on it. If you have other data to return from the main query, additional properties that you ask for will come out as consecutive unnamed parameters (so if you include | ?population, that will go into the template as {{{2}}} and will need to be added to the row structure or it will be dropped).