Semantic MediaWiki and related extensions
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
SMWSql3SmwIds Class Reference

Public Member Functions

 __construct (SMWSQLStore3 $store, IdToDataItemMatchFinder $idToDataItemMatchFinder)
 
 checkIsRedirect (DIWikiPage $subject)
 
 findRedirectIdFor ($title, $namespace)
 
 addRedirectForId ($id, $title, $namespace)
 
 deleteRedirectEntry ($title, $namespace)
 
 getSMWPageIDandSort ($title, $namespace, $iw, $subobjectName, &$sortkey, $canonical, $fetchHashes=false)
 
 getListOfIdMatchesFor ($title, $namespace, $iw, $subobjectName= '')
 
 exists (DIWikiPage $subject)
 
 getIDFor (DIWikiPage $subject)
 
 getSMWPageID ($title, $namespace, $iw, $subobjectName, $canonical=true, $fetchHashes=false)
 
 makeSMWPageID ($title, $namespace, $iw, $subobjectName, $canonical=true, $sortkey= '', $fetchHashes=false)
 
 getPropertyInterwiki (SMWDIProperty $property)
 
 updateInterwikiField ($sid, DIWikiPage $subject, $interWiki=null)
 
 getSMWPropertyID (SMWDIProperty $property)
 
 makeSMWPropertyID (SMWDIProperty $property)
 
 moveSMWPageID ($curid, $targetid=0)
 
 setCache ($title, $namespace, $interwiki, $subobject, $id, $sortkey)
 
 getDataItemById ($id)
 
 getDataItemPoolHashListFor (array $idlist, RequestOptions $requestOptions=null)
 
 deleteCache ($title, $namespace, $interwiki, $subobject)
 
 moveSubobjects ($oldtitle, $oldnamespace, $newtitle, $newnamespace)
 
 clearCaches ()
 
 getPropertyTableHashes ($subjectId)
 
 setPropertyTableHashes ($sid, array $newTableHashes)
 
 getIdTable ()
 

Static Public Member Functions

static debugDumpCacheStats ()
 

Public Attributes

const FXD_PROP_BORDER_ID = SMWSQLStore3::FIXED_PROPERTY_ID_UPPERBOUND
 
const TABLE_NAME = SMWSQLStore3::ID_TABLE
 
const POOLCACHE_ID = 'sql.store.id.cache'
 
 $store
 

Static Public Attributes

static $PROP_CACHE_MAX_SIZE = 250
 
static $PAGE_CACHE_MAX_SIZE = 500
 
static $special_ids
 

Protected Member Functions

 getDatabaseIdAndSort ($title, $namespace, $iw, $subobjectName, &$sortkey, $canonical, $fetchHashes)
 
 makeDatabaseId ($title, $namespace, $iw, $subobjectName, $canonical, $sortkey, $fetchHashes)
 
 getPredefinedData (&$title, &$namespace, &$iw, &$subobjectName, &$sortkey)
 
 getCachedId ($title, $namespace, $interwiki, $subobject)
 
 getCachedSortKey ($title, $namespace, $interwiki, $subobject)
 
 checkPropertySizeLimit ()
 
 checkRegularSizeLimit ()
 
 setPropertyTableHashesCache ($id, $propertyTableHash)
 

Protected Attributes

 $hashCacheId = 0
 
 $hashCacheContents = ''
 
 $selectrow_sort_debug = 0
 
 $selectrow_redi_debug = 0
 
 $prophit_debug = 0
 
 $propmiss_debug = 0
 
 $reghit_debug = 0
 
 $regmiss_debug = 0
 
 $prop_ids = array()
 
 $prop_sortkeys = array()
 
 $regular_ids = array()
 
 $regular_sortkeys = array()
 

Static Protected Attributes

static $singleton_debug = null
 

Detailed Description

Since
1.8
Author
Markus Krötzsch Class to access the SMW IDs table in SQLStore3. Provides transparent in-memory caching facilities.

Documentation for the SMW IDs table: This table is a dictionary that assigns integer IDs to pages, properties, and other objects used by SMW. All tables that refer to such objects store these IDs instead. If the ID information is lost (e.g., table gets deleted), then the data stored in SMW is no longer meaningful: all tables need to be dropped, recreated, and refreshed to get back to a working database.

The table has a column for storing interwiki prefixes, used to refer to pages on external sites (like in MediaWiki). This column is also used to mark some special objects in the table, using "interwiki prefixes" that cannot occur in MediaWiki:

Note
Do not call the constructor of SMWDIWikiPage using data from the SMW IDs table; use SMWDIHandlerWikiPage::dataItemFromDBKeys() instead. The table does not always contain data as required wiki pages. Especially predefined properties are represented by language-independent keys rather than proper titles. SMWDIHandlerWikiPage takes care of this.
Since
1.8

