MediaWiki master
MediaWiki\Deferred\LinksUpdate\LinksTable Class Reference

The base class for classes which update a single link table. More...

Inherited by MediaWiki\Deferred\LinksUpdate\ExternalLinksTable, MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable, MediaWiki\Deferred\LinksUpdate\LangLinksTable, MediaWiki\Deferred\LinksUpdate\PagePropsTable, and MediaWiki\Deferred\LinksUpdate\TitleLinksTable.

Collaboration diagram for MediaWiki\Deferred\LinksUpdate\LinksTable:

Public Member Functions

 beforeLock ()
 Subclasses can override this to do any necessary setup before the lock is acquired.
 
 injectBaseDependencies (LBFactory $lbFactory, LinkTargetLookup $linkTargetLookup, PageIdentity $sourcePage, $batchSize)
 This is called by the factory to inject dependencies for the base class.
 
 setMoveDetails (PageReference $movedPage)
 Notify the object that the operation is a page move, and set the original title.
 
 setParserOutput (ParserOutput $parserOutput)
 Subclasses should implement this to extract the data they need from the ParserOutput.
 
 setRevision (RevisionRecord $revision)
 Set the revision associated with the edit.
 
 setStrictTestMode ( $mode=true)
 Omit conflict resolution options from the insert query so that testing can confirm that the incremental update logic was correct.
 
 setTransactionTicket ( $ticket)
 Set the empty transaction ticket.
 
 update ()
 Execute an edit/delete update.
 

Public Attributes

const CHANGED = 3
 Link type: Changed (inserted or removed) links.
 
const DELETED = 2
 Link type: Deleted (removed) links.
 
const INSERTED = 1
 Link type: Inserted (added) links.
 
const NEW = 5
 Link type: new links (from the ParserOutput)
 
const OLD = 4
 Link type: existing/old links.
 
const VIRTUAL_DOMAIN = 'virtual-links'
 

Protected Member Functions

 deleteLink ( $linkId)
 Delete a link identified by ID.
 
 deleteRow ( $conds)
 Queue a deletion operation.
 
 doWrites ()
 Do the common DB operations.
 
 fetchExistingRows ()
 Do a select query to fetch the existing rows.
 
 finishUpdate ()
 Subclasses can override this to do any updates associated with their link data, for example dispatching HTML update jobs.
 
 getBatchSize ()
 Get the maximum number of rows to update in a batch.
 
 getDB ()
 
 getExistingFields ()
 Get the fields to be used in fetchExistingRows().
 
 getExistingLinkIDs ()
 Get an array (or iterator) of link IDs for the existing state.
 
 getFromConds ()
 Get field=>value associative array for the from field(s)
 
 getFromField ()
 Get the name of the field which links to page_id.
 
 getInsertOptions ()
 Get the options for the insert queries.
 
 getLBFactory ()
 
 getLinkIDs ( $setType)
 Get an array or iterator of link IDs of a given type.
 
 getMovedPage ()
 Assuming the page was moved, get the original page title before the move.
 
 getNewLinkIDs ()
 Get an array (or iterator) of link IDs for the new state.
 
 getReplicaDB ()
 
 getRevision ()
 Get the RevisionRecord of the new revision, if the LinksUpdate caller injected one.
 
 getSourcePage ()
 Get the source page, i.e.
 
 getSourcePageId ()
 Get the page_id of the source page.
 
 getTableName ()
 Get the table name.
 
 getTransactionTicket ()
 Get the empty transaction ticket, or null if there is none.
 
 insertLink ( $linkId)
 Insert a link identified by ID.
 
 insertRow ( $row)
 Queue a row for insertion.
 
 isCrossNamespaceMove ()
 Determine whether the page was moved to a different namespace.
 
 isExisting ( $linkId)
 Determine whether a link (from the new set) is in the existing set.
 
 isInNewSet ( $linkId)
 Determine whether a link (from the existing set) is in the new set.
 
 isMove ()
 Determine whether the page was moved.
 
 needForcedLinkRefresh ()
 Subclasses can override this to return true in order to force reinsertion of all the links due to some property of the link changing for reasons not represented by the link ID.
 
 startUpdate ()
 Subclasses can override this to do any necessary setup before individual write operations begin.
 
 virtualDomain ()
 What virtual domain should be used to read/write from the table.
 

Protected Attributes

array $deletedLinks = []
 Link IDs for deleted links.
 
array $insertedLinks = []
 Link IDs for inserted links.
 
LinkTargetLookup $linkTargetLookup
 
array $rowsToDelete = []
 Rows to delete.
 
array $rowsToInsert = []
 Rows to insert.
 
bool $strictTestMode
 

Detailed Description

The base class for classes which update a single link table.

