X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FCategoryFinder.php;h=720abc3b466ba796ae32073adc7d210c7f8eafb0;hb=5209b053541517073e669ff8584e0508bf8f5b06;hp=2a70f5f3fd4749e534f42a6b059058d920348513;hpb=a15bb6bb4fbc7617ed58e0bb9b73172f45b4e437;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CategoryFinder.php b/includes/CategoryFinder.php index 2a70f5f3fd..720abc3b46 100644 --- a/includes/CategoryFinder.php +++ b/includes/CategoryFinder.php @@ -42,6 +42,8 @@ use Wikimedia\Rdbms\IDatabase; * $a = $cf->run(); * print implode( ',' , $a ); * @endcode + * + * @deprecated since 1.31 */ class CategoryFinder { /** @var int[] The original article IDs passed to the seed function */ @@ -56,6 +58,9 @@ class CategoryFinder { /** @var array Array of article/category IDs */ protected $next = []; + /** @var int Max layer depth **/ + protected $maxdepth = -1; + /** @var array Array of DBKEY category names */ protected $targets = []; @@ -73,12 +78,17 @@ class CategoryFinder { * @param array $articleIds Array of article IDs * @param array $categories FIXME * @param string $mode FIXME, default 'AND'. + * @param int $maxdepth Maximum layer depth. Where: + * -1 means deep recursion (default); + * 0 means no-parents; + * 1 means one parent layer, etc. * @todo FIXME: $categories/$mode */ - public function seed( $articleIds, $categories, $mode = 'AND' ) { + public function seed( $articleIds, $categories, $mode = 'AND', $maxdepth = -1 ) { $this->articles = $articleIds; $this->next = $articleIds; $this->mode = $mode; + $this->maxdepth = $maxdepth; # Set the list of target categories; convert them to DBKEY form first $this->targets = []; @@ -98,8 +108,17 @@ class CategoryFinder { */ public function run() { $this->dbr = wfGetDB( DB_REPLICA ); - while ( count( $this->next ) > 0 ) { + + $i = 0; + $dig = true; + while ( count( $this->next ) && $dig ) { $this->scanNextLayer(); + + // Is there any depth limit? + if ( $this->maxdepth !== -1 ) { + $dig = $i < $this->maxdepth; + $i++; + } } # Now check if this applies to the individual articles @@ -194,14 +213,14 @@ class CategoryFinder { /* WHERE */ [ 'cl_from' => $this->next ], __METHOD__ . '-1' ); - foreach ( $res as $o ) { - $k = $o->cl_to; + foreach ( $res as $row ) { + $k = $row->cl_to; # Update parent tree - if ( !isset( $this->parents[$o->cl_from] ) ) { - $this->parents[$o->cl_from] = []; + if ( !isset( $this->parents[$row->cl_from] ) ) { + $this->parents[$row->cl_from] = []; } - $this->parents[$o->cl_from][$k] = $o; + $this->parents[$row->cl_from][$k] = $row; # Ignore those we already have if ( in_array( $k, $this->deadend ) ) { @@ -226,9 +245,9 @@ class CategoryFinder { /* WHERE */ [ 'page_namespace' => NS_CATEGORY, 'page_title' => $layer ], __METHOD__ . '-2' ); - foreach ( $res as $o ) { - $id = $o->page_id; - $name = $o->page_title; + foreach ( $res as $row ) { + $id = $row->page_id; + $name = $row->page_title; $this->name2id[$name] = $id; $this->next[] = $id; unset( $layer[$name] );