Last modified: 2009-01-17 17:03:45 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T8692, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 6692 - time() and timestamps might become inconsistent during parsing
time() and timestamps might become inconsistent during parsing
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
unspecified
All All
: Normal minor (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks: 6693
  Show dependency treegraph
 
Reported: 2006-07-15 15:15 UTC by William Allen Simpson
Modified: 2009-01-17 17:03 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
same as in original description, hopefully with everything intact (2.30 KB, patch)
2006-07-15 15:19 UTC, William Allen Simpson
Details

Description William Allen Simpson 2006-07-15 15:15:57 UTC
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 @@
 	# Temporary
 	# 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 ) {
Comment 1 William Allen Simpson 2006-07-15 15:19:17 UTC
Created attachment 2088 [details]
same as in original description, hopefully with everything intact
Comment 2 Aaron Schulz 2009-01-17 17:03:45 UTC
As of 1.14, I only see two harmless instances of time() in the "scary" template fetch code

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links