A LinksTable object is a container for new and existing link sets outbound from a single page, and an abstraction of the associated DB schema. The object stores state related to an update of the outbound links of a page.

Explanation of link ID concept

Link IDs identify a link in the new or old state, or in the change arrays. They are opaque to the base class and are type-hinted here as mixed.

Conventionally, the link ID is string|string[] and contains the link target fields.

The link ID should contain enough information so that the base class can tell whether an existing link is in the new set, or vice versa, for the purposes of incremental updates. If a change to a field would cause a DB update, the field should be in the link ID.

For example, a change to cl_timestamp does not trigger an update, so cl_timestamp is not in the link ID.

Stability: stable
to extend
Since
1.38

Definition at line 43 of file LinksTable.php.

Member Function Documentation

◆ beforeLock()

MediaWiki\Deferred\LinksUpdate\LinksTable::beforeLock ( )

Subclasses can override this to do any necessary setup before the lock is acquired.

Stability: stable
to override

Definition at line 421 of file LinksTable.php.

◆ deleteLink()

MediaWiki\Deferred\LinksUpdate\LinksTable::deleteLink ( $linkId)
abstractprotected

◆ deleteRow()

MediaWiki\Deferred\LinksUpdate\LinksTable::deleteRow ( $conds)
protected

Queue a deletion operation.

Subclasses are expected to call this from deleteLink(). The "from" field does not need to be included in the conditions.

Most often, the conditions match a single row, but this is not required.

Parameters
array$condsAssociative array mapping fields to values, specifying the conditions for a delete query.

Definition at line 409 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\ExternalLinksTable\deleteLink(), MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable\deleteLink(), MediaWiki\Deferred\LinksUpdate\ImageLinksTable\deleteLink(), MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\deleteLink(), and MediaWiki\Deferred\LinksUpdate\LangLinksTable\deleteLink().

◆ doWrites()

MediaWiki\Deferred\LinksUpdate\LinksTable::doWrites ( )
protected

◆ fetchExistingRows()

MediaWiki\Deferred\LinksUpdate\LinksTable::fetchExistingRows ( )
protected

Do a select query to fetch the existing rows.

This is a helper for subclasses.

Reimplemented in MediaWiki\Deferred\LinksUpdate\TitleLinksTable.

Definition at line 356 of file LinksTable.php.

◆ finishUpdate()

MediaWiki\Deferred\LinksUpdate\LinksTable::finishUpdate ( )
protected

Subclasses can override this to do any updates associated with their link data, for example dispatching HTML update jobs.

Stability: stable
to override

Reimplemented in MediaWiki\Deferred\LinksUpdate\CategoryLinksTable, MediaWiki\Deferred\LinksUpdate\ImageLinksTable, and MediaWiki\Deferred\LinksUpdate\PagePropsTable.

Definition at line 439 of file LinksTable.php.

◆ getBatchSize()

MediaWiki\Deferred\LinksUpdate\LinksTable::getBatchSize ( )
protected

Get the maximum number of rows to update in a batch.

Definition at line 319 of file LinksTable.php.

◆ getDB()

MediaWiki\Deferred\LinksUpdate\LinksTable::getDB ( )
protected
Stability: stable
to override
Returns
IDatabase

Definition at line 262 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable\insertLink().

◆ getExistingFields()

MediaWiki\Deferred\LinksUpdate\LinksTable::getExistingFields ( )
abstractprotected

Get the fields to be used in fetchExistingRows().

Note that fetchExistingRows() is just a helper for subclasses. The value returned here is effectively private to the subclass.

Returns
array

Reimplemented in MediaWiki\Deferred\LinksUpdate\CategoryLinksTable, MediaWiki\Deferred\LinksUpdate\ExternalLinksTable, MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable, MediaWiki\Deferred\LinksUpdate\ImageLinksTable, MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable, MediaWiki\Deferred\LinksUpdate\LangLinksTable, and MediaWiki\Deferred\LinksUpdate\PagePropsTable.

◆ getExistingLinkIDs()

MediaWiki\Deferred\LinksUpdate\LinksTable::getExistingLinkIDs ( )
abstractprotected

Get an array (or iterator) of link IDs for the existing state.

The subclass should load the data from the database. There is fetchExistingRows() to make this easier but the subclass is responsible for caching.

See the LinksTable doc comment for an explanation of link IDs.

Returns
iterable<mixed>

Reimplemented in MediaWiki\Deferred\LinksUpdate\CategoryLinksTable, MediaWiki\Deferred\LinksUpdate\ExternalLinksTable, MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable, MediaWiki\Deferred\LinksUpdate\ImageLinksTable, MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable, MediaWiki\Deferred\LinksUpdate\LangLinksTable, and MediaWiki\Deferred\LinksUpdate\PagePropsTable.

