MediaWiki REL1_31
CategoryFinder Class Reference

The "CategoryFinder" class takes a list of articles, creates an internal representation of all their parent categories (as well as parents of parents etc.). More...

Collaboration diagram for CategoryFinder:

Public Member Functions

 getParents ()
 Get the parents.
 
 run ()
 Iterates through the parent tree starting with the seed values, then checks the articles if they match the conditions.
 
 seed ( $articleIds, $categories, $mode='AND', $maxdepth=-1)
 Initializes the instance.
 

Protected Attributes

int[] $articles = []
 The original article IDs passed to the seed function.
 
IDatabase $dbr
 Read-DB replica DB.
 
array $deadend = []
 Array of DBKEY category names for categories that don't have a page.
 
int $maxdepth = -1
 Max layer depth.
 
string $mode
 "AND" or "OR"
 
array $name2id = []
 
array $next = []
 Array of article/category IDs.
 
array $parents = []
 Array of [ ID => [] ].
 
array $targets = []
 Array of DBKEY category names.
 

Private Member Functions

 check ( $id, &$conds, $path=[])
 This functions recurses through the parent representation, trying to match the conditions.
 
 scanNextLayer ()
 Scans a "parent layer" of the articles/categories in $this->next.
 

Detailed Description

The "CategoryFinder" class takes a list of articles, creates an internal representation of all their parent categories (as well as parents of parents etc.).

From this representation, it determines which of these articles are in one or all of a given subset of categories.

Example use :

# Determines whether the article with the page_id 12345 is in both
# "Category 1" and "Category 2" or their subcategories, respectively
$cf = new CategoryFinder;
$cf->seed(
[ 12345 ],
[ 'Category 1', 'Category 2' ],
'AND'
);
$a = $cf->run();
print implode( ',' , $a );
The "CategoryFinder" class takes a list of articles, creates an internal representation of all their ...
seed( $articleIds, $categories, $mode='AND', $maxdepth=-1)
Initializes the instance.
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
Deprecated
since 1.31

Definition at line 48 of file CategoryFinder.php.

Member Function Documentation

◆ check()

CategoryFinder::check ( $id,
& $conds,
$path = [] )
private

This functions recurses through the parent representation, trying to match the conditions.

Parameters
int$idThe article/category to check
array$condsThe array of categories to match
array$pathUsed to check for recursion loops
Returns
bool Does this match the conditions?

Definition at line 152 of file CategoryFinder.php.

References check.

◆ getParents()

CategoryFinder::getParents ( )

Get the parents.

Only really useful if run() has been called already

Returns
array

Definition at line 141 of file CategoryFinder.php.

References $parents.

◆ run()

CategoryFinder::run ( )

Iterates through the parent tree starting with the seed values, then checks the articles if they match the conditions.

Returns
array Array of page_ids (those given to seed() that match the conditions)

Definition at line 109 of file CategoryFinder.php.

References $article, $maxdepth, $ret, $targets, check, DB_REPLICA, scanNextLayer(), and wfGetDB().

◆ scanNextLayer()

CategoryFinder::scanNextLayer ( )
private

Scans a "parent layer" of the articles/categories in $this->next.

Definition at line 207 of file CategoryFinder.php.

References $name, $res, and NS_CATEGORY.

Referenced by run().

◆ seed()

CategoryFinder::seed ( $articleIds,
$categories,
$mode = 'AND',
$maxdepth = -1 )

Initializes the instance.

Do this prior to calling run().

Parameters
array$articleIdsArray of article IDs
array$categoriesFIXME
string$modeFIXME, default 'AND'.
int$maxdepthMaximum layer depth. Where: -1 means deep recursion (default); 0 means no-parents; 1 means one parent layer, etc.
Todo
FIXME: $categories/$mode

Definition at line 87 of file CategoryFinder.php.

References $maxdepth, $mode, and NS_CATEGORY.

Referenced by SpecialRecentChanges\filterByCategories().

Member Data Documentation

◆ $articles

int [] CategoryFinder::$articles = []
protected

The original article IDs passed to the seed function.

Definition at line 50 of file CategoryFinder.php.

◆ $dbr

IDatabase CategoryFinder::$dbr
protected

Read-DB replica DB.

Definition at line 74 of file CategoryFinder.php.

◆ $deadend

array CategoryFinder::$deadend = []
protected

Array of DBKEY category names for categories that don't have a page.

Definition at line 53 of file CategoryFinder.php.

◆ $maxdepth

int CategoryFinder::$maxdepth = -1
protected

Max layer depth.

Definition at line 62 of file CategoryFinder.php.

Referenced by run(), and seed().

◆ $mode

string CategoryFinder::$mode
protected

"AND" or "OR"

Definition at line 71 of file CategoryFinder.php.

Referenced by seed().

◆ $name2id

array CategoryFinder::$name2id = []
protected

Definition at line 68 of file CategoryFinder.php.

◆ $next

array CategoryFinder::$next = []
protected

Array of article/category IDs.

Definition at line 59 of file CategoryFinder.php.

◆ $parents

array CategoryFinder::$parents = []
protected

Array of [ ID => [] ].

Definition at line 56 of file CategoryFinder.php.

Referenced by getParents().

◆ $targets

array CategoryFinder::$targets = []
protected

Array of DBKEY category names.

Definition at line 65 of file CategoryFinder.php.

Referenced by run().


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