Constructor & Destructor Documentation

SMWSql3SmwIds::__construct ( SMWSQLStore3  $store,
IdToDataItemMatchFinder  $idToDataItemMatchFinder 
)

Constructor.

Since
1.8
Parameters
SMWSQLStore3$store

Member Function Documentation

SMWSql3SmwIds::addRedirectForId (   $id,
  $title,
  $namespace 
)
See also
RedirectInfoStore::addRedirectForId
Since
2.1
Parameters
integer$id
string$title
integer$namespace
SMWSql3SmwIds::checkIsRedirect ( DIWikiPage  $subject)
Since
2.1
Parameters
DIWikiPage$subject
Returns
boolean
SMWSql3SmwIds::checkPropertySizeLimit ( )
protected

Ensure that the property ID and sortkey caches have space to insert at least one more element. If not, some other entries will be unset.

Since
1.8
SMWSql3SmwIds::checkRegularSizeLimit ( )
protected

Ensure that the non-property ID and sortkey caches have space to insert at least one more element. If not, some other entries will be unset.

Since
1.8
SMWSql3SmwIds::clearCaches ( )

Delete all cached information.

Since
1.8
static SMWSql3SmwIds::debugDumpCacheStats ( )
static

Simple helper method for debugging cache performance. Prints statistics about the SMWSql3SmwIds object created last. The following code can be used in LocalSettings.php to enable this in a wiki:

$wgHooks['SkinAfterContent'][] = 'showCacheStats'; function showCacheStats() { self::debugDumpCacheStats(); return true; }

Note
This is a debugging/profiling method that no published code should rely on.
Since
1.8
SMWSql3SmwIds::deleteCache (   $title,
  $namespace,
  $interwiki,
  $subobject 
)

Remove any cache entry for the given data. The key consists of the parameters $title, $namespace, $interwiki, and $subobject. The cached data is $id and $sortkey.

Since
1.8
Parameters
string$title
integer$namespace
string$interwiki
string$subobject
SMWSql3SmwIds::deleteRedirectEntry (   $title,
  $namespace 
)
See also
RedirectInfoStore::deleteRedirectEntry
Since
2.1
Parameters
string$title
integer$namespace
SMWSql3SmwIds::exists ( DIWikiPage  $subject)
Since
2.4
Parameters
DIWikiPage$subject
boolean
SMWSql3SmwIds::findRedirectIdFor (   $title,
  $namespace 
)
See also
RedirectInfoStore::findRedirectIdFor
Since
2.1
Parameters
string$titleDB key
integer$namespace
Returns
integer
SMWSql3SmwIds::getCachedId (   $title,
  $namespace,
  $interwiki,
  $subobject 
)
protected

Get a cached SMW ID, or false if no cache entry is found.

Since
1.8
Parameters
string$title
integer$namespace
string$interwiki
string$subobject
Returns
integer|boolean
SMWSql3SmwIds::getCachedSortKey (   $title,
  $namespace,
  $interwiki,
  $subobject 
)
protected

Get a cached SMW sortkey, or false if no cache entry is found.

Since
1.8
Parameters
string$title
integer$namespace
string$interwiki
string$subobject
Returns
string|boolean
SMWSql3SmwIds::getDatabaseIdAndSort (   $title,
  $namespace,
  $iw,
  $subobjectName,
$sortkey,
  $canonical,
  $fetchHashes 
)
protected

Find the numeric ID used for the page of the given normalized title, namespace, interwiki, and subobjectName. Predefined IDs are not taken into account (however, they would still be found correctly by an avoidable database read if they are stored correctly in the database; this should always be the case). In all other aspects, the method works just like getSMWPageIDandSort().

Since
1.8
Parameters
string$titleDB key
integer$namespacenamespace
string$iwinterwiki prefix
string$subobjectNamename of subobject
string$sortkeycall-by-ref will be set to sortkey
boolean$canonicalshould redirects be resolved?
boolean$fetchHashesshould the property hashes be obtained and cached?
Returns
integer SMW id or 0 if there is none
SMWSql3SmwIds::getDataItemById (   $id)
Since
2.1
Parameters
integer$id
Returns
DIWikiPage|null
SMWSql3SmwIds::getDataItemPoolHashListFor ( array  $idlist,
RequestOptions  $requestOptions = null 
)
Since
2.3
Parameters
integer$id
RequestOptions | null$requestOptions
Returns
string[]
SMWSql3SmwIds::getIDFor ( DIWikiPage  $subject)
Note
SMWSql3SmwIds::getSMWPageID has some issues with the cache as it returned 0 even though an object was matchable, using this method is safer then trying to encipher getSMWPageID related methods.

