MediaWiki master
MediaWiki\Category\Category Class Reference

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

Public Member Functions

 getFileCount ()
 
 getID ()
 
 getMemberCount ()
 
 getMembers ( $limit=false, $offset='')
 Fetch a TitleArray of up to $limit category members, beginning after the category sort key $offset.
 
 getName ()
 
 getPage ()
 
 getPageCount ( $type=self::COUNT_ALL_MEMBERS)
 
 getSubcatCount ()
 
 getTitle ()
 
 refreshCounts ()
 Refresh the counts for this 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.
 
 refreshCountsIfSmall ( $maxSize=self::ROW_COUNT_SMALL)
 Call refreshCounts() if there are few entries in the categorylinks table.
 

Static Public Member Functions

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

Public Attributes

const COUNT_ALL_MEMBERS = 0
 
const COUNT_CONTENT_PAGES = 1
 
const ROW_COUNT_SMALL = 100
 

Protected Member Functions

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

Protected Attributes

const LAZY_INIT_ROW = 1
 
const LOAD_ONLY = 0
 

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 42 of file Category.php.

Member Function Documentation

◆ getFileCount()

MediaWiki\Category\Category::getFileCount ( )
Returns
int Number of member files

Definition at line 292 of file Category.php.

◆ getID()

MediaWiki\Category\Category::getID ( )
Returns
string|false Category ID, or false on failure

Definition at line 255 of file Category.php.

◆ getMemberCount()

MediaWiki\Category\Category::getMemberCount ( )
Returns
int Total number of members count (sum of subcats, files and pages)

Definition at line 262 of file Category.php.

◆ getMembers()

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

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

Parameters
int | false$limit
string$offset
Returns
TitleArrayFromResult Title objects for category members.

Definition at line 329 of file Category.php.

◆ getName()

MediaWiki\Category\Category::getName ( )
Returns
string|false DB key name, or false on failure

Definition at line 248 of file Category.php.

◆ getPage()

MediaWiki\Category\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 301 of file Category.php.

Referenced by MediaWiki\Category\CategoryViewer\addSubcategoryObject().

◆ getPageCount()

MediaWiki\Category\Category::getPageCount ( $type = self::COUNT_ALL_MEMBERS)
Parameters
int$typeOne of self::COUNT_ALL_MEMBERS and self::COUNT_CONTENT_PAGES
Returns
int Total number of member count or content page count

Definition at line 272 of file Category.php.

◆ getSubcatCount()

MediaWiki\Category\Category::getSubcatCount ( )
Returns
int Number of subcategories

Definition at line 285 of file Category.php.

◆ getTitle()

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

Definition at line 318 of file Category.php.

◆ initialize()

MediaWiki\Category\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)
Returns
bool True on success, false on failure.

Definition at line 91 of file Category.php.

◆ newFromID()

static MediaWiki\Category\Category::newFromID ( $id)
static

Factory function.

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

Definition at line 195 of file Category.php.

◆ newFromName()

static MediaWiki\Category\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 160 of file Category.php.

References NS_CATEGORY.

◆ newFromRow()

static MediaWiki\Category\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 211 of file Category.php.

References MediaWiki\Page\PageReference\getDBkey().

◆ newFromTitle()

static MediaWiki\Category\Category::newFromTitle ( PageIdentity $page)
static

Factory function.

Parameters
PageIdentity$pageCategory page. Warning, no validation is performed!
Returns
Category

Definition at line 180 of file Category.php.

Referenced by MediaWiki\Category\CategoryViewer\__construct().

◆ refreshCounts()

MediaWiki\Category\Category::refreshCounts ( )

Refresh the counts for this category.

Returns
bool True on success, false on failure

Definition at line 368 of file Category.php.

References NS_CATEGORY, and NS_FILE.

◆ refreshCountsIfEmpty()

MediaWiki\Category\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 502 of file Category.php.

◆ refreshCountsIfSmall()

MediaWiki\Category\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 519 of file Category.php.

Member Data Documentation

◆ COUNT_ALL_MEMBERS

const MediaWiki\Category\Category::COUNT_ALL_MEMBERS = 0

Definition at line 67 of file Category.php.

◆ COUNT_CONTENT_PAGES

const MediaWiki\Category\Category::COUNT_CONTENT_PAGES = 1

Definition at line 68 of file Category.php.

◆ LAZY_INIT_ROW

const MediaWiki\Category\Category::LAZY_INIT_ROW = 1
protected

Definition at line 63 of file Category.php.

◆ LOAD_ONLY

const MediaWiki\Category\Category::LOAD_ONLY = 0
protected

Definition at line 62 of file Category.php.

◆ ROW_COUNT_SMALL

const MediaWiki\Category\Category::ROW_COUNT_SMALL = 100

Definition at line 65 of file Category.php.


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