X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FCategoryFinder.php;h=4efa2ff84ca2e014d72ee557e6f21506180532c2;hb=c2602eaed5c726e1b78cc9ecb55a94392e923642;hp=d779141052eff9a1a02745ed4816c8503f0fa35f;hpb=38ba6b620be9f6333d902055ae1c0c610af4985e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CategoryFinder.php b/includes/CategoryFinder.php index d779141052..4efa2ff84c 100644 --- a/includes/CategoryFinder.php +++ b/includes/CategoryFinder.php @@ -33,8 +33,8 @@ * * $cf = new CategoryFinder; * $cf->seed( - * array( 12345 ), - * array( 'Category 1', 'Category 2' ), + * [ 12345 ], + * [ 'Category 1', 'Category 2' ], * 'AND' * ); * $a = $cf->run(); @@ -44,27 +44,27 @@ */ class CategoryFinder { /** @var int[] The original article IDs passed to the seed function */ - protected $articles = array(); + protected $articles = []; /** @var array Array of DBKEY category names for categories that don't have a page */ - protected $deadend = array(); + protected $deadend = []; - /** @var array Array of [ID => array()] */ - protected $parents = array(); + /** @var array Array of [ ID => [] ] */ + protected $parents = []; /** @var array Array of article/category IDs */ - protected $next = array(); + protected $next = []; /** @var array Array of DBKEY category names */ - protected $targets = array(); + protected $targets = []; /** @var array */ - protected $name2id = array(); + protected $name2id = []; /** @var string "AND" or "OR" */ protected $mode; - /** @var IDatabase Read-DB slave */ + /** @var IDatabase Read-DB replica DB */ protected $dbr; /** @@ -80,7 +80,7 @@ class CategoryFinder { $this->mode = $mode; # Set the list of target categories; convert them to DBKEY form first - $this->targets = array(); + $this->targets = []; foreach ( $categories as $c ) { $ct = Title::makeTitleSafe( NS_CATEGORY, $c ); if ( $ct ) { @@ -96,13 +96,13 @@ class CategoryFinder { * @return array Array of page_ids (those given to seed() that match the conditions) */ public function run() { - $this->dbr = wfGetDB( DB_SLAVE ); + $this->dbr = wfGetDB( DB_REPLICA ); while ( count( $this->next ) > 0 ) { $this->scanNextLayer(); } # Now check if this applies to the individual articles - $ret = array(); + $ret = []; foreach ( $this->articles as $article ) { $conds = $this->targets; @@ -129,7 +129,7 @@ class CategoryFinder { * @param array $path Used to check for recursion loops * @return bool Does this match the conditions? */ - private function check( $id, &$conds, $path = array() ) { + private function check( $id, &$conds, $path = [] ) { // Check for loops and stop! if ( in_array( $id, $path ) ) { return false; @@ -155,7 +155,7 @@ class CategoryFinder { # This key is in the category list! if ( $this->mode == 'OR' ) { # One found, that's enough! - $conds = array(); + $conds = []; return true; } else { # Assuming "AND" as default @@ -187,11 +187,11 @@ class CategoryFinder { private function scanNextLayer() { # Find all parents of the article currently in $this->next - $layer = array(); + $layer = []; $res = $this->dbr->select( /* FROM */ 'categorylinks', /* SELECT */ '*', - /* WHERE */ array( 'cl_from' => $this->next ), + /* WHERE */ [ 'cl_from' => $this->next ], __METHOD__ . '-1' ); foreach ( $res as $o ) { @@ -199,7 +199,7 @@ class CategoryFinder { # Update parent tree if ( !isset( $this->parents[$o->cl_from] ) ) { - $this->parents[$o->cl_from] = array(); + $this->parents[$o->cl_from] = []; } $this->parents[$o->cl_from][$k] = $o; @@ -216,14 +216,14 @@ class CategoryFinder { $layer[$k] = $k; } - $this->next = array(); + $this->next = []; # Find the IDs of all category pages in $layer, if they exist if ( count( $layer ) > 0 ) { $res = $this->dbr->select( /* FROM */ 'page', - /* SELECT */ array( 'page_id', 'page_title' ), - /* WHERE */ array( 'page_namespace' => NS_CATEGORY, 'page_title' => $layer ), + /* SELECT */ [ 'page_id', 'page_title' ], + /* WHERE */ [ 'page_namespace' => NS_CATEGORY, 'page_title' => $layer ], __METHOD__ . '-2' ); foreach ( $res as $o ) {