* articles are in one or all of a given subset of categories.
*
* Example use :
- * <code>
+ * @code
* # Determines whether the article with the page_id 12345 is in both
* # "Category 1" and "Category 2" or their subcategories, respectively
*
* );
* $a = $cf->run();
* print implode( ',' , $a );
- * </code>
+ * @endcode
*
*/
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();
+ 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 DatabaseBase Read-DB slave */
+ /** @var IDatabase Read-DB slave */
protected $dbr;
/**
$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 ) {
}
# Now check if this applies to the individual articles
- $ret = array();
+ $ret = [];
foreach ( $this->articles as $article ) {
$conds = $this->targets;
* @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;
# 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
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 ) {
# 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;
$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 ) {