Help:SMW Page Refresh
From Tetherless World Wiki
Contents |
Contact and History
Jie Bao, baojie AT gmail.com
First release: Jan 26, 2009
Feb 6, 2009: this extension has been integrated into SMW 1.4.2 [1]. This extension may still be used with previous versions of SMW.
Purpose
To update semantic data of a list of pages in SMW. This is needed since the SMW_refreshPage.php script does not allow by-name refreshing.
This script is particularly useful for importing pages into SMW, since many of those importing scripts will not invoke automatic semantic updating.
Installation
Copy the following code in a file: "extensions/SMWGadget/SMW_refreshPageList.php"
<?php /* Refresh semantic data for a list of pages separated by '|' Usage example: * php SMW_refreshPageList.php --page="Page 1|Page2" * php SMW_refreshPageList.php --page="Page 1,Page2" --delimiter="," Tip: To refresh a category Jie Bao. 2008 Dec 27 */ global $wgParser; require_once(dirname( __FILE__ ) . '../../../maintenance/commandLine.inc'); if ( isset( $options['page'] ) ) { $page = $options['page']; } else { echo "Usage Example: php SMW_refreshPageList.php --page=\"Page 1|Page2\"\n"; echo " or php SMW_refreshPageList.php --page=\"Page 1,Page2\" --delimiter=\",\"\n"; exit; } $delimiter = "|"; if ( isset( $options['delimiter'] ) ) { $delimiter = $options['delimiter']; } $options = new ParserOptions(); $pieces = explode($delimiter, $page); foreach ($pieces as $pagetitle){ echo $pagetitle; $title = Title::newFromText($pagetitle); if ($title){ if (smwfIsSemanticsProcessed($title->getNamespace()) ) { $revision = Revision::newFromTitle( $title ); if ( $revision === NULL ) { echo " not found.\n"; continue; } $wgParser->parse($revision->getText(), $title, $options, true, true, $revision->getID()); SMWFactbox::storeData(true); echo " updated."; } else{ echo " is in non-semantic namespace."; } } else { echo " not found."; } echo "\n"; }
Usage
Goto the folder of this script. Usage example:
php SMW_refreshPageList.php --page="Page 1|Page2"
by default the delimiter is "|", because it can not be in a wiki page name.
php SMW_refreshPageList.php --page="Page 1,Page2" --delimiter=","
How to generate a page list
There are many ways to generate a page list. One of the more convenient way is to use a semantic query. For example, the following query generates a list of pages in the Category:Meeting
{{#ask:[[Category:Meeting]]|format=list}}
If you want other delimiters, especially when some pages have "," in their names, it is useful to use the "String Functions" extension to generate a list, e.g.
{{#replace:{{#ask:[[Category:Meeting]]|format=ul}}|<li>|{{!}}}}
Where "Template:!" is a page with single character "|".
Use it in a wiki bot
This script can be called from another program as a system call. For example, in a perl program, simply call:
$command = "php ". $scriptPath."SMW_refreshPageList.php --page=". $name; system ($command);
where $scriptPath is the full path where this script is saved, and $name is the page to refresh
It is also possible to call from php, Java, C++, Python, etc., in the similar fashion.
It is also a common practice to call this script from a cron job. Check [2] for how to set up a cron job.
