r12143 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12142‎ | r12143 | r12144 >
Date:22:13, 18 December 2005
Author:magnus_manske
Status:old
Tags:
Comment:
statistics, part 3
Modified paths:
  • /trunk/extensions/Review/Review.php (modified) (history)
  • /trunk/extensions/Review/language/en.php (modified) (history)
  • /trunk/extensions/Review/review.css (modified) (history)

Diff [purge]

Index: trunk/extensions/Review/language/en.php
@@ -23,7 +23,8 @@
2424 'review_sidebar_you_have_other_reviews_for_this_article' => "You have already reviewed other versions of this article. Your other ratings will be merged into this one where you selected 'no opinion'.",
2525 'review_page_link' => "review statistics",
2626 'review_sidebar_final' => "For review data of this page view, see its $1",
27 - 'review_for_page' => "Review for \"$1\"",
 27+ 'review_for_page' => "Review for page \"$1\"",
 28+ 'review_for_user' => "Review for user \"$1\"",
2829 'review_error' => "Something's wrong!",
2930 'review_no_reviews_for_page' => "There are currently no reviews for \"$1\".",
3031 'review_total_statistics' => "Total",
@@ -32,6 +33,11 @@
3334 'review_statistic_cell' => "Average: $1 of $2<br/>($4 users, $5 anons)",
3435 'review_version_statistic_cell' => "$1 of $2",
3536 'review_version_reviews_link' => "<small>(version reviews)</small>",
 37+ 'review_concerns_page' => "This review is about the page \"$1\".",
 38+ 'review_concerns_user' => "This is about reviews by user \"$1\".",
 39+ 'review_user_reviews' => "<small>(reviews by this user)</small>",
 40+ 'review_user_page_list' => "The user reviewed the following pages:",
 41+ 'review_user_details_link' => "(details)",
3642 )
3743 );
3844 ?>
Index: trunk/extensions/Review/Review.php
@@ -168,7 +168,6 @@
169169 # Create the revision array, if necessary
170170 if ( !isset ( $ret[$line->val_revision] ) )
171171 $ret[$line->val_revision] = array () ;
172 -
173172 # Store the data
174173 $ret[$line->val_revision][$line->val_type] = $line ;
175174 }
@@ -349,7 +348,7 @@
350349 <?php
351350 }
352351 print "<input type='hidden' name='review_oldid' value='{$revision}'/>" ;
353 - print "<div style='text-align:right'><input type='submit' name='save_review' value='" . wfMsgForContent('review_save') . "'/></div>" ;
 352+ print "<input style='width:100%' type='submit' name='save_review' value='" . wfMsgForContent('review_save') . "'/>" ;
