22 use 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->getMaxSize() < $size ) {
93 $this->cache->setMaxSize( $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;
132 } elseif ( $gotArray ) {
133 $values[$pageID][$propertyName] = $propertyValue;
135 $values[$pageID] = $propertyValue;
142 $result =
$dbr->select(
150 'pp_page' => $queryIDs,
151 'pp_propname' => $propertyNames
156 foreach ( $result as $row ) {
157 $pageID = $row->pp_page;
158 $propertyName = $row->pp_propname;
159 $propertyValue = $row->pp_value;
160 $this->
cacheProperty( $pageID, $propertyName, $propertyValue );
162 $values[$pageID][$propertyName] = $propertyValue;
164 $values[$pageID] = $propertyValue;
189 foreach ( $goodIDs as $pageID ) {
191 if ( $pageProperties ===
false ) {
192 $queryIDs[] = $pageID;
194 $values[$pageID] = $pageProperties;
198 if ( $queryIDs != [] ) {
200 $result =
$dbr->select(
208 'pp_page' => $queryIDs,
214 $pageProperties = [];
215 foreach ( $result as $row ) {
216 $pageID = $row->pp_page;
217 if ( $currentPageID != $pageID ) {
218 if ( $pageProperties != [] ) {
220 $values[$currentPageID] = $pageProperties;
222 $currentPageID = $pageID;
223 $pageProperties = [];
225 $pageProperties[$row->pp_propname] = $row->pp_value;
227 if ( $pageProperties != [] ) {
229 $values[$pageID] = $pageProperties;
242 if ( is_array( $titles ) ) {
245 foreach ( $titles as
$title ) {
246 $pageID =
$title->getArticleID();
252 $pageID = $titles->getArticleID();
268 if ( $this->cache->hasField( $pageID, $propertyName, self::CACHE_TTL ) ) {
269 return $this->cache->getField( $pageID, $propertyName );
271 if ( $this->cache->hasField( 0, $pageID, self::CACHE_TTL ) ) {
272 $pageProperties = $this->cache->getField( 0, $pageID );
273 if ( isset( $pageProperties[$propertyName] ) ) {
274 return $pageProperties[$propertyName];
287 if ( $this->cache->hasField( 0, $pageID, self::CACHE_TTL ) ) {
288 return $this->cache->getField( 0, $pageID );
301 $this->cache->setField( $pageID, $propertyName, $propertyValue );
311 $this->cache->clear( $pageID );
312 $this->cache->setField( 0, $pageID, $pageProperties );