◆ getFromConds()

MediaWiki\Deferred\LinksUpdate\LinksTable::getFromConds ( )
protected

Get field=>value associative array for the from field(s)

Stability: stable
to override
Returns
array

Definition at line 348 of file LinksTable.php.

◆ getFromField()

◆ getInsertOptions()

MediaWiki\Deferred\LinksUpdate\LinksTable::getInsertOptions ( )
protected

Get the options for the insert queries.

Returns
array

Definition at line 490 of file LinksTable.php.

◆ getLBFactory()

MediaWiki\Deferred\LinksUpdate\LinksTable::getLBFactory ( )
protected

Definition at line 270 of file LinksTable.php.

◆ getLinkIDs()

MediaWiki\Deferred\LinksUpdate\LinksTable::getLinkIDs ( $setType)
protected

Get an array or iterator of link IDs of a given type.

Some subclasses use this to provide typed data to callers. This is not public because link IDs are a private concept.

Parameters
int$setTypeOne of the class constants: self::INSERTED, self::DELETED, self::CHANGED, self::OLD or self::NEW.
Returns
iterable<mixed>

Definition at line 507 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\ExternalLinksTable\getStringArray().

◆ getMovedPage()

MediaWiki\Deferred\LinksUpdate\LinksTable::getMovedPage ( )
protected

Assuming the page was moved, get the original page title before the move.

This will throw an exception if the page wasn't moved.

Definition at line 312 of file LinksTable.php.

◆ getNewLinkIDs()

MediaWiki\Deferred\LinksUpdate\LinksTable::getNewLinkIDs ( )
abstractprotected

◆ getReplicaDB()

MediaWiki\Deferred\LinksUpdate\LinksTable::getReplicaDB ( )
protected

Definition at line 266 of file LinksTable.php.

◆ getRevision()

MediaWiki\Deferred\LinksUpdate\LinksTable::getRevision ( )
protected

Get the RevisionRecord of the new revision, if the LinksUpdate caller injected one.

Returns
RevisionRecord|null

Definition at line 338 of file LinksTable.php.

◆ getSourcePage()

MediaWiki\Deferred\LinksUpdate\LinksTable::getSourcePage ( )
protected

◆ getSourcePageId()

MediaWiki\Deferred\LinksUpdate\LinksTable::getSourcePageId ( )
protected

Get the page_id of the source page.

Definition at line 277 of file LinksTable.php.

◆ getTableName()

◆ getTransactionTicket()

MediaWiki\Deferred\LinksUpdate\LinksTable::getTransactionTicket ( )
protected

Get the empty transaction ticket, or null if there is none.

Returns
mixed

Definition at line 328 of file LinksTable.php.

◆ injectBaseDependencies()

MediaWiki\Deferred\LinksUpdate\LinksTable::injectBaseDependencies ( LBFactory $lbFactory,
LinkTargetLookup $linkTargetLookup,
PageIdentity $sourcePage,
$batchSize )
final

This is called by the factory to inject dependencies for the base class.

This is used instead of the constructor so that changes can be made to the injected parameters without breaking the subclass constructors.

Parameters
LBFactory$lbFactory
LinkTargetLookup$linkTargetLookup
PageIdentity$sourcePage
int$batchSize

Definition at line 124 of file LinksTable.php.

References MediaWiki\Deferred\LinksUpdate\LinksTable\$linkTargetLookup, Wikimedia\Rdbms\LBFactory\getPrimaryDatabase(), and MediaWiki\Deferred\LinksUpdate\LinksTable\virtualDomain().

◆ insertLink()

MediaWiki\Deferred\LinksUpdate\LinksTable::insertLink ( $linkId)
abstractprotected

◆ insertRow()

MediaWiki\Deferred\LinksUpdate\LinksTable::insertRow ( $row)
protected

Queue a row for insertion.

Subclasses are expected to call this from insertLink(). The "from" field should not be included in the row.

Parameters
array$rowAssociative array mapping fields to values.

Definition at line 394 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\ExternalLinksTable\insertLink(), MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable\insertLink(), MediaWiki\Deferred\LinksUpdate\ImageLinksTable\insertLink(), MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\insertLink(), and MediaWiki\Deferred\LinksUpdate\LangLinksTable\insertLink().

◆ isCrossNamespaceMove()

MediaWiki\Deferred\LinksUpdate\LinksTable::isCrossNamespaceMove ( )
protected

Determine whether the page was moved to a different namespace.

Returns
bool

Definition at line 303 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable\needForcedLinkRefresh(), and MediaWiki\Deferred\LinksUpdate\ImageLinksTable\needForcedLinkRefresh().

◆ isExisting()

◆ isInNewSet()

◆ isMove()

MediaWiki\Deferred\LinksUpdate\LinksTable::isMove ( )
protected

