r12142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12141‎ | r12142 | r12143 >
Date:21:19, 18 December 2005
Author:magnus_manske
Status:old
Tags:
Comment:
statistics, part 2
Modified paths:
  • /trunk/extensions/Review/Review.php (modified) (history)
  • /trunk/extensions/Review/language/en.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Review/language/en.php
@@ -11,6 +11,9 @@
1212 array(
1313 'review_sidebar_title' => "Review",
1414 'review_topics' => "
 15+ # The following is the list of topics and ranges for the review extension.
 16+ # Each topic is defined by a line of five values, separated by ':' (all other lines are ignored).
 17+ # The order is: numerical key (>0), name, max range (>1; 2=yes/no), meaning of lowest value (e.g., 'bad'), meaning of highest value (e.g., 'good').
1518 1:Quality:5:bad:good
1619 2:Ready for 1.0:2:no:yes",
1720 'review_topic_page' => "Review topics",
@@ -27,6 +30,8 @@
2831 'review_statistics_left_corner' => "Revision",
2932 'review_version_link' => "Revision #$1",
3033 'review_statistic_cell' => "Average: $1 of $2<br/>($4 users, $5 anons)",
 34+ 'review_version_statistic_cell' => "$1 of $2",
 35+ 'review_version_reviews_link' => "<small>(version reviews)</small>",
3136 )
3237 );
3338 ?>
Index: trunk/extensions/Review/Review.php
@@ -75,11 +75,14 @@
7676 $v = explode ( ':' , trim ( $v ) ) ;
7777 if ( count ( $v ) != 5 ) continue ; # Some other line, ignore it
7878 $x = "" ;
79 - $x->key = trim ( array_shift ( $v ) ) ;
 79+ $x->key = (int) trim ( array_shift ( $v ) ) ;
8080 $x->name = trim ( array_shift ( $v ) ) ;
8181 $x->range = (int) trim ( array_shift ( $v ) ) ;
8282 $x->left = trim ( array_shift ( $v ) ) ;
8383 $x->right = trim ( array_shift ( $v ) ) ;
 84+ if ( $x->key == 0 ) continue ; # Paranoia
 85+ if ( $x->range < 2 ) continue ; # Paranoia
 86+ if ( $x->name == "" ) continue ; # Paranoia
8487 $wgReviewExtensionTopics[$x->key] = $x ;
8588 }
8689 }
@@ -483,42 +486,79 @@
484487 * @param $title The page
485488 * @param $revision The revision ID (or -1 for table header, 0 for total statistics)
486489 * @param $data The data for this revision
 490+ * @param $revision_mode Set "true" when viewing an individual revision
487491 * @return HTML table row
488492 */
489 - function get_revision_statistics_row ( $title , $revision , &$data ) {
490 - global $wgReviewExtensionTopics , $wgUser ;
 493+ function get_revision_statistics_row ( $title , $revision , &$data , $revision_mode = false ) {
 494+ global $wgReviewExtensionTopics , $wgUser , $wgTitle , $wgRequest ;
491495 $skin =& $wgUser->getSkin() ;
492496
493497 # Row header
494 - $ret = "<tr><th id='review_statistics_table_header' align='left'>" ;
495 - if ( $revision == -1 ) {
 498+ $ret = "<tr><th id='review_statistics_table_header' align='left' nowrap>" ;
 499+ if ( $revision < 0 ) {
496500 # Table headers
497 - $ret .= wfMsgForContent ( 'review_statistics_left_corner' ) ;
 501+ if ( $revision == -1 ) {
 502+ $ret .= wfMsgForContent ( 'review_statistics_left_corner' ) ;
 503+ } else {
 504+ $rev_id = $wgRequest->getInt ( 'rev_id' , 0 ) ;
 505+ $page_id = $title->getArticleID() ;
 506+ $version_link = $skin->makeLinkObj ( $title , wfMsgForContent('review_version_link',$rev_id) , "oldid={$rev_id}" ) ;
 507+ $ret .= $version_link ;
 508+ }
498509 } else if ( $revision == 0 ) {
499510 # Total statistics
500511 $ret .= wfMsgForContent ( 'review_total_statistics' ) ;
 512+ } else if ( $revision_mode ) {
 513+ # User
 514+ $ak = array_keys ( $data ) ;
 515+ $k = array_shift ( $ak ) ;
 516+ if ( $data[$k]->val_user == 0 ) {
 517+ #$user = User::newFromName ( $data[$k]->val_ip ) ;
 518+ $user = new User ;
 519+ $user->setName ( $data[$k]->val_ip ) ;
 520+ } else {
 521+ $user = new User ;
 522+ $user->setID ( $data[$k]->val_user ) ;
 523+ $user->loadFromDatabase() ;
 524+ }
 525+ $ret .= $skin->makeLinkObj ( $user->getUserPage() , $user->getName() ) ;
501526 } else {
502527 # Individual revision
 528+ $page_id = $title->getArticleID() ;
503529 $version_link = $skin->makeLinkObj ( $title , wfMsgForContent('review_version_link',$revision) , "oldid={$revision}" ) ;
504 - $ret .= $version_link ;
 530+ $version_review_link = $skin->makeLinkObj ( $wgTitle , wfMsgForContent('review_version_reviews_link') ,
 531+ "mode=view_version_statistics&page_id={$page_id}&rev_id={$revision}" ) ;
 532+ $ret .= $version_link . "<br/>" . $version_review_link ;
505533 }
506534 $ret .= "</th>" ;
507535
508536 foreach ( $wgReviewExtensionTopics AS $type => $topic ) {
509 - if ( $revision == -1 ) {
 537+ if ( $revision < 0 ) {
510538 # Table header row
511 - $ret .= "<th id='review_statistics_table_header'>" ;
 539+ $ret .= "<th id='review_statistics_table_header' nowrap>" ;
512540 $ret .= $topic->name ;
513541 $ret .= "</th>" ;
 542+ } else if ( $revision_mode ) {
 543+ $ret .= "<td id='review_statistics_table_cell'>" ;
 544+ if ( isset ( $data[$type] ) ) {
 545+ $ret .= "<div id='" ;
 546+ $ret .= "review_radio_" . $data[$type]->val_value . "_of_" . $topic->range ;
 547+ $ret .= "'>" ;
 548+ $ret .= wfMsgForContent ( 'review_version_statistic_cell' , $data[$type]->val_value , $topic->range ) ;
 549+ $ret .= "</div>" ;
 550+ } else {
 551+ $ret .= "&mdash;" ;
 552+ }
 553+ $ret .= "</td>" ;
514554 } else {
515555 $ret .= "<td id='review_statistics_table_cell'>" ;
516556 if ( $data[$type]->total_count > 0 ) {
517557 $average = $data[$type]->sum / $data[$type]->total_count ;
518558 $ret .= "<div id='" ;
519 - $ret .= "review_radio_" . $average . "_of_" . $data[$type]->max ;
 559+ $ret .= "review_radio_" . (int) $average . "_of_" . $data[$type]->max ;
520560 $ret .= "'>" ;
521561 $ret .= wfMsgForContent ( 'review_statistic_cell' ,
522 - $average ,
 562+ sprintf ( "%1.1f" , $average ) ,
523563 $data[$type]->max ,
524564 $data[$type]->total_count ,
525565 $data[$type]->total_count - $data[$type]->anon_count ,
@@ -536,6 +576,24 @@
537577 }
538578
539579 /**
 580+ * Groups data *for a single revision* by user
 581+ * @param $reviews The review data *for a single revision*
 582+ * @return array[user arbitary key] => ( array[types] => revision data )
 583+ */
 584+ function group_data_by_user ( &$reviews ) {
 585+ $data = array () ;
 586+ foreach ( $reviews AS $review ) {
 587+ $type = $review->val_type ;
 588+ $user = $review->val_user == 0 ? $review->val_ip : $review->val_user ;
 589+ if ( !isset ( $data[$user] ) ) {
 590+ $data[$user] = array () ;
 591+ }
 592+ $data[$user][$type] = $review ;
 593+ }
 594+ return $data ;
 595+ }
 596+
 597+ /**
540598 * Special page main function
541599 */
542600 function execute( $par = null ) {
@@ -546,6 +604,7 @@
547605 $skin =& $wgUser->getSkin () ;
548606 $mode = $wgRequest->getText ( 'mode' , "" ) ;
549607 $page_id = $wgRequest->getInt ( 'page_id' , 0 ) ;
 608+ $rev_id = $wgRequest->getInt ( 'rev_id' , 0 ) ;
550609 $error = false ;
551610
552611 if ( $page_id == 0 ) {
@@ -577,6 +636,18 @@
578637 $out .= $out2 ;
579638 $out .= "</table>\n" ;
580639 }
 640+ } else if ( $mode == 'view_version_statistics' ) {
 641+ $data = array () ;
 642+ $out .= "<table id='review_statistics_table'>\n" ;
 643+ $out .= $this->get_revision_statistics_row ( $title , -2 , $data ) ;
 644+ $reviews = $this->get_reviews_for_revision ( $title , $rev_id ) ;
 645+ $this->analyze_review_data ( $title , $rev_id , $reviews , $data ) ;
 646+ $out .= $this->get_revision_statistics_row ( $title , 0 , $data ) ; # Statistics for the revision
 647+ $data = $this->group_data_by_user ( $reviews ) ;
 648+ foreach ( $data AS $entry ) {
 649+ $out .= $this->get_revision_statistics_row ( $title , 1 , $entry , true ) ;
 650+ }
 651+ $out .= "</table>\n" ;
581652 } else {
582653 $error = true ;
583654 }

Status & tagging log