354353 print "<div id='review_sidebar_note'>" ;
355354 print wfMsgForContent ( 'review_sidebar_explanation' ) ;
356355 if ( count ( $ratings ) > 1 ) {
@@ -482,7 +481,7 @@
483482 }
484483
485484 /**
486 - * Returns a HTML table row for the statistics of a revision
 485+ * Returns a HTML table row for the statistics of a revision. Output heavy!
487486 * @param $title The page
488487 * @param $revision The revision ID (or -1 for table header, 0 for total statistics)
489488 * @param $data The data for this revision
@@ -496,7 +495,7 @@
497496 # Row header
498497 $ret = "<tr><th id='review_statistics_table_header' align='left' nowrap>" ;
499498 if ( $revision < 0 ) {
500 - # Table headers
 499+ # Table headersconcerns
501500 if ( $revision == -1 ) {
502501 $ret .= wfMsgForContent ( 'review_statistics_left_corner' ) ;
503502 } else {
@@ -513,15 +512,20 @@
514513 $ak = array_keys ( $data ) ;
515514 $k = array_shift ( $ak ) ;
516515 if ( $data[$k]->val_user == 0 ) {
517 - #$user = User::newFromName ( $data[$k]->val_ip ) ;
518516 $user = new User ;
519517 $user->setName ( $data[$k]->val_ip ) ;
 518+ $user_reviews = "user_ip=" . $data[$k]->val_ip ;
520519 } else {
521520 $user = new User ;
522521 $user->setID ( $data[$k]->val_user ) ;
523522 $user->loadFromDatabase() ;
 523+ $user_reviews = "user_id=" . $data[$k]->val_user ;
524524 }
525525 $ret .= $skin->makeLinkObj ( $user->getUserPage() , $user->getName() ) ;
 526+ $ret .= "<br/>" ;
 527+ $ret .= $skin->makeLinkObj ( $wgTitle ,
 528+ wfMsgForContent('review_user_reviews') ,
 529+ "mode=view_user_reviews&{$user_reviews}" ) ;
526530 } else {
527531 # Individual revision
528532 $page_id = $title->getArticleID() ;
@@ -535,7 +539,7 @@
536540 foreach ( $wgReviewExtensionTopics AS $type => $topic ) {
537541 if ( $revision < 0 ) {
538542 # Table header row
539 - $ret .= "<th id='review_statistics_table_header' nowrap>" ;
 543+ $ret .= "<th id='review_statistics_table_header'>" ;
540544 $ret .= $topic->name ;
541545 $ret .= "</th>" ;
542546 } else if ( $revision_mode ) {
@@ -594,10 +598,30 @@
595599 }
596600
597601 /**
 602+ */
 603+ function get_list_of_pages_reviewed_by_user ( $user ) {
 604+ $conds = array () ;
 605+ wfReviewExtensionSetUserCondition ( $user , $conds ) ;
 606+ $dbr =& wfGetDB( DB_SLAVE );
 607+ $res = $dbr->select(
 608+ /* FROM */ 'validate',
 609+ /* SELECT */ 'DISTINCT val_page',
 610+ /* WHERE */ $conds,
 611+ $fname
 612+ );
 613+
 614+ $ret = array() ;
 615+ while ( $line = $dbr->fetchObject( $res ) ) {
 616+ $ret[] = $line->val_page ;
 617+ }
 618+ return $ret ;
 619+ }
 620+
 621+ /**
598622 * Special page main function
599623 */
600624 function execute( $par = null ) {
601 - global $wgRequest , $wgOut , $wgUser ;
 625+ global $wgRequest , $wgOut , $wgUser , $wgTitle ;
602626 wfReviewExtensionInitMessages () ;
603627
604628 $out = "" ;
@@ -605,18 +629,43 @@
606630 $mode = $wgRequest->getText ( 'mode' , "" ) ;
607631 $page_id = $wgRequest->getInt ( 'page_id' , 0 ) ;
608632 $rev_id = $wgRequest->getInt ( 'rev_id' , 0 ) ;
 633+ $user_id = $wgRequest->getInt ( 'user_id' , 0 ) ;
 634+ $user_ip = $wgRequest->getText ( 'user_ip' , "" ) ;
609635 $error = false ;
 636+
 637+ if ( $user_id != 0 OR $user_ip != "" ) {
 638+ $theuser = new User ;
 639+ if ( $user_id == 0 ) {
 640+ $theuser->setName ( $user_ip ) ;
 641+ } else {
 642+ $theuser->setID ( $user_id ) ;
 643+ $theuser->loadFromDatabase() ;
 644+ }
 645+ }
610646
611647 if ( $page_id == 0 ) {
612 - $title = new Title ;
613 - $error = true ;
 648+ $title = NULL ;
614649 } else {
615650 $title = Title::newFromID ( $page_id ) ;
616651 }
617652
618 - if ( $error ) {
619 - # Do nothing
620 - } else if ( $mode == 'view_page_statistics' ) {
 653+ # Info ahead
 654+ $o = array () ;
 655+ if ( $page_id != 0 ) {
 656+ $link = $skin->makeLinkObj( $title ) ;
 657+ $o[] = wfMsgForContent ( 'review_concerns_page' , $link ) ;
 658+ }
 659+ if ( isset ( $theuser ) ) {
 660+ $link = $skin->makeLinkObj ( $theuser->getUserPage() , $theuser->getName() ) ;
 661+ $o[] = wfMsgForContent ( 'review_concerns_user' , $link ) ;
 662+ }
 663+ if ( count ( $o ) > 0 ) {
 664+ $out .= "<ul><li>" . implode ( "</li>\n<li>" , $o ) . "</li></ul>" ;
 665+ }
 666+
 667+ # Modes
 668+ if ( $mode == 'view_page_statistics' ) {
 669+ # View statistics for one page
621670 $revisions = $this->get_reviewed_revisions ( $title ) ;
622671 arsort ( $revisions ) ; # Newest first
623672 if ( count ( $revisions ) == 0 ) {
@@ -636,18 +685,63 @@
637686 $out .= $out2 ;
638687 $out .= "</table>\n" ;
639688 }
 689+ $page_title = wfMsgForContent ( 'review_for_page' , $title->getPrefixedText() ) ;
640690 } else if ( $mode == 'view_version_statistics' ) {
641 - $data = array () ;
 691+ # View statistics for a specific version of a page
 692+ $data = array () ;
 693+ $out .= "<table id='review_statistics_table'>\n" ;
 694+ $out .= $this->get_revision_statistics_row ( $title , -2 , $data ) ;
 695+ $reviews = $this->get_reviews_for_revision ( $title , $rev_id ) ;
 696+ $this->analyze_review_data ( $title , $rev_id , $reviews , $data ) ;
 697+ $out .= $this->get_revision_statistics_row ( $title , 0 , $data ) ; # Statistics for the revision
 698+ $data = $this->group_data_by_user ( $reviews ) ;
 699+ foreach ( $data AS $entry ) {
 700+ $out .= $this->get_revision_statistics_row ( $title , 1 , $entry , true ) ;
 701+ }
 702+ $out .= "</table>\n" ;
 703+ $page_title = wfMsgForContent ( 'review_for_page' , $title->getPrefixedText() ) ;
 704+ } else if ( $mode == 'view_user_reviews' AND isset ( $theuser ) ) {
 705+ if ( $page_id != 0 ) {
 706+ # View the reviews of a user for a specific page
 707+ $revisions = wfReviewExtensionGetUserRatingsForPage ( $title , $theuser ) ;
 708+ print count ( $revisions ) ;
 709+
 710+ $statistics = array() ;
642711 $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 ) ;
 712+ $out .= $this->get_revision_statistics_row ( $title , -1 , $statistics ) ;
 713+ $out2 = "" ;
 714+ foreach ( $revisions AS $revision => $reviews ) {
 715+ $data = $this->analyze_review_data ( $title , $revision , $reviews , $statistics ) ;
 716+ $out2 .= $this->get_revision_statistics_row ( $title , $revision , $data ) ;
650717 }
 718+ $out .= $this->get_revision_statistics_row ( $title , 0 , $statistics ) ;
 719+ $out .= $out2 ;
651720 $out .= "</table>\n" ;
 721+
 722+
 723+ } else {
 724+ # View the pages reviewed by a user
 725+ $data = $this->get_list_of_pages_reviewed_by_user ( $theuser ) ;
 726+ $out .= "<h2>" . wfMsgForContent ( 'review_user_page_list' ) . "</h2>\n" ;
 727+ $data2 = array () ;
 728+ if ( $user_id == 0 )
 729+ $user_link = "user_ip=".$user_ip ;
 730+ else
 731+ $user_link = "user_id=".$user_id ;
 732+ foreach ( $data AS $pid ) {
 733+ $t = Title::newFromID ( $pid ) ;
 734+ $link1 = $skin->makeLinkObj ( $t ) ;
 735+ $link2 = $skin->makeLinkObj ( $wgTitle ,
 736+ wfMsgForContent('review_user_details_link') ,
 737+ "mode=view_user_reviews&" . $user_link . "&page_id={$pid}"
 738+ ) ;
 739+ $data2[] = $link1 . " " . $link2 ;
 740+ }
 741+ asort ( $data2 ) ;
 742+ if ( count ( $data2 ) > 0 )
 743+ $out .= "<ol><li>" . implode ( "</li>\n<li>" , $data2 ) . "</li></ul>" ;
 744+ }
 745+ $page_title = wfMsgForContent ( 'review_for_user' , $theuser->getName() ) ;
652746 } else {
653747 $error = true ;
654748 }
@@ -656,7 +750,7 @@
657751 if ( $error ) {
658752 $wgOut->addHtml( wfMsgForContent ( 'review_error' ) );
659753 } else {
660 - $wgOut->setPageTitle ( wfMsgForContent ( 'review_for_page' , $title->getPrefixedText() ) ) ;
 754+ $wgOut->setPageTitle ( $page_title ) ;
661755 $wgOut->addHtml( $out );
662756 }
663757 }
Index: trunk/extensions/Review/review.css
@@ -1,4 +1,3 @@
2 -
32 #review_sidebar_range {
43 font-size:80%;
54 }

Status & tagging log