Index: trunk/phase3/includes/Categoryfinder.php |
— | — | @@ -1,15 +1,16 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * The "Categoryfinder" class takes a list of articles, creates an internal representation of all their parent |
6 | | - * categories (as well as parents of parents etc.). From this representation, it determines which of these articles |
7 | | - * are in one or all of a given subset of categories. |
8 | | - * |
| 5 | + * The "Categoryfinder" class takes a list of articles, creates an internal |
| 6 | + * representation of all their parent categories (as well as parents of |
| 7 | + * parents etc.). From this representation, it determines which of these |
| 8 | + * articles are in one or all of a given subset of categories. |
| 9 | + * |
9 | 10 | * Example use : |
10 | | - * |
| 11 | + * |
11 | 12 | * # Determines wether the article with the page_id 12345 is in both |
12 | 13 | * # "Category 1" and "Category 2" or their subcategories, respectively |
13 | | - * |
| 14 | + * |
14 | 15 | * $cf = new Categoryfinder ; |
15 | 16 | * $cf->seed ( |
16 | 17 | * array ( 12345 ) , |
— | — | @@ -18,8 +19,8 @@ |
19 | 20 | * ) ; |
20 | 21 | * $a = $cf->run() ; |
21 | 22 | * print implode ( "," , $a ) ; |
22 | | - * |
23 | | - * |
| 23 | + * |
| 24 | + * |
24 | 25 | */ |
25 | 26 | class Categoryfinder { |
26 | 27 | |
— | — | @@ -90,13 +91,13 @@ |
91 | 92 | function check ( $id , &$conds ) { |
92 | 93 | # Shortcut (runtime paranoia): No contitions=all matched |
93 | 94 | if ( count ( $conds ) == 0 ) return true ; |
94 | | - |
| 95 | + |
95 | 96 | if ( !isset ( $this->parents[$id] ) ) return false ; |
96 | 97 | |
97 | 98 | # iterate through the parents |
98 | 99 | foreach ( $this->parents[$id] AS $p ) { |
99 | 100 | $pname = $p->cl_to ; |
100 | | - |
| 101 | + |
101 | 102 | # Is this a condition? |
102 | 103 | if ( isset ( $conds[$pname] ) ) { |
103 | 104 | # This key is in the category list! |
— | — | @@ -113,7 +114,7 @@ |
114 | 115 | } |
115 | 116 | } |
116 | 117 | } |
117 | | - |
| 118 | + |
118 | 119 | # Not done yet, try sub-parents |
119 | 120 | if ( !isset ( $this->name2id[$pname] ) ) { |
120 | 121 | # No sub-parent |
— | — | @@ -133,7 +134,7 @@ |
134 | 135 | */ |
135 | 136 | function scan_next_layer () { |
136 | 137 | $fname = "Categoryfinder::scan_next_layer" ; |
137 | | - |
| 138 | + |
138 | 139 | # Find all parents of the article currently in $this->next |
139 | 140 | $layer = array () ; |
140 | 141 | $res = $this->dbr->select( |
— | — | @@ -161,7 +162,7 @@ |
162 | 163 | $this->dbr->freeResult( $res ) ; |
163 | 164 | |
164 | 165 | $this->next = array() ; |
165 | | - |
| 166 | + |
166 | 167 | # Find the IDs of all category pages in $layer, if they exist |
167 | 168 | if ( count ( $layer ) > 0 ) { |
168 | 169 | $res = $this->dbr->select( |