Index: trunk/phase3/includes/diff/DifferenceEngine.php |
— | — | @@ -798,12 +798,12 @@ |
799 | 799 | |
800 | 800 | /** |
801 | 801 | * If there are revisions between the ones being compared, return a note saying so. |
| 802 | + * @return string |
802 | 803 | */ |
803 | 804 | function getMultiNotice() { |
804 | | - if ( !is_object($this->mOldRev) || !is_object($this->mNewRev) ) |
805 | | - return ''; |
806 | | - |
807 | | - if( !$this->mOldPage->equals( $this->mNewPage ) ) { |
| 805 | + if ( !is_object( $this->mOldRev ) || !is_object( $this->mNewRev ) ) { |
| 806 | + return ''; |
| 807 | + } elseif ( !$this->mOldPage->equals( $this->mNewPage ) ) { |
808 | 808 | // Comparing two different pages? Count would be meaningless. |
809 | 809 | return ''; |
810 | 810 | } |
— | — | @@ -814,37 +814,35 @@ |
815 | 815 | $tmp = $oldid; $oldid = $newid; $newid = $tmp; |
816 | 816 | } |
817 | 817 | |
818 | | - $n = $this->mTitle->countRevisionsBetween( $oldid, $newid ); |
819 | | - if ( !$n ) { |
820 | | - return ''; |
821 | | - } else { |
822 | | - global $wgLang; |
823 | | - $dbr = wfGetDB( DB_SLAVE ); |
824 | | - |
825 | | - // Actually, the limit is $limit + 1. We do this so we can detect |
826 | | - // if there are > 100 authors in a given revision range. If they |
827 | | - // are, $limit will be passed to diff-multi-manyusers for l10n. |
| 818 | + $nEdits = $this->mTitle->countRevisionsBetween( $oldid, $newid ); |
| 819 | + if ( $nEdits> 0 ) { |
828 | 820 | $limit = 100; |
829 | | - $res = $dbr->select( 'revision', 'DISTINCT rev_user_text', |
830 | | - array( |
831 | | - 'rev_page = ' . $this->mOldRev->getPage(), |
832 | | - 'rev_id > ' . $this->mOldRev->getId(), |
833 | | - 'rev_id < ' . $this->mNewRev->getId() |
834 | | - ), __METHOD__, |
835 | | - array( 'LIMIT' => $limit + 1 ) |
836 | | - ); |
837 | | - $numUsers = $dbr->numRows( $res ); |
838 | | - if( $numUsers > $limit ) { |
839 | | - $msg = 'diff-multi-manyusers'; |
840 | | - $numUsers = $limit; |
841 | | - } else { |
842 | | - $msg = 'diff-multi'; |
843 | | - } |
844 | | - return wfMsgExt( $msg, array( 'parseinline' ), $wgLang->formatnum( $n ), |
845 | | - $wgLang->formatnum( $numUsers ) ); |
| 821 | + // We use ($limit + 1) so we can detect if there are > 100 authors |
| 822 | + // in a given revision range. In that case, diff-multi-manyusers is used. |
| 823 | + $numUsers = $this->mTitle->countAuthorsBetween( $oldid, $newid, $limit+1 ); |
| 824 | + return self::intermediateEditsMsg( $nEdits, $numUsers, $limit ); |
846 | 825 | } |
| 826 | + return ''; // nothing |
847 | 827 | } |
848 | 828 | |
| 829 | + /** |
| 830 | + * Get a notice about how many intermediate edits and users there are |
| 831 | + * @param $numEdits int |
| 832 | + * @param $numUsers int |
| 833 | + * @param $limit int |
| 834 | + * @return string |
| 835 | + */ |
| 836 | + public static function intermediateEditsMsg( $numEdits, $numUsers, $limit ) { |
| 837 | + global $wgLang; |
| 838 | + if ( $numUsers > $limit ) { |
| 839 | + $msg = 'diff-multi-manyusers'; |
| 840 | + $numUsers = $limit; |
| 841 | + } else { |
| 842 | + $msg = 'diff-multi'; |
| 843 | + } |
| 844 | + return wfMsgExt( $msg, 'parseinline', |
| 845 | + $wgLang->formatnum( $numEdits ), $wgLang->formatnum( $numUsers ) ); |
| 846 | + } |
849 | 847 | |
850 | 848 | /** |
851 | 849 | * Add the header to a diff body |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -3715,6 +3715,29 @@ |
3716 | 3716 | } |
3717 | 3717 | |
3718 | 3718 | /** |
| 3719 | + * Get the number of authors between the given revision IDs. |
| 3720 | + * Used for diffs and other things that really need it. |
| 3721 | + * |
| 3722 | + * @param $fromRevId \type{\int} Revision ID (first before range) |
| 3723 | + * @param $toRevId \type{\int} Revision ID (first after range) |
| 3724 | + * @param $limit \type{\int} Maximum number of authors |
| 3725 | + * @param $flags \type{\int} Title::GAID_FOR_UPDATE |
| 3726 | + * @return \type{\int} |
| 3727 | + */ |
| 3728 | + public function countAuthorsBetween( $fromRevId, $toRevId, $limit, $flags = 0 ) { |
| 3729 | + $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
| 3730 | + $res = $db->select( 'revision', 'DISTINCT rev_user_text', |
| 3731 | + array( |
| 3732 | + 'rev_page = ' . $this->getArticleID(), |
| 3733 | + 'rev_id > ' . (int)$fromRevId, |
| 3734 | + 'rev_id < ' . (int)$toRevId |
| 3735 | + ), __METHOD__, |
| 3736 | + array( 'LIMIT' => $limit ) |
| 3737 | + ); |
| 3738 | + return (int)$db->numRows( $res ); |
| 3739 | + } |
| 3740 | + |
| 3741 | + /** |
3719 | 3742 | * Compare with another title. |
3720 | 3743 | * |
3721 | 3744 | * @param $title \type{Title} |
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php |
— | — | @@ -719,13 +719,20 @@ |
720 | 720 | $diffEngine = new DifferenceEngine( $this->article->getTitle() ); |
721 | 721 | $diffEngine->showDiffStyle(); |
722 | 722 | $diffBody = $diffEngine->generateDiffBody( $oText, $nText ); |
723 | | - $n = $revsSince - 1; // this is the full diff-to-stable |
| 723 | + $nEdits = $revsSince - 1; // full diff-to-stable, no need for query |
| 724 | + if ( $nEdits ) { |
| 725 | + $nUsers = $this->article->getTitle()->countAuthorsBetween( |
| 726 | + $this->article->getStable(), $latest, 101 ); |
| 727 | + $multiNotice = DifferenceEngine::intermediateEditsMsg( $nEdits, $nUsers, 100 ); |
| 728 | + } else { |
| 729 | + $multiNotice = ''; |
| 730 | + } |
724 | 731 | $items = array(); |
725 | 732 | $diffHtml = |
726 | 733 | FlaggedRevsXML::pendingEditNotice( $this->article, $srev, $revsSince ) . |
727 | 734 | ' ' . FlaggedRevsXML::diffToggle() . |
728 | 735 | "<div id='mw-fr-stablediff'>" . |
729 | | - self::getFormattedDiff( $diffBody, $n, $leftNote, $rightNote ) . |
| 736 | + self::getFormattedDiff( $diffBody, $multiNotice, $leftNote, $rightNote ) . |
730 | 737 | "</div>\n"; |
731 | 738 | $items[] = $diffHtml; |
732 | 739 | $html = "<table class='flaggedrevs_viewnotice plainlinks'>"; |
— | — | @@ -741,12 +748,12 @@ |
742 | 749 | } |
743 | 750 | |
744 | 751 | // $n number of in-between revs |
745 | | - protected static function getFormattedDiff( $diffBody, $n, $leftStatus, $rightStatus ) { |
746 | | - if ( $n ) { |
| 752 | + protected static function getFormattedDiff( |
| 753 | + $diffBody, $multiNotice, $leftStatus, $rightStatus |
| 754 | + ) { |
| 755 | + if ( $multiNotice != '' ) { |
747 | 756 | $multiNotice = "<tr><td colspan='4' align='center' class='diff-multi'>" . |
748 | | - wfMsgExt( 'diff-multi', array( 'parse' ), $n ) . "</td></tr>"; |
749 | | - } else { |
750 | | - $multiNotice = ''; |
| 757 | + $multiNotice . "</td></tr>"; |
751 | 758 | } |
752 | 759 | return |
753 | 760 | "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" . |
— | — | @@ -920,7 +927,7 @@ |
921 | 928 | wfMsgExt( 'review-edit-diff', 'parseinline' ) . ' ' . |
922 | 929 | FlaggedRevsXML::diffToggle() . |
923 | 930 | "<div id='mw-fr-stablediff'>" . |
924 | | - self::getFormattedDiff( $diffBody, false, $leftNote, $rightNote ) . |
| 931 | + self::getFormattedDiff( $diffBody, '', $leftNote, $rightNote ) . |
925 | 932 | "</div>\n"; |
926 | 933 | $items[] = $diffHtml; |
927 | 934 | } |