Index: trunk/extensions/Review/language/en.php |
— | — | @@ -11,6 +11,9 @@ |
12 | 12 | array( |
13 | 13 | 'review_sidebar_title' => "Review", |
14 | 14 | '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'). |
15 | 18 | 1:Quality:5:bad:good |
16 | 19 | 2:Ready for 1.0:2:no:yes", |
17 | 20 | 'review_topic_page' => "Review topics", |
— | — | @@ -27,6 +30,8 @@ |
28 | 31 | 'review_statistics_left_corner' => "Revision", |
29 | 32 | 'review_version_link' => "Revision #$1", |
30 | 33 | '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>", |
31 | 36 | ) |
32 | 37 | ); |
33 | 38 | ?> |
Index: trunk/extensions/Review/Review.php |
— | — | @@ -75,11 +75,14 @@ |
76 | 76 | $v = explode ( ':' , trim ( $v ) ) ; |
77 | 77 | if ( count ( $v ) != 5 ) continue ; # Some other line, ignore it |
78 | 78 | $x = "" ; |
79 | | - $x->key = trim ( array_shift ( $v ) ) ; |
| 79 | + $x->key = (int) trim ( array_shift ( $v ) ) ; |
80 | 80 | $x->name = trim ( array_shift ( $v ) ) ; |
81 | 81 | $x->range = (int) trim ( array_shift ( $v ) ) ; |
82 | 82 | $x->left = trim ( array_shift ( $v ) ) ; |
83 | 83 | $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 |
84 | 87 | $wgReviewExtensionTopics[$x->key] = $x ; |
85 | 88 | } |
86 | 89 | } |
— | — | @@ -483,42 +486,79 @@ |
484 | 487 | * @param $title The page |
485 | 488 | * @param $revision The revision ID (or -1 for table header, 0 for total statistics) |
486 | 489 | * @param $data The data for this revision |
| 490 | + * @param $revision_mode Set "true" when viewing an individual revision |
487 | 491 | * @return HTML table row |
488 | 492 | */ |
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 ; |
491 | 495 | $skin =& $wgUser->getSkin() ; |
492 | 496 | |
493 | 497 | # 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 ) { |
496 | 500 | # 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 | + } |
498 | 509 | } else if ( $revision == 0 ) { |
499 | 510 | # Total statistics |
500 | 511 | $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() ) ; |
501 | 526 | } else { |
502 | 527 | # Individual revision |
| 528 | + $page_id = $title->getArticleID() ; |
503 | 529 | $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 ; |
505 | 533 | } |
506 | 534 | $ret .= "</th>" ; |
507 | 535 | |
508 | 536 | foreach ( $wgReviewExtensionTopics AS $type => $topic ) { |
509 | | - if ( $revision == -1 ) { |
| 537 | + if ( $revision < 0 ) { |
510 | 538 | # Table header row |
511 | | - $ret .= "<th id='review_statistics_table_header'>" ; |
| 539 | + $ret .= "<th id='review_statistics_table_header' nowrap>" ; |
512 | 540 | $ret .= $topic->name ; |
513 | 541 | $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 .= "—" ; |
| 552 | + } |
| 553 | + $ret .= "</td>" ; |
514 | 554 | } else { |
515 | 555 | $ret .= "<td id='review_statistics_table_cell'>" ; |
516 | 556 | if ( $data[$type]->total_count > 0 ) { |
517 | 557 | $average = $data[$type]->sum / $data[$type]->total_count ; |
518 | 558 | $ret .= "<div id='" ; |
519 | | - $ret .= "review_radio_" . $average . "_of_" . $data[$type]->max ; |
| 559 | + $ret .= "review_radio_" . (int) $average . "_of_" . $data[$type]->max ; |
520 | 560 | $ret .= "'>" ; |
521 | 561 | $ret .= wfMsgForContent ( 'review_statistic_cell' , |
522 | | - $average , |
| 562 | + sprintf ( "%1.1f" , $average ) , |
523 | 563 | $data[$type]->max , |
524 | 564 | $data[$type]->total_count , |
525 | 565 | $data[$type]->total_count - $data[$type]->anon_count , |
— | — | @@ -536,6 +576,24 @@ |
537 | 577 | } |
538 | 578 | |
539 | 579 | /** |
| 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 | + /** |
540 | 598 | * Special page main function |
541 | 599 | */ |
542 | 600 | function execute( $par = null ) { |
— | — | @@ -546,6 +604,7 @@ |
547 | 605 | $skin =& $wgUser->getSkin () ; |
548 | 606 | $mode = $wgRequest->getText ( 'mode' , "" ) ; |
549 | 607 | $page_id = $wgRequest->getInt ( 'page_id' , 0 ) ; |
| 608 | + $rev_id = $wgRequest->getInt ( 'rev_id' , 0 ) ; |
550 | 609 | $error = false ; |
551 | 610 | |
552 | 611 | if ( $page_id == 0 ) { |
— | — | @@ -577,6 +636,18 @@ |
578 | 637 | $out .= $out2 ; |
579 | 638 | $out .= "</table>\n" ; |
580 | 639 | } |
| 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" ; |
581 | 652 | } else { |
582 | 653 | $error = true ; |
583 | 654 | } |