r92939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92938‎ | r92939 | r92940 >
Date:11:12, 23 July 2011
Author:yuvipanda
Status:deferred (Comments)
Tags:
Comment:
Special Page to filter articles by ratings
Modified paths:
  • /trunk/extensions/GPoC/GPoC.php (modified) (history)
  • /trunk/extensions/GPoC/SpecialFilterRatings.php (added) (history)
  • /trunk/extensions/GPoC/models/Rating.php (modified) (history)
  • /trunk/extensions/GPoC/templates (added) (history)
  • /trunk/extensions/GPoC/templates/FilterRatingsTemplate.php (added) (history)

Diff [purge]

Index: trunk/extensions/GPoC/models/Rating.php
@@ -150,11 +150,29 @@
151151 ),
152152 __METHOD__
153153 );
154 - // Article moves not logged
 154+ // Article moves not logged - yet
155155 }
156156
157 - public static function getLogs() {
 157+ public static function filterArticles( $filters ) {
158158 $dbr = wfGetDB( DB_SLAVE );
 159+ $clean_filters = array();
 160+ foreach($filters as $column => $value) {
 161+ if( ! ( !isset($value) or $value == null or $value == "" )) {
 162+ $clean_filters[$column] = $value;
 163+ }
 164+ }
 165+ $query = $dbr->select(
 166+ 'ratings',
 167+ '*',
 168+ $clean_filters,
 169+ __METHOD__
 170+ );
159171
 172+ $articles = array();
 173+ foreach( $query as $article_row ) {
 174+ $article = (array)$article_row;
 175+ array_push( $articles, $article );
 176+ }
 177+ return $articles;
160178 }
161179 }
Index: trunk/extensions/GPoC/SpecialFilterRatings.php
@@ -0,0 +1,40 @@
 2+<?php
 3+/**
 4+ */
 5+
 6+if ( !defined( 'MEDIAWIKI' ) ) {
 7+ echo( "not a valid entry point.\n" );
 8+ die( 1 );
 9+}
 10+
 11+class SpecialFilterRatings extends SpecialPage {
 12+
 13+ public function __construct() {
 14+ parent::__construct( 'FilterRatings' );
 15+ }
 16+
 17+ // prototypey code
 18+ public function execute( $par ) {
 19+ global $wgOut, $wgRequest;
 20+
 21+ $project = $wgRequest->getVal('project');
 22+ $importance = $wgRequest->getVal('importance');
 23+ $quality = $wgRequest->getVal('quality');
 24+
 25+ $filters = array(
 26+ 'r_project' => $project,
 27+ 'r_importance' => $importance,
 28+ 'r_quality' => $quality
 29+ );
 30+ $entries = Rating::filterArticles($filters);
 31+
 32+ $this->setHeaders();
 33+
 34+ $wgOut->setPageTitle("Filter Articles by Ratings");
 35+
 36+ $template = new FilterRatingsTemplate();
 37+ $template->set( 'filters', $filters );
 38+ $template->set( 'articles', $entries );
 39+ $wgOut->addTemplate( $template );
 40+ }
 41+}
Property changes on: trunk/extensions/GPoC/SpecialFilterRatings.php
___________________________________________________________________
Added: svn:eol-style
142 + native
Index: trunk/extensions/GPoC/GPoC.php
@@ -26,7 +26,11 @@
2727 $wgAutoloadClasses['TableDisplay'] = $dir . 'TableDisplay.php';
2828 $wgAutoloadClasses['AssessmentsExtractor'] = $dir . 'AssessmentsExtractor.php';
2929 $wgAutoloadClasses['SpecialAssessmentLog'] = $dir . 'SpecialAssessmentLog.php';
 30+$wgAutoloadClasses['SpecialFilterRatings'] = $dir . 'SpecialFilterRatings.php';
3031
 32+
 33+$wgAutoloadClasses['FilterRatingsTemplate'] = $dir . 'templates/FilterRatingsTemplate.php';
 34+
3135 $wgHooks['ArticleSaveComplete'][] = 'GPoCHooks::ArticleSaveComplete';
3236 $wgHooks['LoadExtensionSchemaUpdates'][] = 'GPoCHooks::SetupSchema';
3337
@@ -36,5 +40,6 @@
3741 $wgHooks['TitleMoveComplete'][] = 'GPoCHooks::TitleMoveComplete';
3842
3943 $wgSpecialPages['AssessmentLog'] = 'SpecialAssessmentLog';
 44+$wgSpecialPages['FilterRatings'] = 'SpecialFilterRatings';
4045
4146 // Configuration
Index: trunk/extensions/GPoC/templates/FilterRatingsTemplate.php
@@ -0,0 +1,45 @@
 2+<?php
 3+if( !defined( 'MEDIAWIKI' ) ) {
 4+ die( -1 );
 5+}
 6+
 7+class FilterRatingsTemplate extends QuickTemplate {
 8+ public function execute() {
 9+ $articles = $this->data['articles'];
 10+ $filters = $this->data['filters'];
 11+?>
 12+
 13+<form method="GET">
 14+<p>
 15+Project Name: <input type="text" name="project" value="<?php echo $filters['r_project']?>" />
 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']?>" />
 18+<input type="submit" />
 19+</p>
 20+</form>
 21+
 22+<div id="">
 23+<?php if( count($articles) > 0 ) { ?>
 24+ <table>
 25+ <tr>
 26+ <th>Article</th>
 27+ <th>Importance</th>
 28+ <th>Quality</th>
 29+ </tr>
 30+ <?php foreach( $articles as $article ) { ?>
 31+ <tr>
 32+ <td><?php echo $article['r_article']; ?></td>
 33+ <td><?php echo $article['r_importance']; ?></td>
 34+ <td><?php echo $article['r_quality']; ?></td>
 35+ </tr>
 36+ <?php } ?>
 37+ </table>
 38+<?php } else { ?>
 39+<p>No results found</p>
 40+<?php } ?>
 41+</div>
 42+
 43+
 44+<?php
 45+ } // execute()
 46+} // class
Property changes on: trunk/extensions/GPoC/templates/FilterRatingsTemplate.php
___________________________________________________________________
Added: svn:eol-style
147 + native

Comments

#Comment by Nikerabbit (talk | contribs)   17:59, 23 July 2011

Work in progress I assume? :)

#Comment by YuviPanda (talk | contribs)   23:40, 23 July 2011

Very much :)

Status & tagging log