From 5174fa8364c95ac8df9d076dbec51b70e086e01a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Mon, 1 Oct 2018 18:33:28 -0700 Subject: [PATCH] Add audience parameter to PoolWorkArticleView The old behavior was that the audience was RAW if the revision object parameter got passed in, otherwise PUBLIC. This was undocumented and not used outside core; this patch gets rid of it in favor of an explicit argument. Bug: T205578 Change-Id: Ic7cdb38f658f6d85c48ff13c7f84c64a45c9b1ee --- includes/page/Article.php | 4 ++- includes/poolcounter/PoolWorkArticleView.php | 11 ++++++-- .../phpunit/includes/page/ArticleViewTest.php | 28 +++++++++++++++++++ .../poolcounter/PoolWorkArticleViewTest.php | 4 +++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/includes/page/Article.php b/includes/page/Article.php index b6f5dce946..4a689d318a 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -767,7 +767,9 @@ class Article implements Page { $parserOptions, $this->getRevIdFetched(), $useParserCache, - $rev + $rev, + // permission checking was done earlier via showDeletedRevisionHeader() + RevisionRecord::RAW ); $ok = $poolArticleView->execute(); $error = $poolArticleView->getError(); diff --git a/includes/poolcounter/PoolWorkArticleView.php b/includes/poolcounter/PoolWorkArticleView.php index 157b5087f0..6e6a574074 100644 --- a/includes/poolcounter/PoolWorkArticleView.php +++ b/includes/poolcounter/PoolWorkArticleView.php @@ -44,6 +44,9 @@ class PoolWorkArticleView extends PoolCounterWork { /** @var RevisionRecord|null */ private $revision = null; + /** @var int */ + private $audience; + /** @var RevisionStore */ private $revisionStore = null; @@ -67,9 +70,10 @@ class PoolWorkArticleView extends PoolCounterWork { * 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(); @@ -108,6 +112,7 @@ class PoolWorkArticleView extends PoolCounterWork { $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' ); @@ -152,8 +157,8 @@ class PoolWorkArticleView extends PoolCounterWork { $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; diff --git a/tests/phpunit/includes/page/ArticleViewTest.php b/tests/phpunit/includes/page/ArticleViewTest.php index d07a9e1400..629621e605 100644 --- a/tests/phpunit/includes/page/ArticleViewTest.php +++ b/tests/phpunit/includes/page/ArticleViewTest.php @@ -298,6 +298,34 @@ class ArticleViewTest extends MediaWikiTestCase { $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__ ); diff --git a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php index a0beb4569a..47adfc00f0 100644 --- a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php +++ b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php @@ -164,6 +164,10 @@ class PoolWorkArticleViewTest extends MediaWikiTestCase { $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 ); -- 2.20.1