| 1 | LinkCache {#linkcache} |
| 2 | ======== |
| 3 | |
| 4 | The LinkCache class maintains a list of article titles and the information about |
| 5 | whether or not the article exists in the database. This is used to mark up links |
| 6 | when displaying a page. If the same link appears more than once on any page, |
| 7 | then it only has to be looked up once. In most cases, link lookups are done in |
| 8 | batches with the LinkBatch class, or the equivalent in Parser::replaceLinkHolders(), |
| 9 | so the link cache is mostly useful for short snippets of parsed text (such as |
| 10 | the site notice), and for links in the navigation areas of the skin. |
| 11 | |
| 12 | The link cache was formerly used to track links used in a document for the |
| 13 | purposes of updating the link tables. This application is now deprecated. |
| 14 | |
| 15 | To create a batch, you can use the following code: |
| 16 | |
| 17 | ```php |
| 18 | $pages = [ 'Main Page', 'Project:Help', /* ... */ ]; |
| 19 | $titles = []; |
| 20 | |
| 21 | foreach( $pages as $page ){ |
| 22 | $titles[] = Title::newFromText( $page ); |
| 23 | } |
| 24 | |
| 25 | $linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory(); |
| 26 | $batch = $linkBatchFactory->newLinkBatch( $titles ); |
| 27 | $batch->execute(); |
| 28 | ``` |