private static $lazyOptions = [
'dateformat' => [ __CLASS__, 'initDateFormat' ],
'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ],
+ 'speculativePageId' => [ __CLASS__, 'initSpeculativePageId' ],
];
/**
*/
private $mExtraKey = '';
- /**
- * @name Option accessors
- * @{
- */
-
/**
* Fetch an option and track that is was accessed
* @since 1.30
return $this->getOption( 'speculativeRevId' );
}
+ /**
+ * A guess for {{PAGEID}}, calculated using the callback provided via
+ * setSpeculativeRevPageCallback(). For consistency, the value will be calculated upon the
+ * first call of this method, and re-used for subsequent calls.
+ *
+ * If no callback was defined via setSpeculativePageIdCallback(), this method will return false.
+ *
+ * @since 1.34
+ * @return int|false
+ */
+ public function getSpeculativePageId() {
+ return $this->getOption( 'speculativePageId' );
+ }
+
/**
* Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativeRevId().
*
* @param ParserOptions $popt
- * @return bool|false
+ * @return int|false
*/
private static function initSpeculativeRevId( ParserOptions $popt ) {
$cb = $popt->getOption( 'speculativeRevIdCallback' );
}
/**
- * Callback to generate a guess for {{REVISIONID}}
- * @since 1.28
- * @deprecated since 1.32, use getSpeculativeRevId() instead!
- * @return callable|null
+ * Callback registered with ParserOptions::$lazyOptions, triggered by getSpeculativePageId().
+ *
+ * @param ParserOptions $popt
+ * @return int|false
*/
- public function getSpeculativeRevIdCallback() {
- return $this->getOption( 'speculativeRevIdCallback' );
+ private static function initSpeculativePageId( ParserOptions $popt ) {
+ $cb = $popt->getOption( 'speculativePageIdCallback' );
+ $id = $cb ? $cb() : null;
+
+ // returning null would result in this being re-called every access
+ return $id ?? false;
}
/**
* Callback to generate a guess for {{REVISIONID}}
- * @since 1.28
- * @param callable|null $x New value (null is no change)
+ * @param callable|null $x New value
* @return callable|null Old value
+ * @since 1.28
*/
public function setSpeculativeRevIdCallback( $x ) {
$this->setOption( 'speculativeRevId', null ); // reset
- return $this->setOptionLegacy( 'speculativeRevIdCallback', $x );
+ return $this->setOption( 'speculativeRevIdCallback', $x );
}
- /**@}*/
+ /**
+ * Callback to generate a guess for {{PAGEID}}
+ * @param callable|null $x New value
+ * @return callable|null Old value
+ * @since 1.34
+ */
+ public function setSpeculativePageIdCallback( $x ) {
+ $this->setOption( 'speculativePageId', null ); // reset
+ return $this->setOption( 'speculativePageIdCallback', $x );
+ }
/**
* Timestamp used for {{CURRENTDAY}} etc.
'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ],
'speculativeRevIdCallback' => null,
'speculativeRevId' => null,
+ 'speculativePageIdCallback' => null,
+ 'speculativePageId' => null,
];
Hooks::run( 'ParserOptionsRegister', [