From a7ab193d45814db08d017f260b99d4884c8efc26 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 28 Aug 2014 18:58:25 -0700 Subject: [PATCH] Category finder style cleanups * Renamed class to CategoryFinder (camel case) * Removed pointless empty constructor * Swapped wfProfileIn/Out for ProfileSection * Renamed scan_next_layer() to scanNextLayer() because underscores are ugly (no public callers) * Made scanNextLayer() and check() private, no callers outside class * Explicitly made run() and seed() public * Removed ugly underscores from seed() parameter * More useful variable name in single caller Change-Id: Iaffea7634c7b17ed5324b3b5c9b938c1a1348555 --- includes/AutoLoader.php | 2 +- .../{Categoryfinder.php => CategoryFinder.php} | 29 +++++++++------------- includes/specials/SpecialRecentchanges.php | 6 ++--- 3 files changed, 16 insertions(+), 21 deletions(-) rename includes/{Categoryfinder.php => CategoryFinder.php} (91%) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 04802f9e973..661f4d64106 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -37,7 +37,7 @@ $wgAutoloadLocalClasses = array( 'Autopromote' => 'includes/Autopromote.php', 'Block' => 'includes/Block.php', 'Category' => 'includes/Category.php', - 'Categoryfinder' => 'includes/Categoryfinder.php', + 'CategoryFinder' => 'includes/CategoryFinder.php', 'CategoryViewer' => 'includes/CategoryViewer.php', 'ChangeTags' => 'includes/ChangeTags.php', 'ChannelFeed' => 'includes/Feed.php', diff --git a/includes/Categoryfinder.php b/includes/CategoryFinder.php similarity index 91% rename from includes/Categoryfinder.php rename to includes/CategoryFinder.php index a5415afd3e1..9fd388352a5 100644 --- a/includes/Categoryfinder.php +++ b/includes/CategoryFinder.php @@ -21,7 +21,7 @@ */ /** - * The "Categoryfinder" class takes a list of articles, creates an internal + * The "CategoryFinder" class takes a list of articles, creates an internal * representation of all their parent categories (as well as parents of * parents etc.). From this representation, it determines which of these * articles are in one or all of a given subset of categories. @@ -31,7 +31,7 @@ * # Determines whether the article with the page_id 12345 is in both * # "Category 1" and "Category 2" or their subcategories, respectively * - * $cf = new Categoryfinder; + * $cf = new CategoryFinder; * $cf->seed( * array( 12345 ), * array( 'Category 1', 'Category 2' ), @@ -42,7 +42,7 @@ * * */ -class Categoryfinder { +class CategoryFinder { /** @var int[] The original article IDs passed to the seed function */ protected $articles = array(); @@ -67,19 +67,16 @@ class Categoryfinder { /** @var DatabaseBase Read-DB slave */ protected $dbr; - function __construct() { - } - /** * Initializes the instance. Do this prior to calling run(). - * @param array $article_ids Array of article IDs + * @param array $articleIds Array of article IDs * @param array $categories FIXME * @param string $mode FIXME, default 'AND'. * @todo FIXME: $categories/$mode */ - function seed( $article_ids, $categories, $mode = 'AND' ) { - $this->articles = $article_ids; - $this->next = $article_ids; + public function seed( $articleIds, $categories, $mode = 'AND' ) { + $this->articles = $articleIds; + $this->next = $articleIds; $this->mode = $mode; # Set the list of target categories; convert them to DBKEY form first @@ -98,10 +95,10 @@ class Categoryfinder { * then checks the articles if they match the conditions * @return array Array of page_ids (those given to seed() that match the conditions) */ - function run() { + public function run() { $this->dbr = wfGetDB( DB_SLAVE ); while ( count( $this->next ) > 0 ) { - $this->scan_next_layer(); + $this->scanNextLayer(); } # Now check if this applies to the individual articles @@ -124,7 +121,7 @@ class Categoryfinder { * @param array $path Used to check for recursion loops * @return bool Does this match the conditions? */ - function check( $id, &$conds, $path = array() ) { + private function check( $id, &$conds, $path = array() ) { // Check for loops and stop! if ( in_array( $id, $path ) ) { return false; @@ -179,8 +176,8 @@ class Categoryfinder { /** * Scans a "parent layer" of the articles/categories in $this->next */ - function scan_next_layer() { - wfProfileIn( __METHOD__ ); + private function scanNextLayer() { + $profiler = new ProfileSection( __METHOD__ ); # Find all parents of the article currently in $this->next $layer = array(); @@ -235,7 +232,5 @@ class Categoryfinder { foreach ( $layer as $v ) { $this->deadend[$v] = $v; } - - wfProfileOut( __METHOD__ ); } } diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 5938f017c72..17d76648d79 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -595,9 +595,9 @@ class SpecialRecentChanges extends ChangesListSpecialPage { } # Look up - $c = new Categoryfinder; - $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' ); - $match = $c->run(); + $catFind = new CategoryFinder; + $catFind->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' ); + $match = $catFind->run(); # Filter $newrows = array(); -- 2.11.4.GIT