MediaWiki  master
PageProps Class Reference

Gives access to properties of a page. More...

Collaboration diagram for PageProps:

Public Member Functions

 __construct (LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer)
 
 ensureCacheSize ( $size)
 Ensure that cache has at least this size. More...
 
 getAllProperties ( $titles)
 Get all page property values. More...
 
 getProperties ( $titles, $propertyNames)
 Given one or more Titles and one or more names of properties, returns an associative array mapping page ID to property value. More...
 

Static Public Member Functions

static getInstance ()
 
static overrideInstance (PageProps $store)
 Overrides the default instance of this class This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined. More...
 

Private Member Functions

 cacheProperties ( $pageID, $pageProperties)
 Save properties to the cache. More...
 
 cacheProperty ( $pageID, $propertyName, $propertyValue)
 Save a property to the cache. More...
 
 getCachedProperties ( $pageID)
 Get properties from the cache. More...
 
 getCachedProperty ( $pageID, $propertyName)
 Get a property from the cache. More...
 
 getGoodIDs ( $titles)
 

Private Attributes

MapCacheLRU $cache = null
 
LinkBatchFactory $linkBatchFactory
 
ILoadBalancer $loadBalancer
 
const CACHE_SIZE = 100
 
const CACHE_TTL = 10
 Cache parameters. More...
 

Detailed Description

Gives access to properties of a page.

Since
1.27

Definition at line 33 of file PageProps.php.

Constructor & Destructor Documentation

◆ __construct()

PageProps::__construct ( LinkBatchFactory  $linkBatchFactory,
ILoadBalancer  $loadBalancer 
)
Parameters
LinkBatchFactory$linkBatchFactory
ILoadBalancer$loadBalancer

Definition at line 90 of file PageProps.php.

References $linkBatchFactory, and $loadBalancer.

Member Function Documentation

◆ cacheProperties()

PageProps::cacheProperties (   $pageID,
  $pageProperties 
)
private

Save properties to the cache.

Parameters
int$pageIDpage ID of page being cached
string[]$pagePropertiesassociative array of page properties to be cached

Definition at line 323 of file PageProps.php.

Referenced by getAllProperties().

◆ cacheProperty()

PageProps::cacheProperty (   $pageID,
  $propertyName,
  $propertyValue 
)
private

Save a property to the cache.

Parameters
int$pageIDpage ID of page being cached
string$propertyNamename of property being cached
mixed$propertyValuevalue of property

Definition at line 313 of file PageProps.php.

Referenced by getProperties().

◆ ensureCacheSize()

PageProps::ensureCacheSize (   $size)

Ensure that cache has at least this size.

Parameters
int$size

Definition at line 103 of file PageProps.php.

◆ getAllProperties()

PageProps::getAllProperties (   $titles)

Get all page property values.

Given one or more Titles, returns an associative array mapping page ID to an associative array mapping property names to property values. Pages in the provided set of Titles that do not have any properties will not appear in the returned array. If a single Title is provided, it does not need to be passed in an array, but an array will always be returned. An empty array will be returned if no matching properties were found.

Parameters
Title[] | TitleArray | Title$titles
Returns
array associative array mapping page ID to property value array

Definition at line 197 of file PageProps.php.

References $dbr, cacheProperties(), DB_REPLICA, getCachedProperties(), and getGoodIDs().

◆ getCachedProperties()

PageProps::getCachedProperties (   $pageID)
private

Get properties from the cache.

Parameters
int$pageIDpage ID of page being queried
Returns
string|bool property value array or false if not found

Definition at line 299 of file PageProps.php.

Referenced by getAllProperties().

◆ getCachedProperty()

PageProps::getCachedProperty (   $pageID,
  $propertyName 
)
private

Get a property from the cache.

Parameters
int$pageIDpage ID of page being queried
string$propertyNamename of property being queried
Returns
string|bool property value array or false if not found

Definition at line 280 of file PageProps.php.

Referenced by getProperties().

◆ getGoodIDs()

PageProps::getGoodIDs (   $titles)
private
Parameters
Title[] | TitleArray | Title$titles
Returns
array array of good page IDs

Definition at line 253 of file PageProps.php.

References $title.

Referenced by getAllProperties(), and getProperties().

◆ getInstance()

◆ getProperties()

PageProps::getProperties (   $titles,
  $propertyNames 
)

Given one or more Titles and one or more names of properties, returns an associative array mapping page ID to property value.

Pages in the provided set of Titles that do not have a value for the given properties will not appear in the returned array. If a single Title is provided, it does not need to be passed in an array, but an array will always be returned. If a single property name is provided, it does not need to be passed in an array. In that case, an associative array mapping page ID to property value will be returned; otherwise, an associative array mapping page ID to an associative array mapping property name to property value will be returned. An empty array will be returned if no matching properties were found.

Parameters
Title[] | TitleArray | Title$titles
string[] | string$propertyNames
Returns
array associative array mapping page ID to property value

Definition at line 127 of file PageProps.php.

References $dbr, cacheProperty(), DB_REPLICA, getCachedProperty(), and getGoodIDs().

◆ overrideInstance()

static PageProps::overrideInstance ( PageProps  $store)
static

Overrides the default instance of this class This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.

Since
1.27
Deprecated:
since 1.36
Parameters
PageProps$store
Returns
ScopedCallback to reset the overridden value
Exceptions
MWException

Definition at line 60 of file PageProps.php.

Member Data Documentation

◆ $cache

MapCacheLRU PageProps::$cache = null
private

Definition at line 46 of file PageProps.php.

◆ $linkBatchFactory

LinkBatchFactory PageProps::$linkBatchFactory
private

Definition at line 36 of file PageProps.php.

Referenced by __construct().

◆ $loadBalancer

ILoadBalancer PageProps::$loadBalancer
private

Definition at line 39 of file PageProps.php.

Referenced by __construct().

◆ CACHE_SIZE

const PageProps::CACHE_SIZE = 100
private

Definition at line 43 of file PageProps.php.

◆ CACHE_TTL

const PageProps::CACHE_TTL = 10
private

Cache parameters.

Definition at line 42 of file PageProps.php.


The documentation for this class was generated from the following file: