Go to the documentation of this file.
107 $dbKey =
$title->getPrefixedDBkey();
123 return array(
'partitionCache',
'fullResultCache',
'title' );
130 $this->partitionCache =
array();
131 $this->fullResultCache =
array();
150 if ( !isset( $this->db ) ) {
165 public function getLinks( $table, $startId =
false, $endId =
false, $max = INF ) {
178 protected function queryLinks( $table, $startId, $endId, $max, $select =
'all' ) {
181 $fromField = $this->
getPrefix( $table ) .
'_from';
183 if ( !$startId && !$endId && is_infinite( $max )
184 && isset( $this->fullResultCache[$table] )
186 wfDebug( __METHOD__ .
": got results from cache\n" );
187 $res = $this->fullResultCache[$table];
189 wfDebug( __METHOD__ .
": got results from DB\n" );
194 $conds[] =
"$fromField >= " . intval( $startId );
197 $conds[] =
"$fromField <= " . intval( $endId );
200 if ( is_finite( $max ) && $max > 0 ) {
204 if ( $select ===
'ids' ) {
209 array_filter( $conds,
function ( $clause ) {
210 return !preg_match(
'/(\b|=)page_id(\b|=)/', $clause );
218 array( $table,
'page' ),
219 array(
'page_namespace',
'page_title',
'page_id' ),
226 if ( $select ===
'all' && !$startId && !$endId &&
$res->numRows() < $max ) {
228 $this->fullResultCache[$table] =
$res;
230 wfDebug( __METHOD__ .
": results from DB were uncacheable\n" );
246 static $prefixes =
array(
248 'imagelinks' =>
'il',
249 'categorylinks' =>
'cl',
250 'templatelinks' =>
'tl',
254 if ( isset( $prefixes[$table] ) ) {
255 return $prefixes[$table];
262 throw new MWException(
"Invalid table \"$table\" in " . __CLASS__ );
279 case 'templatelinks':
281 "{$prefix}_namespace" => $this->
title->getNamespace(),
282 "{$prefix}_title" => $this->
title->getDBkey(),
283 "page_id={$prefix}_from"
288 "{$prefix}_namespace" => $this->
title->getNamespace(),
289 "{$prefix}_title" => $this->
title->getDBkey(),
290 $this->getDb()->makeList(
array(
291 "{$prefix}_interwiki" =>
'',
292 "{$prefix}_interwiki IS NULL",
294 "page_id={$prefix}_from"
298 case 'categorylinks':
300 "{$prefix}_to" => $this->
title->getDBkey(),
301 "page_id={$prefix}_from"
308 throw new MWException(
"Invalid table \"$table\" in " . __CLASS__ );
334 if ( isset( $this->partitionCache[$table] ) ) {
335 $entry = reset( $this->partitionCache[$table] );
337 return min( $max, $entry[
'numRows'] );
341 if ( isset( $this->fullResultCache[$table] ) ) {
342 return min( $max, $this->fullResultCache[$table]->numRows() );
345 $memcKey =
wfMemcKey(
'numbacklinks', md5( $this->
title->getPrefixedDBkey() ), $table );
350 return min( $max,
$count );
354 if ( is_infinite( $max ) ) {
357 $this->
partition( $table, $wgUpdateRowsPerJob );
358 return $this->partitionCache[$table][$wgUpdateRowsPerJob][
'numRows'];
367 return min( $max,
$count );
383 if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
384 wfDebug( __METHOD__ .
": got from partition cache\n" );
386 return $this->partitionCache[$table][$batchSize][
'batches'];
389 $this->partitionCache[$table][$batchSize] =
false;
390 $cacheEntry =& $this->partitionCache[$table][$batchSize];
393 if ( isset( $this->fullResultCache[$table] ) ) {
394 $cacheEntry = $this->
partitionResult( $this->fullResultCache[$table], $batchSize );
395 wfDebug( __METHOD__ .
": got from full result cache\n" );
397 return $cacheEntry[
'batches'];
402 md5( $this->
title->getPrefixedDBkey() ),
408 $memcValue =
$wgMemc->get( $memcKey );
409 if ( is_array( $memcValue ) ) {
410 $cacheEntry = $memcValue;
411 wfDebug( __METHOD__ .
": got from memcached $memcKey\n" );
413 return $cacheEntry[
'batches'];
417 $cacheEntry =
array(
'numRows' => 0,
'batches' =>
array() );
420 $selectSize = max( $batchSize, 200000 - ( 200000 % $batchSize ) );
423 $res = $this->
queryLinks( $table, $start,
false, $selectSize,
'ids' );
426 $cacheEntry[
'numRows'] += $partitions[
'numRows'];
427 $cacheEntry[
'batches'] = array_merge( $cacheEntry[
'batches'], $partitions[
'batches'] );
428 if ( count( $partitions[
'batches'] ) ) {
429 list( , $lEnd ) = end( $partitions[
'batches'] );
432 }
while ( $partitions[
'numRows'] >= $selectSize );
434 if ( count( $cacheEntry[
'batches'] ) ) {
435 $cacheEntry[
'batches'][0][0] =
false;
436 $cacheEntry[
'batches'][count( $cacheEntry[
'batches'] ) - 1][1] =
false;
440 $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
443 $memcKey =
wfMemcKey(
'numbacklinks', md5( $this->
title->getPrefixedDBkey() ), $table );
444 $wgMemc->set( $memcKey, $cacheEntry[
'numRows'], self::CACHE_EXPIRY );
446 wfDebug( __METHOD__ .
": got from database\n" );
448 return $cacheEntry[
'batches'];
461 $numRows =
$res->numRows();
462 $numBatches = ceil( $numRows / $batchSize );
464 for ( $i = 0; $i < $numBatches; $i++ ) {
465 if ( $i == 0 && $isComplete ) {
468 $rowNum = $i * $batchSize;
469 $res->seek( $rowNum );
470 $row =
$res->fetchObject();
471 $start = (int)$row->page_id;
474 if ( $i == ( $numBatches - 1 ) && $isComplete ) {
477 $rowNum = min( $numRows - 1, ( $i + 1 ) * $batchSize - 1 );
478 $res->seek( $rowNum );
479 $row =
$res->fetchObject();
480 $end = (int)$row->page_id;
484 if ( $start && $end && $start > $end ) {
485 throw new MWException( __METHOD__ .
': Internal error: query result out of order' );
488 $batches[] =
array( $start, $end );
491 return array(
'numRows' => $numRows,
'batches' => $batches );
getPrefix( $table)
Get the field name prefix for a given table.
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
static newFromResult( $res)
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
wfProfileIn( $functionname)
Begin profiling of a function.
getDB()
Get the slave 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.
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
wfMemcKey()
Get a cache key.
partition( $table, $batchSize)
Partition the backlinks into batches.
queryLinks( $table, $startId, $endId, $max, $select='all')
Get the backlinks for a given table.
__sleep()
Serialization handler, diasallows to serialize the database to prevent failures after this class is d...
wfProfileOut( $functionname='missing')
Stop profiling of a function.
partitionResult( $res, $batchSize, $isComplete=true)
Partition a DB result with backlinks in it into batches.
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
$partitionCache
Multi dimensions array representing batches.
$fullResultCache
Contains the whole links from a database result.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
when a variable name is used in a it is silently declared as a new masking the global
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.
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
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
$db
Local copy of a database object.
__construct(Title $title)
Create a new BacklinkCache.
hasLinks( $table)
Check if there are any backlinks.
Represents a title within MediaWiki.
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.
Handles per process caching of items.
getLinks( $table, $startId=false, $endId=false, $max=INF)
Get the backlinks for a given table.