92 $this->articles = $articleIds;
93 $this->next = $articleIds;
97 # Set the list of target categories; convert them to DBKEY form first
99 foreach ( $categories as $c ) {
102 $c = $ct->getDBkey();
103 $this->targets[$c] = $c;
118 while ( count( $this->next ) && $dig ) {
122 if ( $this->maxdepth !== -1 ) {
128 # Now check if this applies to the individual articles
131 foreach ( $this->articles as $article ) {
133 if ( $this->
check( $article, $conds ) ) {
134 # Matches the conditions
158 if ( in_array( $id,
$path ) ) {
164 # Shortcut (runtime paranoia): No conditions=all matched
165 if ( count( $conds ) == 0 ) {
169 if ( !isset( $this->parents[$id] ) ) {
173 # iterate through the parents
174 foreach ( $this->parents[$id] as $p ) {
177 # Is this a condition?
178 if ( isset( $conds[$pname] ) ) {
179 # This key is in the category list!
180 if ( $this->mode ==
'OR' ) {
181 # One found, that's enough!
185 # Assuming "AND" as default
186 unset( $conds[$pname] );
187 if ( count( $conds ) == 0 ) {
188 # All conditions met, done
194 # Not done yet, try sub-parents
195 if ( !isset( $this->name2id[$pname] ) ) {
199 $done = $this->
check( $this->name2id[$pname], $conds,
$path );
200 if ( $done || count( $conds ) == 0 ) {
201 # Subparents have done it!
212 # Find all parents of the article currently in $this->next
214 $res = $this->dbr->select(
216 [
'cl_to',
'cl_from' ],
217 [
'cl_from' => $this->next ],
220 foreach (
$res as $row ) {
224 if ( !isset( $this->parents[$row->cl_from] ) ) {
225 $this->parents[$row->cl_from] = [];
227 $this->parents[$row->cl_from][$k] = $row;
229 # Ignore those we already have
230 if ( in_array( $k, $this->deadend ) ) {
234 if ( isset( $this->name2id[$k] ) ) {
244 # Find the IDs of all category pages in $layer, if they exist
245 if ( count( $layer ) > 0 ) {
246 $res = $this->dbr->select(
248 [
'page_id',
'page_title' ],
249 [
'page_namespace' =>
NS_CATEGORY,
'page_title' => $layer ],
252 foreach (
$res as $row ) {
254 $name = $row->page_title;
255 $this->name2id[$name] = $id;
257 unset( $layer[$name] );
262 foreach ( $layer as $v ) {
263 $this->deadend[$v] = $v;
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
The "CategoryFinder" class takes a list of articles, creates an internal representation of all their ...
check( $id, &$conds, $path=[])
This functions recurses through the parent representation, trying to match the conditions.
array $targets
Array of DBKEY category names.
int[] $articles
The original article IDs passed to the seed function.
int $maxdepth
Max layer depth.
array $next
Array of article/category IDs.
array $parents
Array of [ ID => [] ].
array $deadend
Array of DBKEY category names for categories that don't have a page.
string $mode
"AND" or "OR"
run()
Iterates through the parent tree starting with the seed values, then checks the articles if they matc...
scanNextLayer()
Scans a "parent layer" of the articles/categories in $this->next.
seed( $articleIds, $categories, $mode='AND', $maxdepth=-1)
Initializes the instance.
getParents()
Get the parents.
IDatabase $dbr
Read-DB replica DB.