35use Wikimedia\Assert\Assert;
112 $this->forceArticlePath = $force;
126 $this->expandUrls = $expand;
161 $target, $text =
null, array $extraAttribs = [], array $query = []
163 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $target,
'$target' );
165 return $this->
makeKnownLink( $target, $text, $extraAttribs, $query );
167 return $this->
makeBrokenLink( $target, $text, $extraAttribs, $query );
171 private function runBeginHook( $target, &$text, &$extraAttribs, &$query, $isKnown ) {
173 if ( !$this->hookRunner->onHtmlPageLinkRendererBegin(
174 $this, $this->castToTitle( $target ), $text, $extraAttribs, $query, $ret )
192 $target, $text =
null, $classes =
'', array $extraAttribs = [], array $query = []
194 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $target,
'$target' );
197 $ret = $this->
runBeginHook( $target, $text, $extraAttribs, $query,
true );
198 if ( $ret !==
null ) {
203 $attribs = [
'class' => $classes ];
204 $prefixedText = $this->titleFormatter->getPrefixedText( $target );
205 if ( $prefixedText !==
'' ) {
206 $attribs[
'title'] = $prefixedText;
213 if ( $text ===
null ) {
217 return $this->
buildAElement( $target, $text, $attribs,
true );
228 $target, $text =
null, array $extraAttribs = [], array $query = []
230 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $target,
'$target' );
232 $isExternal = $target->isExternal();
240 $classes[] =
'extiw';
243 if ( $colour !==
'' ) {
244 $classes[] = $colour;
250 implode(
' ', $classes ),
265 $target, $text =
null, array $extraAttribs = [], array $query = []
267 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $target,
'$target' );
269 $ret = $this->
runBeginHook( $target, $text, $extraAttribs, $query,
false );
270 if ( $ret !==
null ) {
275 # We don't want to include fragments for broken links, because they
276 # generally make no sense.
277 if ( $target->hasFragment() ) {
278 $target = $target->createFragmentTarget(
'' );
283 if ( !isset( $query[
'action'] ) && $target->getNamespace() !==
NS_SPECIAL ) {
284 $query[
'action'] =
'edit';
285 $query[
'redlink'] =
'1';
289 $attribs = [
'class' =>
'new' ];
290 $prefixedText = $this->titleFormatter->getPrefixedText( $target );
291 if ( $prefixedText !==
'' ) {
293 $attribs[
'title'] =
wfMessage(
'red-link-title', $prefixedText )
294 ->inContentLanguage()
302 if ( $text ===
null ) {
306 return $this->
buildAElement( $target, $text, $attribs,
false );
318 private function buildAElement( $target, $text, array $attribs, $isKnown ) {
320 if ( !$this->hookRunner->onHtmlPageLinkRendererEnd(
321 $this, $this->castToLinkTarget( $target ), $isKnown, $text, $attribs, $ret )
326 return Html::rawElement(
'a', $attribs, HtmlArmor::getHtml( $text ) );
334 $prefixedText = $this->titleFormatter->getPrefixedText( $target );
338 return $target->getFragment();
341 return $prefixedText;
350 if ( $this->forceArticlePath ) {
356 $url = $this->
castToTitle( $target )->getLinkURL( $query,
false, $this->expandUrls );
358 if ( $this->forceArticlePath && $realQuery ) {
375 if ( $target->getNamespace() ===
NS_SPECIAL && !$target->isExternal() ) {
376 list( $name, $subpage ) = $this->specialPageFactory->resolveAlias(
382 $this->specialPageFactory->getLocalNameFor( $name, $subpage ),
383 $target->getFragment()
403 # Merge the custom attribs with the default ones, and iterate
404 # over that, deleting all "false" attributes.
406 $merged = Sanitizer::mergeAttributes( $defaults, $attribs );
407 foreach ( $merged as $key => $val ) {
408 # A false value suppresses the attribute
409 if ( $val !==
false ) {
423 Assert::parameterType( [ LinkTarget::class, PageReference::class ], $target,
'$target' );
426 if ( $target->isExternal() || $target->getText() ===
'' || $target->getNamespace() < 0 ) {
430 $id = $this->linkCache->addLinkObj( $target );
436 if ( $this->linkCache->getGoodLinkFieldObj( $target,
'redirect' ) ) {
438 return 'mw-redirect';
450 return Title::newFromLinkTarget( $target );
453 return Title::castFromPageReference( $target );
462 return Title::castFromPageReference( $target );
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Marks HTML that shouldn't be escaped.
This class is a collection of static functions that serve two purposes:
Cache for article titles (prefixed DB keys) and ids linked from one source.
Factory for handling the special page list and generating SpecialPage objects.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
HTML sanitizer for MediaWiki.
Represents a page (or page fragment) title within MediaWiki.
Represents a title within MediaWiki.