MediaWiki  master
Category Class Reference

Category objects are immutable, strictly speaking. More...

Collaboration diagram for Category:

Public Member Functions

 getFileCount ()
 
 getID ()
 
 getMembers ( $limit=false, $offset='')
 Fetch a TitleArray of up to $limit category members, beginning after the category sort key $offset. More...
 
 getName ()
 
 getPage ()
 
 getPageCount ()
 
 getSubcatCount ()
 
 getTitle ()
 
 refreshCounts ()
 Refresh the counts for this category. More...
 
 refreshCountsIfEmpty ()
 Call refreshCounts() if there are no entries in the categorylinks table or if the category table has a row that states that there are no entries. More...
 
 refreshCountsIfSmall ( $maxSize=self::ROW_COUNT_SMALL)
 Call refreshCounts() if there are few entries in the categorylinks table. More...
 

Static Public Member Functions

static newFromID ( $id)
 Factory function. More...
 
static newFromName ( $name)
 Factory function. More...
 
static newFromRow (stdClass $row, ?PageIdentity $page=null)
 Factory function, for constructing a Category object from a result set. More...
 
static newFromTitle (PageIdentity $page)
 Factory function. More...
 

Public Attributes

 $mFiles = null
 
 $mSubcats = null
 
const ROW_COUNT_SMALL = 100
 

Protected Member Functions

 initialize ( $mode=self::LOAD_ONLY)
 Set up all member variables using a database query. More...
 

Protected Attributes

const LAZY_INIT_ROW = 1
 
const LOAD_ONLY = 0
 

Private Member Functions

 __construct ()
 
 getX ( $key)
 Generic accessor. More...
 

Private Attributes

ILoadBalancer $loadBalancer
 
 $mID = null
 
 $mName = null
 Name of the category, normalized to DB-key form. More...
 
PageIdentity $mPage = null
 Category page title. More...
 
 $mPages = null
 Counts of membership (cat_pages, cat_subcats, cat_files) More...
 
ReadOnlyMode $readOnlyMode
 

Detailed Description

Category objects are immutable, strictly speaking.

If you call methods that change the database, like to refresh link counts, the objects will be appropriately reinitialized. Member variables are lazy-initialized.

Definition at line 33 of file Category.php.

Constructor & Destructor Documentation

◆ __construct()

Category::__construct ( )
private

Definition at line 56 of file Category.php.

Member Function Documentation

◆ getFileCount()

Category::getFileCount ( )
Returns
mixed Number of member files, or false on failure

Definition at line 255 of file Category.php.

References getX().

◆ getID()

Category::getID ( )
Returns
mixed Category ID, or false on failure

Definition at line 234 of file Category.php.

References getX().

◆ getMembers()

Category::getMembers (   $limit = false,
  $offset = '' 
)

Fetch a TitleArray of up to $limit category members, beginning after the category sort key $offset.

Parameters
int | bool$limit
string$offset
Returns
TitleArray TitleArray object for category members.

Definition at line 292 of file Category.php.

References $dbr, DB_REPLICA, getName(), and TitleArray\newFromResult().

◆ getName()

Category::getName ( )
Returns
mixed DB key name, or false on failure

Definition at line 227 of file Category.php.

References getX().

Referenced by getMembers(), and refreshCountsIfSmall().

◆ getPage()

Category::getPage ( )
Since
1.37
Returns
?PageIdentity the page associated with this category, or null on failure. NOTE: This returns null on failure, unlike getTitle() which returns false.

Definition at line 264 of file Category.php.

References $mPage, initialize(), Title\makeTitleSafe(), and NS_CATEGORY.

Referenced by CategoryViewer\addSubcategoryObject(), getTitle(), and refreshCounts().

◆ getPageCount()

Category::getPageCount ( )
Returns
mixed Total number of member pages, or false on failure

Definition at line 241 of file Category.php.

References getX().

◆ getSubcatCount()

Category::getSubcatCount ( )
Returns
mixed Number of subcategories, or false on failure

Definition at line 248 of file Category.php.

References getX().

◆ getTitle()

Category::getTitle ( )
Deprecated:
since 1.37, use getPage() instead.
Returns
Title|bool Title for this category, or false on failure.

Definition at line 281 of file Category.php.

References Title\castFromPageIdentity(), and getPage().

◆ getX()

Category::getX (   $key)
private

Generic accessor.

Parameters
string$key
Returns
mixed

Definition at line 325 of file Category.php.

References initialize().

Referenced by getFileCount(), getID(), getName(), getPageCount(), and getSubcatCount().

◆ initialize()

Category::initialize (   $mode = self::LOAD_ONLY)
protected

Set up all member variables using a database query.

