Stop calling FileRepo->streamFile()
[lhc/web/wiklou.git] / includes / specials / SpecialUndelete.php
index a93dec0..456face 100644 (file)
@@ -23,6 +23,7 @@
 
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Revision\RevisionRecord;
+use MediaWiki\Storage\NameTableAccessException;
 use Wikimedia\Rdbms\IResultWrapper;
 
 /**
@@ -94,7 +95,8 @@ class SpecialUndelete extends SpecialPage {
                $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
                $this->mToken = $request->getVal( 'token' );
 
-               if ( $this->isAllowed( 'undelete' ) && !$user->isBlocked() ) {
+               $block = $user->getBlock();
+               if ( $this->isAllowed( 'undelete' ) && !( $block && $block->isSitewide() ) ) {
                        $this->mAllowed = true; // user can restore
                        $this->mCanView = true; // user can view content
                } elseif ( $this->isAllowed( 'deletedtext' ) ) {
@@ -198,7 +200,7 @@ class SpecialUndelete extends SpecialPage {
                        } else {
                                $this->showFile( $this->mFilename );
                        }
-               } elseif ( $this->mAction === "submit" ) {
+               } elseif ( $this->mAction === 'submit' ) {
                        if ( $this->mRestore ) {
                                $this->undelete();
                        } elseif ( $this->mRevdel ) {
@@ -222,13 +224,14 @@ class SpecialUndelete extends SpecialPage {
                foreach ( $this->getRequest()->getValues() as $key => $val ) {
                        $matches = [];
                        if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
-                               $revisions[ $archive->getRevision( $matches[1] )->getId() ] = 1;
+                               $revisions[$archive->getRevision( $matches[1] )->getId()] = 1;
                        }
                }
+
                $query = [
-                       "type" => "revision",
-                       "ids" => $revisions,
-                       "target" => $this->mTargetObj->getPrefixedText()
+                       'type' => 'revision',
+                       'ids' => $revisions,
+                       'target' => $this->mTargetObj->getPrefixedText()
                ];
                $url = SpecialPage::getTitleFor( 'Revisiondelete' )->getFullURL( $query );
                $this->getOutput()->redirect( $url );
@@ -347,7 +350,13 @@ class SpecialUndelete extends SpecialPage {
                                );
                        }
                        $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count )->parse();
-                       $out->addHTML( "<li class='undeleteResult'>{$item} ({$revs})</li>\n" );
+                       $out->addHTML(
+                               Html::rawElement(
+                                       'li',
+                                       [ 'class' => 'undeleteResult' ],
+                                       "{$item} ({$revs})"
+                               )
+                       );
                }
                $result->free();
                $out->addHTML( "</ul>\n" );
@@ -443,8 +452,12 @@ class SpecialUndelete extends SpecialPage {
                        }
                }
 
-               $out->addHTML( $this->msg( 'undelete-revision' )->rawParams( $link )->params(
-                       $time )->rawParams( $userLink )->params( $d, $t )->parse() . '</div>' );
+               $out->addWikiMsg(
+                       'undelete-revision',
+                       Message::rawParam( $link ), $time,
+                       Message::rawParam( $userLink ), $d, $t
+               );
+               $out->addHTML( '</div>' );
 
                if ( !Hooks::run( 'UndeleteShowRevision', [ $this->mTargetObj, $rev ] ) ) {
                        return;
@@ -482,7 +495,7 @@ class SpecialUndelete extends SpecialPage {
                                'readonly' => 'readonly',
                                'cols' => 80,
                                'rows' => 25
-                       ], $content->getNativeData() . "\n" );
+                       ], $content->getText() . "\n" );
 
                        $buttonFields[] = new OOUI\ButtonInputWidget( [
                                'type' => 'submit',
@@ -491,7 +504,6 @@ class SpecialUndelete extends SpecialPage {
                        ] );
                } else {
                        $sourceView = '';
-                       $previewButton = '';
                }
 
                $buttonFields[] = new OOUI\ButtonInputWidget( [
@@ -537,7 +549,6 @@ class SpecialUndelete extends SpecialPage {
         *
         * @param Revision $previousRev
         * @param Revision $currentRev
-        * @return string HTML
         */
        function showDiff( $previousRev, $currentRev ) {
                $diffContext = clone $this->getContext();
@@ -545,15 +556,9 @@ class SpecialUndelete extends SpecialPage {
                $diffContext->setWikiPage( WikiPage::factory( $currentRev->getTitle() ) );
 
                $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine( $diffContext );
+               $diffEngine->setRevisions( $previousRev->getRevisionRecord(), $currentRev->getRevisionRecord() );
                $diffEngine->showDiffStyle();
-
-               $formattedDiff = $diffEngine->generateContentDiffBody(
-                       $previousRev->getContent( Revision::FOR_THIS_USER, $this->getUser() ),
-                       $currentRev->getContent( Revision::FOR_THIS_USER, $this->getUser() )
-               );
-
-               $formattedDiff = $diffEngine->addHeader(
-                       $formattedDiff,
+               $formattedDiff = $diffEngine->getDiff(
                        $this->diffHeader( $previousRev, 'o' ),
                        $this->diffHeader( $currentRev, 'n' )
                );
@@ -592,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
@@ -672,7 +687,7 @@ class SpecialUndelete extends SpecialPage {
 
                $repo = RepoGroup::singleton()->getLocalRepo();
                $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
-               $repo->streamFile( $path );
+               $repo->streamFileWithStatus( $path );
        }
 
        protected function showHistory() {
@@ -754,9 +769,6 @@ class SpecialUndelete extends SpecialPage {
                                'content' => new OOUI\HtmlSnippet( $this->msg( 'undeleteextrahelp' )->parseAsBlock() )
                        ] );
 
-                       $conf = $this->getConfig();
-                       $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
-
                        $fields[] = new OOUI\FieldLayout(
                                new OOUI\TextInputWidget( [
                                        'name' => 'wpComment',
@@ -766,8 +778,8 @@ class SpecialUndelete extends SpecialPage {
                                        'autofocus' => true,
                                        // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
                                        // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
-                                       // Unicode codepoints (or 255 UTF-8 bytes for old schema).
-                                       'maxLength' => $oldCommentSchema ? 255 : CommentStore::COMMENT_CHARACTER_LIMIT,
+                                       // Unicode codepoints.
+                                       'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
                                ] ),
                                [
                                        'label' => $this->msg( 'undeletecomment' )->text(),
@@ -1169,7 +1181,7 @@ class SpecialUndelete extends SpecialPage {
                        }
 
                        $link = $this->getLinkRenderer()->makeKnownLink( $this->mTargetObj );
-                       $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
+                       $out->addWikiMsg( 'undeletedpage', Message::rawParam( $link ) );
                } else {
                        $out->setPageTitle( $this->msg( 'undelete-error' ) );
                }