r61854 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61853‎ | r61854 | r61855 >
Date:13:20, 2 February 2010
Author:demon
Status:deferred
Tags:
Comment:
Fix a bunch of really weird spacing, other style fixes
Modified paths:
  • /trunk/phase3/includes/Categoryfinder.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Categoryfinder.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * The "Categoryfinder" class takes a list of articles, creates an internal
65 * representation of all their parent categories (as well as parents of
@@ -24,14 +23,14 @@
2524 */
2625 class Categoryfinder {
2726
28 - var $articles = array () ; # The original article IDs passed to the seed function
29 - var $deadend = array () ; # Array of DBKEY category names for categories that don't have a page
30 - var $parents = array () ; # Array of [ID => array()]
31 - var $next = array () ; # Array of article/category IDs
32 - var $targets = array () ; # Array of DBKEY category names
33 - var $name2id = array () ;
34 - var $mode ; # "AND" or "OR"
35 - var $dbr ; # Read-DB slave
 27+ var $articles = array(); # The original article IDs passed to the seed function
 28+ var $deadend = array(); # Array of DBKEY category names for categories that don't have a page
 29+ var $parents = array(); # Array of [ID => array()]
 30+ var $next = array(); # Array of article/category IDs
 31+ var $targets = array(); # Array of DBKEY category names
 32+ var $name2id = array();
 33+ var $mode; # "AND" or "OR"
 34+ var $dbr; # Read-DB slave
3635
3736 /**
3837 * Constructor (currently empty).
@@ -45,14 +44,14 @@
4645 * @param $categories FIXME
4746 * @param $mode String: FIXME, default 'AND'.
4847 */
49 - function seed ( $article_ids , $categories , $mode = "AND" ) {
50 - $this->articles = $article_ids ;
51 - $this->next = $article_ids ;
52 - $this->mode = $mode ;
 48+ function seed( $article_ids, $categories, $mode = "AND" ) {
 49+ $this->articles = $article_ids;
 50+ $this->next = $article_ids;
 51+ $this->mode = $mode;
5352
5453 # Set the list of target categories; convert them to DBKEY form first
55 - $this->targets = array () ;
56 - foreach ( $categories AS $c ) {
 54+ $this->targets = array();
 55+ foreach ( $categories as $c ) {
5756 $ct = Title::makeTitleSafe( NS_CATEGORY, $c );
5857 if( $ct ) {
5958 $c = $ct->getDBkey();
@@ -69,19 +68,19 @@
7069 function run () {
7170 $this->dbr = wfGetDB( DB_SLAVE );
7271 while ( count ( $this->next ) > 0 ) {
73 - $this->scan_next_layer () ;
 72+ $this->scan_next_layer();
7473 }
7574
7675 # Now check if this applies to the individual articles
77 - $ret = array () ;
78 - foreach ( $this->articles AS $article ) {
79 - $conds = $this->targets ;
80 - if ( $this->check ( $article , $conds ) ) {
 76+ $ret = array();
 77+ foreach ( $this->articles as $article ) {
 78+ $conds = $this->targets;
 79+ if ( $this->check( $article, $conds ) ) {
8180 # Matches the conditions
82 - $ret[] = $article ;
 81+ $ret[] = $article;
8382 }
8483 }
85 - return $ret ;
 84+ return $ret;
8685 }
8786
8887 /**
@@ -91,107 +90,103 @@
9291 * @param $path used to check for recursion loops
9392 * @return bool Does this match the conditions?
9493 */
95 - function check ( $id , &$conds, $path=array() ) {
 94+ function check( $id , &$conds, $path = array() ) {
9695 // Check for loops and stop!
9796 if( in_array( $id, $path ) )
9897 return false;
9998 $path[] = $id;
10099
101100 # Shortcut (runtime paranoia): No contitions=all matched
102 - if ( count ( $conds ) == 0 ) return true ;
 101+ if ( count( $conds ) == 0 ) return true;
103102
104 - if ( !isset ( $this->parents[$id] ) ) return false ;
 103+ if ( !isset( $this->parents[$id] ) ) return false;
105104
106105 # iterate through the parents
107 - foreach ( $this->parents[$id] AS $p ) {
 106+ foreach ( $this->parents[$id] as $p ) {
108107 $pname = $p->cl_to ;
109108
110109 # Is this a condition?
111 - if ( isset ( $conds[$pname] ) ) {
 110+ if ( isset( $conds[$pname] ) ) {
112111 # This key is in the category list!
113112 if ( $this->mode == "OR" ) {
114113 # One found, that's enough!
115 - $conds = array () ;
116 - return true ;
 114+ $conds = array();
 115+ return true;
117116 } else {
118117 # Assuming "AND" as default
119 - unset ( $conds[$pname] ) ;
120 - if ( count ( $conds ) == 0 ) {
 118+ unset( $conds[$pname] ) ;
 119+ if ( count( $conds ) == 0 ) {
121120 # All conditions met, done
122 - return true ;
 121+ return true;
123122 }
124123 }
125124 }
126125
127126 # Not done yet, try sub-parents
128 - if ( !isset ( $this->name2id[$pname] ) ) {
 127+ if ( !isset( $this->name2id[$pname] ) ) {
129128 # No sub-parent
130129 continue ;
131130 }
132 - $done = $this->check ( $this->name2id[$pname] , $conds, $path );
133 - if ( $done OR count ( $conds ) == 0 ) {
 131+ $done = $this->check( $this->name2id[$pname], $conds,$path );
 132+ if ( $done || count( $conds ) == 0 ) {
134133 # Subparents have done it!
135 - return true ;
 134+ return true;
136135 }
137136 }
138 - return false ;
 137+ return false;
139138 }
140139
141140 /**
142141 * Scans a "parent layer" of the articles/categories in $this->next
143142 */
144 - function scan_next_layer () {
145 - $fname = "Categoryfinder::scan_next_layer" ;
146 -
 143+ function scan_next_layer() {
147144 # Find all parents of the article currently in $this->next
148 - $layer = array () ;
 145+ $layer = array();
149146 $res = $this->dbr->select(
150147 /* FROM */ 'categorylinks',
151148 /* SELECT */ '*',
152149 /* WHERE */ array( 'cl_from' => $this->next ),
153 - $fname."-1"
 150+ __METHOD__ . "-1"
154151 );
155152 while ( $o = $this->dbr->fetchObject( $res ) ) {
156153 $k = $o->cl_to ;
157154
158155 # Update parent tree
159 - if ( !isset ( $this->parents[$o->cl_from] ) ) {
160 - $this->parents[$o->cl_from] = array () ;
 156+ if ( !isset( $this->parents[$o->cl_from] ) ) {
 157+ $this->parents[$o->cl_from] = array();
161158 }
162 - $this->parents[$o->cl_from][$k] = $o ;
 159+ $this->parents[$o->cl_from][$k] = $o;
163160
164161 # Ignore those we already have
165 - if ( in_array ( $k , $this->deadend ) ) continue ;
166 - if ( isset ( $this->name2id[$k] ) ) continue ;
 162+ if ( in_array ( $k , $this->deadend ) ) continue;
 163+ if ( isset ( $this->name2id[$k] ) ) continue;
167164
168165 # Hey, new category!
169 - $layer[$k] = $k ;
 166+ $layer[$k] = $k;
170167 }
171 - $this->dbr->freeResult( $res ) ;
172168
173 - $this->next = array() ;
 169+ $this->next = array();
174170
175171 # Find the IDs of all category pages in $layer, if they exist
176172 if ( count ( $layer ) > 0 ) {
177173 $res = $this->dbr->select(
178174 /* FROM */ 'page',
179 - /* SELECT */ 'page_id,page_title',
 175+ /* SELECT */ array( 'page_id', 'page_title' ),
180176 /* WHERE */ array( 'page_namespace' => NS_CATEGORY , 'page_title' => $layer ),
181 - $fname."-2"
 177+ __METHOD__ . "-2"
182178 );
183179 while ( $o = $this->dbr->fetchObject( $res ) ) {
184 - $id = $o->page_id ;
185 - $name = $o->page_title ;
186 - $this->name2id[$name] = $id ;
187 - $this->next[] = $id ;
188 - unset ( $layer[$name] ) ;
 180+ $id = $o->page_id;
 181+ $name = $o->page_title;
 182+ $this->name2id[$name] = $id;
 183+ $this->next[] = $id;
 184+ unset( $layer[$name] );
189185 }
190 - $this->dbr->freeResult( $res ) ;
191 - }
 186+ }
192187
193188 # Mark dead ends
194 - foreach ( $layer AS $v ) {
195 - $this->deadend[$v] = $v ;
 189+ foreach ( $layer as $v ) {
 190+ $this->deadend[$v] = $v;
196191 }
197192 }
198193

Status & tagging log