MediaWiki REL1_40
BacklinkCache Class Reference

Class for fetching backlink lists, approximate backlink counts and partitions. More...

Collaboration diagram for BacklinkCache:

Public Member Functions

 __construct (WANObjectCache $wanCache, HookContainer $hookContainer, PageReference $page)
 Create a new BacklinkCache.
 
 getCascadeProtectedLinkPages ()
 Get a PageIdentity iterator for cascade-protected template/file use backlinks.
 
 getCascadeProtectedLinks ()
 Get a Title iterator for cascade-protected template/file use backlinks.
 
 getLinkPages (string $table, $startId=false, $endId=false, $max=INF)
 Get the backlinks for a given table.
 
 getLinks ( $table, $startId=false, $endId=false, $max=INF)
 Get the backlinks for a given table.
 
 getNumLinks ( $table, $max=INF)
 Get the approximate number of backlinks.
 
 getPage ()
 
 hasLinks ( $table)
 Check if there are any backlinks.
 
 partition ( $table, $batchSize)
 Partition the backlinks into batches.
 

Static Public Member Functions

static get (PageReference $page)
 Create a new BacklinkCache or reuse any existing one.
 

Protected Member Functions

 getDB ()
 Get the replica DB connection to the database.
 
 getPrefix ( $table)
 Get the field name prefix for a given table.
 
 partitionResult ( $res, $batchSize, $isComplete=true)
 Partition a DB result with backlinks in it into batches.
 
 queryLinks ( $table, $startId, $endId, $max, $select='all')
 Get the backlinks for a given table.
 

Protected Attributes

IResultWrapper[] $fullResultCache = []
 Contains the whole links from a database result.
 
PageReference $page
 Local copy of a PageReference object.
 
array[] $partitionCache = []
 Multi dimensions array representing batches.
 
WANObjectCache $wanCache
 

Detailed Description

Class for fetching backlink lists, approximate backlink counts and partitions.

This is a shared cache.

Instances of this class should typically be fetched with the method ::getBacklinkCache() from the BacklinkCacheFactory service.

Ideally you should only get your backlinks from here when you think there is some advantage in caching them. Otherwise, it's just a waste of memory.

Introduced by r47317

Definition at line 58 of file BacklinkCache.php.

Constructor & Destructor Documentation

◆ __construct()

BacklinkCache::__construct ( WANObjectCache $wanCache,
HookContainer $hookContainer,
PageReference $page )

Create a new BacklinkCache.

Parameters
WANObjectCache$wanCache
HookContainer$hookContainer
PageReference$pagePage to create a backlink cache for

Definition at line 103 of file BacklinkCache.php.

Member Function Documentation

◆ get()

static BacklinkCache::get ( PageReference $page)
static

Create a new BacklinkCache or reuse any existing one.

Currently, only one cache instance can exist; callers that need multiple backlink cache objects should keep them in scope.

Deprecated
since 1.37 Use BacklinkCacheFactory::getBacklinkCache() instead. Hard deprecated in 1.40.
Parameters
PageReference$pagePage to get a backlink cache for
Returns
BacklinkCache

Definition at line 123 of file BacklinkCache.php.

◆ getCascadeProtectedLinkPages()

BacklinkCache::getCascadeProtectedLinkPages ( )

Get a PageIdentity iterator for cascade-protected template/file use backlinks.

Returns
Iterator<PageIdentity>
Since
1.37

Definition at line 527 of file BacklinkCache.php.

◆ getCascadeProtectedLinks()

BacklinkCache::getCascadeProtectedLinks ( )

Get a Title iterator for cascade-protected template/file use backlinks.

Deprecated
since 1.37, use getCascadeProtectedLinkPages(). Hard deprecated in 1.40.
Returns
TitleArray
Since
1.25

Definition at line 541 of file BacklinkCache.php.

References wfDeprecated().

◆ getDB()

BacklinkCache::getDB ( )
protected

Get the replica DB connection to the database.

Returns
IDatabase

Definition at line 143 of file BacklinkCache.php.

References DB_REPLICA, and wfGetDB().

