MediaWiki REL1_40
MediaWiki\Linker\LinkRenderer Class Reference

Class that generates HTML for internal links. More...

Public Member Functions

 __construct (TitleFormatter $titleFormatter, LinkCache $linkCache, SpecialPageFactory $specialPageFactory, HookContainer $hookContainer, ServiceOptions $options)
 
 getExpandURLs ()
 
 getForceArticlePath ()
 
 getLinkClasses ( $target)
 Returns CSS classes to add to a known link.
 
 isForComment ()
 True when the links will be rendered in an edit summary or log comment.
 
 makeBrokenLink ( $target, $text=null, array $extraAttribs=[], array $query=[])
 Make a link that's styled as if the target page doesn't exist (a "red link").
 
 makeKnownLink ( $target, $text=null, array $extraAttribs=[], array $query=[])
 Make a link that's styled as if the target page exists (usually a "blue link", although the styling might depend on e.g.
 
 makeLink ( $target, $text=null, array $extraAttribs=[], array $query=[])
 Render a wikilink.
 
 makePreloadedLink ( $target, $text=null, $classes='', array $extraAttribs=[], array $query=[])
 Make a link that's styled as if the target page exists (a "blue link"), with a specified class attribute.
 
 normalizeTarget ( $target)
 Normalizes the provided target.
 
 setExpandURLs ( $expand)
 Whether/how to expand URLs.
 
 setForceArticlePath ( $force)
 Whether to force the link to use the article path ($wgArticlePath) even if a query string is present, resulting in URLs like /wiki/Main_Page?action=foobar.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Detailed Description

Class that generates HTML for internal links.

See the Linker class for other kinds of links.

See also
https://www.mediawiki.org/wiki/Manual:LinkRenderer
Since
1.28

Definition at line 44 of file LinkRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Linker\LinkRenderer::__construct ( TitleFormatter $titleFormatter,
LinkCache $linkCache,
SpecialPageFactory $specialPageFactory,
HookContainer $hookContainer,
ServiceOptions $options )
Access: internal
For use by LinkRendererFactory
Parameters
TitleFormatter$titleFormatter
LinkCache$linkCache
SpecialPageFactory$specialPageFactory
HookContainer$hookContainer
ServiceOptions$options

Definition at line 98 of file LinkRenderer.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), and MediaWiki\Config\ServiceOptions\get().

Member Function Documentation

◆ getExpandURLs()

MediaWiki\Linker\LinkRenderer::getExpandURLs ( )
Returns
string|bool|int a PROTO_* constant or false for no expansion
See also
setExpandURLs()

Definition at line 146 of file LinkRenderer.php.

◆ getForceArticlePath()

MediaWiki\Linker\LinkRenderer::getForceArticlePath ( )
Returns
bool
See also
setForceArticlePath()

Definition at line 128 of file LinkRenderer.php.

◆ getLinkClasses()

MediaWiki\Linker\LinkRenderer::getLinkClasses ( $target)

Returns CSS classes to add to a known link.

Note that most CSS classes set on wikilinks are actually handled elsewhere (e.g. in makeKnownLink() or in LinkHolderArray).

Parameters
LinkTarget | PageReference$target
Returns
string CSS class

Definition at line 445 of file LinkRenderer.php.

◆ isForComment()

MediaWiki\Linker\LinkRenderer::isForComment ( )

True when the links will be rendered in an edit summary or log comment.

Returns
bool

Definition at line 155 of file LinkRenderer.php.

◆ makeBrokenLink()

MediaWiki\Linker\LinkRenderer::makeBrokenLink ( $target,
$text = null,
array $extraAttribs = [],
array $query = [] )

Make a link that's styled as if the target page doesn't exist (a "red link").

Parameters
LinkTarget | PageReference$target
-taint$targetnone
string | HtmlArmor | null$text
array$extraAttribs
array$query
Returns
string

Definition at line 286 of file LinkRenderer.php.

References NS_SPECIAL, and wfMessage().

◆ makeKnownLink()

MediaWiki\Linker\LinkRenderer::makeKnownLink ( $target,
$text = null,
array $extraAttribs = [],
array $query = [] )

Make a link that's styled as if the target page exists (usually a "blue link", although the styling might depend on e.g.

whether the target is a redirect).

This will result in a DB lookup if the title wasn't cached yet. If you want to avoid that, and don't care about matching the exact styling of links within page content, you can use makePreloadedLink() instead.

Parameters
LinkTarget | PageReference$target
string | HtmlArmor | null$text
array$extraAttribs
array$query
Returns
string HTML

Definition at line 247 of file LinkRenderer.php.

Referenced by PagerTools\__construct(), TraditionalImageGallery\getCaptionHtml(), Article\getRedirectHeaderHtml(), ImagePage\imageDupes(), ImagePage\imageLinks(), ImagePage\openShowImage(), and InfoAction\pageInfo().

◆ makeLink()

MediaWiki\Linker\LinkRenderer::makeLink ( $target,
$text = null,
array $extraAttribs = [],
array $query = [] )

Render a wikilink.

Will call makeKnownLink() or makeBrokenLink() as appropriate.

Parameters
LinkTarget | PageReference$target
string | HtmlArmor | null$text
array$extraAttribs
array$query
Returns
string HTML

Definition at line 170 of file LinkRenderer.php.

Referenced by Article\getRedirectHeaderHtml(), and InfoAction\pageInfo().

◆ makePreloadedLink()

MediaWiki\Linker\LinkRenderer::makePreloadedLink ( $target,
$text = null,
$classes = '',
array $extraAttribs = [],
array $query = [] )

Make a link that's styled as if the target page exists (a "blue link"), with a specified class attribute.

Usually you should use makeLink() or makeKnownLink() instead, which will select the CSS classes automatically. Use this method if the exact styling doesn't matter and you want to ensure no extra DB lookup happens, e.g. for links generated by the skin.

Parameters
LinkTarget | PageReference$target
string | HtmlArmor | null$text
string$classesCSS classes to add
array$extraAttribs
array$query
Returns
string

Definition at line 206 of file LinkRenderer.php.

◆ normalizeTarget()

MediaWiki\Linker\LinkRenderer::normalizeTarget ( $target)

Normalizes the provided target.

Access: internal
For use by Linker::getImageLinkMTOParams()
Parameters
LinkTarget | PageReference$target
Returns
LinkTarget

Definition at line 393 of file LinkRenderer.php.

References NS_SPECIAL.

◆ setExpandURLs()

MediaWiki\Linker\LinkRenderer::setExpandURLs ( $expand)

Whether/how to expand URLs.

Parameters
string | bool | int$expandA PROTO_* constant or false for no expansion
See also
UrlUtils::expand()

Definition at line 138 of file LinkRenderer.php.

◆ setForceArticlePath()

MediaWiki\Linker\LinkRenderer::setForceArticlePath ( $force)

Whether to force the link to use the article path ($wgArticlePath) even if a query string is present, resulting in URLs like /wiki/Main_Page?action=foobar.

Parameters
bool$force

Definition at line 120 of file LinkRenderer.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Linker\LinkRenderer::CONSTRUCTOR_OPTIONS
Initial value:
= [
'renderForComment',
]

Definition at line 46 of file LinkRenderer.php.

Referenced by MediaWiki\Linker\LinkRendererFactory\create().


The documentation for this class was generated from the following file: