diff: Display "(No difference)" instead of an empty diff
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index c551107..6657667 100644 (file)
@@ -38,6 +38,7 @@ class DifferenceEngine extends ContextSource {
         * @private
         */
        var $mOldid, $mNewid;
+       var $mOldTags, $mNewTags;
        /**
         * @var Content
         */
@@ -302,12 +303,14 @@ class DifferenceEngine extends ContextSource {
 
                        $ldel = $this->revisionDeleteLink( $this->mOldRev );
                        $oldRevisionHeader = $this->getRevisionHeader( $this->mOldRev, 'complete' );
+                       $oldChangeTags = ChangeTags::formatSummaryRow( $this->mOldTags, 'diff' );
 
                        $oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' .
                                '<div id="mw-diff-otitle2">' .
                                        Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '</div>' .
                                '<div id="mw-diff-otitle3">' . $oldminor .
                                        Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
+                               '<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
                                '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
 
                        if ( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
@@ -353,12 +356,14 @@ class DifferenceEngine extends ContextSource {
                        $formattedRevisionTools[] = $this->msg( 'parentheses' )->rawParams( $tool )->escaped();
                }
                $newRevisionHeader = $this->getRevisionHeader( $this->mNewRev, 'complete' ) . ' ' . implode( ' ', $formattedRevisionTools );
+               $newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff' );
 
                $newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
                        '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
                                " $rollback</div>" .
                        '<div id="mw-diff-ntitle3">' . $newminor .
                                Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
+                       '<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
                        '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
 
                if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
@@ -410,8 +415,7 @@ class DifferenceEngine extends ContextSource {
         * @return String
         */
        protected function markPatrolledLink() {
-               global $wgUseRCPatrol, $wgRCMaxAge;
-               $cache = wfGetMainCache();
+               global $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
 
                if ( $this->mMarkPatrolledLink === null ) {
                        // Prepare a change patrol link, if applicable
@@ -420,9 +424,7 @@ class DifferenceEngine extends ContextSource {
                                $wgUseRCPatrol && $this->mNewPage->quickUserCan( 'patrol', $this->getUser() ) &&
                                // Only do this if the revision isn't more than 6 hours older
                                // than the Max RC age (6h because the RC might not be cleaned out regularly)
-                               RecentChange::isInRCLifespan( $this->mNewRev->getTimestamp(), 21600 ) &&
-                               // Maybe the result is cached
-                               !$cache->get( wfMemcKey( 'NotPatrollableRevId', $this->mNewid ) )
+                               RecentChange::isInRCLifespan( $this->mNewRev->getTimestamp(), 21600 )
                        ) {
                                // Look for an unpatrolled change corresponding to this diff
 
@@ -431,7 +433,6 @@ class DifferenceEngine extends ContextSource {
                                        array(
                                                'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ),
                                                'rc_this_oldid' => $this->mNewid,
-                                               'rc_last_oldid' => $this->mOldid,
                                                'rc_patrolled' => 0
                                        ),
                                        __METHOD__,
@@ -447,7 +448,11 @@ class DifferenceEngine extends ContextSource {
                                // Build the link
                                if ( $rcid ) {
                                        $this->getOutput()->preventClickjacking();
-                                       $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' );
+                                       if ( $wgEnableAPI && $wgEnableWriteAPI
+                                               && $this->getUser()->isAllowed( 'writeapi' )
+                                       ) {
+                                               $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' );
+                                       }
 
                                        $token = $this->getUser()->getEditToken( $rcid );
                                        $this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
@@ -461,7 +466,6 @@ class DifferenceEngine extends ContextSource {
                                                )
                                        ) . ']</span>';
                                } else {
-                                       $cache->set( wfMemcKey( 'NotPatrollableRevId', $this->mNewid ), '1', $wgRCMaxAge );
                                        $this->mMarkPatrolledLink = '';
                                }
                        } else {
@@ -606,6 +610,13 @@ class DifferenceEngine extends ContextSource {
                        return false;
                } else {
                        $multi = $this->getMultiNotice();
+                       // Display a message when the diff is empty
+                       if ( $body === '' ) {
+                               if ( $multi !== '' ) {
+                                       $multi .= '<br />';
+                               }
+                               $multi .= $this->msg( 'diff-empty' )->parse();
+                       }
                        return $this->addHeader( $body, $otitle, $ntitle, $multi, $notice );
                }
        }
@@ -995,11 +1006,13 @@ class DifferenceEngine extends ContextSource {
                                $colspan = 1;
                                $multiColspan = 2;
                        }
-                       $header .= "
-                       <tr style='vertical-align: top;'>
-                       <td colspan='$colspan' class='diff-otitle'>{$otitle}</td>
-                       <td colspan='$colspan' class='diff-ntitle'>{$ntitle}</td>
-                       </tr>";
+                       if ( $otitle || $ntitle ) {
+                               $header .= "
+                               <tr style='vertical-align: top;'>
+                               <td colspan='$colspan' class='diff-otitle'>{$otitle}</td>
+                               <td colspan='$colspan' class='diff-ntitle'>{$ntitle}</td>
+                               </tr>";
+                       }
                }
 
                if ( $multi != '' ) {
@@ -1140,6 +1153,25 @@ class DifferenceEngine extends ContextSource {
                        $this->mOldPage = $this->mOldRev->getTitle();
                }
 
+               // Load tags information for both revisions
+               $dbr = wfGetDB( DB_SLAVE );
+               if ( $this->mOldid !== false ) {
+                       $this->mOldTags = $dbr->selectField(
+                               'tag_summary',
+                               'ts_tags',
+                               array( 'ts_rev_id' => $this->mOldid ),
+                               __METHOD__
+                       );
+               } else {
+                       $this->mOldTags = false;
+               }
+               $this->mNewTags = $dbr->selectField(
+                       'tag_summary',
+                       'ts_tags',
+                       array( 'ts_rev_id' => $this->mNewid ),
+                       __METHOD__
+               );
+
                return true;
        }