From 2c4d15154ac29c41bf33373fa70967f47f6ee01a Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Sat, 21 May 2005 18:27:55 +0000 Subject: [PATCH] validation updates --- includes/SpecialValidate.php | 82 +++++++++++++++++++++++++++++++++--- languages/Language.php | 5 +++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/includes/SpecialValidate.php b/includes/SpecialValidate.php index b95716256d..540d3fa79d 100644 --- a/includes/SpecialValidate.php +++ b/includes/SpecialValidate.php @@ -173,6 +173,22 @@ class Validation { return $r ; } + # Reads the entire vote list for this user for all articles + function getAllVoteLists ( $user ) { + global $wgDBprefix ; + $r = array () ; # Revisions + $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_user=" . $user ; + $res = wfQuery( $sql, DB_READ ); + while( $x = wfFetchObject( $res ) ) { + $a = $x->val_page ; + $y = $x->val_revision ; + if ( !isset ( $r[$a] ) ) $r[$a] = array () ; + if ( !isset($r[$a][$y]) ) $r[$a][$y] = array () ; + $r[$a][$y][$x->val_type] = $x ; + } + return $r ; + } + # This functions adds a topic to the database function addTopic ( $topic , $limit ) { global $wgDBprefix ; @@ -212,6 +228,13 @@ class Validation { return wfMsg ( 'val_revision_stats_link', $url ); } + # This function returns a link text to the user rating statistics page + function link2userratings ( $user , $text ) { + $nt = Title::newFromText ( "Special:Validate" ) ; + $url = htmlspecialchars( $nt->getLocalURL( "mode=userstats&user={$user}" ) ); + return "{$text}" ; + } + # Returns the timestamp of a revision based on the revision number function getTimestamp ( $revision ) { $ts = $this->rev2date[$revision] ; @@ -313,7 +336,7 @@ class Validation { # Generates the page from the validation tab function validatePageForm ( &$article , $revision ) { - global $wgOut, $wgRequest ; + global $wgOut, $wgRequest, $wgUser ; $ret = "" ; $this->prepareRevisions ( $article->getID() ) ; @@ -351,6 +374,7 @@ class Validation { $ret .= "
\n" ; } $ret .= $this->link2statistics ( $article ) ; + $ret .= "

" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "

" ; return $ret ; } @@ -400,7 +424,7 @@ class Validation { } function showDetails ( &$article , $revision ) { - global $wgDBprefix , $wgOut ; + global $wgDBprefix , $wgOut, $wgUser ; $this->prepareRevisions ( $article->getID() ) ; $this->topicList = $this->getTopicList() ; @@ -456,6 +480,7 @@ class Validation { } $ret .= "" ; $ret .= "

" . $this->link2statistics ( $article ) . "

" ; + $ret .= "

" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "

" ; return $ret ; } @@ -509,9 +534,54 @@ class Validation { $ret .= "\n" ; } $ret .= "\n" ; + $ret .= "

" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "

" ; + return $ret ; + } + + function getRatingText ( $value , $max ) { + if ( $max == 2 && $value == 1 ) $ret = wfMsg ( "val_no" ) . " " ; + else if ( $max == 2 && $value == 2 ) $ret = wfMsg ( "val_yes" ) ; + else if ( $value != 0 ) $ret = wfMsg ( "val_of" , $value , $max ) . " " ; + else $ret = "" ; return $ret ; } + function showUserStats ( $user ) { + global $wgDBprefix , $wgOut, $wgUser ; + $this->topicList = $this->getTopicList() ; + $data = $this->getAllVoteLists ( $user ) ; + + if ( $user == $wgUser->getID() ) $wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) ) ; + else $wgOut->setPageTitle ( wfMsg ( 'val_user_stats_title' , $user ) ) ; + + $ret = "" ; + $ret .= "\n" ; + + foreach ( $data AS $articleid => $revisions ) { + $title = Title::newFromID ( $articleid ) ; + $ret .= "" ; + krsort ( $revisions ) ; + foreach ( $revisions AS $revid => $revision ) { + $url = $title->getLocalURL ( "oldid={$revid}" ) ; + $ret .= "" ; + ksort ( $revision ) ; + $initial = true ; + foreach ( $revision AS $topic => $rating ) { + if ( !$initial ) $ret .= "" ; + $ret .= "" ; + $ret .= "" ; + $ret .= "" ; + } + } + $ret .= "" ; + } + $ret .= "
getLocalURL() . "\">" . $title->getPrefixedText() . "
" . wfMsg ( 'val_revision_number' , $revid ) . "
" ; + $initial = false ; + $ret .= "" . $this->topicList[$topic]->val_comment . "" . $this->getRatingText ( $rating->val_value , $this->topicList[$topic]->val_value ) . "" . htmlentities ( $rating->val_comment ) . "
" ; + + return $ret ; + } + } /** @@ -540,9 +610,11 @@ function wfSpecialValidate( $page = '' ) { if ( $mode == "manage" ) { $v = new Validation ; $html = $v->manageTopics () ; -# } else if ( $mode == "list" ) { -# $v = new Validation ; -# $html = $v->showList ( $wgRequest->getVal ( "id" ) ) ; + } else if ( $mode == "userstats" ) { + $v = new Validation ; + $user = $wgUser->GetID() ; + #$user = $wgRequest->getVal ( "user" ) ; # Uncomment this to allow all user statistics to be public + $html = $v->showUserStats ( $user ) ; } else { $html = "$mode" ; $html .= "