From f2e3c4d09fdf55b6778766b50c405d00120e1ee3 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 6 Aug 2018 20:48:15 +0300 Subject: [PATCH] Give pages with ~~~~ a different cache TTL This was supposed to already be the case, but it wasn't. The flag that was set got cleared and never did anything. Change-Id: Ide960f8cb9228f9a9d68c540369f122ada0a2a6f --- includes/content/WikitextContent.php | 23 ++++++++++++++++++- .../includes/content/WikitextContentTest.php | 15 ++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index 21947d2061..a7021b1e7b 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -35,6 +35,12 @@ use MediaWiki\MediaWikiServices; class WikitextContent extends TextContent { private $redirectTargetAndText = null; + /** + * @var bool Tracks if the parser set the user-signature flag when creating this content, which + * would make it expire faster in ApiStashEdit. + */ + private $hadSignature = false; + public function __construct( $text ) { parent::__construct( $text, CONTENT_MODEL_WIKITEXT ); } @@ -140,7 +146,17 @@ class WikitextContent extends TextContent { $text = $this->getNativeData(); $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts ); - return ( $text === $pst ) ? $this : new static( $pst ); + if ( $text === $pst ) { + return $this; + } + + $ret = new static( $pst ); + + if ( $wgParser->getOutput()->getFlag( 'user-signature' ) ) { + $ret->hadSignature = true; + } + + return $ret; } /** @@ -337,6 +353,11 @@ class WikitextContent extends TextContent { $output->addModuleStyles( 'mediawiki.action.view.redirectPage' ); } } + + // Pass along user-signature flag + if ( $this->hadSignature ) { + $output->setFlag( 'user-signature' ); + } } /** diff --git a/tests/phpunit/includes/content/WikitextContentTest.php b/tests/phpunit/includes/content/WikitextContentTest.php index 687c7e034c..91255eb0f5 100644 --- a/tests/phpunit/includes/content/WikitextContentTest.php +++ b/tests/phpunit/includes/content/WikitextContentTest.php @@ -442,4 +442,19 @@ just a test" // @todo more...? ]; } + + /** + * @covers WikitextContent::preSaveTransform + * @covers WikitextContent::fillParserOutput + */ + public function testHadSignature() { + $titleObj = Title::newFromText( __CLASS__ ); + + $content = new WikitextContent( '~~~~' ); + $pstContent = $content->preSaveTransform( + $titleObj, $this->getTestUser()->getUser(), new ParserOptions() + ); + + $this->assertTrue( $pstContent->getParserOutput( $titleObj )->getFlag( 'user-signature' ) ); + } } -- 2.20.1