Migrate SpecialUndelete and Diff from tag_summary to change_tag
authorAmir Sarabadani <Ladsgroup@gmail.com>
Tue, 27 Nov 2018 17:48:18 +0000 (18:48 +0100)
committerAmir Sarabadani <Ladsgroup@gmail.com>
Mon, 3 Dec 2018 17:07:11 +0000 (18:07 +0100)
There is some code duplication that should be factored into ChangeTags
but it can be done later.

Bug: T209525
Change-Id: Ie929d541754634a7be15cbb87da1d9db1f05bf0c

includes/diff/DifferenceEngine.php
includes/specials/SpecialUndelete.php

index 8d0971e..c198876 100644 (file)
  * @ingroup DifferenceEngine
  */
 
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Revision\RevisionRecord;
 use MediaWiki\Revision\SlotRecord;
+use MediaWiki\Storage\NameTableAccessException;
 
 /**
  * DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
@@ -1797,22 +1799,42 @@ class DifferenceEngine extends ContextSource {
 
                // Load tags information for both revisions
                $dbr = wfGetDB( DB_REPLICA );
+               $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
                if ( $this->mOldid !== false ) {
-                       $this->mOldTags = $dbr->selectField(
-                               'tag_summary',
-                               'ts_tags',
-                               [ 'ts_rev_id' => $this->mOldid ],
+                       $tagIds = $dbr->selectFieldValues(
+                               'change_tag',
+                               'ct_tag_id',
+                               [ 'ct_rev_id' => $this->mOldid ],
                                __METHOD__
                        );
+                       $tags = [];
+                       foreach ( $tagIds as $tagId ) {
+                               try {
+                                       $tags[] = $changeTagDefStore->getName( (int)$tagId );
+                               } catch ( NameTableAccessException $exception ) {
+                                       continue;
+                               }
+                       }
+                       $this->mOldTags = implode( ',', $tags );
                } else {
                        $this->mOldTags = false;
                }
-               $this->mNewTags = $dbr->selectField(
-                       'tag_summary',
-                       'ts_tags',
-                       [ 'ts_rev_id' => $this->mNewid ],
+
+               $tagIds = $dbr->selectFieldValues(
+                       'change_tag',
+                       'ct_tag_id',
+                       [ 'ct_rev_id' => $this->mNewid ],
                        __METHOD__
                );
+               $tags = [];
+               foreach ( $tagIds as $tagId ) {
+                       try {
+                               $tags[] = $changeTagDefStore->getName( (int)$tagId );
+                       } catch ( NameTableAccessException $exception ) {
+                               continue;
+                       }
+               }
+               $this->mNewTags = implode( ',', $tags );
 
                return true;
        }
index 6a01b0c..cd754ca 100644 (file)
@@ -23,6 +23,7 @@
 
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Revision\RevisionRecord;
+use MediaWiki\Storage\NameTableAccessException;
 use Wikimedia\Rdbms\IResultWrapper;
 
 /**
@@ -596,12 +597,22 @@ class SpecialUndelete extends SpecialPage {
 
                $minor = $rev->isMinor() ? ChangesList::flag( 'minor' ) : '';
 
-               $tags = wfGetDB( DB_REPLICA )->selectField(
-                       'tag_summary',
-                       'ts_tags',
-                       [ 'ts_rev_id' => $rev->getId() ],
+               $tagIds = wfGetDB( DB_REPLICA )->selectFieldValues(
+                       'change_tag',
+                       'ct_tag_id',
+                       [ 'ct_rev_id' => $rev->getId() ],
                        __METHOD__
                );
+               $tags = [];
+               $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
+               foreach ( $tagIds as $tagId ) {
+                       try {
+                               $tags[] = $changeTagDefStore->getName( (int)$tagId );
+                       } catch ( NameTableAccessException $exception ) {
+                               continue;
+                       }
+               }
+               $tags = implode( ',', $tags );
                $tagSummary = ChangeTags::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() );
 
                // FIXME This is reimplementing DifferenceEngine#getRevisionHeader