Go to the documentation of this file.
107 if ( !self::$instance || !self::$instance->
title->equals(
$title ) ) {
108 self::$instance =
new self(
$title );
121 return [
'partitionCache',
'fullResultCache',
'title' ];
128 $this->partitionCache = [];
129 $this->fullResultCache = [];
148 if ( !isset( $this->db ) ) {
163 public function getLinks( $table, $startId =
false, $endId =
false, $max = INF ) {
176 protected function queryLinks( $table, $startId, $endId, $max, $select =
'all' ) {
177 $fromField = $this->
getPrefix( $table ) .
'_from';
179 if ( !$startId && !$endId && is_infinite( $max )
180 && isset( $this->fullResultCache[$table] )
182 wfDebug( __METHOD__ .
": got results from cache\n" );
183 $res = $this->fullResultCache[$table];
185 wfDebug( __METHOD__ .
": got results from DB\n" );
190 $conds[] =
"$fromField >= " . intval( $startId );
193 $conds[] =
"$fromField <= " . intval( $endId );
195 $options = [
'ORDER BY' => $fromField ];
196 if ( is_finite( $max ) && $max > 0 ) {
200 if ( $select ===
'ids' ) {
204 [ $this->
getPrefix( $table ) .
'_from AS page_id' ],
205 array_filter( $conds,
function ( $clause ) {
206 return !preg_match(
'/(\b|=)page_id(\b|=)/', $clause );
215 [
'page_namespace',
'page_title',
'page_id' ],
218 array_merge( [
'STRAIGHT_JOIN' ],
$options )
222 if ( $select ===
'all' && !$startId && !$endId &&
$res->numRows() < $max ) {
224 $this->fullResultCache[$table] =
$res;
226 wfDebug( __METHOD__ .
": results from DB were uncacheable\n" );
242 'imagelinks' =>
'il',
243 'categorylinks' =>
'cl',
244 'templatelinks' =>
'tl',
248 if ( isset( $prefixes[$table] ) ) {
249 return $prefixes[$table];
252 Hooks::run(
'BacklinkCacheGetPrefix', [ $table, &$prefix ] );
256 throw new MWException(
"Invalid table \"$table\" in " . __CLASS__ );
273 case 'templatelinks':
275 "{$prefix}_namespace" => $this->
title->getNamespace(),
276 "{$prefix}_title" => $this->
title->getDBkey(),
277 "page_id={$prefix}_from"
282 "{$prefix}_namespace" => $this->
title->getNamespace(),
283 "{$prefix}_title" => $this->
title->getDBkey(),
284 $this->
getDB()->makeList( [
285 "{$prefix}_interwiki" =>
'',
286 "{$prefix}_interwiki IS NULL",
288 "page_id={$prefix}_from"
292 case 'categorylinks':
294 "{$prefix}_to" => $this->
title->getDBkey(),
295 "page_id={$prefix}_from"
300 Hooks::run(
'BacklinkCacheGetConditions', [ $table, $this->
title, &$conds ] );
302 throw new MWException(
"Invalid table \"$table\" in " . __CLASS__ );
329 if ( isset( $this->partitionCache[$table] ) ) {
330 $entry = reset( $this->partitionCache[$table] );
332 return min( $max, $entry[
'numRows'] );
336 if ( isset( $this->fullResultCache[$table] ) ) {
337 return min( $max, $this->fullResultCache[$table]->numRows() );
340 $memcKey =
$cache->makeKey(
342 md5( $this->
title->getPrefixedDBkey() ),
347 $count =
$cache->get( $memcKey );
349 return min( $max, $count );
353 if ( is_infinite( $max ) ) {
360 $count = $this->
getLinks( $table,
false,
false, $max )->count();
361 if ( $count < $max ) {
362 $cache->set( $memcKey, $count, self::CACHE_EXPIRY );
366 return min( $max, $count );
380 if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
381 wfDebug( __METHOD__ .
": got from partition cache\n" );
383 return $this->partitionCache[$table][$batchSize][
'batches'];
387 $this->partitionCache[$table][$batchSize] =
false;
388 $cacheEntry =& $this->partitionCache[$table][$batchSize];
391 if ( isset( $this->fullResultCache[$table] ) ) {
392 $cacheEntry = $this->
partitionResult( $this->fullResultCache[$table], $batchSize );
393 wfDebug( __METHOD__ .
": got from full result cache\n" );
395 return $cacheEntry[
'batches'];
398 $memcKey =
$cache->makeKey(
400 md5( $this->
title->getPrefixedDBkey() ),
406 $memcValue =
$cache->get( $memcKey );
407 if ( is_array( $memcValue ) ) {
408 $cacheEntry = $memcValue;
409 wfDebug( __METHOD__ .
": got from memcached $memcKey\n" );
411 return $cacheEntry[
'batches'];
415 $cacheEntry = [
'numRows' => 0,
'batches' => [] ];
418 $selectSize = max( $batchSize, 200000 - ( 200000 % $batchSize ) );
421 $res = $this->
queryLinks( $table, $start,
false, $selectSize,
'ids' );
424 $cacheEntry[
'numRows'] += $partitions[
'numRows'];
425 $cacheEntry[
'batches'] = array_merge( $cacheEntry[
'batches'], $partitions[
'batches'] );
426 if (
count( $partitions[
'batches'] ) ) {
427 list( , $lEnd ) = end( $partitions[
'batches'] );
430 }
while ( $partitions[
'numRows'] >= $selectSize );
432 if (
count( $cacheEntry[
'batches'] ) ) {
433 $cacheEntry[
'batches'][0][0] =
false;
434 $cacheEntry[
'batches'][
count( $cacheEntry[
'batches'] ) - 1][1] =
false;
438 $cache->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
441 $memcKey =
$cache->makeKey(
443 md5( $this->
title->getPrefixedDBkey() ),
446 $cache->set( $memcKey, $cacheEntry[
'numRows'], self::CACHE_EXPIRY );
448 wfDebug( __METHOD__ .
": got from database\n" );
450 return $cacheEntry[
'batches'];
463 $numRows =
$res->numRows();
464 $numBatches = ceil( $numRows / $batchSize );
466 for ( $i = 0; $i < $numBatches; $i++ ) {
467 if ( $i == 0 && $isComplete ) {
470 $rowNum = $i * $batchSize;
471 $res->seek( $rowNum );
472 $row =
$res->fetchObject();
473 $start = (int)$row->page_id;
476 if ( $i == ( $numBatches - 1 ) && $isComplete ) {
479 $rowNum = min( $numRows - 1, ( $i + 1 ) * $batchSize - 1 );
480 $res->seek( $rowNum );
481 $row =
$res->fetchObject();
482 $end = (int)$row->page_id;
486 if ( $start && $end && $start > $end ) {
487 throw new MWException( __METHOD__ .
': Internal error: query result out of order' );
490 $batches[] = [ $start, $end ];
493 return [
'numRows' => $numRows,
'batches' => $batches ];
507 $resSets[] =
$dbr->select(
508 [
'templatelinks',
'page_restrictions',
'page' ],
509 [
'page_namespace',
'page_title',
'page_id' ],
511 'tl_namespace' => $this->
title->getNamespace(),
512 'tl_title' => $this->
title->getDBkey(),
521 $resSets[] =
$dbr->select(
522 [
'imagelinks',
'page_restrictions',
'page' ],
523 [
'page_namespace',
'page_title',
'page_id' ],
525 'il_to' => $this->
title->getDBkey(),
537 foreach ( $resSets
as $res ) {
538 foreach (
$res as $row ) {
539 $mergedRes[$row->page_id] = $row;
getPrefix( $table)
Get the field name prefix for a given table.
static newFromResult( $res)
ResultWrapper[] $fullResultCache
Contains the whole links from a database result.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
getDB()
Get the replica DB connection to the database When non existing, will initialize the connection.
Class for fetching backlink lists, approximate backlink counts and partitions.
$title
Local copy of a Title object.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getNumLinks( $table, $max=INF)
Get the approximate number of backlinks.
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
partition( $table, $batchSize)
Partition the backlinks into batches.
queryLinks( $table, $startId, $endId, $max, $select='all')
Get the backlinks for a given table.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
__sleep()
Serialization handler, diasallows to serialize the database to prevent failures after this class is d...
partitionResult( $res, $batchSize, $isComplete=true)
Partition a DB result with backlinks in it into batches.
when a variable name is used in a it is silently declared as a new masking the global
$wgUpdateRowsPerJob
Number of rows to update per job.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
clear()
Clear locally stored data and database object.
$db
Local copy of a database object.
__construct(Title $title)
Create a new BacklinkCache.
hasLinks( $table)
Check if there are any backlinks.
getCascadeProtectedLinks()
Get a Title iterator for cascade-protected template/file use backlinks.
Represents a title within MediaWiki.
array[] $partitionCache
Multi dimensions array representing batches.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
static getMainWANInstance()
Get the main WAN cache object.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
setDB( $db)
Set the Database object to use.
getConditions( $table)
Get the SQL condition array for selecting backlinks, with a join on the page table.
static BacklinkCache $instance
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
the array() calling protocol came about after MediaWiki 1.4rc1.
getLinks( $table, $startId=false, $endId=false, $max=INF)
Get the backlinks for a given table.