r9126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r9125‎ | r9126 | r9127 >
Date:18:27, 21 May 2005
Author:magnus_manske
Status:old
Tags:
Comment:
validation updates
Modified paths:
  • /trunk/phase3/includes/SpecialValidate.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialValidate.php
@@ -173,6 +173,22 @@
174174 return $r ;
175175 }
176176
 177+ # Reads the entire vote list for this user for all articles
 178+ function getAllVoteLists ( $user ) {
 179+ global $wgDBprefix ;
 180+ $r = array () ; # Revisions
 181+ $sql = "SELECT * FROM {$wgDBprefix}validate WHERE val_user=" . $user ;
 182+ $res = wfQuery( $sql, DB_READ );
 183+ while( $x = wfFetchObject( $res ) ) {
 184+ $a = $x->val_page ;
 185+ $y = $x->val_revision ;
 186+ if ( !isset ( $r[$a] ) ) $r[$a] = array () ;
 187+ if ( !isset($r[$a][$y]) ) $r[$a][$y] = array () ;
 188+ $r[$a][$y][$x->val_type] = $x ;
 189+ }
 190+ return $r ;
 191+ }
 192+
177193 # This functions adds a topic to the database
178194 function addTopic ( $topic , $limit ) {
179195 global $wgDBprefix ;
@@ -212,6 +228,13 @@
213229 return wfMsg ( 'val_revision_stats_link', $url );
214230 }
215231
 232+ # This function returns a link text to the user rating statistics page
 233+ function link2userratings ( $user , $text ) {
 234+ $nt = Title::newFromText ( "Special:Validate" ) ;
 235+ $url = htmlspecialchars( $nt->getLocalURL( "mode=userstats&user={$user}" ) );
 236+ return "<a href=\"{$url}\">{$text}</a>" ;
 237+ }
 238+
216239 # Returns the timestamp of a revision based on the revision number
217240 function getTimestamp ( $revision ) {
218241 $ts = $this->rev2date[$revision] ;
@@ -313,7 +336,7 @@
314337
315338 # Generates the page from the validation tab
316339 function validatePageForm ( &$article , $revision ) {
317 - global $wgOut, $wgRequest ;
 340+ global $wgOut, $wgRequest, $wgUser ;
318341
319342 $ret = "" ;
320343 $this->prepareRevisions ( $article->getID() ) ;
@@ -351,6 +374,7 @@
352375 $ret .= "<br/>\n" ;
353376 }
354377 $ret .= $this->link2statistics ( $article ) ;
 378+ $ret .= "<p>" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "</p>" ;
355379 return $ret ;
356380 }
357381
@@ -400,7 +424,7 @@
401425 }
402426
403427 function showDetails ( &$article , $revision ) {
404 - global $wgDBprefix , $wgOut ;
 428+ global $wgDBprefix , $wgOut, $wgUser ;
405429 $this->prepareRevisions ( $article->getID() ) ;
406430 $this->topicList = $this->getTopicList() ;
407431
@@ -456,6 +480,7 @@
457481 }
458482 $ret .= "</table>" ;
459483 $ret .= "<p>" . $this->link2statistics ( $article ) . "</p>" ;
 484+ $ret .= "<p>" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "</p>" ;
460485
461486 return $ret ;
462487 }
@@ -509,9 +534,54 @@
510535 $ret .= "</tr>\n" ;
511536 }
512537 $ret .= "</table>\n" ;
 538+ $ret .= "<p>" . $this->link2userratings ( $wgUser->GetID() , wfMsg('val_show_my_ratings') ) . "</p>" ;
513539 return $ret ;
514540 }
 541+
 542+ function getRatingText ( $value , $max ) {
 543+ if ( $max == 2 && $value == 1 ) $ret = wfMsg ( "val_no" ) . " " ;
 544+ else if ( $max == 2 && $value == 2 ) $ret = wfMsg ( "val_yes" ) ;
 545+ else if ( $value != 0 ) $ret = wfMsg ( "val_of" , $value , $max ) . " " ;
 546+ else $ret = "" ;
 547+ return $ret ;
 548+ }
515549
 550+ function showUserStats ( $user ) {
 551+ global $wgDBprefix , $wgOut, $wgUser ;
 552+ $this->topicList = $this->getTopicList() ;
 553+ $data = $this->getAllVoteLists ( $user ) ;
 554+
 555+ if ( $user == $wgUser->getID() ) $wgOut->setPageTitle ( wfMsg ( 'val_my_stats_title' ) ) ;
 556+ else $wgOut->setPageTitle ( wfMsg ( 'val_user_stats_title' , $user ) ) ;
 557+
 558+ $ret = "" ;
 559+ $ret .= "<table border='1' cellspacing='0' cellpadding='2'>\n" ;
 560+
 561+ foreach ( $data AS $articleid => $revisions ) {
 562+ $title = Title::newFromID ( $articleid ) ;
 563+ $ret .= "<tr><th align='left' colspan='4'><a href=\"" . $title->getLocalURL() . "\">" . $title->getPrefixedText() . "</a></th></tr>" ;
 564+ krsort ( $revisions ) ;
 565+ foreach ( $revisions AS $revid => $revision ) {
 566+ $url = $title->getLocalURL ( "oldid={$revid}" ) ;
 567+ $ret .= "<tr><th align='left'><a href=\"{$url}\">" . wfMsg ( 'val_revision_number' , $revid ) . "</a></th>" ;
 568+ ksort ( $revision ) ;
 569+ $initial = true ;
 570+ foreach ( $revision AS $topic => $rating ) {
 571+ if ( !$initial ) $ret .= "<tr><td/>" ;
 572+ $initial = false ;
 573+ $ret .= "<td>" . $this->topicList[$topic]->val_comment . "</td>" ;
 574+ $ret .= "<td>" . $this->getRatingText ( $rating->val_value , $this->topicList[$topic]->val_value ) . "</td>" ;
 575+ $ret .= "<td>" . htmlentities ( $rating->val_comment ) . "</td>" ;
 576+ $ret .= "</tr>" ;
 577+ }
 578+ }
 579+ $ret .= "</tr>" ;
 580+ }
 581+ $ret .= "</table>" ;
 582+
 583+ return $ret ;
 584+ }
 585+
516586 }
517587
518588 /**
@@ -540,9 +610,11 @@
541611 if ( $mode == "manage" ) {
542612 $v = new Validation ;
543613 $html = $v->manageTopics () ;
544 -# } else if ( $mode == "list" ) {
545 -# $v = new Validation ;
546 -# $html = $v->showList ( $wgRequest->getVal ( "id" ) ) ;
 614+ } else if ( $mode == "userstats" ) {
 615+ $v = new Validation ;
 616+ $user = $wgUser->GetID() ;
 617+ #$user = $wgRequest->getVal ( "user" ) ; # Uncomment this to allow all user statistics to be public
 618+ $html = $v->showUserStats ( $user ) ;
547619 } else {
548620 $html = "$mode" ;
549621 $html .= "<ul>\n" ;
Index: trunk/phase3/languages/Language.php
@@ -1477,11 +1477,16 @@
14781478 # Validation
14791479 'val_yes' => 'Yes',
14801480 'val_no' => 'No',
 1481+'val_of' => '$1 of $2',
14811482 'val_revision' => 'Revision',
14821483 'val_time' => 'Time',
 1484+'val_user_stats_title' => 'Validation overview of user #$1',
 1485+'val_my_stats_title' => 'My validation overview',
14831486 'val_list_header' => '<th>#</th><th>Topic</th><th>Range</th><th>Action</th>',
14841487 'val_add' => 'Add',
14851488 'val_del' => 'Delete',
 1489+'val_show_my_ratings' => 'Show my validations',
 1490+'val_revision_number' => 'Revision #$1',
14861491 'val_warning' => '<b>Never, <i>ever</i>, change something here without <i>explicit</i> community consensus!</b>',
14871492 'val_rev_for' => 'Revisions for ',
14881493 'val_details_th_user' => 'User #$1',

Status & tagging log