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

Public Member Functions

 __construct (SMWSQLStore3 $store, SQLStoreFactory $factory)
 
 isRedirect (DIWikiPage $subject)
 
 isUnique (DataItem $dataItem)
 
 findRedirect ( $title, $namespace)
 
 addRedirect ( $id, $title, $namespace)
 
 updateRedirect ( $id, $title, $namespace)
 
 deleteRedirect ( $title, $namespace)
 
 getSMWPageIDandSort ( $title, $namespace, $iw, $subobjectName, &$sortkey, $canonical, $fetchHashes=false)
 
 findDuplicates ()
 
 findAllEntitiesThatMatch ( $title, $namespace, $iw=null, $subobjectName='')
 
 exists (DIWikiPage $subject)
 
 getId (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)
 
 findAssociatedRev ( $title, $namespace='', $iw='')
 
 updateRevField ( $sid, $rev_id)
 
 getSMWPropertyID (SMWDIProperty $property)
 
 makeSMWPropertyID (SMWDIProperty $property)
 
 moveSMWPageID ( $curid, $targetid=0)
 
 computeSha1 ( $args='')
 
 warmUpCache ( $list=[])
 
 setCache ( $title, $namespace, $interwiki, $subobject, $id, $sortkey)
 
 getDataItemById ( $id)
 
 getDataItemsFromList (array $idlist, RequestOptions $requestOptions=null)
 
 getDataItemPoolHashListFor (array $idlist, RequestOptions $requestOptions=null)
 
 deleteCache ( $title, $namespace, $interwiki, $subobject)
 
 initCache ()
 
 getPropertyTableHashes ( $sid)
 
 setPropertyTableHashes ( $sid, $hash=null)
 
 getIdTable ()
 

Public Attributes

const FXD_PROP_BORDER_ID = SMWSQLStore3::FIXED_PROPERTY_ID_UPPERBOUND
 
const TABLE_NAME = SMWSQLStore3::ID_TABLE
 
const MAX_CACHE_SIZE = 1000
 
const POOLCACHE_ID = 'smw.sqlstore'
 
 $store
 

Static Public Attributes

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)
 
 setPropertyTableHashesCache ( $sid, $hash)
 

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

◆ __construct()

SMWSql3SmwIds::__construct ( SMWSQLStore3  $store,
SQLStoreFactory  $factory 
)
Since
1.8
Parameters
SMWSQLStore3$store

Member Function Documentation

◆ addRedirect()

SMWSql3SmwIds::addRedirect (   $id,
  $title,
  $namespace 
)
See also
RedirectStore::addRedirect
Since
2.1
Parameters
integer$id
string$title
integer$namespace

◆ computeSha1()

SMWSql3SmwIds::computeSha1 (   $args = '')
Since
3.0
Parameters
string | array$args
Returns
string

◆ deleteCache()

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

◆ deleteRedirect()

SMWSql3SmwIds::deleteRedirect (   $title,
  $namespace 
)
See also
RedirectStore::deleteRedirect
Since
2.1
Parameters
string$title
integer$namespace

◆ exists()

SMWSql3SmwIds::exists ( DIWikiPage  $subject)
Since
2.4
Parameters
DIWikiPage$subject
boolean

◆ findAllEntitiesThatMatch()

SMWSql3SmwIds::findAllEntitiesThatMatch (   $title,
  $namespace,
  $iw = null,
  $subobjectName = '' 
)
Since
2.3
Parameters
string$titleDB key
integer$namespacenamespace
string | null$iwinterwiki prefix
string$subobjectNamename of subobject
array

◆ findAssociatedRev()

SMWSql3SmwIds::findAssociatedRev (   $title,
  $namespace = '',
  $iw = '' 
)
Since
3.0
Parameters
DIWikiPage | string$title
integer$namespace
string$iw

◆ findDuplicates()

