http://www.mediawiki.org/wiki/Special:Code/MediaWiki/93574

Revision: 93574
Author:   yuvipanda
Date:     2011-07-31 06:24:43 +0000 (Sun, 31 Jul 2011)
Log Message:
-----------
Added 'add to article selection' functionality

Modified Paths:
--------------
    trunk/extensions/GPoC/GPoC.hooks.php
    trunk/extensions/GPoC/GPoC.php
    trunk/extensions/GPoC/SpecialFilterRatings.php
    trunk/extensions/GPoC/templates/FilterRatingsTemplate.php

Added Paths:
-----------
    trunk/extensions/GPoC/models/Selection.php
    trunk/extensions/GPoC/schema/selections.sql

Modified: trunk/extensions/GPoC/GPoC.hooks.php
===================================================================
--- trunk/extensions/GPoC/GPoC.hooks.php        2011-07-31 05:33:28 UTC (rev 
93573)
+++ trunk/extensions/GPoC/GPoC.hooks.php        2011-07-31 06:24:43 UTC (rev 
93574)
@@ -59,6 +59,7 @@
                $du->addExtensionTable( "ratings", "$base/ratings.sql");
                $du->addExtensionTable( "project_stats", 
"$base/project_stats.sql" );
                $du->addExtensionTable( "assessment_changelog", "$base/log.sql" 
);
+               $du->addExtensionTable( "selections", "$base/selections.sql" );
                return true;
        }
 }

Modified: trunk/extensions/GPoC/GPoC.php
===================================================================
--- trunk/extensions/GPoC/GPoC.php      2011-07-31 05:33:28 UTC (rev 93573)
+++ trunk/extensions/GPoC/GPoC.php      2011-07-31 06:24:43 UTC (rev 93574)
@@ -23,12 +23,12 @@
 $wgAutoloadClasses['Statistics'] = $dir . 'models/Statistics.php';
 $wgAutoloadClasses['Rating'] = $dir . 'models/Rating.php';
 $wgAutoloadClasses['AssessmentChangeLog'] = $dir . 'models/Log.php';
+$wgAutoloadClasses['Selection'] = $dir . 'models/Selection.php';
 $wgAutoloadClasses['TableDisplay'] = $dir . 'TableDisplay.php';
 $wgAutoloadClasses['AssessmentsExtractor'] = $dir . 'AssessmentsExtractor.php';
 $wgAutoloadClasses['SpecialAssessmentLog'] = $dir . 'SpecialAssessmentLog.php';
 $wgAutoloadClasses['SpecialFilterRatings'] = $dir . 'SpecialFilterRatings.php';
 
-
 $wgAutoloadClasses['FilterRatingsTemplate'] = $dir . 
'templates/FilterRatingsTemplate.php';
 
 $wgHooks['ArticleSaveComplete'][] = 'GPoCHooks::ArticleSaveComplete';

Modified: trunk/extensions/GPoC/SpecialFilterRatings.php
===================================================================
--- trunk/extensions/GPoC/SpecialFilterRatings.php      2011-07-31 05:33:28 UTC 
(rev 93573)
+++ trunk/extensions/GPoC/SpecialFilterRatings.php      2011-07-31 06:24:43 UTC 
(rev 93574)
@@ -21,6 +21,8 @@
                $importance = $wgRequest->getVal('importance');
                $quality = $wgRequest->getVal('quality');
                $categories = $wgRequest->getVal('categories');
+        $action = $wgRequest->getVal('action');
+        $selection_name = $wgRequest->getVal('selection');
 
                $filters = array(
                        'r_project' => $project,
@@ -37,11 +39,18 @@
 
                $this->setHeaders();
 
-               $wgOut->setPageTitle("Filter Articles by Ratings");
+        $wgOut->setPageTitle("Filter Articles by Ratings");
 
+        if( $action == 'addtoselection' ) {
+            Selection::addEntries($selection_name, $entries);
+        }
+
                $template = new FilterRatingsTemplate();
                $template->set( 'filters', $filters );
-               $template->set( 'articles', $entries );
+        $template->set( 'articles', $entries );
+        $template->set( 'action', $action );
+        $template->set( 'selection', $selection );
+
                $wgOut->addTemplate( $template );
        }
 }

Added: trunk/extensions/GPoC/models/Selection.php
===================================================================
--- trunk/extensions/GPoC/models/Selection.php                          (rev 0)
+++ trunk/extensions/GPoC/models/Selection.php  2011-07-31 06:24:43 UTC (rev 
93574)
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * Represents an convenience methods for logging
+ **/
+class Selection {
+    public static function addEntries( $name, $articles ) {
+        $dbw = wfGetDB( DB_MASTER );
+        $timestamp = wfTimestamp( TS_MW );
+        foreach( $articles as $article ) {
+            $success = $dbw->insert(
+                'selections',
+                array(
+                    's_selection_name' => $name,
+                    's_namespace' => $article['r_namespace'],
+                    's_article' => $article['r_article'],
+                    's_timestamp' => $timestamp
+                ),
+                __METHOD__,
+                array( 'IGNORE' )
+            );
+        }
+    }
+}

Added: trunk/extensions/GPoC/schema/selections.sql
===================================================================
--- trunk/extensions/GPoC/schema/selections.sql                         (rev 0)
+++ trunk/extensions/GPoC/schema/selections.sql 2011-07-31 06:24:43 UTC (rev 
93574)
@@ -0,0 +1,20 @@
+-- Replace /*_*/ with the proper prefix
+-- Replace /*$wgDBTableOptions*/ with the correct options
+
+CREATE TABLE IF NOT EXISTS /*_*/selections (
+    s_selection_name        varchar(63)  not null,   
+    -- project name
+
+    s_namespace      int unsigned not null,
+    -- article namespace
+
+    s_article        varchar(255) not null,
+    -- article name
+
+       s_timestamp      binary(14) not null,
+    -- timestamp when entry was added
+
+    primary key (s_selection_name, s_namespace, s_article)
+) /*$wgDBTableOptions*/;
+
+CREATE INDEX /*i*/s_selection_name ON /*_*/selections (s_selection_name);

Modified: trunk/extensions/GPoC/templates/FilterRatingsTemplate.php
===================================================================
--- trunk/extensions/GPoC/templates/FilterRatingsTemplate.php   2011-07-31 
05:33:28 UTC (rev 93573)
+++ trunk/extensions/GPoC/templates/FilterRatingsTemplate.php   2011-07-31 
06:24:43 UTC (rev 93574)
@@ -7,6 +7,8 @@
        public function execute() {
                $articles = $this->data['articles'];
                $filters = $this->data['filters'];
+               $action = $this->data['action'];
+               $selection = $this->data['selection'];
 ?>
 
 <form method="GET">
@@ -19,7 +21,11 @@
 <input type="submit" />
 </p>
 </form>
-
+<div id="notice">
+<?php if( $action == 'addtoselection' ) { ?> 
+Articles successfully added to selection <?php echo $selection; ?>
+<?php } ?>
+</div>
 <div id="">
 <?php if( count($articles) > 0 ) { ?>
 <h3>Results</h3>


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to