* @subpackage SpecialPage
*/
+
class Validation {
var $topicList;
var $voteCache;
var $page_id;
+ var $rev_fields = "rev_id,rev_page,rev_timestamp,rev_user_text,rev_user,rev_comment" ;
function getRevisionFromId( $rev_id ) {
if( isset( $this->id2rev[$rev_id] ) ) return $this->id2rev[$rev_id];
$db =& wfGetDB( DB_SLAVE );
$fname = 'SpecialValidate::getRevisionFromId';
- $res = $db->select( 'revision', '*', array( 'rev_id' => $rev_id ), $fname, array( 'LIMIT' => 1 ) );
+ $res = $db->select( 'revision', $this->rev_fields, array( 'rev_id' => $rev_id ), $fname, array( 'LIMIT' => 1 ) );
$rev = $db->fetchObject($res);
$db->freeResult($res);
$db =& wfGetDB( DB_SLAVE );
$fname = 'SpecialValidate::getRevisionFromTimestamp';
- $res = $db->select( 'revision', '*',
+ $res = $db->select( 'revision', $this->rev_fields,
array( 'rev_page' => $this->page_id, 'rev_timestamp' => $timestamp ),
$fname, array( 'LIMIT' => 1 )
);
$db =& wfGetDB( DB_SLAVE );
$topics = array();
+
+ # NOTE : This query returns only the topics to vote on
$res = $db->select( 'validate', '*', array( 'val_page' => 0 ), 'SpecialValidate::getTopicList' );
while( $topic = $db->fetchObject($res) ) {
$topics[$topic->val_type] = $topic;
# Reads the entire vote list for this user for the given article
function getVoteList( $id, $user = "" ) {
$db =& wfGetDB( DB_SLAVE );
+
+ # NOTE : This query gets the votes for a single user on a single page.
+ # Assuming most people will use the "merge" feature,
+ # this will be only a single entry.
$res = $db->select( 'validate', '*', array_merge( array( 'val_page' => $id ), $this->identifyUser($user) ) );
$revisions = array();
return $revisions;
}
- # Reads the entire vote list for this user for all articles
- # XXX Should be paged
- function getAllVoteLists( $user ) {
+ # Reads a partial vote list for this user for all articles
+ function getAllVoteLists( $user , $offset , $limit ) {
$db =& wfGetDB( DB_SLAVE );
- $res = $db->select( 'validate', '*', $this->identifyUser($user) );
-
+ $a = $this->identifyUser($user) ;
+ $b = array ( "ORDER BY" => "val_page,val_revision" , "OFFSET" => $offset , "LIMIT" => $limit ) ;
+ $res = $db->select( 'validate', '*', $a , 'getAllVotesList' , $b );
+
$votes = array();
while( $vote = $db->fetchObject($res) ) {
$votes[$vote->val_page][$vote->val_revision][$vote->val_type] = $vote;
}
$db->freeResult($res);
-
- return $votes;
+
+ return $votes ;
}
# This functions adds a topic to the database
ksort( $this->topicList );
}
+ # This function deletes a topic and all votes for it. CAREFUL!
function deleteTopic( $id ) {
$db =& wfGetDB( DB_MASTER );
$db->delete( 'validate', array( 'val_type' => $id ), 'SpecialValidate::deleteTopic' );
global $wgRequest;
$this->topicList = $this->getTopicList();
- $iamsure = $wgRequest->getVal( "iamsure", "0" ) == 1;
+ $iamsure = true ; # Sure by default # $wgRequest->getVal( "iamsure", "0" ) == 1;
if( $iamsure && $wgRequest->getVal( "m_add", "--" ) != "--" ) {
$new_topic = $wgRequest->getVal( "m_topic" );
$r .= '<td>1 .. <input type="text" name="m_limit" value="" size="4"/></td>' . "\n";
$r .= '<td><input type="submit" name="m_add" value="' . htmlspecialchars( wfMsg( 'val_add' ) ) . '"/></td>' . "\n";
$r .= "</tr></table>\n";
- $r .= '<p><input type="checkbox" name="iamsure" id="iamsure" value="1"/>';
- $r .= '<label for="iamsure">' . $this->getParsedWiki( wfMsg( 'val_iamsure' ) ) . "</label></p>\n";
+# $r .= '<p><input type="checkbox" name="iamsure" id="iamsure" value="1"/>';
+# $r .= '<label for="iamsure">' . $this->getParsedWiki( wfMsg( 'val_iamsure' ) ) . "</label></p>\n";
$r .= "</form>\n";
return $r;
}
return $ret;
}
- # XXX This should be paged
function showList( &$article ) {
- global $wgOut, $wgUser;
+ global $wgOut, $wgUser , $wgRequest;
$this->page_id = $article->getID();
$this->topicList = $this->getTopicList();
$title = $article->getTitle();
- $wgOut->setPageTitle( str_replace( '$1', $title->getPrefixedText(), wfMsg( 'val_validation_of' ) ) );
+ $wgOut->setPageTitle( wfMsg( 'val_validation_of', $title->getPrefixedText() ) );
+
+ $offset = $wgRequest->getVal ( "offset" , 0 ) ;
+ $limit = $wgRequest->getVal ( "limit" , 25 ) ;
# Collecting statistic data
+ # Unfortunately, it has to read all the data, though it will only display a part
$db =& wfGetDB( DB_SLAVE );
- $res = $db->select( 'validate', '*', array( "val_page" => $this->page_id ), 'SpecialValidate::showList' );
+ $res = $db->select( 'validate', 'val_revision,val_type,val_value', array( "val_page" => $this->page_id ), 'SpecialValidate::showList' );#, $b );
$statistics = array();
while( $vote = $db->fetchObject($res) ) {
$db->freeResult($res);
krsort( $statistics );
-
+
$ret = "<table><tr>\n";
$ret .= "<th>" . $this->getParsedWiki( wfMsg( "val_revision" ) ) . "</th>\n";
foreach( $this->topicList as $topic ) {
}
$ret .= "</tr>\n";
+ # Paging
+ $statistics = array_slice ( $statistics , $offset , $limit ) ;
+
foreach( $statistics as $ts => $data ) {
$rev_id = $this->getRevisionId( $ts );
$revision_link = $this->getRevisionLink( $article, $rev_id, wfTimestamp( TS_DB, $ts ) );
$ret .= "</tr>\n";
}
$ret .= "</table>\n";
+
+ # Navbar
+ $s = $this->navBar ( $offset , $limit , count ( $statistics ) , "list" ) ;
+ $ret = $s . $ret . $s . "<p/>" ;
+
$ret .= "<p>" . $this->getUserRatingsLink( $wgUser->getID(), wfMsg( 'val_show_my_ratings' ) ) . "</p>";
+
return $ret;
}
return $ret;
}
- # XXX This should be paged
- function showUserStats( $user ) {
- global $wgOut, $wgUser;
+ function navBar ( $offset , $limit , $lastcount , $mode = "userstats" ) {
+ global $wgRequest , $wgUser , $wgTitle ;
+ $sk = $wgUser->getSkin();
+ $r = array () ;
+ $user = $wgRequest->getVal( "user" );
+
+ if ( $mode == "userstats" ) {
+ $nt = Title::newFromText( 'Special:Validate' );
+ } else {
+ $nt = $wgTitle ;
+ }
+
+ $base = "action=validate&mode={$mode}&" ;
+ if ( $user != "" ) $base .= "user={$user}&" ;
+ $base .= "limit={$limit}&offset=" ;
+
+ if ( $offset > 0 ) {
+ $o = $offset - $limit ;
+ $t = $offset-$limit+1 ;
+ $r[] = $sk->makeKnownLinkObj( $nt, "{$t} <<" , $base.$o );
+ }
+
+ $s1 = $offset + 1 ;
+ $s2 = $s1 + $lastcount - 1 ;
+ $r[] = $s1 . " - " . $s2 ;
+
+ if ( $lastcount == $limit ) {
+ $o = $offset + $limit ;
+ $t = $offset+$limit+1 ;
+ $r[] = $sk->makeKnownLinkObj( $nt, ">> {$t}" , $base.$o );
+ }
+
+ $r = implode ( " | " , $r ) ;
+ return $r ;
+ }
+
+ function showUserStats( $user ) {
+ global $wgOut, $wgUser, $wgRequest;
$this->topicList = $this->getTopicList();
- $data = $this->getAllVoteLists( $user );
$sk = $wgUser->getSkin();
+ $offset = $wgRequest->getVal( "offset" , 0 );
+ $limit = $wgRequest->getVal( "limit" , 25 );
+ $data = $this->getAllVoteLists( $user , $offset , $limit ) ;
+
if( $user == $wgUser->getID() ) {
$wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) );
} elseif( !User::IsIP( $user ) ) {
$wgOut->setPageTitle( wfMsg( 'val_user_stats_title', $user ) );
}
+ $ret = "" ;
$ret = "<table>\n";
- foreach( $data as $articleid => $revisions ) {
+
+ $linecount = 0 ;
+ $lastpage = -1 ;
+ $lastrevision = -1 ;
+ $initial = false ;
+ foreach ( $data AS $articleid => $revisions ) {
$title = Title::newFromID( $articleid );
- $ret .= "<tr><th colspan='4'>";
- $ret .= $sk->makeKnownLinkObj( $title, $title->getEscapedText() );
- $ret .= "</th></tr>";
+ if ( $lastpage != $articleid ) {
+ $ret .= "<tr><th colspan='4'>";
+ $ret .= $sk->makeKnownLinkObj( $title, $title->getEscapedText() );
+ $ret .= "</th></tr>";
+ $lastpage = $articleid ;
+ $lastrevision = -1 ;
+ }
krsort( $revisions );
foreach( $revisions as $revid => $revision ) {
$url = $title->getLocalURL( "oldid={$revid}" );
- $ret .= "<tr><th>";
- $ret .= $sk->makeKnownLinkObj( $title, wfMsg('val_revision_number', $revid ), "oldid={$revid}" );
- $ret .= "</th>";
+ if ( $lastrevision != $revid ) {
+ $initial = true ;
+ $lastrevision = $revid ;
+ }
+ $ret .= "<tr>" ;
+ if ( $initial ) {
+ $ret .= "<th>";
+ $ret .= $sk->makeKnownLinkObj( $title, wfMsg('val_revision_number', $revid ), "oldid={$revid}" );
+ $ret .= "</th>";
+ }
ksort( $revision );
- $initial = true;
+ #$initial = true;
foreach( $revision as $topic => $rating ) {
if( !$initial ) {
$ret .= "<tr><td/>";
$ret .= "<td>" . $this->getRatingText( $rating->val_value, $this->topicList[$topic]->val_value ) . "</td>";
$ret .= "<td>" . $sk->commentBlock( $rating->val_comment ) . "</td>";
$ret .= "</tr>";
+ $linecount++ ;
}
}
$ret .= "</tr>";
}
$ret .= "</table>";
+
+ $s = $this->navBar ( $offset , $limit , $linecount ) ;
+ if ( $s != "" ) $ret = $s . "<br/>" . $ret . "<br/>" . $s ;
+
return $ret;
}
return;
}
-/*
+
# Can do?
- if( ! $wgUser->isAllowed('change_validation') ) {
+ if( ! $wgUser->isSysop() ) {#isAllowed('change_validation') ) {
$wgOut->sysopRequired();
return;
}
-*/
+
$mode = $wgRequest->getVal( "mode" );
$skin = $wgUser->getSkin();