r85467 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85466‎ | r85467 | r85468 >
Date:20:42, 5 April 2011
Author:aaron
Status:resolved
Tags:
Comment:
* Cleanups to getFirstRevision and getEarliestTime
* Rewrote countRevisionsBetween/countAuthorsBetween to avoid assuming rev_id is in chronological order
* Made countAuthorsBetween use $limit+1 automatically for convenience; updated callers
Modified paths:
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedArticleView.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/diff/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/diff/DifferenceEngine.php
@@ -844,7 +844,7 @@
845845 $limit = 100;
846846 // We use ($limit + 1) so we can detect if there are > 100 authors
847847 // 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 );
849849 return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
850850 }
851851 return ''; // nothing
Index: trunk/phase3/includes/Title.php
@@ -3638,65 +3638,68 @@
36393639 * @return Revision|Null if page doesn't exist
36403640 */
36413641 public function getFirstRevision( $flags = 0 ) {
3642 - $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
36433642 $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+ }
36463653 }
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;
36573655 }
36583656
36593657 /**
3660 - * Check if this is a new page
 3658+ * Get the oldest revision timestamp of this page
36613659 *
3662 - * @return bool
 3660+ * @param $flags Int Title::GAID_FOR_UPDATE
 3661+ * @return String: MW timestamp
36633662 */
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;
36673666 }
36683667
36693668 /**
3670 - * Get the oldest revision timestamp of this page
 3669+ * Check if this is a new page
36713670 *
3672 - * @return String: MW timestamp
 3671+ * @return bool
36733672 */
3674 - public function getEarliestRevTime() {
 3673+ public function isNewPage() {
36753674 $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__ );
36843676 }
36853677
36863678 /**
3687 - * Get the number of revisions between the given revision IDs.
 3679+ * Get the number of revisions between the given revision.
36883680 * Used for diffs and other things that really need it.
36893681 *
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.
36933685 */
36943686 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+ }
36953696 $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__
37013704 );
37023705 }
37033706
@@ -3704,23 +3707,31 @@
37053708 * Get the number of authors between the given revision IDs.
37063709 * Used for diffs and other things that really need it.
37073710 *
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)
37103713 * @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.
37133715 */
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',
37173728 array(
37183729 '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() ) )
37213732 ), __METHOD__,
3722 - array( 'LIMIT' => $limit )
 3733+ array( 'LIMIT' => $limit + 1 ) // add one so caller knows it was truncated
37233734 );
3724 - return (int)$db->numRows( $res );
 3735+ return (int)$dbr->numRows( $res );
37253736 }
37263737
37273738 /**
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedArticleView.php
@@ -776,8 +776,9 @@
777777 if ( strlen( $diffBody ) > 0 ) {
778778 $nEdits = $revsSince - 1; // full diff-to-stable, no need for query
779779 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 );
782783 } else {
783784 $multiNotice = '';
784785 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r85490Follow up r85467: changed some countRevisionsBetween/countAuthorsBetween call...aaron23:28, 5 April 2011

Status & tagging log