My ever growing collection of SMW facts.
Contents
Important Docs[edit]
- Compatibility: Which SMW can go with which MW, which PHP version can I use?
- Selecting pages - How to get the right results
- Inline queries - How to use #ask and #show
- Configuration
- FAQ
Installing[edit]
- Info which SMW version supports which MW version: COMPATIBILITY or https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/COMPATIBILITY.md
- To install the master version add the following to
composer.local.json
:
{ "require": { "mediawiki/semantic-media-wiki": "dev-master" } }
Upgrading[edit]
My steps to upgrade SMW:
- Extra step if there is a major update: Update the version number of SMW in
composer.json
: Replace2.5
with3.0
for example. - Log in via SSH / Putty.
- Go to my /mediawiki folder.
- Run
composer update --no-dev
- If there are any errors, run
composer update
in the /mediawiki folder and/or in the extensions/SemanticMediaWiki folder. Then run the "require" again. - Run
php_cli maintenance/update.php
.
It there's an error likeYour composer.lock file is not up to date. Run "composer update" to install newer dependencies
runphp_cli maintenance/update.php --skip-external-dependencies
(see this reference) - Run
php_cli extensions/SemanticMediaWiki/maintenance/rebuildData.php -d 50 -v
to rebuild the semantic data.
Official docu see Help:Installation/Using_Composer_with_MediaWiki_1.25+#Update
To install SMW:
- Run
composer require mediawiki/semantic-media-wiki "~2.x" --update-no-dev
(Replace "x" with the current version. Omit the bugfix release number, i.e. the third number.)
Selecting pages[edit]
- Docu: Selecting pages
- Wildcard:
+
- Get pages from category WITHOUT pages from subcategories - Solution: set $smwgUseCategoryHierarchy to false in LocalSettings.php
- 3 ways to exclude a page from an inline query (if you use this methode, make sure to create a property of type "String", not of type "Page"!)
- It is not possible to ask for all pages of a query that are not in a specific category or concepts. For example, the query {{#ask: [[Category:!City]] }} will query every page in category "!City" instead of every page that is not in category "City".
- Workaround to show pages from all categories except one category (German)
- If you have a property with certain allowed values and in your ask query you have something like
[[Property::{{PAGENAME}}]]
you'll get an error most of the times, because you query for a value that is not allowed. For some reason all pages that have this property set, are given out as a result (which is bad).
Solution: use the tilde[[Property::~{{PAGENAME}}]]
#show[edit]
- Syntax for #show:
{{#show:Berlin|?population}}
- Print Category of current page:
{{#show: {{FULLPAGENAME}} | ?Category }}
Note: It's important to use "Category", not "category". - Check if page is in a certain category (among others) and print out the result:
{{#ifeq:{{#pos:{{#show: {{FULLPAGENAME}} | ?Category }}|Category_To_Check}}| |Output for "not in this category"|Output for "in this category"}}
#ask[edit]
- #ask doesn't work within poem tags!
- Changing the heading for the first result column
|mainlabel=heading
- Don't link property headers to their property page:
|headers=plain
- Link only the pages itself within results (also good to suppress that URL properties are converted to links automatically):
|link=subject
- Change outputs of #ask: Use
|format=template
- how to generate an customized table see here - Show number of results: Help:Count_format (Is there any easier way?)
- Dealing with HTML within #ask template: [1]
format
:
- all available formats see Result formats
- If omitted, all queries are displayed as tables (format table), unless there would be only one column, in which case the results are displayed as a comma-separated list (format list).
- Help:Feed_format
Sorting:
- Sorting by SMW takes into account
{{DEFAULTSORT:Your_Sort_Stuff}}
- The usual ("natural") date sorting is oldest dates on top (ascending). To get the reverse (newest dates on top) I found the following way with both
#LOCL
and#SORTKEY
(if you use#SORTKEY
only, the sorting works as well, but you can't output the date since it's a number that no user understands):
{{#ask: [[Start-Date::Some]] | ?Start-Date#LOCL#SORTKEY | format=ul | sort=Start-Date | order=desc }}
URLs length issue[edit]
URLs can only take up to 255 characters (see this bug report).
To find out which of your URLs get truncated you can do the following:
{{#ask: [[YourURLProperty::+]] |?YourURLProperty | format=ul | template=temp | limit=2000 }}
In your template "temp" do something like:
{{{1}}} {{#len:{{{2}}}}}
Note that the length returned is two times the real URL length plus 3 characters (I assume that's from the format [URL URL]). So you have to check your list for values of 513 (= 2*255 + 3) and shorten those links with an URL shortener.
Concepts[edit]
- = dynamic categories
- useful to create "categories" like "People, born in 1982, born in Germany" for example
- big advantage: Pages don't need to be adapted, one just has to change/create the concept
Display data[edit]
Usefull stuff for displaying data via templates:
- Show "something" if a value is true (in German "wahr"):
{{#ifeq:{{{18}}}|wahr|something|}}
- If you updated SWM from 1.x to 2.x changes are, that commas between several values in your template disappeared. You could add
|sep=,
to all of your ask queries to fix that. Or, easier, you just add$smwgResultFormatsFeatures = SMW_RF_NONE;
to your LocalSettings.php.
Semantic Forms[edit]
input type=dropdown
also works for attributes of data type "text"default=now
doesn't work when usinginput type=year
. Workaround:default=2024
- Use multiple values for the same field (for example in a property "tags")
- Edit with form on main namespace on a German wiki: Put
[[Hat Standardformular::Foo]]
on the page Wiki_Name:Startseite - see discussion here - If the allowed values of a property are not shown in alphabetical order in a dropdown: Copy the content of the property page, blank the property page, then paste the content again.
- One can't change the page name within a form - see [2] (also for a workaround)
- Set a property of type URL and use it as URL at the same time:
- Doesn't work for me:
[[[Property::{{{Field|}}}]] Anchor text]
- Workaround:
{{#set:Property={{{Field|}}}}} [{{{Field|}}} Anchor text]
- Doesn't work for me:
- Autocomplete tricks
- If one wants to use autocomplete without using a property add
|input type=text with autocomplete
to the form field. - If
values from namespace=
doesn't work add|property=Foo
to the field tag.
- If one wants to use autocomplete without using a property add
- Preloading data
- 1st way: with
|query string=preload=Template:foo
added to a button - cons: Template is not loaded if a red link is clicked for example - 2nd way: add
preload
directly to free text input within the form (don't usedefault
here because default will override existing content if editing a page) - adddefault
to other fields (for example to category input - in this case default doesn't override existing categories)
- 1st way: with
- Deal with existing pages
- Parameter
show on select
- One can't use different tags (for example "placeholders") for the same field - see [6]
- One can assign different ids to a chosen value - for example
Same-Value=>id_one;Same-Value=>id_two;
. This is very helpful since it's not possible to use the same id twice. - One can do nested divs.
- It seems impossible to use the generated div ids directly in table rows - use a separate table instead like:
<div id="fooid"> {| class="formtable" |- ! Bla | {{{field|blupp}}} |} </div>
Properties[edit]
- SMW has some useful built-in properties: see Help:Special_properties
- If no value is provided (in a form), the corresponding property is not defined for that page.
- Parser functions: I found that
{#if: [[Property::{{{Value|}}}]] | {{{Value|}}} | some text }}
doesn't assign the value to the property. With{#if: {{{Value|}}} | [[Property::{{{Value|}}}]] | some text }}
it works.
Ways to define a property:
- Put [[has type::foo_datatype]] on page Property:Foo
German: Put [[Datentyp::foo_datatype]] on page Attribut:Foo - Use Special:CreateProperty - German: Spezial:Attribut_erstellen
German:
- In German a property is called "Attribut"
[[Allows value::foo]]
in German:[[Erlaubt Wert::foo]]
Doing math on numeric property values:
#set[edit]
- = creating a silent property
- see Help:Setting_values
Examples:
{{#set:Has population=3,396,990|Has country=Germany}} {{#set:Property={{{Field|}}}}}
Types[edit]
- Since SMW 1.8.0 datatype "String" (German: Zeichenkette) was deprecated and replaced by datatype "Text"
- If your wiki doesn't run in English and you have issues changing dates with the parser function #time, then add
#ISO
after the search for your date property - see this for more info - Output a date property the German way:
{{#time:d.m.Y|{{{1}}}}}
Search[edit]
Semantic Drilldown
- Faceted search without fulltext search support.
- + Very nice setup interface and very flexible extension.
- - Incomprehensible appearance by default: you will have to write your own CSS to make it clear.
- - can be slow on the big amount of properties
Filtered result format
- Good for visualizing the queries (<1K-2K pages Yury Katkov guesses).
- Nice setup of facets, allow search by property values.
- Doesn't provide full text search by pages
Filtered format of the Semantic Results Format extension.
- Neill Mitchell often couples it with a Semantic Forms runQuery to provide search capabilities with property filters.
- Example: http://www.hampshiregateway.info - Click the "Find regular club activities near your postcode" button and enter GU32 1EP in the Postcode field
- Example2: http://www.aroundisleofwight.info - Just click on a subsection e.g. Days Out
Misc[edit]
- Nice description of SMW / Cargo from Yaron Koren: "With these extensions, you can store the wiki's text as data, and then query that data elsewhere."
- About the Process format: https://www.mediawiki.org/wiki/User:Hummel-riegel/SRF_Process
- Biggest semantic MediaWikis: http://wikiapiary.com/wiki/Semantic_statistics
- Benefits of a semantic website: http://www.youtube.com/watch?v=4rEP2YCn5WQ
- Companies that use SMW
- Related articles: http://wikimedia.7.n6.nabble.com/Show-related-articles-td554047.html
- Data visualization tools: http://selection.datavisualization.ch/
- Using
=
in{{#info: foo}}
: use=
instead of=
(see [8])
If a = is used, one might get a red error message saying "Schwerwiegender Fehler: Der notwendige Parameter „message“ wurde nicht angegeben." - Help:Querying_for_queries
- Remove the "Powered by SMW" logo from the footer: Write the following in LocalSettings.php:
unset($wgFooterIcons['poweredby']['semanticmediawiki']);
- Pagination for pages (next page/last page): see [9]
Cargo:
- Yaron Koren: Cargo is a simpler alternative to SMW.
SMW and WordPress
How to enable SMW in custom namespaces:
- Help:Troubleshooting#Missing_data_on_custom_namespaces
- Example: http://www.mediawiki.org/wiki/Extension_talk:Semantic_Forms/Archive_July_to_August_2012#Has_default_form.2C_based_on_namespace
SMW development[edit]
Interesting facts from Jeroen de Dauw [2]:
- In 2013 20 developers contributed to SMW Core (total: 68 developers) -> SMW is in the top 10 % in the world regarding contributers to Open Source projects - The vast majority of Open Source projects have only 1 contributor
- SMW maintainers: Markus Krötzsch, James Hong Kong, Jeroen de Dauw
- ~1000 commits during 2013
- Tool to test new code: Jenkins, Travis CI
Unsolved issues[edit]
- Strange issue when I add returns within a text property. Second return is interpreted as a paragraph and table form gets broken...
- Selecting pages: 2 queries on the same property (one with !) - (if I have
[[Prop::!x]] [[Prop::!y]]
it works just fine)
Things that fail (all of them just output all pages containing x):[[Prop::x]] [[Prop::!y]]
[[Property::x]] <q>[[Property::!y]]</q>
- Creating a concept with
[[Prop::x]]
and then using[[Concept:foo]] [[Prop::!y]]
- Thread:Talk:Semantic Maps/Form: How to set input to mandatory?
Links[edit]
German Articles about SMW:
- http://www.linux-magazin.de/Ausgaben/2009/07/Struktur-fuers-Wiki
- http://www.heise.de/ct/inhalt/2013/19/158/
Semantic Books: