Show change tags on diffs
authorMatmaRex <matma.rex@gmail.com>
Sat, 6 Jul 2013 20:53:27 +0000 (22:53 +0200)
committerMatmaRex <matma.rex@gmail.com>
Sat, 6 Jul 2013 21:02:31 +0000 (23:02 +0200)
This adds two very simple queries for every diff page view.

It could be made to only add one (loading tags for both revisions at
once), but it would be a little ugly.

It could even be made to add zero, but this would require either
rewriting and duplicating a lot of code here and constructing
Revisions by hand or making the Revision itself know about its tags.

Bug: 25824
Bug: 49602
Change-Id: Ic2ae58c703db7ceee5de4b320229d8c93810a73b

includes/diff/DifferenceEngine.php

index 975d490..4c2de4e 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 ) ) {
@@ -1141,6 +1146,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;
        }