wiki.techinc.nl/includes/parser/Hook/ParserOutputPostCacheTransformHook.php
Timo Tijhof 01f3efe4ff Hook: Mark abortable=false hooks as void
* Remove the mention of 'return true' being legal.
  This is only allowed for compat with code from before MW 1.21,
  when I added hook aborting as well as tolerance for null to
  be the same as true.

  Since then, there is no reason to return null or return true.
  For early returns, an explicitly void 'return;' should be used
  instead. Returning anything else like null/true serves no purpose
  other than to confuse the reader.

* Mark the interfaces as natively 'void' with return type hints.

  This means in core code that runs the hook, static analysis
  like Phan and in IDEs, it will be known that these onFoo()s
  never return a value, thus allowing them to detect if its
  return value is assigned or used in a conditional for any
  reason, which can be an easy mistake.

  It also means that in the future when extensions start using
  these interfaces in 'implements' statement, they will be
  required to mark their hooks as void.

  That migration is opt-in and still up ahead. This is not
  a breaking change even for all existing extensions where
  a return true/null may exist in an abortable hook since this
  only applies to code directly typed against the interface.
  The internal run() method doesn't care.

Change-Id: Ib79289bd486ac97cec492e72f9a8dee70cf2f6c2
2020-06-22 19:07:35 +00:00

26 lines
641 B
PHP

<?php
namespace MediaWiki\Hook;
use ParserOutput;
/**
* @stable for implementation
* @ingroup Hooks
*/
interface ParserOutputPostCacheTransformHook {
/**
* This hook is called from ParserOutput::getText() to do
* post-cache transforms.
*
* @since 1.35
*
* @param ParserOutput $parserOutput
* @param string &$text Text being transformed, before core transformations are done
* @param array &$options Options array being used for the transformation
* @return void This hook must not abort, it must return no value
*/
public function onParserOutputPostCacheTransform( $parserOutput, &$text,
&$options
) : void;
}