Index: trunk/phase3/includes/diff/DifferenceEngine.php |
— | — | @@ -844,7 +844,7 @@ |
845 | 845 | $limit = 100; |
846 | 846 | // We use ($limit + 1) so we can detect if there are > 100 authors |
847 | 847 | // in a given revision range. In that case, diff-multi-manyusers is used. |
848 | | - $numUsers = $this->mTitle->countAuthorsBetween( $oldid, $newid, $limit + 1 ); |
| 848 | + $numUsers = $this->mTitle->countAuthorsBetween( $oldid, $newid, $limit ); |
849 | 849 | return self::intermediateEditsMsg( $nEdits, $numUsers, $limit ); |
850 | 850 | } |
851 | 851 | return ''; // nothing |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -3638,65 +3638,68 @@ |
3639 | 3639 | * @return Revision|Null if page doesn't exist |
3640 | 3640 | */ |
3641 | 3641 | public function getFirstRevision( $flags = 0 ) { |
3642 | | - $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
3643 | 3642 | $pageId = $this->getArticleId( $flags ); |
3644 | | - if ( !$pageId ) { |
3645 | | - return null; |
| 3643 | + if ( $pageId ) { |
| 3644 | + $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
| 3645 | + $row = $db->selectRow( 'revision', '*', |
| 3646 | + array( 'rev_page' => $pageId ), |
| 3647 | + __METHOD__, |
| 3648 | + array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 ) |
| 3649 | + ); |
| 3650 | + if ( $row ) { |
| 3651 | + return new Revision( $row ); |
| 3652 | + } |
3646 | 3653 | } |
3647 | | - $row = $db->selectRow( 'revision', '*', |
3648 | | - array( 'rev_page' => $pageId ), |
3649 | | - __METHOD__, |
3650 | | - array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 ) |
3651 | | - ); |
3652 | | - if ( !$row ) { |
3653 | | - return null; |
3654 | | - } else { |
3655 | | - return new Revision( $row ); |
3656 | | - } |
| 3654 | + return null; |
3657 | 3655 | } |
3658 | 3656 | |
3659 | 3657 | /** |
3660 | | - * Check if this is a new page |
| 3658 | + * Get the oldest revision timestamp of this page |
3661 | 3659 | * |
3662 | | - * @return bool |
| 3660 | + * @param $flags Int Title::GAID_FOR_UPDATE |
| 3661 | + * @return String: MW timestamp |
3663 | 3662 | */ |
3664 | | - public function isNewPage() { |
3665 | | - $dbr = wfGetDB( DB_SLAVE ); |
3666 | | - return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ ); |
| 3663 | + public function getEarliestRevTime( $flags = 0 ) { |
| 3664 | + $rev = $this->getFirstRevision( $flags ); |
| 3665 | + return $rev ? $rev->getTimestamp() : null; |
3667 | 3666 | } |
3668 | 3667 | |
3669 | 3668 | /** |
3670 | | - * Get the oldest revision timestamp of this page |
| 3669 | + * Check if this is a new page |
3671 | 3670 | * |
3672 | | - * @return String: MW timestamp |
| 3671 | + * @return bool |
3673 | 3672 | */ |
3674 | | - public function getEarliestRevTime() { |
| 3673 | + public function isNewPage() { |
3675 | 3674 | $dbr = wfGetDB( DB_SLAVE ); |
3676 | | - if ( $this->exists() ) { |
3677 | | - $min = $dbr->selectField( 'revision', |
3678 | | - 'MIN(rev_timestamp)', |
3679 | | - array( 'rev_page' => $this->getArticleId() ), |
3680 | | - __METHOD__ ); |
3681 | | - return wfTimestampOrNull( TS_MW, $min ); |
3682 | | - } |
3683 | | - return null; |
| 3675 | + return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ ); |
3684 | 3676 | } |
3685 | 3677 | |
3686 | 3678 | /** |
3687 | | - * Get the number of revisions between the given revision IDs. |
| 3679 | + * Get the number of revisions between the given revision. |
3688 | 3680 | * Used for diffs and other things that really need it. |
3689 | 3681 | * |
3690 | | - * @param $old Int Revision ID. |
3691 | | - * @param $new Int Revision ID. |
3692 | | - * @return Int Number of revisions between these IDs. |
| 3682 | + * @param $old int|Revision Old revision or rev ID (first before range) |
| 3683 | + * @param $new int|Revision New revision or rev ID (first after range) |
| 3684 | + * @return Int Number of revisions between these revisions. |
3693 | 3685 | */ |
3694 | 3686 | public function countRevisionsBetween( $old, $new ) { |
| 3687 | + if ( !( $old instanceof Revision ) ) { |
| 3688 | + $old = Revision::newFromTitle( $this, (int)$old ); |
| 3689 | + } |
| 3690 | + if ( !( $new instanceof Revision ) ) { |
| 3691 | + $new = Revision::newFromTitle( $this, (int)$new ); |
| 3692 | + } |
| 3693 | + if ( !$old || !$new ) { |
| 3694 | + return 0; // nothing to compare |
| 3695 | + } |
3695 | 3696 | $dbr = wfGetDB( DB_SLAVE ); |
3696 | | - return (int)$dbr->selectField( 'revision', 'count(*)', array( |
3697 | | - 'rev_page' => intval( $this->getArticleId() ), |
3698 | | - 'rev_id > ' . intval( $old ), |
3699 | | - 'rev_id < ' . intval( $new ) |
3700 | | - ), __METHOD__ |
| 3697 | + return (int)$dbr->selectField( 'revision', 'count(*)', |
| 3698 | + array( |
| 3699 | + 'rev_page' => $this->getArticleId(), |
| 3700 | + 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $old->getTimestamp() ) ), |
| 3701 | + 'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $new->getTimestamp() ) ) |
| 3702 | + ), |
| 3703 | + __METHOD__ |
3701 | 3704 | ); |
3702 | 3705 | } |
3703 | 3706 | |
— | — | @@ -3704,23 +3707,31 @@ |
3705 | 3708 | * Get the number of authors between the given revision IDs. |
3706 | 3709 | * Used for diffs and other things that really need it. |
3707 | 3710 | * |
3708 | | - * @param $fromRevId Int Revision ID (first before range) |
3709 | | - * @param $toRevId Int Revision ID (first after range) |
| 3711 | + * @param $old int|Revision Old revision or rev ID (first before range) |
| 3712 | + * @param $new int|Revision New revision or rev ID (first after range) |
3710 | 3713 | * @param $limit Int Maximum number of authors |
3711 | | - * @param $flags Int Title::GAID_FOR_UPDATE |
3712 | | - * @return Int |
| 3714 | + * @return Int Number of revision authors between these revisions. |
3713 | 3715 | */ |
3714 | | - public function countAuthorsBetween( $fromRevId, $toRevId, $limit, $flags = 0 ) { |
3715 | | - $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
3716 | | - $res = $db->select( 'revision', 'DISTINCT rev_user_text', |
| 3716 | + public function countAuthorsBetween( $old, $new, $limit ) { |
| 3717 | + if ( !( $old instanceof Revision ) ) { |
| 3718 | + $old = Revision::newFromTitle( $this, (int)$old ); |
| 3719 | + } |
| 3720 | + if ( !( $new instanceof Revision ) ) { |
| 3721 | + $new = Revision::newFromTitle( $this, (int)$new ); |
| 3722 | + } |
| 3723 | + if ( !$old || !$new ) { |
| 3724 | + return 0; // nothing to compare |
| 3725 | + } |
| 3726 | + $dbr = wfGetDB( DB_SLAVE ); |
| 3727 | + $res = $dbr->select( 'revision', 'DISTINCT rev_user_text', |
3717 | 3728 | array( |
3718 | 3729 | 'rev_page' => $this->getArticleID(), |
3719 | | - 'rev_id > ' . (int)$fromRevId, |
3720 | | - 'rev_id < ' . (int)$toRevId |
| 3730 | + 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $old->getTimestamp() ) ), |
| 3731 | + 'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $new->getTimestamp() ) ) |
3721 | 3732 | ), __METHOD__, |
3722 | | - array( 'LIMIT' => $limit ) |
| 3733 | + array( 'LIMIT' => $limit + 1 ) // add one so caller knows it was truncated |
3723 | 3734 | ); |
3724 | | - return (int)$db->numRows( $res ); |
| 3735 | + return (int)$dbr->numRows( $res ); |
3725 | 3736 | } |
3726 | 3737 | |
3727 | 3738 | /** |
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedArticleView.php |
— | — | @@ -776,8 +776,9 @@ |
777 | 777 | if ( strlen( $diffBody ) > 0 ) { |
778 | 778 | $nEdits = $revsSince - 1; // full diff-to-stable, no need for query |
779 | 779 | if ( $nEdits ) { |
780 | | - $nUsers = $title->countAuthorsBetween( $srev->getRevId(), $latest, 101 ); |
781 | | - $multiNotice = DifferenceEngine::intermediateEditsMsg( $nEdits, $nUsers, 100 ); |
| 780 | + $limit = 100; |
| 781 | + $nUsers = $title->countAuthorsBetween( $srev->getRevId(), $latest, $limit ); |
| 782 | + $multiNotice = DifferenceEngine::intermediateEditsMsg( $nEdits, $nUsers, $limit ); |
782 | 783 | } else { |
783 | 784 | $multiNotice = ''; |
784 | 785 | } |