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.
 

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.
 
 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.
 
 linksTargetNormalizationStage ()
 Normalization stage of the links table (see T222224)
 
 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.
 

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 42 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 429 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 417 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\CategoryLinksTable\deleteLink(), MediaWiki\Deferred\LinksUpdate\ExternalLinksTable\deleteLink(), MediaWiki\Deferred\LinksUpdate\ImageLinksTable\deleteLink(), MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable\deleteLink(), MediaWiki\Deferred\LinksUpdate\LangLinksTable\deleteLink(), and MediaWiki\Deferred\LinksUpdate\PagePropsTable\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.

Returns
IResultWrapper

Reimplemented in MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable.

Definition at line 364 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 447 of file LinksTable.php.

◆ getBatchSize()

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

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

Returns
int

Definition at line 325 of file LinksTable.php.

◆ getDB()

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

Definition at line 261 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\CategoryLinksTable\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 354 of file LinksTable.php.

◆ getFromField()

◆ getInsertOptions()

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

Get the options for the insert queries.

Returns
array

Definition at line 499 of file LinksTable.php.

◆ getLBFactory()

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

Definition at line 268 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 516 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\PagePropsTable\getAssocArray(), and 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.

Returns
PageReference

Definition at line 316 of file LinksTable.php.

◆ getNewLinkIDs()

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

◆ 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 344 of file LinksTable.php.

◆ getSourcePage()

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

Get the source page, i.e.

the page which is being updated and is the source of links.

Returns
PageIdentity

Definition at line 287 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\ImageLinksTable\insertLink(), MediaWiki\Deferred\LinksUpdate\CategoryLinksTable\setParserOutput(), and MediaWiki\Deferred\LinksUpdate\CategoryLinksTable\startUpdate().

◆ getSourcePageId()

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

Get the page_id of the source page.

Returns
int

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 334 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 118 of file LinksTable.php.

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

◆ 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 402 of file LinksTable.php.

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

◆ isCrossNamespaceMove()

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

Determine whether the page was moved to a different namespace.

Returns
bool

Definition at line 305 of file LinksTable.php.

Referenced by 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 296 of file LinksTable.php.

Referenced by MediaWiki\Deferred\LinksUpdate\CategoryLinksTable\needForcedLinkRefresh().

◆ linksTargetNormalizationStage()

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

Normalization stage of the links table (see T222224)

Returns
int

Reimplemented in MediaWiki\Deferred\LinksUpdate\PageLinksTable, and MediaWiki\Deferred\LinksUpdate\TemplateLinksTable.

Definition at line 542 of file LinksTable.php.

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

◆ 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 253 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.

Parameters
PageReference$movedPage

Definition at line 155 of file LinksTable.php.

◆ setParserOutput()

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

Subclasses should implement this to extract the data they need from the ParserOutput.

To support a future refactor of LinksDeletionUpdate, if this method is not called, the subclass should assume that the new state is empty.

Parameters
ParserOutput$parserOutput

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

◆ setRevision()

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

Set the revision associated with the edit.

Parameters
RevisionRecord$revision

Definition at line 145 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 490 of file LinksTable.php.

◆ setTransactionTicket()

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

Set the empty transaction ticket.

Parameters
mixed$ticket

Definition at line 136 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 438 of file LinksTable.php.

◆ update()

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

Execute an edit/delete update.

Definition at line 376 of file LinksTable.php.

Member Data Documentation

◆ $deletedLinks

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

Link IDs for deleted links.

Definition at line 79 of file LinksTable.php.

◆ $insertedLinks

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

Link IDs for inserted links.

Definition at line 76 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 65 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 73 of file LinksTable.php.

◆ $strictTestMode

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

Definition at line 106 of file LinksTable.php.

◆ CHANGED

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

Link type: Changed (inserted or removed) links.

Definition at line 50 of file LinksTable.php.

◆ DELETED

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

Link type: Deleted (removed) links.

Definition at line 47 of file LinksTable.php.

◆ INSERTED

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

Link type: Inserted (added) links.

Definition at line 44 of file LinksTable.php.

◆ NEW

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

Link type: new links (from the ParserOutput)

Definition at line 56 of file LinksTable.php.

◆ OLD

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

Link type: existing/old links.

Definition at line 53 of file LinksTable.php.


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