r92544 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92543‎ | r92544 | r92545 >
Date:17:27, 19 July 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added support for SMW 1.6 for exporting RDF - this included moving the classes related to the RDF export into two new files, SIO_RDFClasses.php and SIO_RDFClasses2.php, with the choice of file based on whether the SMW version is 1.5 or 1.6+
Modified paths:
  • /trunk/extensions/SemanticInternalObjects/SIO_RDFClasses.php (added) (history)
  • /trunk/extensions/SemanticInternalObjects/SIO_RDFClasses2.php (added) (history)
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php (modified) (history)
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects.php
@@ -34,6 +34,12 @@
3535 $wgExtensionMessagesFiles['SemanticInternalObjects'] = $siogIP . '/SemanticInternalObjects.i18n.php';
3636 $wgAutoloadClasses['SIOHandler'] = $siogIP . '/SemanticInternalObjects_body.php';
3737 $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+}
3844
3945 function siofRegisterParserFunctions( &$parser ) {
4046 $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 @@
22 <?php
 3+/**
 4+ * Main classes used by the Semantic Internal Objects extension.
 5+ *
 6+ * @author Yaron Koren
 7+ */
38
49 /**
510 * Class that holds information on a single internal object, including all
611 * its properties.
7 - *
8 - * @author Yaron Koren
912 */
1013 class SIOInternalObject {
1114 protected $mMainTitle;
@@ -45,65 +48,6 @@
4649 }
4750
4851 /**
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 -/**
10852 * Class for all database-related actions.
10953 * This class exists mostly because SMWSQLStore2's functions makeSMWPageID()
11054 * and makeSMWPropertyID(), which are needed for the DB access, are both
@@ -248,8 +192,8 @@
249193 $pageName = $title->getDBkey();
250194 $namespace = $title->getNamespace();
251195
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.
254198 $iw = '';
255199 $db = wfGetDB( DB_SLAVE );
256200 $res = $db->select(
@@ -260,8 +204,13 @@
261205 );
262206
263207 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+ }
266215 $propertyTables = SMWSQLStore2::getPropertyTables();
267216 foreach ( $propertyTables as $tableName => $propertyTable ) {
268217 $data = smwfGetStore()->fetchSemanticData( $row->smw_id, null, $propertyTable );