Formatting query result of Url as given string in Semantic MediaWiki - mediawiki

I want to embed the result of an ask query on a page in Semantic MediaWiki. The result column has the type Url as in [[Has type:Url]]. However, when embedding the code I would like to show the URL not explicitly since it is very long but as a fixed string (e.g. "Website" )as I would have typed:
[https://someURL.com Website]
I tried to set the name on the page in the property assignment itself by including:
[[Has website::https://someURL.com | Website]]
This is the basic structure of an example query.
{{#ask: [[Has website_example::true]]
|?Has website
|format=table
|limit=50 |offset=0
|link=all
|sort=
|order=asc
|headers=show
|searchlabel=... further results
|class=sortable wikitable smwtable
}}
Is it possible to render the ?Has website as a link with the text "Website" in the table?

You may be have to pass through a 'template' format, and reconstruct your rows based on this template.
Example :
|-
! [{{{1}}} | Website]
then just surround your 'ask' request by table headers and footers.

Related

Meta tags in skin from MediaWiki template

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}}} ?
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.

Parse tag content of simple HTML form/table using Regular Expression

I have a simple HTML file only containing a table with no further CSS or any other attributes. The structure of this file never changes, but its content is always different.
I try to match the content of a specific cell (td) which shall give me the name of the first occurence of a contact which has the type 'Misc'.
In my example I try to match the name 'Michael Jackson':
This is what I've got so far:
(<td>\s*Contact:\s*<\/td>((?!<br>).)*<td>\s*Misc\s*<\/td>)
But this only selects the two contact blocks containing the type 'Misc'. I don't know how to go on from this point ...
Here again is my regex and the HTML string I am using:
https://regex101.com/r/xIzr3a/1/
Thanks for any help or advises!

Inline query for listing all pages from a namespace without any subobjects

I need an inline query that lists all pages from a specific namespace, but without listing subobjects specified on these pages.
Restricting results to a namespace is possible like that:
{{#ask: [[ExampleNamespace:+]] }}
But it lists all subobjects, too.
Workarounds:
Specify a category on these pages (subobjects don’t inherit it) and query for the category instead:
{{#ask: [[ExampleCategory]] }}
Specify a property on these pages (and never on the subobjects) and query for the property (with a wildcard value) instead:
{{#ask: [[ExampleProperty::+]] }}
But both workarounds require editing, which I would like to avoid. Is there a better way to solve this?
Not sure if it's a better way, but it looks like array formats/arrays and their #arraymap and #arrayunique functions are a way to go in order to trim SMW subobject tags and make the DISTINCT operation. Unfortunately, the solution below has a query result limit issue described as well (at least out of what I understand in SMW). In general, it may look like the following, and I will appreciate if someone suggests a nicer solution:
<!-- Fetch all pages from the "Live event" namespace -->
{{#arraydefine: QUERY_RESULT
| {{#ask: [[Live event:+]]
| format = array
| link = none <!-- NOTE: array item link -->
| limit = 10000 <!-- NOTE: limit -->
}}
}}
<!-- Store the mapped result into another array -->
{{#arraydefine: MAPPED_QUERY_RESULT
| {{#arraymap: {{#arrayprint: QUERY_RESULT}}
| ,
| $O <!-- NOTE: array map iterator value -->
| {{#explode: $O <!-- NOTE: explode by hash -->
| #
| 0
}}
}}
| ,
| unique
}}
<!-- Generate links markup -->
{{#arraymap: {{#arrayprint: MAPPED_QUERY_RESULT}}
| ,
| $O
| [[$O]] <!-- NOTE: plain links -->
}}
The notes from the code above:
NOTE: array item link - Not suppressing the links causes the mapper to be more complicated (including parsing HTML <span> tags and class attributes).
NOTE: limit - This is probably the biggest issue here as the number of subobjects affects the query result. SMW by default limits the query results, and the maximum query limit cannot be overridden as far as I know. Having more rows, which count is greater than the limits is, will cause the 'Further limits' link to appear. Actually speaking, I have no idea how to work around it nicely.
NOTE: array map iterator value - {{#arraymap}} seems to replace strings in the simplest way like sed or a simple text editor app do. So $O is used as the iterator value placeholder for the formula parameter trying not to clash with other string tokens.
NOTE: explode by hash - #ask subobject results generate hashed links like PageA#_159c1f213de2fcaf165f2c9c5c56686b. Just getting rid of them. In case you need to strip wiki links, you might also play around with [[ or | (encoded like [<nowiki/>[ and <nowiki>|</nowiki> respectively)
NOTE: plain links - The generated links will have underscores instead of spaces. Unfortunately, [[{{#replace: $O | _ | <nowiki> </nowiki>}}]] didn't work for me -- the underscores are simply consumed for some reason, however this approach is also recommended at the #replace function wiki page.
Some links:
SMW array result format
SMW configuration
SMW further results
#arraymap:
#explode:
#replace:
Help:List the set of unique values for a property (pay attention at the "Limitations and issues" section)

MediaWiki template to filter table contents

I have a MediaWiki site hosted on ShoutWiki. I want to create a template that will return a table, with rows filtered by the template's single argument. The table could be stored in whatever format works. It will have three columns, and I want to display rows only if the template's argument is a substring of the text in the first cell in the row. The search needs to be case sensitive.
There are JavaScript solutions for this, but I'd like to do it on the server if possible.
If you don't have a special extension handling that (e.g. Scribunto adding Lua support and therefore a real programming language to MediaWiki), you need to encapsulate each row into an own template call.
Example:
Template:FilteredRow
{{#ifeq:{{{1|}}}|{{{2|}}}|<tr><td>{{{2|empty row}}}</tr></td> }}
Template:A_Table
<table>
{{FilteredRow|1={{{filter|}}}|2=some content here}}
{{FilteredRow|1={{{filter|}}}|2=some content here in row 2}}
{{FilteredRow|1={{{filter|}}}|2=some content here in row 3}}
{{FilteredRow|1={{{filter|}}}|2=baz}}
</table>
Using:
{{A_Table|filter=baz}}
Result:
<table>
<tr><td>baz</td></tr>
</table>
With Scribunto, you could simply save your table as HTML table, or JSON, or whatever parser you find. Note that JSON support (recognition, formatting, validation) in MediaWiki and user namespace is being worked on.

use ask as a parameter in semantic media wiki

How can I pass an ask as a parameter of a query?
For example:
myvar={#ask: [[Category:City]][[London]]
|?population
|?currency
|}
Then use the data again in a custom function:
{#ask: [[England]]
|?population
|?currency
|capital=myvar
|}
If I try using something like the code below, when I debug the application, capital is equal to an empty String ( it's declared but empty ):
{#ask: [[England]]
|?population
|?currency
|capital={#ask: [[Category:City]][[London]]
|?population
|?currency
|}
|}
Your syntax is not correct.
It should be like this:
{{#ask: [[Category:City]] [[located in::England]]
| ?population
| ?currency
}}
You can have more informations about inline queries at the Semantic MediaWiki website.
And you can see how build nested queries at this question: Semantic mediawiki #ask query: Displaying nested properties on the same query
Hope that help you. Thanks!