X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FCategoryFinder.php;h=7446b590255cd97e41171587d10e160f6aa55f69;hb=051d2e9aca28cc3baff42b79ba7d8e23cc05e855;hp=504b35f885d9c6a674a6a56fdefa4bc42963a87f;hpb=f9f12ba25270cce567b696b79730511a6ea81797;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CategoryFinder.php b/includes/CategoryFinder.php index 504b35f885..7446b59025 100644 --- a/includes/CategoryFinder.php +++ b/includes/CategoryFinder.php @@ -20,6 +20,8 @@ * @file */ +use Wikimedia\Rdbms\IDatabase; + /** * The "CategoryFinder" class takes a list of articles, creates an internal * representation of all their parent categories (as well as parents of @@ -40,6 +42,8 @@ * $a = $cf->run(); * print implode( ',' , $a ); * @endcode + * + * @deprecated since 1.31 */ class CategoryFinder { /** @var int[] The original article IDs passed to the seed function */ @@ -54,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 = []; @@ -71,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 = []; @@ -96,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 @@ -184,12 +205,11 @@ class CategoryFinder { * Scans a "parent layer" of the articles/categories in $this->next */ private function scanNextLayer() { - # Find all parents of the article currently in $this->next $layer = []; $res = $this->dbr->select( /* FROM */ 'categorylinks', - /* SELECT */ '*', + /* SELECT */ [ 'cl_to', 'cl_from' ], /* WHERE */ [ 'cl_from' => $this->next ], __METHOD__ . '-1' );