Page MenuHomePhabricator

time() and timestamps might become inconsistent during parsing
Closed, DeclinedPublic

Description

Author: William.Allen.Simpson

Description:
As the page is parsed, the time() can be accessed over and over. This can lead
to inconsistency of time-based template names, and other errors.

The fix is simple, a per parse $mRunTime.

(I also grouped a few of the variable access functions in one place as I was
trying to figure out the existing code, so they were easier to find, and added
some missing function header block comments for them.)

  • Parser.php Fri Jul 14 01:28:01 2006

+++ xParser.php Sat Jul 15 10:42:19 2006
@@ -117,9 +117,10 @@

    1. Temporary
    2. These are variables reset at least once per parse regardless of $clearState var $mOptions, // ParserOptions object
  • $mTitle, Title context, used for self-link rendering and similar things $mOutputType, Output type, one of the OT_xxx constants
  • $mRevisionId; // ID to display in {{REVISIONID}} tags

+ $mRevisionId, ID to display in {{REVISIONID}} tags
+ $mRunTime,
constant time() used for parse
+ $mTitle; // Title context, used for self-link rendering and similar things

	/**#@-*/

@@ -210,6 +211,7 @@

			'titles' => array()
		);
		$this->mRevisionId = null;

+ $this->mRunTime = time();

		
		/**
		 * Prefix for temporary replacement strings for the multipass parser.

@@ -231,6 +233,26 @@

	}

	/**

+ * Accessors for Temporary variables.
+ *
+ * @public
+ */
+ function getRunTime() { return $this->mRunTime; }
+ function &getTitle() { return $this->mTitle; }
+
+ /
+ * Accessors for Temporary Options variables.
+ *
+ * @public
+ */
+ function getOptions() { return $this->mOptions; }
+
+ function getFunctionLang() {
+ global $wgLang, $wgContLang;
+ return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang;
+ }
+
+ /

  • Accessor for mUniqPrefix. *
  • @public

@@ -273,6 +295,7 @@

			$this->mRevisionId = $revid;
		}
		$this->mOutputType = OT_HTML;

+ $this->mRunTime = time();

		//$text = $this->strip( $text, $this->mStripState );
		// VOODOO MAGIC FIX! Sometimes the above segfaults in PHP5.

@@ -368,14 +391,6 @@

		return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
	}
  • function &getTitle() { return $this->mTitle; }
  • function getOptions() { return $this->mOptions; } -
  • function getFunctionLang() {
  • global $wgLang, $wgContLang;
  • return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang;
  • } - /**
    • Replaces all occurrences of HTML-style comments and the given tags
    • in the text with a random marker and returns teh next text. The output

@@ -2213,7 +2228,7 @@

			if ( isset( $varCache[$index] ) )
				return $varCache[$index];
  • $ts = time();

+ $ts = $this->$mRunTime();

		wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );

		switch ( $index ) {

Version: unspecified
Severity: minor

Details

Reference
bz6692

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:21 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz6692.
bzimport added a subscriber: Unknown Object (MLST).

William.Allen.Simpson wrote:

same as in original description, hopefully with everything intact

Attached:

As of 1.14, I only see two harmless instances of time() in the "scary" template fetch code