88 $this->articles = $articleIds;
89 $this->next = $articleIds;
93 # Set the list of target categories; convert them to DBKEY form first
95 foreach ( $categories as $c ) {
99 $this->targets[$c] = $c;
114 while ( count( $this->next ) && $dig ) {
118 if ( $this->maxdepth !== -1 ) {
124 # Now check if this applies to the individual articles
127 foreach ( $this->articles as $article ) {
129 if ( $this->
check( $article, $conds ) ) {
130 # Matches the conditions
154 if ( in_array( $id,
$path ) ) {
160 # Shortcut (runtime paranoia): No conditions=all matched
161 if ( count( $conds ) == 0 ) {
165 if ( !isset( $this->parents[$id] ) ) {
169 # iterate through the parents
170 foreach ( $this->parents[$id] as $p ) {
173 # Is this a condition?
174 if ( isset( $conds[$pname] ) ) {
175 # This key is in the category list!
176 if ( $this->mode ==
'OR' ) {
177 # One found, that's enough!
181 # Assuming "AND" as default
182 unset( $conds[$pname] );
183 if ( count( $conds ) == 0 ) {
184 # All conditions met, done
190 # Not done yet, try sub-parents
191 if ( !isset( $this->name2id[$pname] ) ) {
195 $done = $this->
check( $this->name2id[$pname], $conds,
$path );
196 if ( $done || count( $conds ) == 0 ) {
197 # Subparents have done it!
208 # Find all parents of the article currently in $this->next
210 $res = $this->dbr->select(
212 [
'cl_to',
'cl_from' ],
213 [
'cl_from' => $this->next ],
216 foreach (
$res as $row ) {
220 if ( !isset( $this->parents[$row->cl_from] ) ) {
221 $this->parents[$row->cl_from] = [];
223 $this->parents[$row->cl_from][$k] = $row;
225 # Ignore those we already have
226 if ( in_array( $k, $this->deadend ) ) {
230 if ( isset( $this->name2id[$k] ) ) {
240 # Find the IDs of all category pages in $layer, if they exist
241 if ( count( $layer ) > 0 ) {
242 $res = $this->dbr->select(
244 [
'page_id',
'page_title' ],
245 [
'page_namespace' =>
NS_CATEGORY,
'page_title' => $layer ],
248 foreach (
$res as $row ) {
250 $name = $row->page_title;
251 $this->name2id[$name] = $id;
253 unset( $layer[$name] );
258 foreach ( $layer as $v ) {
259 $this->deadend[$v] = $v;
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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.