Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php |
— | — | @@ -34,6 +34,12 @@ |
35 | 35 | $wgExtensionMessagesFiles['SemanticInternalObjects'] = $siogIP . '/SemanticInternalObjects.i18n.php'; |
36 | 36 | $wgAutoloadClasses['SIOHandler'] = $siogIP . '/SemanticInternalObjects_body.php'; |
37 | 37 | $wgAutoloadClasses['SIOSQLStore'] = $siogIP . '/SemanticInternalObjects_body.php'; |
| 38 | +if ( class_exists( 'SMWDIWikiPage' ) ) { |
| 39 | + // SMW >= 1.6 |
| 40 | + $wgAutoloadClasses['SIOInternalObjectValue'] = $siogIP . '/SIO_RDFClasses2.php'; |
| 41 | +} else { |
| 42 | + $wgAutoloadClasses['SIOInternalObjectValue'] = $siogIP . '/SIO_RDFClasses.php'; |
| 43 | +} |
38 | 44 | |
39 | 45 | function siofRegisterParserFunctions( &$parser ) { |
40 | 46 | $parser->setFunctionHook( 'set_internal', array( 'SIOHandler', 'doSetInternal' ) ); |
Index: trunk/extensions/SemanticInternalObjects/SIO_RDFClasses.php |
— | — | @@ -0,0 +1,62 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Classes that enable correct RDF export of Semantic Internal Objects data. |
| 6 | + * This file holds the versions of these classes necessary for SMW 1.5 only. |
| 7 | + * |
| 8 | + * @author Yaron Koren |
| 9 | + */ |
| 10 | + |
| 11 | +class SIOTitle { |
| 12 | + function __construct ($name, $namespace) { |
| 13 | + $this->mName = $name; |
| 14 | + $this->mNamespace = $namespace; |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * Based on functions in Title class |
| 19 | + */ |
| 20 | + function getPrefixedName() { |
| 21 | + $s = ''; |
| 22 | + if ( 0 != $this->mNamespace ) { |
| 23 | + global $wgContLang; |
| 24 | + $s .= $wgContLang->getNsText( $this->mNamespace ) . ':'; |
| 25 | + } |
| 26 | + $s .= $this->mName; |
| 27 | + return $s; |
| 28 | + } |
| 29 | + |
| 30 | + function getPrefixedURL() { |
| 31 | + $s = $this->getPrefixedName(); |
| 32 | + return wfUrlencode( str_replace( ' ', '_', $s ) ); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +class SIOInternalObjectValue extends SMWWikiPageValue { |
| 37 | + function __construct($name, $namespace) { |
| 38 | + $this->mSIOTitle = new SIOTitle( $name, $namespace ); |
| 39 | + } |
| 40 | + |
| 41 | + function getExportData() { |
| 42 | + global $smwgNamespace; |
| 43 | + return new SMWExpData( new SMWExpResource( SIOExporter::getResolverURL() . $this->mSIOTitle->getPrefixedURL() ) ); |
| 44 | + } |
| 45 | + |
| 46 | + function getTitle() { |
| 47 | + return $this->mSIOTitle; |
| 48 | + } |
| 49 | + |
| 50 | + function getWikiValue() { |
| 51 | + return $this->mSIOTitle->getPrefixedName(); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +/** |
| 56 | + * Class to work around the fact that SMWExporter::$m_ent_wiki is protected. |
| 57 | + **/ |
| 58 | +class SIOExporter extends SMWExporter { |
| 59 | + |
| 60 | + static function getResolverURL() { |
| 61 | + return SMWExporter::$m_ent_wiki; |
| 62 | + } |
| 63 | +} |
Index: trunk/extensions/SemanticInternalObjects/SIO_RDFClasses2.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Classes that enable correct RDF export of Semantic Internal Objects data. |
| 6 | + * This file holds the versions of these classes necessary for SMW >= 1.6. |
| 7 | + * |
| 8 | + * @author Yaron Koren |
| 9 | + */ |
| 10 | + |
| 11 | +class SIOTitle { |
| 12 | + function __construct ($name, $namespace) { |
| 13 | + $this->mName = $name; |
| 14 | + $this->mNamespace = $namespace; |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * @TODO - should this take advantage of the "internal object"/sub-object/ |
| 20 | + * blank-node functionality in SMW 1.6, put in place for use by the Record |
| 21 | + * type? For now, just ignore that. |
| 22 | + */ |
| 23 | +class SIOInternalObjectValue extends SMWDIWikiPage { |
| 24 | + function __construct($name, $namespace) { |
| 25 | + $this->mSIOTitle = new SIOTitle( $name, $namespace ); |
| 26 | + } |
| 27 | + |
| 28 | + function getDBkey() { |
| 29 | + return $this->mSIOTitle->mName; |
| 30 | + } |
| 31 | + |
| 32 | + function getNamespace() { |
| 33 | + return $this->mSIOTitle->mNamespace; |
| 34 | + } |
| 35 | +} |
Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php |
— | — | @@ -1,10 +1,13 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Main classes used by the Semantic Internal Objects extension. |
| 5 | + * |
| 6 | + * @author Yaron Koren |
| 7 | + */ |
3 | 8 | |
4 | 9 | /** |
5 | 10 | * Class that holds information on a single internal object, including all |
6 | 11 | * its properties. |
7 | | - * |
8 | | - * @author Yaron Koren |
9 | 12 | */ |
10 | 13 | class SIOInternalObject { |
11 | 14 | protected $mMainTitle; |
— | — | @@ -45,65 +48,6 @@ |
46 | 49 | } |
47 | 50 | |
48 | 51 | /** |
49 | | - * The SIOTitle and SIOInternalObjectValue exist for only one reason: in order |
50 | | - * to be used by SIOSQLStore::createRDF(), to spoof Semantic MediaWiki's |
51 | | - * RDF-exporting code into thinking that it's dealing with actual wiki pages. |
52 | | - */ |
53 | | -class SIOTitle { |
54 | | - function __construct ($name, $namespace) { |
55 | | - $this->mName = $name; |
56 | | - $this->mNamespace = $namespace; |
57 | | - } |
58 | | - |
59 | | - /** |
60 | | - * Based on functions in Title class |
61 | | - */ |
62 | | - function getPrefixedName() { |
63 | | - $s = ''; |
64 | | - if ( 0 != $this->mNamespace ) { |
65 | | - global $wgContLang; |
66 | | - $s .= $wgContLang->getNsText( $this->mNamespace ) . ':'; |
67 | | - } |
68 | | - $s .= $this->mName; |
69 | | - return $s; |
70 | | - } |
71 | | - |
72 | | - function getPrefixedURL() { |
73 | | - $s = $this->getPrefixedName(); |
74 | | - return wfUrlencode( str_replace( ' ', '_', $s ) ); |
75 | | - } |
76 | | -} |
77 | | - |
78 | | -class SIOInternalObjectValue extends SMWWikiPageValue { |
79 | | - function __construct($name, $namespace) { |
80 | | - $this->mSIOTitle = new SIOTitle( $name, $namespace ); |
81 | | - } |
82 | | - |
83 | | - function getExportData() { |
84 | | - global $smwgNamespace; |
85 | | - return new SMWExpData( new SMWExpResource( SIOExporter::getResolverURL() . $this->mSIOTitle->getPrefixedURL() ) ); |
86 | | - } |
87 | | - |
88 | | - function getTitle() { |
89 | | - return $this->mSIOTitle; |
90 | | - } |
91 | | - |
92 | | - function getWikiValue() { |
93 | | - return $this->mSIOTitle->getPrefixedName(); |
94 | | - } |
95 | | -} |
96 | | - |
97 | | -/** |
98 | | - * Class to work around the fact that SMWExporter::$m_ent_wiki is protected. |
99 | | - **/ |
100 | | -class SIOExporter extends SMWExporter { |
101 | | - |
102 | | - static function getResolverURL() { |
103 | | - return SMWExporter::$m_ent_wiki; |
104 | | - } |
105 | | -} |
106 | | - |
107 | | -/** |
108 | 52 | * Class for all database-related actions. |
109 | 53 | * This class exists mostly because SMWSQLStore2's functions makeSMWPageID() |
110 | 54 | * and makeSMWPropertyID(), which are needed for the DB access, are both |
— | — | @@ -248,8 +192,8 @@ |
249 | 193 | $pageName = $title->getDBkey(); |
250 | 194 | $namespace = $title->getNamespace(); |
251 | 195 | |
252 | | - // go through all SIOs for the current page, create RDF for |
253 | | - // each one, and add it to the general array |
| 196 | + // Go through all SIOs for the current page, create RDF for |
| 197 | + // each one, and add it to the general array. |
254 | 198 | $iw = ''; |
255 | 199 | $db = wfGetDB( DB_SLAVE ); |
256 | 200 | $res = $db->select( |
— | — | @@ -260,8 +204,13 @@ |
261 | 205 | ); |
262 | 206 | |
263 | 207 | while ( $row = $db->fetchObject( $res ) ) { |
264 | | - $value = new SIOInternalObjectValue( $row->smw_title, $row->smw_namespace ); |
265 | | - $semdata = new SMWSemanticData( $value, false ); |
| 208 | + $value = new SIOInternalObjectValue( $row->smw_title, intval( $row->smw_namespace ) ); |
| 209 | + if ( class_exists( 'SMWSqlStubSemanticData' ) ) { |
| 210 | + // SMW >= 1.6 |
| 211 | + $semdata = new SMWSqlStubSemanticData( $value, false ); |
| 212 | + } else { |
| 213 | + $semdata = new SMWSemanticData( $value, false ); |
| 214 | + } |
266 | 215 | $propertyTables = SMWSQLStore2::getPropertyTables(); |
267 | 216 | foreach ( $propertyTables as $tableName => $propertyTable ) { |
268 | 217 | $data = smwfGetStore()->fetchSemanticData( $row->smw_id, null, $propertyTable ); |