return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
} elseif ( in_array( 'broken', $options, true ) ) {
return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
+ } elseif ( in_array( 'noclasses', $options, true ) ) {
+ return $linkRenderer->makePreloadedLink( $target, $text, '', $customAttribs, $query );
} else {
return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
}
*/
private $expandUrls = false;
- /**
- * Whether extra classes should be added
- *
- * @var bool
- */
- private $noClasses = false;
-
/**
* @var int
*/
return $this->expandUrls;
}
- /**
- * @param bool $no
- */
- public function setNoClasses( $no ) {
- $this->noClasses = $no;
- }
-
- /**
- * @return bool
- */
- public function getNoClasses() {
- return $this->noClasses;
- }
-
/**
* @param int $threshold
*/
*/
private function getLegacyOptions( $isKnown ) {
$options = [ 'stubThreshold' => $this->stubThreshold ];
- if ( $this->noClasses ) {
- $options[] = 'noclasses';
- }
if ( $this->forceArticlePath ) {
$options[] = 'forcearticlepath';
}
}
/**
+ * If you have already looked up the proper CSS classes using Linker::getLinkColour()
+ * or some other method, use this to avoid looking it up again.
+ *
* @param LinkTarget $target
* @param string|HtmlArmor|null $text
+ * @param string $classes CSS classes to add
* @param array $extraAttribs
* @param array $query
* @return string
*/
- public function makeKnownLink(
- LinkTarget $target, $text = null, array $extraAttribs = [], array $query = []
+ public function makePreloadedLink(
+ LinkTarget $target, $text = null, $classes, array $extraAttribs = [], array $query = []
) {
// Run begin hook
$ret = $this->runBeginHook( $target, $text, $extraAttribs, $query, true );
}
$target = $this->normalizeTarget( $target );
$url = $this->getLinkURL( $target, $query );
- $attribs = [];
- if ( !$this->noClasses ) {
- $classes = [];
- if ( $target->isExternal() ) {
- $classes[] = 'extiw';
- }
- $title = Title::newFromLinkTarget( $target );
- $colour = Linker::getLinkColour( $title, $this->stubThreshold );
- if ( $colour !== '' ) {
- $classes[] = $colour;
- }
- if ( $classes ) {
- $attribs['class'] = implode( ' ', $classes );
- }
- }
-
+ $attribs = [ 'class' => $classes ];
$prefixedText = $this->titleFormatter->getPrefixedText( $target );
if ( $prefixedText !== '' ) {
$attribs['title'] = $prefixedText;
return $this->buildAElement( $target, $text, $attribs, true );
}
+ /**
+ * @param LinkTarget $target
+ * @param string|HtmlArmor|null $text
+ * @param array $extraAttribs
+ * @param array $query
+ * @return string
+ */
+ public function makeKnownLink(
+ LinkTarget $target, $text = null, array $extraAttribs = [], array $query = []
+ ) {
+ $classes = [];
+ if ( $target->isExternal() ) {
+ $classes[] = 'extiw';
+ }
+ $title = Title::newFromLinkTarget( $target );
+ $colour = Linker::getLinkColour( $title, $this->stubThreshold );
+ if ( $colour !== '' ) {
+ $classes[] = $colour;
+ }
+
+ return $this->makePreloadedLink(
+ $target,
+ $text,
+ $classes ? implode( ' ', $classes ) : '',
+ $extraAttribs,
+ $query
+ );
+ }
+
/**
* @param LinkTarget $target
* @param string|HtmlArmor|null $text
}
$url = $this->getLinkURL( $target, $query );
- $attribs = $this->noClasses ? [] : [ 'class' => 'new' ];
+ $attribs = [ 'class' => 'new' ];
$prefixedText = $this->titleFormatter->getPrefixedText( $target );
if ( $prefixedText !== '' ) {
// This ends up in parser cache!
public function createFromLegacyOptions( array $options ) {
$linkRenderer = $this->create();
- if ( in_array( 'noclasses', $options, true ) ) {
- $linkRenderer->setNoClasses( true );
- }
-
if ( in_array( 'forcearticlepath', $options, true ) ) {
$linkRenderer->setForceArticlePath( true );
}
!! wikitext
[[Image:Barfoo.jpg]]
!! html/php
-<p><a href="/wiki/File:Barfoo.jpg" title="File:Barfoo.jpg" class="mw-redirect">File:Barfoo.jpg</a>
+<p><a href="/wiki/File:Barfoo.jpg" class="mw-redirect" title="File:Barfoo.jpg">File:Barfoo.jpg</a>
</p>
!! end
# ## ANONYMOUS USER ########################################
[
'<a href="/wiki/Special:Contributions/JohnDoe" '
- . 'title="Special:Contributions/JohnDoe" '
- . 'class="mw-userlink mw-anonuserlink">JohnDoe</a>',
+ . 'class="mw-userlink mw-anonuserlink" '
+ . 'title="Special:Contributions/JohnDoe">JohnDoe</a>',
0, 'JohnDoe', false,
],
[
'<a href="/wiki/Special:Contributions/::1" '
- . 'title="Special:Contributions/::1" '
- . 'class="mw-userlink mw-anonuserlink">::1</a>',
+ . 'class="mw-userlink mw-anonuserlink" '
+ . 'title="Special:Contributions/::1">::1</a>',
0, '::1', false,
'Anonymous with pretty IPv6'
],
[
'<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
- . 'title="Special:Contributions/0:0:0:0:0:0:0:1" '
- . 'class="mw-userlink mw-anonuserlink">::1</a>',
+ . 'class="mw-userlink mw-anonuserlink" '
+ . 'title="Special:Contributions/0:0:0:0:0:0:0:1">::1</a>',
0, '0:0:0:0:0:0:0:1', false,
'Anonymous with almost pretty IPv6'
],
[
'<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
- . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
- . 'class="mw-userlink mw-anonuserlink">::1</a>',
+ . 'class="mw-userlink mw-anonuserlink" '
+ . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001">::1</a>',
0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
'Anonymous with full IPv6'
],
[
'<a href="/wiki/Special:Contributions/::1" '
- . 'title="Special:Contributions/::1" '
- . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
+ . 'class="mw-userlink mw-anonuserlink" '
+ . 'title="Special:Contributions/::1">AlternativeUsername</a>',
0, '::1', 'AlternativeUsername',
'Anonymous with pretty IPv6 and an alternative username'
],
# IPV4
[
'<a href="/wiki/Special:Contributions/127.0.0.1" '
- . 'title="Special:Contributions/127.0.0.1" '
- . 'class="mw-userlink mw-anonuserlink">127.0.0.1</a>',
+ . 'class="mw-userlink mw-anonuserlink" '
+ . 'title="Special:Contributions/127.0.0.1">127.0.0.1</a>',
0, '127.0.0.1', false,
'Anonymous with IPv4'
],
[
'<a href="/wiki/Special:Contributions/127.0.0.1" '
- . 'title="Special:Contributions/127.0.0.1" '
- . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
+ . 'class="mw-userlink mw-anonuserlink" '
+ . 'title="Special:Contributions/127.0.0.1">AlternativeUsername</a>',
0, '127.0.0.1', 'AlternativeUsername',
'Anonymous with IPv4 and an alternative username'
],
public static function provideCreateFromLegacyOptions() {
return [
- [
- [ 'noclasses' ],
- 'getNoClasses',
- true
- ],
[
[ 'forcearticlepath' ],
'getForceArticlePath',