It uses the PoolCache which means Lru is in place to avoid memory leakage.

Since
2.4
Parameters
DIWikiPage$subject
integer
SMWSql3SmwIds::getIdTable ( )

Returns store Id table name

Returns
string
SMWSql3SmwIds::getListOfIdMatchesFor (   $title,
  $namespace,
  $iw,
  $subobjectName = '' 
)
Since
2.3
Parameters
string$titleDB key
integer$namespacenamespace
string$iwinterwiki prefix
string$subobjectNamename of subobject
array
SMWSql3SmwIds::getPredefinedData ( $title,
$namespace,
$iw,
$subobjectName,
$sortkey 
)
protected

Normalize the information for an SMW object (page etc.) and return the predefined ID if any. All parameters are call-by-reference and will be changed to perform any kind of built-in normalization that SMW requires. This mainly applies to predefined properties that should always use their property key as a title, have fixed sortkeys, etc. Some very special properties also have fixed IDs that do not require any DB lookups. In such cases, the method returns this ID; otherwise it returns 0.

Note
This function could be extended to account for further kinds of normalization and predefined ID. However, both getSMWPropertyID and makeSMWPropertyID must then also be adjusted to do the same.
Since
1.8
Parameters
string$titleDB key
integer$namespacenamespace
string$iwinterwiki prefix
string$subobjectName
string$sortkey
Returns
integer predefined id or 0 if none
SMWSql3SmwIds::getPropertyInterwiki ( SMWDIProperty  $property)

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).

Todo:
This documentation is out of date. Right now, the special interwiki is used only for special properties without a label, i.e., which cannot be shown to a user. This allows us to filter such cases from all queries that retrieve lists of properties. It should be checked that this is really the only use that this has throughout the code.
Since
1.8
Parameters
SMWDIProperty$property
Returns
string
SMWSql3SmwIds::getPropertyTableHashes (   $subjectId)

Return an array of hashes with table names as keys. These hashes are used to compare new data with old data for each property-value table when updating data

Since
1.8
Parameters
integer$subjectIdID of the page as stored in the SMW IDs table
Returns
array
SMWSql3SmwIds::getSMWPageID (   $title,
  $namespace,
  $iw,
  $subobjectName,
  $canonical = true,
  $fetchHashes = false 
)

Convenience method for calling getSMWPageIDandSort without specifying a sortkey (if not asked for).

Since
1.8
Parameters
string$titleDB key
integer$namespacenamespace
string$iwinterwiki prefix
string$subobjectNamename of subobject
boolean$canonicalshould redirects be resolved?
boolean$fetchHashesshould the property hashes be obtained and cached?
Returns
integer SMW id or 0 if there is none
SMWSql3SmwIds::getSMWPageIDandSort (   $title,
  $namespace,
  $iw,
  $subobjectName,
$sortkey,
  $canonical,
  $fetchHashes = false 
)

Find the numeric ID used for the page of the given title, namespace, interwiki, and subobject. 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. The Call-By-Ref parameter $sortkey is set to the current sortkey, or to '' if no ID exists.

If $fetchhashes is true, the property table hash blob will be retrieved in passing if the opportunity arises, and cached internally. This will speed up a subsequent call to getPropertyTableHashes() for this id. This should only be done if such a call is intended, both to safe the previous cache and to avoid extra work (even if only a little) to fill it.

Since
1.8
Parameters
string$titleDB key
integer$namespacenamespace
string$iwinterwiki prefix
string$subobjectNamename of subobject
string$sortkeycall-by-ref will be set to sortkey
boolean$canonicalshould redirects be resolved?
boolean$fetchHashesshould the property hashes be obtained and cached?
Returns
integer SMW id or 0 if there is none
SMWSql3SmwIds::getSMWPropertyID ( SMWDIProperty  $property)

Fetch the ID for an SMWDIProperty object. This method achieves the same as getSMWPageID(), but avoids additional normalization steps that have already been performed when creating an SMWDIProperty object.

Note
There is no distinction between properties and inverse properties here. A property and its inverse have the same ID in SMW.
Parameters
SMWDIProperty$property
Returns
integer
SMWSql3SmwIds::makeDatabaseId (   $title,
  $namespace,
  $iw,
  $subobjectName,
  $canonical,
  $sortkey,
  $fetchHashes 
)
protected

Find the numeric ID used for the page of the given normalized title, namespace, interwiki, and subobjectName. Predefined IDs are not taken into account (however, they would still be found correctly by an avoidable database read if they are stored correctly in the database; this should always be the case). In all other aspects, the method works just like makeSMWPageID(). Especially, if no ID exists, a new ID is created and returned.

