[MediaWiki-l] Help with SWM

Markus Krötzsch markus at semantic-mediawiki.org
Thu Feb 11 08:51:56 UTC 2016

Hi Larry,

in general, the best place to ask SMW questions is the semediawiki-user 
mailing list. Quick answers below:

On 11.02.2016 04:16, Larry Martell wrote:
> I am a total newbie with SMW, and I've inherited a system that no one
> knows any details about.
> I have a few questions:
> How can I find out what and where the database behind the SMW is? I
> would think there is a config file somewhere, but I can't find it.

The data is stored in the database you have configured for your wiki. 
The config file where this is defined is LocalSettings.php. You can 
(additionally) store it in an RDF database if you wish (for this, you 
need to install such a database management system and add some config 
options; see SMW documentation).

> When I look at a page with browsebysubject I see a type associated
> with the data, e.g.:
> {u'property': u'HasSide', u'dataitem': [{u'item': u'Left', u'type': 2}]}
> {u'property': u'HasReferenceDataset', u'dataitem': [{u'item':
> u'RefData, u'type': 9}]}
> What do these types mean?

This is probably not relevant to what you want to do.

> I have been asked to edit 1000's of pages to remove 2 fields and add a
> new field.

Take a look at the extension ReplaceText. It can probably do this for you.

> To do this with the API would I get the data with
> browsebysubject and modify that dict? But then how would I write that
> back?
> Or would I get the raw data with index.php?action=raw, modify that,
> and then write it back with edit
> (https://www.mediawiki.org/wiki/API:Edit)

An easier way to modify page texts in a one-time operation might be to 
export the text using Special:Export, modify the resulting XML file with 
any tool you like, and then re-import the file. Won't work well if your 
wiki is edited by many people, but if you have the modification script 
ready you could do this in a few minutes, which is good enough on a 
relatively static site.

Whatever method you pick, changing the page text in one or the other way 
it the right way of changing SMW data. SMW's primary data storage is the 
page text, so you do not need to worry about any specific database 
related to SMW: the extension will make sure that its contents is 
updated to agree with the page text. *Never* edit SMW's database tables 
directly. Your changes will be lost as soon as the wiki pages are edited 
next time.

This is also why SMW does not have a direct API to write data. Data must 
be stored in wiki pages, and there is no good way to change an arbitrary 
page (with all the complexities of MediaWiki: templates, parser 
functions, LUA code, etc.) so that it will lead to a specific data being 
stored. It would be easy enough to add some data (in hidden mark-up at 
the bottom of a page), but modifying existing data will not work in 
general -- you need to know how your templates work for knowing how to 
change the contents to get the result you want.



> Thanks much!
> Larry
> _______________________________________________
> MediaWiki-l mailing list
> To unsubscribe, go to:
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l

More information about the MediaWiki-l mailing list