SMWSql3SmwIds::findDuplicates ( )
Since
3.0
Returns
[]

◆ findRedirect()

SMWSql3SmwIds::findRedirect (   $title,
  $namespace 
)
See also
RedirectStore::findRedirect
Since
2.1
Parameters
string$titleDB key
integer$namespace
Returns
integer

◆ getDatabaseIdAndSort()

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

◆ getDataItemById()

SMWSql3SmwIds::getDataItemById (   $id)
Since
2.1
Parameters
integer$id
Returns
DIWikiPage|null

◆ getDataItemPoolHashListFor()

SMWSql3SmwIds::getDataItemPoolHashListFor ( array  $idlist,
RequestOptions  $requestOptions = null 
)

◆ getDataItemsFromList()

SMWSql3SmwIds::getDataItemsFromList ( array  $idlist,
RequestOptions  $requestOptions = null 
)
Since
2.3
Parameters
integer$id
RequestOptions | null$requestOptions
Returns
string[]

◆ getId()

SMWSql3SmwIds::getId ( 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

◆ getIdTable()

SMWSql3SmwIds::getIdTable ( )

Returns store Id table name

Returns
string

◆ getPredefinedData()

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

◆ getPropertyInterwiki()

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

◆ getPropertyTableHashes()

SMWSql3SmwIds::getPropertyTableHashes (   $sid)

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

◆ getSMWPageID()

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

◆ getSMWPageIDandSort()

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

◆ getSMWPropertyID()

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

◆ initCache()

SMWSql3SmwIds::initCache ( )
Since
3.0

◆ isRedirect()

SMWSql3SmwIds::isRedirect ( DIWikiPage  $subject)
Since
2.1
Parameters
DIWikiPage$subject
Returns
boolean

◆ isUnique()

SMWSql3SmwIds::isUnique ( DataItem  $dataItem)
Since
3.0
Parameters
DataItem$dataItem
Returns
boolean

◆ makeDatabaseId()

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

◆ makeSMWPageID()

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

◆ makeSMWPropertyID()

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

◆ moveSMWPageID()

SMWSql3SmwIds::moveSMWPageID (   $curid,
  $targetid = 0 
)
See also
IdChanger::move
Since
1.8
Parameters
integer$curid
integer$targetid

◆ setCache()

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

◆ setPropertyTableHashes()

SMWSql3SmwIds::setPropertyTableHashes (   $sid,
  $hash = null 
)

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

◆ setPropertyTableHashesCache()

SMWSql3SmwIds::setPropertyTableHashesCache (   $sid,
  $hash 
)
protected

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

Since
1.8
Parameters
$idinteger
$propertyTableHashstring Temporarily cache a property tablehash that has been retrieved for the given SMW ID.
Since
1.8
Parameters
$idinteger
$propertyTableHashstring

◆ updateInterwikiField()

SMWSql3SmwIds::updateInterwikiField (   $sid,
DIWikiPage  $subject,
  $interwiki = null 
)
Since
2.1
Parameters
integer$sid
DIWikiPage$subject
integer | string | null$interwiki

◆ updateRedirect()

SMWSql3SmwIds::updateRedirect (   $id,
  $title,
  $namespace 
)
See also
RedirectStore::updateRedirect
Since
3.0
Parameters
integer$id
string$title
integer$namespace

◆ updateRevField()

SMWSql3SmwIds::updateRevField (   $sid,
  $rev_id 
)
Since
3.0
Parameters
integer$sid
integer$sid

◆ warmUpCache()

SMWSql3SmwIds::warmUpCache (   $list = [])
Since
3.0
Parameters
array$list

Member Data Documentation

◆ FXD_PROP_BORDER_ID

const SMWSql3SmwIds::FXD_PROP_BORDER_ID = SMWSQLStore3::FIXED_PROPERTY_ID_UPPERBOUND

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

◆ TABLE_NAME

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:

About | General disclaimer | Privacy policy