MediaWiki  1.33.1
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 ()
 
 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...
 

Static Public Member Functions

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

Public Attributes

 $mFiles = null
 
 $mSubcats = null
 
const LAZY_INIT_ROW = 1
 
const LOAD_ONLY = 0
 

Protected Member Functions

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

Private Member Functions

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

Private Attributes

 $mID = null
 
 $mName = null
 Name of the category, normalized to DB-key form. More...
 
 $mPages = null
 Counts of membership (cat_pages, cat_subcats, cat_files) More...
 
Title $mTitle = null
 Category page title. More...
 

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.

Todo:
Move some stuff from CategoryPage.php to here, and use that.

Definition at line 31 of file Category.php.

Constructor & Destructor Documentation

◆ __construct()

Category::__construct ( )
private

Definition at line 46 of file Category.php.

Member Function Documentation

◆ getFileCount()

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

Definition at line 244 of file Category.php.

References getX().

◆ getID()

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

Definition at line 223 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 271 of file Category.php.

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

◆ getName()

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

Definition at line 216 of file Category.php.

References getX().

Referenced by getMembers(), and refreshCountsIfEmpty().

◆ getPageCount()

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

Definition at line 230 of file Category.php.

References getX().

◆ getSubcatCount()

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

Definition at line 237 of file Category.php.

References getX().

◆ getTitle()

Category::getTitle ( )
Returns
Title|bool Title for this category, or false on failure.

Definition at line 251 of file Category.php.

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

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

◆ getX()

Category::getX (   $key)
private

Generic accessor.

Parameters
string$key
Returns
mixed

Definition at line 304 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 55 of file Category.php.

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

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

◆ newFromID()

static Category::newFromID (   $id)
static

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

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

Referenced by LinksDeletionUpdate\doIncrementalUpdate(), PopulateCategory\execute(), MediaWiki\Search\ParserOutputSearchDataExtractor\getCategories(), CategoryTest\testNewFromName_invalidTitle(), CategoryTest\testNewFromName_validTitle(), and WikiPage\updateCategoryCounts().

◆ newFromRow()

static Category::newFromRow (   $row,
  $title = null 
)
static

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

Parameters
object$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 title object was given. If the fields are null and no title was given, this method fails and returns false.
Title | null$titleOptional title object for the category represented by the given row. May be provided if it is already known, to avoid having to re-create a title object later.
Returns
Category|false

Definition at line 179 of file Category.php.

References $title.

Referenced by CategoryViewer\doCategoryQuery(), CategoryTreeHooks\onSpecialTrackingCategoriesPreprocess(), CategoryTree\renderChildren(), CategoryTest\testNewFromRow_found(), CategoryTest\testNewFromRow_notFoundWithoutTitle(), and CategoryTest\testNewFromRow_notFoundWithTitle().

◆ newFromTitle()

static Category::newFromTitle (   $title)
static

◆ refreshCounts()

Category::refreshCounts ( )

Refresh the counts for this category.

Returns
bool True on success, false on failure

Definition at line 316 of file Category.php.

References $name, DB_MASTER, getTitle(), initialize(), NS_CATEGORY, NS_FILE, wfGetDB(), and wfReadOnly().

Referenced by refreshCountsIfEmpty().

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

References DB_MASTER, getName(), refreshCounts(), and wfGetDB().

Member Data Documentation

◆ $mFiles

Category::$mFiles = null

Definition at line 41 of file Category.php.

◆ $mID

Category::$mID = null
private

Definition at line 34 of file Category.php.

Referenced by initialize().

◆ $mName

Category::$mName = null
private

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

Definition at line 33 of file Category.php.

Referenced by initialize().

◆ $mPages

Category::$mPages = null
private

Counts of membership (cat_pages, cat_subcats, cat_files)

Definition at line 41 of file Category.php.

◆ $mSubcats

Category::$mSubcats = null

Definition at line 41 of file Category.php.

◆ $mTitle

Title Category::$mTitle = null
private

Category page title.

Definition at line 39 of file Category.php.

Referenced by getTitle().

◆ LAZY_INIT_ROW

const Category::LAZY_INIT_ROW = 1

Definition at line 44 of file Category.php.

◆ LOAD_ONLY

const Category::LOAD_ONLY = 0

Definition at line 43 of file Category.php.


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