r76924 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76923‎ | r76924 | r76925 >
Date:00:08, 18 November 2010
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* Moved author count check to new Title::countAuthorsBetween() function
* Added static DifferenceEngine::intermediateEditsMsg() function
* diff-multi msg use by FlaggedRevs wasn't updated after $2 param was added. Fixed this.
* Minor cleanups to getMultiNotice()
Modified paths:
  • /trunk/extensions/FlaggedRevs/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
@@ -798,12 +798,12 @@
799799
800800 /**
801801 * If there are revisions between the ones being compared, return a note saying so.
 802+ * @return string
802803 */
803804 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 ) ) {
808808 // Comparing two different pages? Count would be meaningless.
809809 return '';
810810 }
@@ -814,37 +814,35 @@
815815 $tmp = $oldid; $oldid = $newid; $newid = $tmp;
816816 }
817817
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 ) {
828820 $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 );
846825 }
 826+ return ''; // nothing
847827 }
848828
 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+ }
849847
850848 /**
851849 * Add the header to a diff body
Index: trunk/phase3/includes/Title.php
@@ -3715,6 +3715,29 @@
37163716 }
37173717
37183718 /**
 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+ /**
37193742 * Compare with another title.
37203743 *
37213744 * @param $title \type{Title}
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -719,13 +719,20 @@
720720 $diffEngine = new DifferenceEngine( $this->article->getTitle() );
721721 $diffEngine->showDiffStyle();
722722 $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+ }
724731 $items = array();
725732 $diffHtml =
726733 FlaggedRevsXML::pendingEditNotice( $this->article, $srev, $revsSince ) .
727734 ' ' . FlaggedRevsXML::diffToggle() .
728735 "<div id='mw-fr-stablediff'>" .
729 - self::getFormattedDiff( $diffBody, $n, $leftNote, $rightNote ) .
 736+ self::getFormattedDiff( $diffBody, $multiNotice, $leftNote, $rightNote ) .
730737 "</div>\n";
731738 $items[] = $diffHtml;
732739 $html = "<table class='flaggedrevs_viewnotice plainlinks'>";
@@ -741,12 +748,12 @@
742749 }
743750
744751 // $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 != '' ) {
747756 $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>";
751758 }
752759 return
753760 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
@@ -920,7 +927,7 @@
921928 wfMsgExt( 'review-edit-diff', 'parseinline' ) . ' ' .
922929 FlaggedRevsXML::diffToggle() .
923930 "<div id='mw-fr-stablediff'>" .
924 - self::getFormattedDiff( $diffBody, false, $leftNote, $rightNote ) .
 931+ self::getFormattedDiff( $diffBody, '', $leftNote, $rightNote ) .
925932 "</div>\n";
926933 $items[] = $diffHtml;
927934 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r77114MFT r76866, r76895, r76902, r76924-r77113demon21:18, 22 November 2010

Comments

#Comment by Platonides (talk | contribs)   16:33, 18 November 2010

Looks good.

#Comment by Aaron Schulz (talk | contribs)   19:06, 18 November 2010

Well, intermediateEditsMsg() sounds funny :)

Status & tagging log