Add LinkRenderer (rewrite of Linker::link())
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 21 Apr 2016 20:13:21 +0000 (13:13 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Mon, 23 May 2016 19:00:09 +0000 (12:00 -0700)
commit67e62c0b25e991843043794770c02f9392d28fe1
tree8364e0e8aeab4e3da64b30d54b83f177f0363758
parent1f7d032f8309fe60561c1f085bc8bf6f03786299
Add LinkRenderer (rewrite of Linker::link())

This is a rewrite of Linker::link() to a non-static, LinkTarget-based
interface. Users of plain Linker::link() with no options can use the
LinkRenderer instance provided by MediaWikiServices. Others that
have specific options should create and configure their own instance,
which can be used to create as many links as necessary.

The main entrypoints for making links are:
* ->makeLink( $target, $text, $attribs, $query );
* ->makeKnownLink( $target, $text, $attribs, $query );
* ->makeBrokenLink( $target, $text, $attribs, $query );

The order of the parameters are the same as Linker::link(), except
$options are now part of the LinkRenderer instance, and
known/broken status requires calling the function explicitly.
Additionally, instead of passing in raw $html for the link text, the
$text parameter will automatically be escaped unless it is specially
marked as safe HTML using the MediaWiki\Linker\HtmlArmor class.

The LinkBegin and LinkEnd hooks are now deprecated, but still function
for backwards-compatability. Clients should migrate to the nearly-
equivalent LinkRendererBegin and LinkRendererEnd hooks.
The main differences between the hooks are:
* Passing HtmlPageLinkRenderer object instead of deprecated DummyLinker
* Using LinkTarget instead of Title
* Begin hook can no longer change known/broken status of link. Use the
TitleIsAlwaysKnown hook for that.
* $options are no longer passed, they can be read (but shouldn't be
modified!) from the LinkRenderer object.

Bug: T469
Change-Id: I057cc86ae6404a080aa3c8e0e956ecbb10a897d5
13 files changed:
autoload.php
docs/hooks.txt
includes/Linker.php
includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/libs/HtmlArmor.php [new file with mode: 0644]
includes/linker/LinkRenderer.php [new file with mode: 0644]
includes/linker/LinkRendererFactory.php [new file with mode: 0644]
tests/parser/parserTest.inc
tests/phpunit/includes/MediaWikiServicesTest.php
tests/phpunit/includes/libs/HtmlArmorTest.php [new file with mode: 0644]
tests/phpunit/includes/linker/LinkRendererFactoryTest.php [new file with mode: 0644]
tests/phpunit/includes/linker/LinkRendererTest.php [new file with mode: 0644]