◆ getLinkPages()

BacklinkCache::getLinkPages ( string $table,
$startId = false,
$endId = false,
$max = INF )

Get the backlinks for a given table.

Cached in process memory only.

Parameters
string$table
int | bool$startId
int | bool$endId
int | float$maxInteger, or INF for no max
Returns
Iterator<PageIdentity>
Since
1.37

Definition at line 156 of file BacklinkCache.php.

◆ getLinks()

BacklinkCache::getLinks ( $table,
$startId = false,
$endId = false,
$max = INF )

Get the backlinks for a given table.

Cached in process memory only.

Deprecated
in 1.37, use getLinkPages(). Hard deprecated in 1.40.
Parameters
string$table
int | bool$startId
int | bool$endId
int | float$maxInteger, or INF for no max
Returns
TitleArrayFromResult

Definition at line 175 of file BacklinkCache.php.

References wfDeprecated().

◆ getNumLinks()

BacklinkCache::getNumLinks ( $table,
$max = INF )

Get the approximate number of backlinks.

Parameters
string$table
int | float$maxOnly count up to this many backlinks, or INF for no max
Returns
int

Definition at line 366 of file BacklinkCache.php.

References Wikimedia\Rdbms\Database\getCacheSetOptions(), and getDB().

◆ getPage()

BacklinkCache::getPage ( )
Since
1.37
Returns
PageReference

Definition at line 134 of file BacklinkCache.php.

◆ getPrefix()

BacklinkCache::getPrefix ( $table)
protected

Get the field name prefix for a given table.

Parameters
string$table
Exceptions
MWException
Returns
null|string

Definition at line 235 of file BacklinkCache.php.

◆ hasLinks()

BacklinkCache::hasLinks ( $table)

Check if there are any backlinks.

Parameters
string$table
Returns
bool

Definition at line 356 of file BacklinkCache.php.

◆ partition()

BacklinkCache::partition ( $table,
$batchSize )

Partition the backlinks into batches.

Returns an array giving the start and end of each range. The first batch has a start of false, and the last batch has an end of false.

Parameters
string$tableThe links table name
int$batchSize
Returns
array

Definition at line 420 of file BacklinkCache.php.

References $res, Wikimedia\Rdbms\Database\getCacheSetOptions(), getDB(), and wfDebug().

◆ partitionResult()

BacklinkCache::partitionResult ( $res,
$batchSize,
$isComplete = true )
protected

Partition a DB result with backlinks in it into batches.

Parameters
IResultWrapper$resDatabase result
int$batchSize
bool$isCompleteWhether $res includes all the backlinks
Exceptions
MWException
Returns
array

Definition at line 486 of file BacklinkCache.php.

References $res.

◆ queryLinks()

BacklinkCache::queryLinks ( $table,
$startId,
$endId,
$max,
$select = 'all' )
protected

Get the backlinks for a given table.

Cached in process memory only.

Parameters
string$table
int | bool$startId
int | bool$endId
int$max
string$select'all' or 'ids'
Returns
IResultWrapper

Definition at line 189 of file BacklinkCache.php.

References $res, getDB(), and wfDebug().

Member Data Documentation

◆ $fullResultCache

IResultWrapper [] BacklinkCache::$fullResultCache = []
protected

Contains the whole links from a database result.

This is raw data that will be partitioned in $partitionCache

Initialized with BacklinkCache::queryLinks()

Definition at line 80 of file BacklinkCache.php.

◆ $page

PageReference BacklinkCache::$page
protected

Local copy of a PageReference object.

Definition at line 92 of file BacklinkCache.php.

◆ $partitionCache

array [] BacklinkCache::$partitionCache = []
protected

Multi dimensions array representing batches.

Keys are:

‍(string) links table name (int) batch size 'numRows' : Number of rows for this link table 'batches' : [ $start, $end ]

See also
BacklinkCache::partitionResult()

Definition at line 70 of file BacklinkCache.php.

◆ $wanCache

WANObjectCache BacklinkCache::$wanCache
protected

Definition at line 83 of file BacklinkCache.php.


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