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();
}
# Reads the entire vote list for this user for all articles
- # XXX Should be paged
function getAllVoteLists( $user ) {
$db =& wfGetDB( DB_SLAVE );
- $res = $db->select( 'validate', '*', $this->identifyUser($user) );
-
- $votes = array();
- while( $vote = $db->fetchObject($res) ) {
- $votes[$vote->val_page][$vote->val_revision][$vote->val_type] = $vote;
- }
- $db->freeResult($res);
-
- return $votes;
+ $this->allVoteDb = $db ;
+ $a = $this->identifyUser($user) ;
+ $b = array ( "ORDER BY" => "val_page,val_revision" ) ;
+ $res = $db->select( 'validate', '*', $a , 'getAllVotesList' , $b );
+ return $res ;
}
# This functions adds a topic to the database
return $ret;
}
- # XXX This should be paged
+
+ var $allVotesCount ;
+ var $allVoteRes ;
+ var $allVoteDb ;
+
+ # This function will get an SQL results handle on the first call
+ # and iterate through the results on each call, until
+ # it hits the end; after that, it will return an empty array
+ # to signal the calling function to stop
+ function iterateAllVotes ( $user ) {
+ if ( $this->allVotesCount == -1 ) return array () ; # This is the end, my friend, the end
+
+ if ( $this->allVotesCount == 0 ) {
+ $this->allVoteRes = $this->getAllVoteLists( $user ) ;
+ $this->allVotesCount = 1 ;
+ }
+
+
+ $votes = array();
+ if( $vote = $this->allVoteDb->fetchObject($this->allVoteRes) ) {
+ $votes[$vote->val_page][$vote->val_revision][$vote->val_type] = $vote;
+ } else {
+ $this->allVoteDb->freeResult($this->allVoteRes);
+ $this->allVotesCount = -1 ; # Setting stop mark
+ return array () ;
+ }
+
+ $a = array () ;
+ if ( count ( $votes ) != 0 ) {
+ foreach ( $votes AS $k => $v ) {
+ $a[$k] = $v ;
+ break ; # Just once...
+ }
+ unset ( $this->allVotesCache[$k] ) ;
+ }
+ return $a ;
+ }
+
function showUserStats( $user ) {
global $wgOut, $wgUser;
$this->topicList = $this->getTopicList();
- $data = $this->getAllVoteLists( $user );
$sk = $wgUser->getSkin();
+ $this->allVotesCount = 0 ; # Initialize
if( $user == $wgUser->getID() ) {
$wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) );
}
$ret = "<table>\n";
- foreach( $data as $articleid => $revisions ) {
+
+ while ( 1 ) {
+ $temp = $this->iterateAllVotes ( $user ) ;
+ if ( count ( $temp ) == 0 ) break ; # All done
+ $articleid = array_shift ( array_keys ( $temp ) ) ;
+ $revisions = array_shift ( $temp ) ;
$title = Title::newFromID( $articleid );
$ret .= "<tr><th colspan='4'>";
$ret .= $sk->makeKnownLinkObj( $title, $title->getEscapedText() );