SMWSQLStore2 Class Reference
[SMWStore]

Storage access class for using the standard MediaWiki SQL database for keeping semantic data. More...

Inherits SMWStore.

Inherited by SMWSparqlStore.

List of all members.

Public Member Functions

 __construct ()
 getSemanticData (SMWDIWikiPage $subject, $filter=false)
 Retrieve all data stored about the given subject and return it as a SMWSemanticData container.
 getPropertyValues ($subject, SMWDIProperty $property, $requestoptions=null)
 getPropertySubjects (SMWDIProperty $property, $value, $requestoptions=null)
 getAllPropertySubjects (SMWDIProperty $property, $requestoptions=null)
 getProperties (SMWDIWikiPage $subject, $requestoptions=null)
 getInProperties (SMWDataItem $value, $requestoptions=null)
 Implementation of SMWStore::getInProperties().
 deleteSubject (Title $subject)
 doDataUpdate (SMWSemanticData $data)
 changeTitle (Title $oldtitle, Title $newtitle, $pageid, $redirid=0)
 Implementation of SMWStore::changeTitle().
 getQueryResult (SMWQuery $query)
 getPropertiesSpecial ($requestoptions=null)
 getUnusedPropertiesSpecial ($requestoptions=null)
 Implementation of SMWStore::getUnusedPropertiesSpecial().
 getWantedPropertiesSpecial ($requestoptions=null)
 Implementation of SMWStore::getWantedPropertiesSpecial().
 getStatistics ()
 Return statistical information as an associative array with the following keys:
  • 'PROPUSES': Number of property instances (value assignments) in the datatbase
  • 'USEDPROPS': Number of properties that are used with at least one value
  • 'DECLPROPS': Number of properties that have been declared (i.e.

 setup ($verbose=true)
 Setup all storage structures properly for using the store.
 drop ($verbose=true)
 Drop (delete) all storage structures created by setup().
 refreshData (&$index, $count, $namespaces=false, $usejobs=true)
 refreshConceptCache (Title $concept)
 Refresh the concept cache for the given concept.
 deleteConceptCache ($concept)
 Delete the concept cache for the given concept.
 getConceptCacheStatus ($concept)
 Return status of the concept cache for the given concept as an array with key 'status' ('empty': not cached, 'full': cached, 'no': not cachable).
 reportProgress ($msg, $verbose=true)
 Print some output to indicate progress.
 getSMWPageID ($title, $namespace, $iw, $subobjectName, $canonical=true)
 Find the numeric ID used for the page of the given title and namespace.
 getSMWPageIDandSort ($title, $namespace, $iw, $subobjectName, &$sort, $canonical)
 Like getSMWPageID(), but also sets the Call-By-Ref parameter $sort to the current sortkey.
 getRedirectId ($title, $namespace)
 getSMWPropertyID (SMWDIProperty $property)
 This function does the same as getSMWPageID() but takes into account that properties might be predefined.
 cacheSMWPageID ($id, $title, $namespace, $iw, $subobjectName)
 Extend the ID cache as specified.

Static Public Member Functions

static getTypeSignature ($typeid)
 For a given SMW type id, obtain the "signature" from which the appropriate property table and information about sorting/filtering data of this type can be obtained.
static tableFitsType ($tableId, $typeId)
 Check if the given table can be used to store values of the given type.
static findTypeTableId ($typeid)
 Find the id of a property table that is suitable for storing values of the given type.
static findDiTypeTableId ($dataItemId)
 Find the id of a property table that is normally used to store data items of the given type.
static findAllDiTypeTableIds ($dataItemId)
 Find the id of all property tables where data items of the given type could possibly be stored.
static findPropertyTableID (SMWDIProperty $diProperty)
 Retrieve the id of the property table that is to be used for storing values for the given property object.
static getPropertyTables ()
 Return the array of predefined property table declarations, initialising it if necessary.

Protected Member Functions

 fetchSemanticData ($id, $object, $proptable, $issubject=true, $requestoptions=null)
 Helper function for reading all data for from a given property table (specified by an SMWSQLStore2Table object), based on certain restrictions.
 prepareValueQuery (&$from, &$where, $proptable, $value, $tableindex=1)
 Helper function to compute from and where strings for a DB query so that only rows of the given value object match.
 prepareDBUpdates (&$updates, SMWSemanticData $data, $sid, SMWDIWikiPage $subject)
 Extend the given update array to account for the data in the SMWSemanticData object.
 setupTables ($verbose, $db)
 Create required SQL tables.
 setupPropertyTables (array $dbtypes, $db, $reportTo)
 Sets up the property tables.
 setupPredefinedProperties ($verbose, $db)
 Create some initial DB entries for important built-in properties.
 getSQLOptions ($requestoptions, $valuecol= '')
 Transform input parameters into a suitable array of SQL options.
 getSQLConditions ($requestoptions, $valuecol= '', $labelcol= '', $addand=true)
 Transform input parameters into a suitable string of additional SQL conditions.
 applyRequestOptions ($data, $requestoptions)
 Not in all cases can requestoptions be forwarded to the DB using getSQLConditions() and getSQLOptions(): some data comes from caches that do not respect the options yet.
 makeSMWPageID ($title, $namespace, $iw, $subobjectName, $canonical=true, $sortkey= '')
 Find the numeric ID used for the page of the given title and namespace.
 getPropertyInterwiki (SMWDIProperty $property)
 Properties have a mechanisms for being predefined (i.e.
 makeSMWPropertyID (SMWDIProperty $property)
 This function does the same as makeSMWPageID() but takes into account that properties might be predefined.
 moveSMWPageID ($curid, $targetid=0)
 Change an internal id to another value.
 changeSMWPageID ($oldid, $newid, $oldnamespace=-1, $newnamespace=-1, $sdata=true, $podata=true)
 Change an SMW page id across all relevant tables.
 deleteSemanticData (SMWDIWikiPage $subject)
 Delete all semantic data stored for the given subject.
 updateRedirects ($subject_t, $subject_ns, $curtarget_t= '', $curtarget_ns=-1)
 Helper method to write information about some redirect.

Protected Attributes

 $m_idCache
 Cache for SMW IDs.
 $m_semdata = array()
 Cache for SMWSemanticData objects, indexed by SMW ID.
 $m_sdstate = array()
 Like SMWSQLStore2::m_semdata, but containing flags indicating completeness of the SMWSemanticData objs.

Static Protected Attributes

static $in_getSemanticData = 0
 >0 while getSemanticData runs, used to prevent nested calls from clearing the cache while another call runs and is about to fill it with data
static $prop_tables = array()
 Array for keeping property table table data, indexed by table id.
static $fixed_prop_tables = null
 Array to cache "propkey => table id" associations for fixed property tables. Built only when needed.
static $special_ids
 Use pre-defined ids for Very Important Properties, avoiding frequent ID lookups for those.
static $special_tables
 Use special tables for Very Important Properties.
static $di_type_tables
 Default tables to use for storing data of certain types.


Detailed Description

Storage access class for using the standard MediaWiki SQL database for keeping semantic data.

Note:
Regarding the use of interwiki links in the store, there is currently no support for storing semantic data about interwiki objects, and hence queries that involve interwiki objects really make sense only for them occurring in object positions. Most methods still use the given input interwiki text as a simple way to filter out results that may be found if an interwiki object is given but a local object of the same name exists. It is currently not planned to support things like interwiki reuse of properties.

Definition at line 33 of file SMW_SQLStore2.php.


Constructor & Destructor Documentation

SMWSQLStore2::__construct (  ) 

Definition at line 115 of file SMW_SQLStore2.php.


Member Function Documentation

SMWSQLStore2::getSemanticData ( SMWDIWikiPage subject,
filter = false 
)

Retrieve all data stored about the given subject and return it as a SMWSemanticData container.

There are no options: it just returns all available data as shown in the page's Factbox. $filter is an array of strings that are datatype IDs. If given, the function will avoid any work that is not necessary if only properties of these types are of interest.

Note:
There is no guarantee that the store does not retrieve more data than requested when a filter is used. Filtering just ensures that only necessary requests are made, i.e. it improves performance.

Reimplemented from SMWStore.

Definition at line 121 of file SMW_SQLStore2.php.

References $filter, fetchSemanticData(), and getSMWPageIDandSort().

Referenced by getPropertyValues(), and prepareDBUpdates().

SMWSQLStore2::getPropertyValues ( subject,
SMWDIProperty property,
requestoptions = null 
)

SMWSQLStore2::fetchSemanticData ( id,
object,
proptable,
issubject = true,
requestoptions = null 
) [protected]

Helper function for reading all data for from a given property table (specified by an SMWSQLStore2Table object), based on certain restrictions.

The function can filter data based on the subject (1) or on the property it belongs to (2) -- but one of those must be done. The Boolean $issubject is true for (1) and false for (2).

In case (1), the first two parameters are taken to refer to a subject; in case (2) they are taken to refer to a property. In any case, the retrieval is limited to the specified $proptable. The parameters are an internal $id (of a subject or property), and an $object (being an SMWDIWikiPage or SMWDIProperty). Moreover, when filtering by property, it is assumed that the given $proptable belongs to the property: if it is a table with fixed property, it will not be checked that this is the same property as the one that was given in $object.

In case (1), the result in general is an array of pairs (arrays of size 2) consisting of a property name (string), and an array of DB keys (array) from which a datvalue object for this value could be built. It is possible that some of the DB keys are based on internal objects; these will be represented by similar result arrays of (recursive calls of) fetchSemanticData().

In case (2), the result is simply an array of DB keys (array) without the property strings. Container objects will be encoded with nested arrays like in case (1).

Todo:
Maybe share DB handler; asking for it seems to take quite some time and we do not want to change it in one call.
Parameters:
integer $id
SMWDataItem $object
SMWSQLStore2Table $proptable
boolean $issubject
SMWRequestOptions $requestoptions
Returns:
array

Definition at line 281 of file SMW_SQLStore2.php.

References $db, getSQLConditions(), and getSQLOptions().

Referenced by getPropertyValues(), and getSemanticData().

SMWSQLStore2::getPropertySubjects ( SMWDIProperty property,
value,
requestoptions = null 
)

See also:
SMWStore::getPropertySubjects
Parameters:
SMWDIProperty $property
mixed $value SMWDataItem or null
SMWRequestOptions $requestoptions
Returns:
array of SMWDIWikiPage

TODO: should we share code with ask query computation here? Just use queries?

Reimplemented from SMWStore.

Definition at line 394 of file SMW_SQLStore2.php.

References $db, getPropertyValues(), getSMWPropertyID(), getSQLConditions(), getSQLOptions(), and prepareValueQuery().

Referenced by getAllPropertySubjects(), and getPropertyValues().

SMWSQLStore2::prepareValueQuery ( &$  from,
&$  where,
proptable,
value,
tableindex = 1 
) [protected]

Helper function to compute from and where strings for a DB query so that only rows of the given value object match.

The parameter $tableindex counts that tables used in the query to avoid duplicate table names. The parameter $proptable provides the SMWSQLStore2Table object that is queried.

Todo:
Maybe do something about redirects. The old code was $oid = $this->getSMWPageID($value->getDBkey(),$value->getNamespace(),$value->getInterwiki(),false);
Parameters:
string $from
string $where
SMWSQLStore2Table $proptable
SMWDataItem $value
integer $tableindex

TODO This code still partly supports some abandoned flexibility of the DBkeys system; this is not very clean (see break; below) and should be improved

Definition at line 473 of file SMW_SQLStore2.php.

References $db, SMWCompatibilityHelpers::getDBkeysFromDataItem(), getProperties(), getPropertyValues(), getSMWPageID(), and getSMWPropertyID().

Referenced by getInProperties(), and getPropertySubjects().

SMWSQLStore2::getAllPropertySubjects ( SMWDIProperty property,
requestoptions = null 
)

See also:
SMWStore::getAllPropertySubjects
Parameters:
SMWDIProperty $property
SMWRequestOptions $requestoptions
Returns:
array of SMWDIWikiPage

Reimplemented from SMWStore.

Definition at line 534 of file SMW_SQLStore2.php.

References getPropertySubjects().

SMWSQLStore2::getProperties ( SMWDIWikiPage subject,
requestoptions = null 
)

See also:
SMWStore::getProperties
Parameters:
SMWDIWikiPage $subject
SMWRequestOptions $requestoptions

Reimplemented from SMWStore.

Definition at line 548 of file SMW_SQLStore2.php.

References $db, applyRequestOptions(), getSMWPageID(), getSQLConditions(), and getSQLOptions().

Referenced by SMWSparqlStore::expandUpdateExpData(), prepareDBUpdates(), and prepareValueQuery().

SMWSQLStore2::getInProperties ( SMWDataItem value,
requestoptions = null 
)

Implementation of SMWStore::getInProperties().

This function is meant to be used for finding properties that link to wiki pages.

See also:
SMWStore::getInProperties
TODO: When used for other datatypes, the function may return too many properties since it selects results by comparing the stored information (DB keys) only, while not currently comparing the type of the returned property to the type of the queried data. So values with the same DB keys can be confused. This is a minor issue now since no code is known to use this function in cases where this occurs.

Parameters:
SMWDataItem $value
SMWRequestOptions $requestoptions
Returns:
array of SMWWikiPageValue

Reimplemented from SMWStore.

Definition at line 624 of file SMW_SQLStore2.php.

References $db, applyRequestOptions(), getSQLConditions(), getSQLOptions(), and prepareValueQuery().

SMWSQLStore2::deleteSubject ( Title $  subject  ) 

See also:
SMWStore::deleteSubject
Parameters:
Title $subject

FIXME: if a property page is deleted, more pages may need to be updated by jobs! TODO: who is responsible for these updates? Some update jobs are currently created in SMW_Hooks, some internally in the store TODO: Possibly delete ID here (at least for non-properties/categories, if not used in any place in rels2) FIXME: clean internal caches here

Reimplemented from SMWStore.

Reimplemented in SMWSparqlStore.

Definition at line 685 of file SMW_SQLStore2.php.

References $db, deleteSemanticData(), getSMWPageID(), SMWDIWikiPage::newFromTitle(), and updateRedirects().

SMWSQLStore2::doDataUpdate ( SMWSemanticData data  ) 

SMWSQLStore2::prepareDBUpdates ( &$  updates,
SMWSemanticData data,
sid,
SMWDIWikiPage subject 
) [protected]

Extend the given update array to account for the data in the SMWSemanticData object.

The subject page of the data container is ignored, and the given $sid (subject page id) is used directly. If this ID is 0, then $subject is used to find an ID. This is usually the case for all internal objects that are created in writing container values.

The function returns the id that was used for writing. Especially, any newly created internal id is returned.

Parameters:
$updates array
$data SMWSemanticData
$sid integer pre-computed id if available or 0 if ID should be sought
$subject SMWDIWikiPage subject to which the data refers

TODO check needed if subject is null (would happen if a user defined proptable with !idsubject was used on an internal object -- currently this is not possible

Definition at line 808 of file SMW_SQLStore2.php.

References SMWCompatibilityHelpers::getDBkeysFromDataItem(), getProperties(), getPropertyValues(), getSemanticData(), makeSMWPageID(), and makeSMWPropertyID().

Referenced by doDataUpdate().

SMWSQLStore2::changeTitle ( Title $  oldtitle,
Title $  newtitle,
pageid,
redirid = 0 
)

Implementation of SMWStore::changeTitle().

In contrast to updateRedirects(), this function does not simply write a redirect from the old page to the new one, but also deletes all data that may already be stored for the new title (normally the new title should belong to an empty page that has no data but at least it could have a redirect to the old page), and moves all data that exists for the old title to the new location. Thus, the function executes three steps: delete data at newtitle, move data from oldtitle to newtitle, and set redirect from oldtitle to newtitle. In some cases, the goal can be achieved more efficiently, e.g. if the new title does not occur in SMW yet: then we can just change the ID records for the titles instead of changing all data tables

Note that the implementation ignores the MediaWiki IDs since this store has its own ID management. Also, the function requires that both titles are local, i.e. have empty interwiki prefix.

TODO: Currently the sortkey is not moved with the remaining data. It is not possible to move it reliably in all cases: we cannot distinguish an unset sortkey from one that was set to the name of oldtitle. Maybe use update jobs right away?

Parameters:
Title $oldtitle
Title $newtitle
integer $pageid
integer $redirid

NOTE: there is the (bad) case that the moved page is a redirect. As chains of redirects are not supported by MW or SMW, the above is maximally correct in this case too. NOTE: this temporarily leaves existing redirects to oldtitle point to newtitle as well, which will be lost after the next update. Since double redirects are an error anyway, this is not a bad behaviour: everything will continue to work until the existing redirects are updated, which will hopefully be done to fix the double redirect.

TODO: may not be optimal for the standard case that newtitle existed and redirected to oldtitle (PERFORMANCE)

Reimplemented from SMWStore.

Reimplemented in SMWSparqlStore.

Definition at line 898 of file SMW_SQLStore2.php.

References $db, $smwgQEqualitySupport, changeSMWPageID(), deleteSemanticData(), getSMWPageID(), makeSMWPageID(), SMWDIWikiPage::newFromTitle(), and updateRedirects().

SMWSQLStore2::getQueryResult ( SMWQuery query  ) 

See also:
SMWStore::getQueryResult
Parameters:
$query SMWQuery
Returns:
mixed: depends on $query->querymode

Reimplemented from SMWStore.

Reimplemented in SMWSparqlStore.

Definition at line 991 of file SMW_SQLStore2.php.

References $smwgIP.

SMWSQLStore2::getPropertiesSpecial ( requestoptions = null  ) 

Todo:
Properties that are stored in dedicated tables (SMWSQLStore2Table::fixedproperty) are currently ignored.

Reimplemented from SMWStore.

Definition at line 1009 of file SMW_SQLStore2.php.

References $db.

SMWSQLStore2::getUnusedPropertiesSpecial ( requestoptions = null  ) 

Implementation of SMWStore::getUnusedPropertiesSpecial().

It works by creating a temporary table with all property pages from which all used properties are then deleted. This is still a costy operation, and some slower but lessdemanding way of getting at this data is required for larger wikis.

Reimplemented from SMWStore.

Definition at line 1054 of file SMW_SQLStore2.php.

References $db, and getSQLOptions().

SMWSQLStore2::getWantedPropertiesSpecial ( requestoptions = null  ) 

Implementation of SMWStore::getWantedPropertiesSpecial().

Like all WantedFoo specials, this function is very resource intensive and needs to be cached on medium/large wikis.

Parameters:
SMWRequestOptions $requestoptions
Returns:
array of array( SMWDIProperty, int )

Reimplemented from SMWStore.

Definition at line 1159 of file SMW_SQLStore2.php.

References $db, $smwgPDefaultType, and getSQLOptions().

SMWSQLStore2::getStatistics (  ) 

Return statistical information as an associative array with the following keys:

  • 'PROPUSES': Number of property instances (value assignments) in the datatbase
  • 'USEDPROPS': Number of properties that are used with at least one value
  • 'DECLPROPS': Number of properties that have been declared (i.e.

assigned a type)

Returns:
array

Reimplemented from SMWStore.

Definition at line 1192 of file SMW_SQLStore2.php.

References $db, and getSMWPropertyID().

SMWSQLStore2::setup ( verbose = true  ) 

Setup all storage structures properly for using the store.

This function performs tasks like creation of database tables. It is called upon installation as well as on upgrade: hence it must be able to upgrade existing storage structures if needed. It should return "true" if successful and return a meaningful string error message otherwise.

The parameter $verbose determines whether the procedure is allowed to report on its progress. This is doen by just using print and possibly ob_flush/flush. This is also relevant for preventing timeouts during long operations. All output must be valid in an HTML context, but should preferrably be plain text, possibly with some linebreaks and weak markup.

Parameters:
boolean $verbose

Reimplemented from SMWStore.

Definition at line 1238 of file SMW_SQLStore2.php.

References $db, reportProgress(), setupPredefinedProperties(), and setupTables().

SMWSQLStore2::setupTables ( verbose,
db 
) [protected]

Create required SQL tables.

This function also performs upgrades of table contents when required.

Documentation for the table smw_ids: This table is normally used to store references to wiki pages (possibly with some external interwiki prefix). There are, however, some special objects that are also stored therein. These are marked by special interwiki prefixes (iw) that cannot occcur in real life:

  • Rows with iw SMW_SQL2_SMWREDIIW are similar to normal entries for (internal) wiki pages, but the iw indicates that the page is a redirect, the target of which should be sought using the smw_redi2 table.

  • The (unique) row with iw SMW_SQL2_SMWBORDERIW just marks the border between predefined ids (rows that are reserved for hardcoded ids built into SMW) and normal entries. It is no object, but makes sure that SQL's auto increment counter is high enough to not add any objects before that marked "border".

Definition at line 1271 of file SMW_SQLStore2.php.

References $db, SMWSQLHelpers::getStandardDBType(), reportProgress(), SMWSQLHelpers::setupIndex(), setupPropertyTables(), and SMWSQLHelpers::setupTable().

Referenced by setup().

SMWSQLStore2::setupPropertyTables ( array $  dbtypes,
db,
reportTo 
) [protected]

Sets up the property tables.

Parameters:
array $dbtypes
$db 
$reportTo SMWSQLStore2 or null

Definition at line 1342 of file SMW_SQLStore2.php.

References $db, SMWSQLHelpers::setupIndex(), and SMWSQLHelpers::setupTable().

Referenced by setupTables().

SMWSQLStore2::setupPredefinedProperties ( verbose,
db 
) [protected]

Create some initial DB entries for important built-in properties.

Having the DB contents predefined allows us to safe DB calls when certain data is needed. At the same time, the entries in the DB make sure that DB-based functions work as with all other properties.

Definition at line 1384 of file SMW_SQLStore2.php.

References $db, getPropertyInterwiki(), moveSMWPageID(), and reportProgress().

Referenced by setup().

SMWSQLStore2::drop ( verbose = true  ) 

Drop (delete) all storage structures created by setup().

This will delete all semantic data and possibly leave the wiki uninitialised.

Parameters:
boolean $verbose

Reimplemented from SMWStore.

Reimplemented in SMWSparqlStore.

Definition at line 1448 of file SMW_SQLStore2.php.

References $db, and reportProgress().

SMWSQLStore2::refreshData ( &$  index,
count,
namespaces = false,
usejobs = true 
)

See also:
SMWStore::refreshData
Parameters:
integer $index
integer $count
mixed $namespaces Array or false
boolean $usejobs
Returns:
decimal between 0 and 1 to indicate the overall progress of the refreshing

Reimplemented from SMWStore.

Definition at line 1480 of file SMW_SQLStore2.php.

References $db, and deleteSemanticData().

SMWSQLStore2::refreshConceptCache ( Title $  concept  ) 

Refresh the concept cache for the given concept.

Parameters:
$concept Title
Returns:
array

Definition at line 1570 of file SMW_SQLStore2.php.

References $smwgIP.

SMWSQLStore2::deleteConceptCache ( concept  ) 

Delete the concept cache for the given concept.

Parameters:
$concept Title

Definition at line 1589 of file SMW_SQLStore2.php.

References $smwgIP.

SMWSQLStore2::getConceptCacheStatus ( concept  ) 

Return status of the concept cache for the given concept as an array with key 'status' ('empty': not cached, 'full': cached, 'no': not cachable).

If status is not 'no', the array also contains keys 'size' (query size), 'depth' (query depth), 'features' (query features). If status is 'full', the array also contains keys 'date' (timestamp of cache), 'count' (number of results in cache).

Parameters:
$concept Title or SMWWikiPageValue

Definition at line 1613 of file SMW_SQLStore2.php.

References $db, and getSMWPageID().

SMWSQLStore2::getSQLOptions ( requestoptions,
valuecol = '' 
) [protected]

Transform input parameters into a suitable array of SQL options.

The parameter $valuecol defines the string name of the column to which sorting requests etc. are to be applied.

Definition at line 1650 of file SMW_SQLStore2.php.

Referenced by fetchSemanticData(), getInProperties(), getProperties(), getPropertySubjects(), getUnusedPropertiesSpecial(), and getWantedPropertiesSpecial().

SMWSQLStore2::getSQLConditions ( requestoptions,
valuecol = '',
labelcol = '',
addand = true 
) [protected]

Transform input parameters into a suitable string of additional SQL conditions.

The parameter $valuecol defines the string name of the column to which value restrictions etc. are to be applied.

Parameters:
$requestoptions object with options
$valuecol string name of SQL column to which conditions apply
$labelcol string name of SQL column to which string conditions apply, if any
$addand boolean to indicate whether the string should begin with " AND " if non-empty
Returns:
string

TODO avoid doing this here again, all callers should have one

Definition at line 1682 of file SMW_SQLStore2.php.

References $db, SMWStringCondition::STRCOND_MID, SMWStringCondition::STRCOND_POST, and SMWStringCondition::STRCOND_PRE.

Referenced by fetchSemanticData(), getInProperties(), getProperties(), and getPropertySubjects().

SMWSQLStore2::applyRequestOptions ( data,
requestoptions 
) [protected]

Not in all cases can requestoptions be forwarded to the DB using getSQLConditions() and getSQLOptions(): some data comes from caches that do not respect the options yet.

This method takes an array of results (SMWDataItem objects) *of the same type* and applies the given requestoptions as appropriate.

Definition at line 1722 of file SMW_SQLStore2.php.

References SMWStore::getWikiPageSortKey(), SMWStringCondition::STRCOND_MID, SMWStringCondition::STRCOND_POST, and SMWStringCondition::STRCOND_PRE.

Referenced by getInProperties(), getProperties(), and getPropertyValues().

SMWSQLStore2::reportProgress ( msg,
verbose = true 
)

Print some output to indicate progress.

The output message is given by $msg, while $verbose indicates whether or not output is desired at all.

Definition at line 1821 of file SMW_SQLStore2.php.

Referenced by drop(), setup(), setupPredefinedProperties(), and setupTables().

static SMWSQLStore2::getTypeSignature ( typeid  )  [static]

For a given SMW type id, obtain the "signature" from which the appropriate property table and information about sorting/filtering data of this type can be obtained.

The result is an array of three entries: a signature string, the index of the value field, and the index of the label label field.

Definition at line 1840 of file SMW_SQLStore2.php.

References SMWDataValueFactory::getDataItemId(), SMWCompatibilityHelpers::getIndexFromDataItemId(), and SMWCompatibilityHelpers::getSignatureFromDataItemId().

Referenced by SMWSQLStore2QueryEngine::compilePropertyCondition().

static SMWSQLStore2::tableFitsType ( tableId,
typeId 
) [static]

Check if the given table can be used to store values of the given type.

This is needed to apply the type-based filtering in getSemanticData().

Parameters:
$tableId string
$typeId string
Returns:
boolean

Definition at line 1856 of file SMW_SQLStore2.php.

References SMWDataValueFactory::getDataItemId().

static SMWSQLStore2::findTypeTableId ( typeid  )  [static]

Find the id of a property table that is suitable for storing values of the given type.

The type is specified by an SMW type id such as '_wpg'. An empty string is returned if no matching table could be found.

Parameters:
$typeid string
Returns:
string

Definition at line 1881 of file SMW_SQLStore2.php.

References SMWDataValueFactory::getDataItemId().

static SMWSQLStore2::findDiTypeTableId ( dataItemId  )  [static]

Find the id of a property table that is normally used to store data items of the given type.

Parameters:
$dataItemId integer
Returns:
string

Definition at line 1893 of file SMW_SQLStore2.php.

static SMWSQLStore2::findAllDiTypeTableIds ( dataItemId  )  [static]

Find the id of all property tables where data items of the given type could possibly be stored.

Parameters:
$dataItemId integer
Returns:
array of string

Definition at line 1904 of file SMW_SQLStore2.php.

References SMWDataValueFactory::getDataItemId().

static SMWSQLStore2::findPropertyTableID ( SMWDIProperty diProperty  )  [static]

Retrieve the id of the property table that is to be used for storing values for the given property object.

Parameters:
$diProperty SMWDIProperty
Returns:
string

Definition at line 1923 of file SMW_SQLStore2.php.

References SMWDIProperty::getKey().

Referenced by SMWSQLStore2QueryEngine::compilePropertyCondition().

SMWSQLStore2::getSMWPageID ( title,
namespace,
iw,
subobjectName,
canonical = true 
)

Find the numeric ID used for the page of the given title and namespace.

If $canonical is set to true, redirects are taken into account to find the canonical alias ID for the given page. If no such ID exists, 0 is returned.

Definition at line 1938 of file SMW_SQLStore2.php.

References $smwgQEqualitySupport, and getRedirectId().

Referenced by changeTitle(), deleteSemanticData(), deleteSubject(), getConceptCacheStatus(), getProperties(), getSMWPropertyID(), makeSMWPageID(), prepareValueQuery(), and updateRedirects().

SMWSQLStore2::getSMWPageIDandSort ( title,
namespace,
iw,
subobjectName,
&$  sort,
canonical 
)

Like getSMWPageID(), but also sets the Call-By-Ref parameter $sort to the current sortkey.

Definition at line 1960 of file SMW_SQLStore2.php.

References $db, $smwgQEqualitySupport, and getRedirectId().

Referenced by getSemanticData(), and makeSMWPageID().

SMWSQLStore2::getRedirectId ( title,
namespace 
)

Definition at line 2000 of file SMW_SQLStore2.php.

References $db.

Referenced by getSMWPageID(), and getSMWPageIDandSort().

SMWSQLStore2::makeSMWPageID ( title,
namespace,
iw,
subobjectName,
canonical = true,
sortkey = '' 
) [protected]

Find the numeric ID used for the page of the given title and namespace.

If $canonical is set to true, redirects are taken into account to find the canonical alias ID for the given page. If no such ID exists, a new ID is created and returned. In any case, the current sortkey is set to the given one unless $sortkey is empty.

Note:
Using this with $canonical==false can make sense, especially when the title is a redirect target (we do not want chains of redirects). But it is of no relevance if the title does not have an id yet.

Definition at line 2017 of file SMW_SQLStore2.php.

References $db, getSMWPageID(), and getSMWPageIDandSort().

Referenced by changeTitle(), doDataUpdate(), makeSMWPropertyID(), prepareDBUpdates(), and updateRedirects().

SMWSQLStore2::getPropertyInterwiki ( SMWDIProperty property  )  [protected]

Properties have a mechanisms for being predefined (i.e.

in PHP instead of in wiki). Special "interwiki" prefixes separate the ids of such predefined properties from the ids for the current pages (which may, e.g., be moved, while the predefined object is not movable).

Definition at line 2062 of file SMW_SQLStore2.php.

Referenced by getSMWPropertyID(), makeSMWPropertyID(), and setupPredefinedProperties().

SMWSQLStore2::getSMWPropertyID ( SMWDIProperty property  ) 

This function does the same as getSMWPageID() but takes into account that properties might be predefined.

Definition at line 2074 of file SMW_SQLStore2.php.

References SMWDIProperty::getKey(), getPropertyInterwiki(), and getSMWPageID().

Referenced by getPropertySubjects(), getPropertyValues(), getStatistics(), and prepareValueQuery().

SMWSQLStore2::makeSMWPropertyID ( SMWDIProperty property  )  [protected]

This function does the same as makeSMWPageID() but takes into account that properties might be predefined.

Definition at line 2086 of file SMW_SQLStore2.php.

References SMWDIProperty::getKey(), getPropertyInterwiki(), and makeSMWPageID().

Referenced by prepareDBUpdates().

SMWSQLStore2::cacheSMWPageID ( id,
title,
namespace,
iw,
subobjectName 
)

Extend the ID cache as specified.

This is called in places where IDs are retrieved by SQL queries and it would be a pity to throw them away. This function expects to get the contents of a row in smw_ids, i.e. possibly with iw being SMW_SQL2_SMWREDIIW. This information is used to determine whether the given ID is canonical or not.

Definition at line 2102 of file SMW_SQLStore2.php.

SMWSQLStore2::moveSMWPageID ( curid,
targetid = 0 
) [protected]

Change an internal id to another value.

If no target value is given, the value is changed to become the last id entry (based on the automatic id increment of the database). Whatever currently occupies this id will be moved consistently in all relevant tables. Whatever currently occupies the target id will be ignored (it should be ensured that nothing is moved to an id that is still in use somewhere).

Definition at line 2114 of file SMW_SQLStore2.php.

References $db, and changeSMWPageID().

Referenced by setupPredefinedProperties().

SMWSQLStore2::changeSMWPageID ( oldid,
newid,
oldnamespace = -1,
newnamespace = -1,
sdata = true,
podata = true 
) [protected]

Change an SMW page id across all relevant tables.

The redirect table is also updated (without much effect if the change happended due to some redirect, since the table should not contain the id of the redirected page). If namespaces are given, then they are used to delete any entries that are limited to one particular namespace (e.g. only properties can be used as properties) instead of moving them.

The id in smw_ids as such is not touched.

Note:
This method only changes internal page IDs in SMW. It does not assume any change in (title-related) data, as e.g. in a page move. Internal objects (subobject) do not need to be updated since they refer to the title of their parent page, not to its ID.
Parameters:
$oldid numeric ID that is to be changed
$newid numeric ID to which the records are to be changed
$oldnamespace namespace of old id's page (-1 to ignore it)
$newnamespace namespace of new id's page (-1 to ignore it)
$sdata boolean stating whether to update subject references
$podata boolean stating if to update property/object references

Definition at line 2178 of file SMW_SQLStore2.php.

References $db.

Referenced by changeTitle(), moveSMWPageID(), and updateRedirects().

SMWSQLStore2::deleteSemanticData ( SMWDIWikiPage subject  )  [protected]

Delete all semantic data stored for the given subject.

Used for update purposes.

Parameters:
$subject SMWDIWikiPage the data of which is deleted

NOTE: redirects are handled by updateRedirects(), not here!

Definition at line 2227 of file SMW_SQLStore2.php.

References $db, and getSMWPageID().

Referenced by changeTitle(), deleteSubject(), doDataUpdate(), and refreshData().

SMWSQLStore2::updateRedirects ( subject_t,
subject_ns,
curtarget_t = '',
curtarget_ns = -1 
) [protected]

Helper method to write information about some redirect.

Various updates can be necessary if redirects are resolved as identities in SMW. The title and namespace of the affected page and of its updated redirect target are given. The target can be empty ('') to delete any redirect. Returns the canonical ID that is now to be used for the subject.

This method does not change the ids of the affected pages, and thus it is not concerned with updates of the data that is currently stored for the subject. Normally, a subject that is a redirect will not have other data, but this method does not depend on this.

Note:
Please make sure you fully understand this code before making any changes here. Keeping the redirect structure consistent is important, and errors in this code can go unnoticed for quite some time.

This method merely handles the addition or deletion of a redirect statement in the wiki. It does not assume that any page contents has been changed (e.g. moved). See changeTitle() for additional handling in this case.

NOTE: $sid can be 0 here; this is useful to know since it means that fewer table updates are needed

NOTE: $old_tid and $new_tid both (intentionally) ignore further redirects: no redirect chains

NOTE: we do not update the concept cache here; this remains an offline task

NOTE: this only happens if $smwgEnableUpdateJobs was true above:

Definition at line 2308 of file SMW_SQLStore2.php.

References $db, $smwgEnableUpdateJobs, $smwgQEqualitySupport, changeSMWPageID(), getSMWPageID(), and makeSMWPageID().

Referenced by changeTitle(), deleteSubject(), and doDataUpdate().

static SMWSQLStore2::getPropertyTables (  )  [static]

Return the array of predefined property table declarations, initialising it if necessary.

The result is an array of SMWSQLStore2Table objects indexed by table ids. Note that the ids are only for accessing the data and should not be assumed to agree with the table name.

Tables declare value columns ("object fields") by specifying their name and type. Types are given using letters:

  • t for strings of the same maximal length as MediaWiki title names,
  • l for arbitrarily long strings; searching/sorting with such data may be limited for performance reasons,
  • w for strings as used in MediaWiki for encoding interwiki prefixes
  • n for namespace numbers (or other similar integers)
  • f for floating point numbers of double precision
  • p for a reference to an SMW ID as stored in the smw_ids table; this corresponds to a data entry of ID "tnwt".

Returns:
array of SMWSQLStore2Table
Todo:
The concept table should make s_id a primary key; make this possible.

Definition at line 2453 of file SMW_SQLStore2.php.

Referenced by SMWSQLStore2QueryEngine::compilePropertyCondition().


Member Data Documentation

SMWSQLStore2::$m_idCache [protected]

Cache for SMW IDs.

Definition at line 36 of file SMW_SQLStore2.php.

SMWSQLStore2::$m_semdata = array() [protected]

Cache for SMWSemanticData objects, indexed by SMW ID.

Definition at line 39 of file SMW_SQLStore2.php.

SMWSQLStore2::$m_sdstate = array() [protected]

Like SMWSQLStore2::m_semdata, but containing flags indicating completeness of the SMWSemanticData objs.

Definition at line 41 of file SMW_SQLStore2.php.

SMWSQLStore2::$in_getSemanticData = 0 [static, protected]

>0 while getSemanticData runs, used to prevent nested calls from clearing the cache while another call runs and is about to fill it with data

Definition at line 43 of file SMW_SQLStore2.php.

SMWSQLStore2::$prop_tables = array() [static, protected]

Array for keeping property table table data, indexed by table id.

Access this only by calling getPropertyTables().

Definition at line 47 of file SMW_SQLStore2.php.

SMWSQLStore2::$fixed_prop_tables = null [static, protected]

Array to cache "propkey => table id" associations for fixed property tables. Built only when needed.

Definition at line 49 of file SMW_SQLStore2.php.

SMWSQLStore2::$special_ids [static, protected]

Initial value:

 array(
                '_TYPE' => 1,
                '_URI'  => 2,
                '_INST' => 4,
                '_UNIT' => 7,
                '_IMPO' => 8,
                '_CONV' => 12,
                '_SERV' => 13,
                '_PVAL' => 14,
                '_REDI' => 15,
                '_SUBP' => 17,
                '_SUBC' => 18,
                '_CONC' => 19,
                '_SF_DF' => 20, // Semantic Form's default form property
                '_SF_AF' => 21,  // Semantic Form's alternate form property
                '_ERRP' => 22,
//              '_1' => 23, // properties for encoding (short) lists
//              '_2' => 24,
//              '_3' => 25,
//              '_4' => 26,
//              '_5' => 27,
                '_LIST' => 28,
                '_MDAT' => 29,
                '_CDAT' => 30,
                '_NEWP' => 31,
                '_LEDT' => 32,
        )
Use pre-defined ids for Very Important Properties, avoiding frequent ID lookups for those.

Definition at line 52 of file SMW_SQLStore2.php.

SMWSQLStore2::$special_tables [static, protected]

Initial value:

 array(
                '_TYPE' => 'smw_spec2',
                '_URI'  => 'smw_spec2',
                '_INST' => 'smw_inst2',
                '_UNIT' => 'smw_spec2',
                '_IMPO' => 'smw_spec2',
                '_CONV' => 'smw_spec2',
                '_SERV' => 'smw_spec2',
                '_PVAL' => 'smw_spec2',
                '_REDI' => 'smw_redi2',
                '_SUBP' => 'smw_subp2',
                '_SUBC' => 'smw_subs2',
                '_CONC' => 'smw_conc2',
                '_SF_DF' => 'smw_spec2', // Semantic Form's default form property
                '_SF_AF' => 'smw_spec2',  // Semantic Form's alternate form property
                //'_ERRP', '_MDAT', '_CDAT', '_SKEY' // no special table
                '_LIST' => 'smw_spec2',
        )
Use special tables for Very Important Properties.

Definition at line 81 of file SMW_SQLStore2.php.

SMWSQLStore2::$di_type_tables [static, protected]

Initial value:

 array(
                SMWDataItem::TYPE_NUMBER     => 'smw_atts2',
                SMWDataItem::TYPE_STRING     => 'smw_atts2',
                SMWDataItem::TYPE_BLOB       => 'smw_text2',
                SMWDataItem::TYPE_BOOLEAN    => 'smw_atts2',
                SMWDataItem::TYPE_URI        => 'smw_atts2',
                SMWDataItem::TYPE_TIME       => 'smw_atts2',
                SMWDataItem::TYPE_GEO        => 'smw_coords', // currently created only if Semantic Maps are installed
                SMWDataItem::TYPE_CONTAINER  => 'smw_rels2', // values of this type represented by internal objects, stored like pages in smw_rels2
                SMWDataItem::TYPE_WIKIPAGE   => 'smw_rels2',
                SMWDataItem::TYPE_CONCEPT    => 'smw_conc2', // unlikely to occur as value of a normal property
                SMWDataItem::TYPE_PROPERTY   => 'smw_atts2'  // unlikely to occur as value of any property
        )
Default tables to use for storing data of certain types.

Definition at line 101 of file SMW_SQLStore2.php.


The documentation for this class was generated from the following file:

Generated on Sun Mar 18 07:15:44 2012 for Semantic MediaWiki by  doxygen 1.5.6