Merge "DateTimeInputWidget: Fix UI/UX glitches"
[lhc/web/wiklou.git] / includes / api / ApiQueryDeletedrevs.php
index 2d50741..8540190 100644 (file)
@@ -20,6 +20,9 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\NameTableAccessException;
+
 /**
  * Query module to enumerate all deleted revisions.
  *
@@ -128,11 +131,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                }
 
                if ( $fld_tags ) {
-                       $this->addTables( 'tag_summary' );
-                       $this->addJoinConds(
-                               [ 'tag_summary' => [ 'LEFT JOIN', [ 'ar_rev_id=ts_rev_id' ] ] ]
-                       );
-                       $this->addFields( 'ts_tags' );
+                       $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'archive' ) ] );
                }
 
                if ( !is_null( $params['tag'] ) ) {
@@ -140,21 +139,21 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        $this->addJoinConds(
                                [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ]
                        );
-                       $this->addWhereFld( 'ct_tag', $params['tag'] );
+                       $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
+                       try {
+                               $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
+                       } catch ( NameTableAccessException $exception ) {
+                               // Return nothing.
+                               $this->addWhere( '1=0' );
+                       }
                }
 
                if ( $fld_content ) {
-                       // Modern MediaWiki has the content for deleted revs in the 'text'
-                       // table using fields old_text and old_flags. But revisions deleted
-                       // pre-1.5 store the content in the 'archive' table directly using
-                       // fields ar_text and ar_flags, and no corresponding 'text' row. So
-                       // we have to LEFT JOIN and fetch all four fields, plus ar_text_id
-                       // to be able to tell the difference.
                        $this->addTables( 'text' );
                        $this->addJoinConds(
                                [ 'text' => [ 'LEFT JOIN', [ 'ar_text_id=old_id' ] ] ]
                        );
-                       $this->addFields( [ 'ar_text', 'ar_flags', 'ar_text_id', 'old_text', 'old_flags' ] );
+                       $this->addFields( [ 'ar_text_id', 'old_text', 'old_flags' ] );
 
                        // This also means stricter restrictions
                        $this->checkUserRightsAny( [ 'deletedtext', 'undelete' ] );
@@ -370,12 +369,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                                        $anyHidden = true;
                                }
                                if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_TEXT, $user ) ) {
-                                       if ( isset( $row->ar_text ) && !$row->ar_text_id ) {
-                                               // Pre-1.5 ar_text row (if condition from Revision::newFromArchiveRow)
-                                               ApiResult::setContentValue( $rev, 'text', Revision::getRevisionText( $row, 'ar_' ) );
-                                       } else {
-                                               ApiResult::setContentValue( $rev, 'text', Revision::getRevisionText( $row ) );
-                                       }
+                                       ApiResult::setContentValue( $rev, 'text', Revision::getRevisionText( $row ) );
                                }
                        }