Determine whether the page was moved.

Returns
bool

Definition at line 294 of file LinksTable.php.

◆ needForcedLinkRefresh()

MediaWiki\Deferred\LinksUpdate\LinksTable::needForcedLinkRefresh ( )
protected

Subclasses can override this to return true in order to force reinsertion of all the links due to some property of the link changing for reasons not represented by the link ID.

Returns
bool

Reimplemented in MediaWiki\Deferred\LinksUpdate\CategoryLinksTable, MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable, and MediaWiki\Deferred\LinksUpdate\ImageLinksTable.

Definition at line 254 of file LinksTable.php.

◆ setMoveDetails()

MediaWiki\Deferred\LinksUpdate\LinksTable::setMoveDetails ( PageReference $movedPage)

Notify the object that the operation is a page move, and set the original title.

Definition at line 158 of file LinksTable.php.

◆ setParserOutput()

MediaWiki\Deferred\LinksUpdate\LinksTable::setParserOutput ( ParserOutput $parserOutput)
abstract

◆ setRevision()

MediaWiki\Deferred\LinksUpdate\LinksTable::setRevision ( RevisionRecord $revision)

Set the revision associated with the edit.

Definition at line 150 of file LinksTable.php.

◆ setStrictTestMode()

MediaWiki\Deferred\LinksUpdate\LinksTable::setStrictTestMode ( $mode = true)

Omit conflict resolution options from the insert query so that testing can confirm that the incremental update logic was correct.

Parameters
bool$mode

Definition at line 481 of file LinksTable.php.

◆ setTransactionTicket()

MediaWiki\Deferred\LinksUpdate\LinksTable::setTransactionTicket ( $ticket)

Set the empty transaction ticket.

Parameters
mixed$ticket

Definition at line 143 of file LinksTable.php.

◆ startUpdate()

MediaWiki\Deferred\LinksUpdate\LinksTable::startUpdate ( )
protected

Subclasses can override this to do any necessary setup before individual write operations begin.

Stability: stable
to override

Reimplemented in MediaWiki\Deferred\LinksUpdate\CategoryLinksTable.

Definition at line 430 of file LinksTable.php.

◆ update()

MediaWiki\Deferred\LinksUpdate\LinksTable::update ( )
final

Execute an edit/delete update.

Definition at line 368 of file LinksTable.php.

◆ virtualDomain()

Member Data Documentation

◆ $deletedLinks

array MediaWiki\Deferred\LinksUpdate\LinksTable::$deletedLinks = []
protected

Link IDs for deleted links.

Definition at line 82 of file LinksTable.php.

◆ $insertedLinks

array MediaWiki\Deferred\LinksUpdate\LinksTable::$insertedLinks = []
protected

Link IDs for inserted links.

Definition at line 79 of file LinksTable.php.

◆ $linkTargetLookup

LinkTargetLookup MediaWiki\Deferred\LinksUpdate\LinksTable::$linkTargetLookup
protected

◆ $rowsToDelete

array MediaWiki\Deferred\LinksUpdate\LinksTable::$rowsToDelete = []
protected

Rows to delete.

An array of associative arrays, each associative array being the conditions for a delete query. Common conditions should be leftmost in the associative array so that they can be factored out.

Definition at line 68 of file LinksTable.php.

◆ $rowsToInsert

array MediaWiki\Deferred\LinksUpdate\LinksTable::$rowsToInsert = []
protected

Rows to insert.

An array of associative arrays, each associative array mapping field names to values.

Definition at line 76 of file LinksTable.php.

◆ $strictTestMode

bool MediaWiki\Deferred\LinksUpdate\LinksTable::$strictTestMode
protected

Definition at line 112 of file LinksTable.php.

◆ CHANGED

const MediaWiki\Deferred\LinksUpdate\LinksTable::CHANGED = 3

Link type: Changed (inserted or removed) links.

Definition at line 51 of file LinksTable.php.

◆ DELETED

const MediaWiki\Deferred\LinksUpdate\LinksTable::DELETED = 2

Link type: Deleted (removed) links.

Definition at line 48 of file LinksTable.php.

◆ INSERTED

const MediaWiki\Deferred\LinksUpdate\LinksTable::INSERTED = 1

Link type: Inserted (added) links.

Definition at line 45 of file LinksTable.php.

◆ NEW

const MediaWiki\Deferred\LinksUpdate\LinksTable::NEW = 5

Link type: new links (from the ParserOutput)

Definition at line 57 of file LinksTable.php.

◆ OLD

const MediaWiki\Deferred\LinksUpdate\LinksTable::OLD = 4

Link type: existing/old links.

Definition at line 54 of file LinksTable.php.

◆ VIRTUAL_DOMAIN


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