22use Wikimedia\ScopedCallback;
51 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
53 'Cannot override ' . __CLASS__ .
'default instance in operation.'
57 self::$instance = $store;
58 return new ScopedCallback(
function () use ( $previousValue ) {
59 self::$instance = $previousValue;
67 if ( self::$instance ===
null ) {
68 self::$instance =
new self();
92 if ( $this->
cache->getSize() < $size ) {
93 $this->
cache->resize( $size );
116 if ( is_array( $propertyNames ) ) {
119 $propertyNames = [ $propertyNames ];
126 foreach ( $goodIDs as $pageID ) {
127 foreach ( $propertyNames as $propertyName ) {
129 if ( $propertyValue ===
false ) {
130 $queryIDs[] = $pageID;
134 $values[$pageID][$propertyName] = $propertyValue;
136 $values[$pageID] = $propertyValue;
144 $result =
$dbr->select(
152 'pp_page' => $queryIDs,
153 'pp_propname' => $propertyNames
158 foreach ( $result as $row ) {
159 $pageID = $row->pp_page;
160 $propertyName = $row->pp_propname;
161 $propertyValue = $row->pp_value;
162 $this->
cacheProperty( $pageID, $propertyName, $propertyValue );
164 $values[$pageID][$propertyName] = $propertyValue;
166 $values[$pageID] = $propertyValue;
191 foreach ( $goodIDs as $pageID ) {
193 if ( $pageProperties ===
false ) {
194 $queryIDs[] = $pageID;
196 $values[$pageID] = $pageProperties;
200 if ( $queryIDs != [] ) {
202 $result =
$dbr->select(
210 'pp_page' => $queryIDs,
216 $pageProperties = [];
217 foreach ( $result as $row ) {
218 $pageID = $row->pp_page;
219 if ( $currentPageID != $pageID ) {
220 if ( $pageProperties != [] ) {
222 $values[$currentPageID] = $pageProperties;
224 $currentPageID = $pageID;
225 $pageProperties = [];
227 $pageProperties[$row->pp_propname] = $row->pp_value;
229 if ( $pageProperties != [] ) {
231 $values[$pageID] = $pageProperties;
247 foreach (
$titles as $title ) {
248 $pageID = $title->getArticleID();
254 $pageID =
$titles->getArticleID();
270 if ( $this->
cache->has( $pageID, $propertyName, self::CACHE_TTL ) ) {
271 return $this->
cache->get( $pageID, $propertyName );
273 if ( $this->
cache->has( 0, $pageID, self::CACHE_TTL ) ) {
274 $pageProperties = $this->
cache->get( 0, $pageID );
275 if ( isset( $pageProperties[$propertyName] ) ) {
276 return $pageProperties[$propertyName];
289 if ( $this->
cache->has( 0, $pageID, self::CACHE_TTL ) ) {
290 return $this->
cache->get( 0, $pageID );
303 $this->
cache->set( $pageID, $propertyName, $propertyValue );
313 $this->
cache->clear( $pageID );
314 $this->
cache->set( 0, $pageID, $pageProperties );
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Gives access to properties of a page.
static overrideInstance(PageProps $store=null)
Overrides the default instance of this class This is intended for use while testing and will fail if ...
static PageProps $instance
ensureCacheSize( $size)
Ensure that cache has at least this size.
getCachedProperty( $pageID, $propertyName)
Get a property from the cache.
cacheProperty( $pageID, $propertyName, $propertyValue)
Save a property to the cache.
getProperties( $titles, $propertyNames)
Given one or more Titles and one or more names of properties, returns an associative array mapping pa...
const CACHE_TTL
Cache parameters.
getCachedProperties( $pageID)
Get properties from the cache.
__construct()
Create a PageProps object.
cacheProperties( $pageID, $pageProperties)
Save properties to the cache.
getAllProperties( $titles)
Get all page property values.
Handles per process caching of items.
namespace being checked & $result
linkcache txt 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 so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin 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 To create a you can use the following $titles
you have access to all of the normal MediaWiki so you can get a DB use the cache