r66677 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66676‎ | r66677 | r66678 >
Date:03:17, 20 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Splitted code in setupTables and added hook for custom field type signatures.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -151,7 +151,6 @@
152152 '__lin' => 'smw_spec2', // Special linear unit conversion type
153153 '__imp' => 'smw_spec2', // Special import vocabulary type
154154 '__err' => '', // Special error type, used to indicate that the table could not be determined (happens for type-polymorphic _1, _2, ...)
155 - // '__pro' => SMW_SQL2_NONE, // Property page type; actually this should never be stored as a value (_wpp is used there)
156155 );
157156
158157 /// Array to cache signatures of known built-in types. Having this data
@@ -474,6 +473,7 @@
475474 }
476475
477476 /**
 477+ * returns an array of SMWWikiPageValue.
478478 *
479479 * @param SMWPropertyValue $property
480480 * @param $value
@@ -1223,9 +1223,12 @@
12241224 public function setup( $verbose = true ) {
12251225 $this->reportProgress( "Setting up standard database configuration for SMW ...\n\n", $verbose );
12261226 $this->reportProgress( "Selected storage engine is \"SMWSQLStore2\" (or an extension thereof)\n\n", $verbose );
 1227+
12271228 $db = wfGetDB( DB_MASTER );
 1229+
12281230 $this->setupTables( $verbose, $db );
12291231 $this->setupPredefinedProperties( $verbose, $db );
 1232+
12301233 return true;
12311234 }
12321235
@@ -1258,9 +1261,9 @@
12591262 global $wgDBtype;
12601263
12611264 extract( $db->tableNames( 'smw_ids', 'smw_spec2', 'smw_conccache', 'smw_conc2' ) );
1262 - $reportTo = $verbose ? $this:null; // use $this to report back from static SMWSQLHelpers
 1265+ $reportTo = $verbose ? $this : null; // Use $this to report back from static SMWSQLHelpers.
12631266
1264 - // repeatedly used DB field types defined here for convenience
 1267+ // Repeatedly used DB field types defined here for convenience.
12651268 $dbtypes = array(
12661269 't' => SMWSQLHelpers::getStandardDBType( 'title' ),
12671270 'u' => ( $wgDBtype == 'postgres' ? 'TEXT' : 'VARCHAR(63) binary' ),
@@ -1273,7 +1276,7 @@
12741277 'w' => SMWSQLHelpers::getStandardDBType( 'iw' )
12751278 );
12761279
1277 - // DB update: field renaming between SMW 1.3 and SMW 1.4
 1280+ // DB update: field renaming between SMW 1.3 and SMW 1.4.
12781281 if ( ( $db->tableExists( $smw_spec2 ) ) && ( $db->fieldExists( $smw_spec2, 'sp_id', 'SMWSQLStore2::setup' ) ) ) {
12791282 if ( $wgDBtype == 'postgres' ) {
12801283 $db->query( "ALTER TABLE $smw_spec2 ALTER COLUMN sp_id RENAME TO p_id", 'SMWSQLStore2::setup' );
@@ -1288,9 +1291,9 @@
12891292 array(
12901293 'smw_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY AUTO_INCREMENT' ),
12911294 'smw_namespace' => $dbtypes['n'] . ' NOT NULL',
1292 - 'smw_title' => $dbtypes['t'] . ' NOT NULL',
1293 - 'smw_iw' => $dbtypes['w'],
1294 - 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL'
 1295+ 'smw_title' => $dbtypes['t'] . ' NOT NULL',
 1296+ 'smw_iw' => $dbtypes['w'],
 1297+ 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL'
12951298 ),
12961299 $db,
12971300 $reportTo
@@ -1311,20 +1314,41 @@
13121315
13131316 SMWSQLHelpers::setupIndex( $smw_conccache, array( 'o_id' ), $db );
13141317
1315 - // set up concept descriptions
1316 - SMWSQLHelpers::setupTable( $smw_conc2,
1317 - array( 's_id' => $dbtypes['p'] . ' NOT NULL' .
1318 - ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY' ),
1319 - 'concept_txt' => $dbtypes['l'],
1320 - 'concept_docu' => $dbtypes['l'],
1321 - 'concept_features' => $dbtypes['i'],
1322 - 'concept_size' => $dbtypes['i'],
1323 - 'concept_depth' => $dbtypes['i'],
1324 - 'cache_date' => $dbtypes['j'],
1325 - 'cache_count' => $dbtypes['j'] ), $db, $reportTo );
 1318+ // Set up concept descriptions.
 1319+ SMWSQLHelpers::setupTable(
 1320+ $smw_conc2,
 1321+ array(
 1322+ 's_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY' ),
 1323+ 'concept_txt' => $dbtypes['l'],
 1324+ 'concept_docu' => $dbtypes['l'],
 1325+ 'concept_features' => $dbtypes['i'],
 1326+ 'concept_size' => $dbtypes['i'],
 1327+ 'concept_depth' => $dbtypes['i'],
 1328+ 'cache_date' => $dbtypes['j'],
 1329+ 'cache_count' => $dbtypes['j']
 1330+ ),
 1331+ $db,
 1332+ $reportTo
 1333+ );
 1334+
13261335 SMWSQLHelpers::setupIndex( $smw_conc2, array( 's_id' ), $db );
13271336
13281337 // Set up all property tables as defined:
 1338+ $this->setupPropertyTables( $dbtypes, $db, $reportTo );
 1339+
 1340+ $this->reportProgress( "Database initialised successfully.\n\n", $verbose );
 1341+ }
 1342+
 1343+ /**
 1344+ * Sets up the property tables.
 1345+ *
 1346+ * @param array $dbtypes
 1347+ * @param $db
 1348+ * @param $reportTo SMWSQLStore2 or null
 1349+ */
 1350+ protected function setupPropertyTables( array $dbtypes, $db, $reportTo ) {
 1351+ $addedCustomTypeSignatures = false;
 1352+
13291353 foreach ( self::getPropertyTables() as $proptable ) {
13301354 if ( $proptable->idsubject ) {
13311355 $fieldarray = array( 's_id' => $dbtypes['p'] . ' NOT NULL' );
@@ -1334,24 +1358,31 @@
13351359 $indexes = array( 's_title,s_namespace' );
13361360 }
13371361
1338 - if ( $proptable->fixedproperty == false ) {
 1362+ if ( !$proptable->fixedproperty ) {
13391363 $fieldarray['p_id'] = $dbtypes['p'] . ' NOT NULL';
13401364 $indexes[] = 'p_id';
13411365 }
13421366
13431367 foreach ( $proptable->objectfields as $fieldname => $typeid ) {
1344 - $fieldarray[$fieldname] = $dbtypes[$typeid];
 1368+ // If the type signature is not recognized and the custom signatures have not been added, add them.
 1369+ if ( !$addedCustomTypeSignatures && !array_key_exists( $typeid, $dbtypes ) ) {
 1370+ wfRunHooks( 'SMWCustomSQLStoreFieldType', array( &$dbtypes ) );
 1371+ $addedCustomTypeSignatures = true;
 1372+ }
 1373+
 1374+ // Only add the type when the signature was recognized, otherwise ignore it silently.
 1375+ if ( array_key_exists( $typeid, $dbtypes ) ) {
 1376+ $fieldarray[$fieldname] = $dbtypes[$typeid];
 1377+ }
13451378 }
13461379
13471380 $indexes = array_merge( $indexes, $proptable->indexes );
13481381
13491382 SMWSQLHelpers::setupTable( $db->tableName( $proptable->name ), $fieldarray, $db, $reportTo );
1350 - SMWSQLHelpers::setupIndex( $db->tableName( $proptable->name ), $indexes, $db );
1351 - }
1352 -
1353 - $this->reportProgress( "Database initialised successfully.\n\n", $verbose );
 1383+ SMWSQLHelpers::setupIndex( $db->tableName( $proptable->name ), $indexes, $db );
 1384+ }
13541385 }
1355 -
 1386+
13561387 /**
13571388 * Create some initial DB entries for important built-in properties. Having the DB contents predefined
13581389 * allows us to safe DB calls when certain data is needed. At the same time, the entries in the DB
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
@@ -39,6 +39,8 @@
4040 * @note The resulting wikipage object might be invalid if
4141 * the provided title is not allowed. An object is returned
4242 * in any case.
 43+ *
 44+ * @return SMWWikiPageValue
4345 */
4446 static public function makePage( $title, $namespace, $sortkey = '', $interwiki = '' ) {
4547 $page = new SMWWikiPageValue( '_wpg' );

Status & tagging log