wiki.techinc.nl/includes/parser/Hook/ParserGetVariableValueTsHook.php
C. Scott Ananian b72fa830d6 Pass a ConvertibleTimestamp to CoreMagicVariables
This avoids a type mismatch found by phan strict checks
(Ifc7fc64ac26a756f181b7d0155f13a6500114f5e) -- the passed timestamp
from Parser was a string in unix format (ie, an integer as a string)
but was declared as an integer.  It was then passed to
MWTimestamp::getInstance() which expected a string.

However, the 'simple' fix for this issue still caused unnecessary
conversions to/from timestamp format.  We took the string (nominally
in TS_MW format), ran a regexp against it to convert it to an
MWTimestamp instance, then converted that MWTimestamp to UNIX format
and exported that as a string, just to take that string and run four
different regexps against it *again* to convert it back to an
MWTimestamp instance so we can format it.

Better to just pass the MWTimestamp directly.  Only two wrinkles:

1. the ParserGetVariableValueTs hook expects to be passed a string
in TS_UNIX format and then to be able to mutate it. Nothing in production
uses that hook, so only do this conversion if the hook is registered.

2. Parsoid would like to use the definitions in CoreMagicVariables
in the future as well.  So pass the timestamp as the not-MW-@internal
ConvertibleTimestamp class instead of directly as a MWTimestamp.

Change-Id: Ib2c5fa45630c54c2716897370a0580ed48d27242
2022-03-14 17:30:15 -04:00

26 lines
690 B
PHP

<?php
namespace MediaWiki\Hook;
use Parser;
/**
* This is a hook handler interface, see docs/Hooks.md.
* Use the hook name "ParserGetVariableValueTs" to register handlers implementing this interface.
*
* @stable to implement
* @ingroup Hooks
*/
interface ParserGetVariableValueTsHook {
/**
* Use this hook to change the value of the time for time-related
* magic words, ie {{CURRENTMONTH}}, {{LOCALMONTH}}, etc.
*
* @since 1.35
*
* @param Parser $parser
* @param string &$time Actual time (timestamp) in TS_UNIX format
* @return bool|void True or no return value to continue or false to abort
*/
public function onParserGetVariableValueTs( $parser, &$time );
}