$parserOptions,
$this->getRevIdFetched(),
$useParserCache,
- $rev
+ $rev,
+ // permission checking was done earlier via showDeletedRevisionHeader()
+ RevisionRecord::RAW
);
$ok = $poolArticleView->execute();
$error = $poolArticleView->getError();
/** @var RevisionRecord|null */
private $revision = null;
+ /** @var int */
+ private $audience;
+
/** @var RevisionStore */
private $revisionStore = null;
* operation.
* @param RevisionRecord|Content|string|null $revision Revision to render, or null to load it;
* may also be given as a wikitext string, or a Content object, for BC.
+ * @param int $audience One of the RevisionRecord audience constants
*/
public function __construct( WikiPage $page, ParserOptions $parserOptions,
- $revid, $useParserCache, $revision = null
+ $revid, $useParserCache, $revision = null, $audience = RevisionRecord::FOR_PUBLIC
) {
if ( is_string( $revision ) ) { // BC: very old style call
$modelId = $page->getRevision()->getContentModel();
$this->cacheable = $useParserCache;
$this->parserOptions = $parserOptions;
$this->revision = $revision;
+ $this->audience = $audience;
$this->cacheKey = $this->parserCache->getKey( $page, $parserOptions );
$keyPrefix = $this->cacheKey ?: wfMemcKey( 'articleview', 'missingcachekey' );
$isCurrent = $this->revid === $this->page->getLatest();
- // Bypass audience check for current revision
- $audience = $isCurrent ? RevisionRecord::RAW : RevisionRecord::FOR_PUBLIC;
+ // The current revision cannot be hidden so we can skip some checks.
+ $audience = $isCurrent ? RevisionRecord::RAW : $this->audience;
if ( $this->revision !== null ) {
$rev = $this->revision;
$this->assertNotContains( 'Test B', $this->getHtml( $output ) );
}
+ public function testUnhiddenViewOfDeletedRevision() {
+ $revisions = [];
+ $page = $this->getPage( __METHOD__, [ 1 => 'Test A', 2 => 'Test B' ], $revisions );
+ $idA = $revisions[1]->getId();
+
+ $revDelList = new RevDelRevisionList(
+ RequestContext::getMain(), $page->getTitle(), [ $idA ]
+ );
+ $revDelList->setVisibility( [
+ 'value' => [ RevisionRecord::DELETED_TEXT => 1 ],
+ 'comment' => "Testing",
+ ] );
+
+ $article = new Article( $page->getTitle(), $idA );
+ $context = new DerivativeContext( $article->getContext() );
+ $article->setContext( $context );
+ $context->getOutput()->setTitle( $page->getTitle() );
+ $context->getRequest()->setVal( 'unhide', 1 );
+ $context->setUser( $this->getTestUser( [ 'sysop' ] )->getUser() );
+ $article->view();
+
+ $output = $article->getContext()->getOutput();
+ $this->assertContains( '(rev-deleted-text-view)', $this->getHtml( $output ) );
+
+ $this->assertContains( 'Test A', $this->getHtml( $output ) );
+ $this->assertNotContains( 'Test B', $this->getHtml( $output ) );
+ }
+
public function testViewMissingPage() {
$page = $this->getPage( __METHOD__ );
$work = new PoolWorkArticleView( $page, $options, $rev1->getId(), false, $fakeRev );
$this->assertFalse( $work->execute() );
+ $work = new PoolWorkArticleView( $page, $options, $rev1->getId(), false, $fakeRev,
+ RevisionRecord::RAW );
+ $this->assertNotFalse( $work->execute() );
+
// a deleted current revision should still be show
$fakeRev->setId( $rev2->getId() );
$work = new PoolWorkArticleView( $page, $options, $rev2->getId(), false, $fakeRev );