MediaWiki master
CacheKeyHelper.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Page;
8
9use LogicException;
11use Wikimedia\Parsoid\Core\LinkTarget;
12
32abstract class CacheKeyHelper {
33
37 private function __construct() {
38 throw new LogicException( 'May not be instantiated' );
39 }
40
56 public static function getKeyForPage( $page ): string {
57 $prefix = 'ns' . $page->getNamespace();
58
59 if ( $page instanceof WikiAwareEntity && $page->getWikiId() !== WikiAwareEntity::LOCAL ) {
60 $prefix .= '@id@' . $page->getWikiId();
61 } elseif ( $page instanceof LinkTarget && $page->getInterwiki() !== '' ) {
62 $prefix .= '@iw@' . $page->getInterwiki();
63 }
64
65 return $prefix . ':' . $page->getDBkey();
66 }
67}
68
70class_alias( CacheKeyHelper::class, 'MediaWiki\Cache\CacheKeyHelper' );
Helper class for mapping page value objects to a string key.
static getKeyForPage( $page)
Returns a stable key for identifying the given page in a cache.
Marker interface for entities aware of the wiki they belong to.
getWikiId()
Get the ID of the wiki this page belongs to.
Represents the target of a wiki link.
getInterwiki()
The interwiki component of this LinkTarget.