From ec46c467874de0f1814955f1cba31398b9b56f04 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 24 Mar 2018 06:32:58 -0700 Subject: [PATCH] Reduce impact of revision day/month/year variables on edit stashing Change-Id: I0ddebdfa8a13844ab003aad577624e89daba7d6b --- includes/parser/Parser.php | 65 +++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 2ccd4ce387..4e39537d8b 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -138,6 +138,9 @@ class Parser { const TOC_START = ''; const TOC_END = ''; + /** @var int Assume that no output will later be saved this many seconds after parsing */ + const MAX_TTS = 900; + # Persistent: public $mTagHooks = []; public $mTransparentTagHooks = []; @@ -2652,39 +2655,19 @@ class Parser { } break; case 'revisionday': - # Let the edit saving system know we should parse the page - # *after* a revision ID has been assigned. This is for null edits. - $this->mOutput->setFlag( 'vary-revision' ); - wfDebug( __METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n" ); - $value = intval( substr( $this->getRevisionTimestamp(), 6, 2 ) ); + $value = (int)$this->getRevisionTimestampSubstring( 6, 2, self::MAX_TTS, $index ); break; case 'revisionday2': - # Let the edit saving system know we should parse the page - # *after* a revision ID has been assigned. This is for null edits. - $this->mOutput->setFlag( 'vary-revision' ); - wfDebug( __METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n" ); - $value = substr( $this->getRevisionTimestamp(), 6, 2 ); + $value = $this->getRevisionTimestampSubstring( 6, 2, self::MAX_TTS, $index ); break; case 'revisionmonth': - # Let the edit saving system know we should parse the page - # *after* a revision ID has been assigned. This is for null edits. - $this->mOutput->setFlag( 'vary-revision' ); - wfDebug( __METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n" ); - $value = substr( $this->getRevisionTimestamp(), 4, 2 ); + $value = $this->getRevisionTimestampSubstring( 4, 2, self::MAX_TTS, $index ); break; case 'revisionmonth1': - # Let the edit saving system know we should parse the page - # *after* a revision ID has been assigned. This is for null edits. - $this->mOutput->setFlag( 'vary-revision' ); - wfDebug( __METHOD__ . ": {{REVISIONMONTH1}} used, setting vary-revision...\n" ); - $value = intval( substr( $this->getRevisionTimestamp(), 4, 2 ) ); + $value = (int)$this->getRevisionTimestampSubstring( 4, 2, self::MAX_TTS, $index ); break; case 'revisionyear': - # Let the edit saving system know we should parse the page - # *after* a revision ID has been assigned. This is for null edits. - $this->mOutput->setFlag( 'vary-revision' ); - wfDebug( __METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n" ); - $value = substr( $this->getRevisionTimestamp(), 0, 4 ); + $value = $this->getRevisionTimestampSubstring( 0, 4, self::MAX_TTS, $index ); break; case 'revisiontimestamp': # Let the edit saving system know we should parse the page @@ -2842,6 +2825,38 @@ class Parser { return $value; } + /** + * @param int $start + * @param int $len + * @param int $mtts Max time-till-save; sets vary-revision if result might change by then + * @param string $variable Parser variable name + * @return string + */ + private function getRevisionTimestampSubstring( $start, $len, $mtts, $variable ) { + global $wgContLang; + + # Get the timezone-adjusted timestamp to be used for this revision + $resNow = substr( $this->getRevisionTimestamp(), $start, $len ); + # Possibly set vary-revision if there is not yet an associated revision + if ( !$this->getRevisionObject() ) { + # Get the timezone-adjusted timestamp $mtts seconds in the future + $resThen = substr( + $wgContLang->userAdjust( wfTimestamp( TS_MW, time() + $mtts ), '' ), + $start, + $len + ); + + if ( $resNow !== $resThen ) { + # Let the edit saving system know we should parse the page + # *after* a revision ID has been assigned. This is for null edits. + $this->mOutput->setFlag( 'vary-revision' ); + wfDebug( __METHOD__ . ": $variable used, setting vary-revision...\n" ); + } + } + + return $resNow; + } + /** * initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers * -- 2.20.1