User:Yury Katkov/programming examples

Here is a small set of examples that may help anyone who is interested in internal classes of SMW. Many thanks to my student, Rinat Fayzrahmanov for his research.

If you want to develop extensions for SMW, first of all you should read Manual:Extension for MediaWiki.

For good introduction to SMW-classes we recommend to read Architecture guide. However there is no single big book called "Programmer's manual on SMW" and unfortunately you will need to review the code of existing SMW extensions. Programmer's guide to SMW can also help.

If you want to see the Doxygen documentation for the classes we use in these examples, there is a API Documentation doxygen website.

How to actually create Ask queries programmatically
In the next chapter I will operate with a low-level SMW objects. If you just want to execute an ask-query and see its result, you can do so easily: That's it!

SMW Classes
This toy extension just creates a tab where several SMW-queries are represented. The point is to show how those queries look like from inside and how to use some of SMW datatype classes.

Defining and registering our extension
Here is the definition of a new tab:

When tab is pressed the function called action will run. In this function we will run all our ASk-queries:

And here will be a function for print results:

Ask-queries
There are many types of queries in SMW. We'll try to show how each of them can be coded in php.

All pages with the property
Let us start from the most general one: show me all pages that hava the property called test.

All pages with a certain property value
This is the query that asks for all the pages with a property age and the value 24.