2024-03-09 22:04:05 +00:00
|
|
|
LinkCache {#linkcache}
|
|
|
|
|
========
|
|
|
|
|
|
2008-03-13 19:00:19 +00:00
|
|
|
The LinkCache class maintains a list of article titles and the information about
|
|
|
|
|
whether or not the article exists in the database. This is used to mark up links
|
|
|
|
|
when displaying a page. If the same link appears more than once on any page,
|
|
|
|
|
then it only has to be looked up once. In most cases, link lookups are done in
|
|
|
|
|
batches with the LinkBatch class, or the equivalent in Parser::replaceLinkHolders(),
|
|
|
|
|
so the link cache is mostly useful for short snippets of parsed text (such as
|
|
|
|
|
the site notice), and for links in the navigation areas of the skin.
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2008-03-13 19:00:19 +00:00
|
|
|
The link cache was formerly used to track links used in a document for the
|
|
|
|
|
purposes of updating the link tables. This application is now deprecated.
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2008-03-13 19:00:19 +00:00
|
|
|
To create a batch, you can use the following code:
|
|
|
|
|
|
2024-03-09 22:04:05 +00:00
|
|
|
```php
|
2008-03-13 19:00:19 +00:00
|
|
|
$pages = [ 'Main Page', 'Project:Help', /* ... */ ];
|
|
|
|
|
$titles = [];
|
|
|
|
|
|
|
|
|
|
foreach( $pages as $page ){
|
|
|
|
|
$titles[] = Title::newFromText( $page );
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 11:08:40 +00:00
|
|
|
$linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
|
|
|
|
|
$batch = $linkBatchFactory->newLinkBatch( $titles );
|
2015-06-23 03:31:22 +00:00
|
|
|
$batch->execute();
|
2024-03-09 22:04:05 +00:00
|
|
|
```
|