r92976 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92975‎ | r92976 | r92977 >
Date:02:00, 24 July 2011
Author:yuvipanda
Status:deferred
Tags:
Comment:
Filter by Category added
Modified paths:
  • /trunk/extensions/GPoC/SpecialFilterRatings.php (modified) (history)
  • /trunk/extensions/GPoC/models/Rating.php (modified) (history)
  • /trunk/extensions/GPoC/templates/FilterRatingsTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GPoC/models/Rating.php
@@ -153,25 +153,55 @@
154154 // Article moves not logged - yet
155155 }
156156
 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+
157171 public static function filterArticles( $filters ) {
 172+ $database_filters_columns = array( 'r_project', 'r_importance', 'r_quality' );
 173+
158174 $dbr = wfGetDB( DB_SLAVE );
159 - $clean_filters = array();
 175+ $database_filters = array();
 176+
160177 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;
163180 }
164181 }
 182+
 183+ $category_filters = explode( ',', trim( $filters['categories'] ) );
165184 $query = $dbr->select(
166185 'ratings',
167186 '*',
168 - $clean_filters,
 187+ $database_filters,
169188 __METHOD__
170189 );
171190
172191 $articles = array();
173192 foreach( $query as $article_row ) {
174193 $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+ }
176206 }
177207 return $articles;
178208 }
Index: trunk/extensions/GPoC/SpecialFilterRatings.php
@@ -20,12 +20,19 @@
2121 $project = $wgRequest->getVal('project');
2222 $importance = $wgRequest->getVal('importance');
2323 $quality = $wgRequest->getVal('quality');
 24+ $categories = $wgRequest->getVal('categories');
2425
2526 $filters = array(
2627 'r_project' => $project,
2728 'r_importance' => $importance,
28 - 'r_quality' => $quality
 29+ 'r_quality' => $quality,
 30+ 'categories' => $categories
2931 );
 32+
 33+ $categories = explode(',', $wgRequest->getVal('categories'));
 34+ foreach($categories as &$category) {
 35+ $category = trim($category);
 36+ }
3037 $entries = Rating::filterArticles($filters);
3138
3239 $this->setHeaders();
Index: trunk/extensions/GPoC/templates/FilterRatingsTemplate.php
@@ -13,13 +13,16 @@
1414 <p>
1515 Project Name: <input type="text" name="project" value="<?php echo $filters['r_project']?>" />
1616 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']?>" />
1820 <input type="submit" />
1921 </p>
2022 </form>
2123
2224 <div id="">
2325 <?php if( count($articles) > 0 ) { ?>
 26+<h3>Results</h3>
2427 <table>
2528 <tr>
2629 <th>Article</th>

Status & tagging log