MediaWiki  master
MediaWiki\Deferred\LinksUpdate\LinksTable Class Reference

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

Inheritance diagram for MediaWiki\Deferred\LinksUpdate\LinksTable:
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. More...
 
 injectBaseDependencies (LBFactory $lbFactory, LinkTargetLookup $linkTargetLookup, PageIdentity $sourcePage, $batchSize, $afterUpdateHook)
 This is called by the factory to inject dependencies for the base class. More...
 
 setMoveDetails (PageReference $movedPage)
 Notify the object that the operation is a page move, and set the original title. More...
 
 setParserOutput (ParserOutput $parserOutput)
 Subclasses should implement this to extract the data they need from the ParserOutput. More...
 
 setRevision (RevisionRecord $revision)
 Set the revision associated with the edit. More...
 
 setStrictTestMode ( $mode=true)
 Omit conflict resolution options from the insert query so that testing can confirm that the incremental update logic was correct. More...
 
 setTransactionTicket ( $ticket)
 Set the empty transaction ticket. More...
 
 update ()
 Execute an edit/delete update. More...
 

Public Attributes

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

Protected Member Functions

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

Protected Attributes

array $deletedLinks = []
 Link IDs for deleted links. More...
 
array $insertedLinks = []
 Link IDs for inserted links. More...
 
LinkTargetLookup $linkTargetLookup
 
array $rowsToDelete = []
 Rows to delete. More...
 
array $rowsToInsert = []
 Rows to insert. More...
 
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 41 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 434 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 422 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 369 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\PagePropsTable, MediaWiki\Deferred\LinksUpdate\ImageLinksTable, and MediaWiki\Deferred\LinksUpdate\CategoryLinksTable.

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

◆ getDB()

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

Definition at line 266 of file LinksTable.php.

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

◆ getExistingFields()

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

◆ 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\PagePropsTable, MediaWiki\Deferred\LinksUpdate\LangLinksTable, MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable, MediaWiki\Deferred\LinksUpdate\ImageLinksTable, MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable, MediaWiki\Deferred\LinksUpdate\ExternalLinksTable, and MediaWiki\Deferred\LinksUpdate\CategoryLinksTable.

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

◆ getFromField()

◆ getInsertOptions()

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

Get the options for the insert queries.

Returns
array

Definition at line 505 of file LinksTable.php.

◆ getLBFactory()

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

Definition at line 273 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 522 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 321 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 349 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 292 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 282 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 339 of file LinksTable.php.

◆ injectBaseDependencies()

MediaWiki\Deferred\LinksUpdate\LinksTable::injectBaseDependencies ( LBFactory  $lbFactory,
LinkTargetLookup  $linkTargetLookup,
PageIdentity  $sourcePage,
  $batchSize,
  $afterUpdateHook 
)
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
callable | null$afterUpdateHook

Definition at line 121 of file LinksTable.php.

References MediaWiki\Deferred\LinksUpdate\LinksTable\$linkTargetLookup, DB_PRIMARY, and Wikimedia\Rdbms\ILBFactory\getMainLB().

◆ insertLink()

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

◆ insertRow()

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

◆ isCrossNamespaceMove()

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

Determine whether the page was moved to a different namespace.

Returns
bool

Definition at line 310 of file LinksTable.php.

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

◆ isExisting()

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

◆ isInNewSet()

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

◆ isMove()

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

Determine whether the page was moved.

Returns
bool

Definition at line 301 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\TemplateLinksTable.

Definition at line 548 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\ImageLinksTable, MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable, and MediaWiki\Deferred\LinksUpdate\CategoryLinksTable.

Definition at line 258 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 160 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.

Parameters
RevisionRecord$revision

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

◆ setTransactionTicket()

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

Set the empty transaction ticket.

Parameters
mixed$ticket

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

◆ update()

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

Execute an edit/delete update.

Definition at line 381 of file LinksTable.php.

Member Data Documentation

◆ $deletedLinks

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

Link IDs for deleted links.

Definition at line 78 of file LinksTable.php.

◆ $insertedLinks

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

Link IDs for inserted links.

Definition at line 75 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 64 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 72 of file LinksTable.php.

◆ $strictTestMode

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

Definition at line 108 of file LinksTable.php.

◆ CHANGED

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

Link type: Changed (inserted or removed) links.

Definition at line 49 of file LinksTable.php.

◆ DELETED

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

Link type: Deleted (removed) links.

Definition at line 46 of file LinksTable.php.

◆ INSERTED

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

Link type: Inserted (added) links.

Definition at line 43 of file LinksTable.php.

◆ NEW

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

Link type: new links (from the ParserOutput)

Definition at line 55 of file LinksTable.php.

◆ OLD

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

Link type: existing/old links.

Definition at line 52 of file LinksTable.php.


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