Since
1.8
Parameters
string$titleDB key
integer$namespacenamespace
string$iwinterwiki prefix
string$subobjectNamename of subobject
boolean$canonicalshould redirects be resolved?
string$sortkeycall-by-ref will be set to sortkey
boolean$fetchHashesshould the property hashes be obtained and cached?
Returns
integer SMW id or 0 if there is none
SMWSql3SmwIds::makeSMWPageID (   $title,
  $namespace,
  $iw,
  $subobjectName,
  $canonical = true,
  $sortkey = '',
  $fetchHashes = false 
)

Find the numeric ID used for the page of the given title, namespace, interwiki, and subobjectName. 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.
Since
1.8
Parameters
string$titleDB key
integer$namespacenamespace
string$iwinterwiki prefix
string$subobjectNamename of subobject
boolean$canonicalshould redirects be resolved?
string$sortkeycall-by-ref will be set to sortkey
boolean$fetchHashesshould the property hashes be obtained and cached?
Returns
integer SMW id or 0 if there is none
SMWSql3SmwIds::makeSMWPropertyID ( SMWDIProperty  $property)

Fetch and possibly create the ID for an SMWDIProperty object. The method achieves the same as getSMWPageID() but avoids additional normalization steps that have already been performed when creating an SMWDIProperty object.

See also
getSMWPropertyID
Parameters
SMWDIProperty$property
Returns
integer
SMWSql3SmwIds::moveSMWPageID (   $curid,
  $targetid = 0 
)

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).

Since
1.8
Parameters
integer$curid
integer$targetid
SMWSql3SmwIds::moveSubobjects (   $oldtitle,
  $oldnamespace,
  $newtitle,
  $newnamespace 
)

Move all cached information about subobjects.

Todo:
This method is neither efficient nor very convincing architecturally; it should be redesigned.
Since
1.8
Parameters
string$oldtitle
integer$oldnamespace
string$newtitle
integer$newnamespace
SMWSql3SmwIds::setCache (   $title,
  $namespace,
  $interwiki,
  $subobject,
  $id,
  $sortkey 
)

Add or modify a cache entry. The key consists of the parameters $title, $namespace, $interwiki, and $subobject. The cached data is $id and $sortkey.

Since
1.8
Parameters
string$title
integer$namespace
string$interwiki
string$subobject
integer$id
string$sortkey
SMWSql3SmwIds::setPropertyTableHashes (   $sid,
array  $newTableHashes 
)

Update the proptable_hash for a given page.

Since
1.8
Parameters
integer$sidID of the page as stored in SMW IDs table
string[]of hash values with table names as keys
SMWSql3SmwIds::setPropertyTableHashesCache (   $id,
  $propertyTableHash 
)
protected

Temporarily cache a property tablehash that has been retrieved for the given SMW ID.

Since
1.8
Parameters
$idinteger
$propertyTableHashstring
SMWSql3SmwIds::updateInterwikiField (   $sid,
DIWikiPage  $subject,
  $interWiki = null 
)
Since
2.1
Parameters
integer$sid
DIWikiPage$subject
integer | string | null$interWiki

Member Data Documentation

SMWSql3SmwIds::$hashCacheContents = ''
protected
SMWSql3SmwIds::$hashCacheId = 0
protected
SMWSql3SmwIds::$PAGE_CACHE_MAX_SIZE = 500
static
SMWSql3SmwIds::$PROP_CACHE_MAX_SIZE = 250
static
SMWSql3SmwIds::$prop_ids = array()
protected
SMWSql3SmwIds::$prop_sortkeys = array()
protected
SMWSql3SmwIds::$prophit_debug = 0
protected
SMWSql3SmwIds::$propmiss_debug = 0
protected
SMWSql3SmwIds::$reghit_debug = 0
protected
SMWSql3SmwIds::$regmiss_debug = 0
protected
SMWSql3SmwIds::$regular_ids = array()
protected
SMWSql3SmwIds::$regular_sortkeys = array()
protected
SMWSql3SmwIds::$selectrow_redi_debug = 0
protected
SMWSql3SmwIds::$selectrow_sort_debug = 0
protected
SMWSql3SmwIds::$singleton_debug = null
staticprotected
SMWSql3SmwIds::$special_ids
static
SMWSql3SmwIds::$store
const SMWSql3SmwIds::FXD_PROP_BORDER_ID = SMWSQLStore3::FIXED_PROPERTY_ID_UPPERBOUND

Specifies the border limit for pre-defined properties declared in SMWSql3SmwIds::special_ids

const SMWSql3SmwIds::POOLCACHE_ID = 'sql.store.id.cache'
const SMWSql3SmwIds::TABLE_NAME = SMWSQLStore3::ID_TABLE

Name of the table to store IDs in.

Note
This should never change. Existing wikis will have to drop and rebuild their SMW tables completely to recover from any change here.

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