Parameters
int$modeOne of (Category::LOAD_ONLY, Category::LAZY_INIT_ROW)
Exceptions
MWException
Returns
bool True on success, false on failure.

Definition at line 68 of file Category.php.

References $dbr, $mID, $mName, DeferredUpdates\addCallableUpdate(), and DB_REPLICA.

Referenced by getPage(), getX(), and refreshCounts().

◆ newFromID()

static Category::newFromID (   $id)
static

Factory function.

Parameters
int$idA category id. Warning, no validation is performed!
Returns
Category

Definition at line 174 of file Category.php.

◆ newFromName()

static Category::newFromName (   $name)
static

Factory function.

Parameters
string$nameA category name (no "Category:" prefix). It need not be normalized, with spaces replaced by underscores.
Returns
Category|bool Category, or false on a totally invalid name

Definition at line 139 of file Category.php.

References $title, Title\makeTitleSafe(), and NS_CATEGORY.

Referenced by LinksDeletionUpdate\doIncrementalUpdate(), MediaWiki\Search\ParserOutputSearchDataExtractor\getCategories(), and WikiPage\updateCategoryCounts().

◆ newFromRow()

static Category::newFromRow ( stdClass  $row,
?PageIdentity  $page = null 
)
static

Factory function, for constructing a Category object from a result set.

Parameters
stdClass$rowResult set row, must contain the cat_xxx fields. If the fields are null, the resulting Category object will represent an empty category if a page object was given. If the fields are null and no PageIdentity was given, this method fails and returns false.
PageIdentity | null$pageThis must be provided if there is no cat_title field in $row.
Returns
Category|false

Definition at line 190 of file Category.php.

Referenced by CategoryViewer\doCategoryQuery().

◆ newFromTitle()

static Category::newFromTitle ( PageIdentity  $page)
static

◆ refreshCounts()

Category::refreshCounts ( )

Refresh the counts for this category.

Returns
bool True on success, false on failure

Definition at line 337 of file Category.php.

References DB_PRIMARY, getPage(), initialize(), NS_CATEGORY, and NS_FILE.

Referenced by refreshCountsIfSmall().

◆ refreshCountsIfEmpty()

Category::refreshCountsIfEmpty ( )

Call refreshCounts() if there are no entries in the categorylinks table or if the category table has a row that states that there are no entries.

Due to lock errors or other failures, the precomputed counts can get out of sync, making it hard to know when to delete the category row without checking the categorylinks table.

Returns
bool Whether links were refreshed
Since
1.32

Definition at line 456 of file Category.php.

References refreshCountsIfSmall().

◆ refreshCountsIfSmall()

Category::refreshCountsIfSmall (   $maxSize = self::ROW_COUNT_SMALL)

Call refreshCounts() if there are few entries in the categorylinks table.

Due to lock errors or other failures, the precomputed counts can get out of sync, making it hard to know when to delete the category row without checking the categorylinks table.

This method will do a non-locking select first to reduce contention.

Parameters
int$maxSizeOnly refresh if there are this or less many backlinks
Returns
bool Whether links were refreshed
Since
1.34

Definition at line 473 of file Category.php.

References DB_PRIMARY, getName(), and refreshCounts().

Referenced by refreshCountsIfEmpty().

Member Data Documentation

◆ $loadBalancer

ILoadBalancer Category::$loadBalancer
private

Definition at line 51 of file Category.php.

◆ $mFiles

Category::$mFiles = null

Definition at line 43 of file Category.php.

◆ $mID

Category::$mID = null
private

Definition at line 36 of file Category.php.

Referenced by initialize().

◆ $mName

Category::$mName = null
private

Name of the category, normalized to DB-key form.

Definition at line 35 of file Category.php.

Referenced by initialize().

◆ $mPage

PageIdentity Category::$mPage = null
private

Category page title.

Definition at line 41 of file Category.php.

Referenced by getPage().

◆ $mPages

Category::$mPages = null
private

Counts of membership (cat_pages, cat_subcats, cat_files)

Definition at line 43 of file Category.php.

◆ $mSubcats

Category::$mSubcats = null

Definition at line 43 of file Category.php.

◆ $readOnlyMode

ReadOnlyMode Category::$readOnlyMode
private

Definition at line 54 of file Category.php.

◆ LAZY_INIT_ROW

const Category::LAZY_INIT_ROW = 1
protected

Definition at line 46 of file Category.php.

◆ LOAD_ONLY

const Category::LOAD_ONLY = 0
protected

Definition at line 45 of file Category.php.

◆ ROW_COUNT_SMALL

const Category::ROW_COUNT_SMALL = 100

Definition at line 48 of file Category.php.


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