User:Stefahn/SMW

From semantic-mediawiki.org

My ever growing collection of SMW facts.

Important Docs[edit]

Installing[edit]

{
	"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: Replace 2.5 with 3.0 for example.
  • Log in via SSH / Putty.
  • Go to my /mediawiki folder.
  • Runcomposer 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 like Your composer.lock file is not up to date. Run "composer update" to install newer dependencies run php_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 using input 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]
  • 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.
  • 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 use default here because default will override existing content if editing a page) - add default to other fields (for example to category input - in this case default doesn't override existing categories)
  • Deal with existing pages
    • Basically one can use #forminput and do autocomplete on category or namespace (unfortunately autocomplete on property is not possible)
    • My discussion with Yaron regarding my URL problem: [3]
    • Other discussions and proposed solutions: [4], [5]
  • 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:

German:

  • In German a property is called "Attribut"
  • [[Allows value::foo]] in German: [[Erlaubt Wert::foo]]

Doing math on numeric property values:

#set[edit]

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

[1]

Misc[edit]

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:

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]

Links[edit]

German Articles about SMW:

Semantic Books:

References[edit]