*/
/**
- * Fetch an option, generically
+ * Fetch an option and track that is was accessed
* @since 1.30
* @param string $name Option name
* @return mixed
throw new InvalidArgumentException( "Unknown parser option $name" );
}
- if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
- $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
- }
+ $this->lazyLoadOption( $name );
if ( !empty( self::$inCacheKey[$name] ) ) {
$this->optionUsed( $name );
}
return $this->options[$name];
}
+ /**
+ * @param string $name Lazy load option without tracking usage
+ */
+ private function lazyLoadOption( $name ) {
+ if ( isset( self::$lazyOptions[$name] ) && $this->options[$name] === null ) {
+ $this->options[$name] = call_user_func( self::$lazyOptions[$name], $this, $name );
+ }
+ }
+
/**
* Set an option, generically
* @since 1.30
/**
* Timestamp used for {{CURRENTDAY}} etc.
- * @return string
+ * @return string TS_MW timestamp
*/
public function getTimestamp() {
if ( !isset( $this->mTimestamp ) ) {
* @since 1.25
*/
public function matches( ParserOptions $other ) {
- // Populate lazy options
- foreach ( self::$lazyOptions as $name => $callback ) {
- if ( $this->options[$name] === null ) {
- $this->options[$name] = call_user_func( $callback, $this, $name );
- }
- if ( $other->options[$name] === null ) {
- $other->options[$name] = call_user_func( $callback, $other, $name );
- }
- }
-
// Compare most options
$options = array_keys( $this->options );
$options = array_diff( $options, [
'enableLimitReport', // only affects HTML comments
] );
foreach ( $options as $option ) {
+ // Resolve any lazy options
+ $this->lazyLoadOption( $option );
+ $other->lazyLoadOption( $option );
+
$o1 = $this->optionToString( $this->options[$option] );
$o2 = $this->optionToString( $other->options[$option] );
if ( $o1 !== $o2 ) {
return true;
}
+ /**
+ * @param ParserOptions $other
+ * @return bool Whether the cache key relevant options match those of $other
+ * @since 1.33
+ */
+ public function matchesForCacheKey( ParserOptions $other ) {
+ foreach ( self::allCacheVaryingOptions() as $option ) {
+ // Populate any lazy options
+ $this->lazyLoadOption( $option );
+ $other->lazyLoadOption( $option );
+
+ $o1 = $this->optionToString( $this->options[$option] );
+ $o2 = $this->optionToString( $other->options[$option] );
+ if ( $o1 !== $o2 ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
/**
* Registers a callback for tracking which ParserOptions which are used.
* This is a private API with the parser.
}
}
- /**
- * Returns the full array of options that would have been used by
- * in 1.16.
- * Used to get the old parser cache entries when available.
- * @deprecated since 1.30. You probably want self::allCacheVaryingOptions() instead.
- * @return string[]
- */
- public static function legacyOptions() {
- wfDeprecated( __METHOD__, '1.30' );
- return [
- 'stubthreshold',
- 'numberheadings',
- 'userlang',
- 'thumbsize',
- 'editsection',
- 'printable'
- ];
- }
-
/**
* Return all option keys that vary the options hash
* @since 1.30
$inCacheKey = self::allCacheVaryingOptions();
// Resolve any lazy options
- foreach ( array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) ) as $k ) {
- if ( $this->options[$k] === null ) {
- $this->options[$k] = call_user_func( self::$lazyOptions[$k], $this, $k );
- }
+ $lazyOpts = array_intersect( $forOptions, $inCacheKey, array_keys( self::$lazyOptions ) );
+ foreach ( $lazyOpts as $k ) {
+ $this->lazyLoadOption( $k );
}
$options = $this->options;