Index: trunk/extensions/GPoC/models/Rating.php |
— | — | @@ -153,25 +153,55 @@ |
154 | 154 | // Article moves not logged - yet |
155 | 155 | } |
156 | 156 | |
| 157 | + private static function checkArticle( $article, $category_filters ) { |
| 158 | + // Check category |
| 159 | + if( count( $category_filters ) == 0 || ( count($category_filters) == 1 && empty( $category_filters[0] ) ) ) { |
| 160 | + return true; |
| 161 | + } |
| 162 | + |
| 163 | + foreach( $category_filters as $category ) { |
| 164 | + if( in_array( $category, $article['categories'] ) ) { |
| 165 | + return true; |
| 166 | + } |
| 167 | + } |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
157 | 171 | public static function filterArticles( $filters ) { |
| 172 | + $database_filters_columns = array( 'r_project', 'r_importance', 'r_quality' ); |
| 173 | + |
158 | 174 | $dbr = wfGetDB( DB_SLAVE ); |
159 | | - $clean_filters = array(); |
| 175 | + $database_filters = array(); |
| 176 | + |
160 | 177 | foreach($filters as $column => $value) { |
161 | | - if( ! ( !isset($value) or $value == null or $value == "" )) { |
162 | | - $clean_filters[$column] = $value; |
| 178 | + if( ! ( !isset($value) or $value == null or $value == "" ) && in_array( $value, $database_filters_columns ) ) { |
| 179 | + $database_filters[$column] = $value; |
163 | 180 | } |
164 | 181 | } |
| 182 | + |
| 183 | + $category_filters = explode( ',', trim( $filters['categories'] ) ); |
165 | 184 | $query = $dbr->select( |
166 | 185 | 'ratings', |
167 | 186 | '*', |
168 | | - $clean_filters, |
| 187 | + $database_filters, |
169 | 188 | __METHOD__ |
170 | 189 | ); |
171 | 190 | |
172 | 191 | $articles = array(); |
173 | 192 | foreach( $query as $article_row ) { |
174 | 193 | $article = (array)$article_row; |
175 | | - array_push( $articles, $article ); |
| 194 | + $title = Title::makeTitle( $article['r_namespace'], $article['r_article'] ); |
| 195 | + $article['title'] = $title; |
| 196 | + $categories = array_keys( $title->getParentCategories() ); |
| 197 | + $article['categories'] = array(); |
| 198 | + foreach( $categories as $category ) { |
| 199 | + $split = explode(':', $category); |
| 200 | + array_push( $article['categories'], trim( $split[1] ) ); |
| 201 | + } |
| 202 | + |
| 203 | + if( Rating::checkArticle( $article, $category_filters ) ) { |
| 204 | + array_push( $articles, $article ); |
| 205 | + } |
176 | 206 | } |
177 | 207 | return $articles; |
178 | 208 | } |
Index: trunk/extensions/GPoC/SpecialFilterRatings.php |
— | — | @@ -20,12 +20,19 @@ |
21 | 21 | $project = $wgRequest->getVal('project'); |
22 | 22 | $importance = $wgRequest->getVal('importance'); |
23 | 23 | $quality = $wgRequest->getVal('quality'); |
| 24 | + $categories = $wgRequest->getVal('categories'); |
24 | 25 | |
25 | 26 | $filters = array( |
26 | 27 | 'r_project' => $project, |
27 | 28 | 'r_importance' => $importance, |
28 | | - 'r_quality' => $quality |
| 29 | + 'r_quality' => $quality, |
| 30 | + 'categories' => $categories |
29 | 31 | ); |
| 32 | + |
| 33 | + $categories = explode(',', $wgRequest->getVal('categories')); |
| 34 | + foreach($categories as &$category) { |
| 35 | + $category = trim($category); |
| 36 | + } |
30 | 37 | $entries = Rating::filterArticles($filters); |
31 | 38 | |
32 | 39 | $this->setHeaders(); |
Index: trunk/extensions/GPoC/templates/FilterRatingsTemplate.php |
— | — | @@ -13,13 +13,16 @@ |
14 | 14 | <p> |
15 | 15 | Project Name: <input type="text" name="project" value="<?php echo $filters['r_project']?>" /> |
16 | 16 | Importance: <input type="text" name="importance" value="<?php echo $filters['r_importance']?>" /> |
17 | | -Quality: <input type="text" name="quality" value="<?php echo $filters['r_quality']?>" /> |
| 17 | +Quality: <input type="text" name="quality" value="<?php echo $filters['r_quality']?>" /> |
| 18 | +<br /> |
| 19 | +Categories (comma separated): <input type="text" name="categories" value="<?php echo $filters['categories']?>" /> |
18 | 20 | <input type="submit" /> |
19 | 21 | </p> |
20 | 22 | </form> |
21 | 23 | |
22 | 24 | <div id=""> |
23 | 25 | <?php if( count($articles) > 0 ) { ?> |
| 26 | +<h3>Results</h3> |
24 | 27 | <table> |
25 | 28 | <tr> |
26 | 29 | <th>Article</th> |