From 1455b81f0c666d5f5755c6d23acee7301ccc588c Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sat, 5 Feb 2011 23:06:36 +0000 Subject: [PATCH] Kill off Linker::getExternalLinkAttributes. --- includes/Linker.php | 32 ++---- includes/SkinLegacy.php | 11 +- includes/api/ApiParse.php | 13 +-- includes/parser/Parser.php | 5 +- tests/parser/extraParserTests.txt | Bin 1261 -> 1261 bytes tests/parser/parserTests.txt | 184 +++++++++++++++--------------- 6 files changed, 112 insertions(+), 133 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 30a4b00b5d..26d28654fe 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -23,8 +23,10 @@ class Linker { * * @param $class String: the contents of the class attribute; if an empty * string is passed, which is the default value, defaults to 'external'. + * @deprecated Just pass the external class directly to something using Html::expandAttributes */ function getExternalLinkAttributes( $class = 'external' ) { + wfDeprecated( __METHOD__ ); return $this->getLinkAttributesInternal( '', $class ); } @@ -795,25 +797,17 @@ class Linker { * @param $escape Boolean: do we escape the link text? * @param $linktype String: type of external link. Gets added to the classes * @param $attribs Array of extra attributes to - * - * @todo FIXME: This is a really crappy implementation. $linktype and - * 'external' are mashed into the class attrib for the link (which is made - * into a string). Then, if we've got additional params in $attribs, we - * add to it. People using this might want to change the classes (or other - * default link attributes), but passing $attribsText is just messy. Would - * make a lot more sense to make put the classes into $attribs, let the - * hook play with them, *then* expand it all at once. */ function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) { - if ( isset( $attribs['class'] ) ) { - # yet another hack :( - $class = $attribs['class']; - } else { - $class = "external $linktype"; + $class = "external"; + if ( isset($linktype) && $linktype ) { + $class .= " $linktype"; } - - $attribsText = $this->getExternalLinkAttributes( $class ); - $url = htmlspecialchars( $url ); + if ( isset($attribs['class']) && $attribs['class'] ) { + $class .= " {$attribs['class']}"; + } + $attribs['class'] = $class; + if ( $escape ) { $text = htmlspecialchars( $text ); } @@ -823,10 +817,8 @@ class Linker { wfDebug( "Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true ); return $link; } - if ( $attribs ) { - $attribsText .= Html::expandAttributes( $attribs ); - } - return '' . $text . ''; + $attribs['href'] = $url; + return Html::rawElement( 'a', $attribs, $text ); } /** diff --git a/includes/SkinLegacy.php b/includes/SkinLegacy.php index 0137ad21c3..961f7aeabf 100644 --- a/includes/SkinLegacy.php +++ b/includes/SkinLegacy.php @@ -412,16 +412,11 @@ class LegacyTemplate extends BaseTemplate { $first = false; $nt = Title::newFromText( $l ); - $url = $nt->escapeFullURL(); $text = $wgContLang->getLanguageName( $nt->getInterwiki() ); - $title = htmlspecialchars( $nt->getText() ); - if ( $text == '' ) { - $text = $l; - } - - $style = $this->getExternalLinkAttributes(); - $s .= "{$text}"; + $s .= Html::element( 'a', + array( 'href' => $nt->getFullURL(), 'title' => $nt->getText(), 'class' => "external" ), + $text == '' ? $l : $text ); } if ( $wgContLang->isRTL() ) { diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 293df6ba68..c86061f429 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -388,23 +388,16 @@ class ApiParse extends ApiBase { return ''; } - $sk = $wgUser->getSkin(); // @todo Kill this once we kill getExternalLinkAttributes - $s = htmlspecialchars( wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' ) ); $langs = array(); foreach ( $languages as $l ) { $nt = Title::newFromText( $l ); - $url = $nt->escapeFullURL(); $text = $wgContLang->getLanguageName( $nt->getInterwiki() ); - $title = htmlspecialchars( $nt->getText() ); - - if ( $text == '' ) { - $text = $l; - } - $style = $sk->getExternalLinkAttributes(); // @fixme Linker::getExternalLinkAttributes is best off completely killed - $langs[] = "{$text}"; // @fixme Use Html:: + $langs[] = Html::element( 'a', + array( 'href' => $nt->getFullURL(), 'title' => $nt->getText(), 'class' => "external" ), + $text == '' ? $l : $text ); } $s .= implode( htmlspecialchars( wfMsgExt( 'pipe-separator', 'escapenoentities' ) ), $langs ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index b18b4336d5..ab702c3812 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1111,10 +1111,9 @@ class Parser { throw new MWException( __METHOD__.': unrecognised match type "' . substr( $m[0], 0, 20 ) . '"' ); } - $url = wfMsgForContent( $urlmsg, $id); + $url = wfMsgForContent( $urlmsg, $id ); $sk = $this->mOptions->getSkin( $this->mTitle ); - $la = $sk->getExternalLinkAttributes( "external $CssClass" ); - return "{$keyword} {$id}"; + return $sk->makeExternalLink( $url, "{$keyword} {$id}", true, $CssClass ); } elseif ( isset( $m[5] ) && $m[5] !== '' ) { # ISBN $isbn = $m[5]; diff --git a/tests/parser/extraParserTests.txt b/tests/parser/extraParserTests.txt index 7eab3ea765cbe983c78491526caae5b2bc9942ca..bef8f506da50cf32635a51861907122bc0356056 100644 GIT binary patch delta 144 zcmaFM`Id9TQbyjQ)Erx-y!^EMoSgjf$p;xFCa+_bo&14WW->F=Mx3(JlLeXQ;*_1H rf?}$YLUK-Gaj~sZYDGzEQC?z>LJ5$iGA%6cUS}gKNvK8 delta 144 zcmaFM`Id9TQpU-vS!5?4ViM;qO3krV%F9p7&&kOzpZuO#b}}>5Mx3%TlLeXQ;*^~Z pl2KDg&PgmTwpB{4C`m2KOUzLy0kV`7P%Kiio1DlZJoyfbAOJA@G?)MY diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index b13339c36f..2dbaa60410 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -518,7 +518,7 @@ Definition list with URL link !! input ; http://example.com/ : definition !! result -
http://example.com/ 
definition +
http://example.com/ 
definition
!! end @@ -528,7 +528,7 @@ Definition list with bracketed URL link !! input ;[http://www.example.com/ Example]:Something about it !! result -
Example
Something about it +
Example
Something about it
!! end @@ -549,7 +549,7 @@ Definition list with news link containing colon !! input ; news:alt.wikipedia.rox: This isn't even a real newsgroup! !! result -
news:alt.wikipedia.rox
This isn't even a real newsgroup! +
news:alt.wikipedia.rox
This isn't even a real newsgroup!
!! end @@ -559,7 +559,7 @@ Malformed definition list with colon !! input ; news:alt.wikipedia.rox -- don't crash or enter an infinite loop !! result -
news:alt.wikipedia.rox -- don't crash or enter an infinite loop +
news:alt.wikipedia.rox -- don't crash or enter an infinite loop
!! end @@ -569,7 +569,7 @@ Definition lists: colon in external link text !! input ; [http://www.wikipedia2.org/ Wikipedia : The Next Generation]: OK, I made that up !! result -
Wikipedia : The Next Generation
OK, I made that up +
Wikipedia : The Next Generation
OK, I made that up
!! end @@ -623,7 +623,7 @@ External links: non-bracketed !! input Non-bracketed: http://example.com !! result -

Non-bracketed: http://example.com +

Non-bracketed: http://example.com

!! end @@ -634,9 +634,9 @@ Numbered: [http://example.com] Numbered: [http://example.net] Numbered: [http://example.com] !! result -

Numbered: [1] -Numbered: [2] -Numbered: [3] +

Numbered: [1] +Numbered: [2] +Numbered: [3]

!!end @@ -645,7 +645,7 @@ External links: specified text !! input Specified text: [http://example.com link] !! result -

Specified text: link +

Specified text: link

!!end @@ -654,7 +654,7 @@ External links: trail !! input Linktrails should not work for external links: [http://example.com link]s !! result -

Linktrails should not work for external links: links +

Linktrails should not work for external links: links

!! end @@ -663,7 +663,7 @@ External links: dollar sign in URL !! input http://example.com/1$2345 !! result -

http://example.com/1$2345 +

http://example.com/1$2345

!! end @@ -672,7 +672,7 @@ External links: dollar sign in URL (named) !! input [http://example.com/1$2345] !! result -

[1] +

[1]

!!end @@ -681,7 +681,7 @@ External links: open square bracket forbidden in URL (bug 4377) !! input http://example.com/1[2345 !! result -

http://example.com/1[2345 +

http://example.com/1[2345

!! end @@ -690,7 +690,7 @@ External links: open square bracket forbidden in URL (named) (bug 4377) !! input [http://example.com/1[2345] !! result -

[2345 +

[2345

!!end @@ -699,7 +699,7 @@ External links: nowiki in URL link text (bug 6230) !!input [http://example.com/ ''example site''] !! result -

''example site'' +

''example site''

!! end @@ -709,7 +709,7 @@ External links: newline forbidden in text (bug 6230 regression check) [http://example.com/ first second] !! result -

[http://example.com/ first +

[http://example.com/ first second]

!!end @@ -737,7 +737,7 @@ Link to non-http image, no img tag !! input Link to non-http image, no img tag: ftp://example.com/test.jpg !! result -

Link to non-http image, no img tag: ftp://example.com/test.jpg +

Link to non-http image, no img tag: ftp://example.com/test.jpg

!! end @@ -746,7 +746,7 @@ External links: terminating separator !! input Terminating separator: http://example.com/thing, !! result -

Terminating separator: http://example.com/thing, +

Terminating separator: http://example.com/thing,

!! end @@ -755,7 +755,7 @@ External links: intervening separator !! input Intervening separator: http://example.com/1,2,3 !! result -

Intervening separator: http://example.com/1,2,3 +

Intervening separator: http://example.com/1,2,3

!! end @@ -764,7 +764,7 @@ External links: old bug with URL in query !! input Old bug with URL in query: [http://example.com/thing?url=http://example.com link] !! result -

Old bug with URL in query: link +

Old bug with URL in query: link

!! end @@ -773,7 +773,7 @@ External links: old URL-in-URL bug, mixed protocols !! input And again with mixed protocols: [ftp://example.com?url=http://example.com link] !! result -

And again with mixed protocols: link +

And again with mixed protocols: link

!!end @@ -782,7 +782,7 @@ External links: URL in text !! input URL in text: [http://example.com http://example.com] !! result -

URL in text: http://example.com +

URL in text: http://example.com

!! end @@ -791,7 +791,7 @@ External links: Clickable images !! input ja-style clickable images: [http://example.com http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png] !! result -

ja-style clickable images: Ncwikicol.png +

ja-style clickable images: Ncwikicol.png

!!end @@ -800,7 +800,7 @@ External links: raw ampersand !! input Old & use: http://x&y !! result -

Old & use: http://x&y +

Old & use: http://x&y

!! end @@ -809,7 +809,7 @@ External links: encoded ampersand !! input Old & use: http://x&y !! result -

Old & use: http://x&y +

Old & use: http://x&y

!! end @@ -818,7 +818,7 @@ External links: encoded equals (bug 6102) !! input http://example.com/?foo=bar !! result -

http://example.com/?foo=bar +

http://example.com/?foo=bar

!! end @@ -827,7 +827,7 @@ External links: [raw ampersand] !! input Old & use: [http://x&y] !! result -

Old & use: [1] +

Old & use: [1]

!! end @@ -836,7 +836,7 @@ External links: [encoded ampersand] !! input Old & use: [http://x&y] !! result -

Old & use: [1] +

Old & use: [1]

!! end @@ -845,7 +845,7 @@ External links: [encoded equals] (bug 6102) !! input [http://example.com/?foo=bar] !! result -

[1] +

[1]

!! end @@ -854,7 +854,7 @@ External links: [IDN ignored character reference in hostname; strip it right off !! input [http://e‌xample.com/] !! result -

[1] +

[1]

!! end @@ -863,7 +863,7 @@ External links: IDN ignored character reference in hostname; strip it right off !! input http://e‌xample.com/ !! result -

http://example.com/ +

http://example.com/

!! end @@ -872,7 +872,7 @@ External links: www.jpeg.org (bug 554) !! input http://www.jpeg.org !!result -

http://www.jpeg.org +

http://www.jpeg.org

!! end @@ -881,7 +881,7 @@ External links: URL within URL (original bug 2) !! input [http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp] !! result -

[1] +

[1]

!! end @@ -890,7 +890,7 @@ BUG 361: URL inside bracketed URL !! input [http://www.example.com/foo http://www.example.com/bar] !! result -

http://www.example.com/bar +

http://www.example.com/bar

!! end @@ -899,7 +899,7 @@ BUG 361: URL within URL, not bracketed !! input http://www.example.com/foo?=http://www.example.com/bar !! result -

http://www.example.com/foo?=http://www.example.com/bar +

http://www.example.com/foo?=http://www.example.com/bar

!! end @@ -908,7 +908,7 @@ BUG 289: ">"-token in URL-tail !! input http://www.example.com/ !! result -

http://www.example.com/<hello> +

http://www.example.com/<hello>

!!end @@ -917,7 +917,7 @@ BUG 289: literal ">"-token in URL-tail !! input http://www.example.com/html !! result -

http://www.example.com/html +

http://www.example.com/html

!!end @@ -926,7 +926,7 @@ BUG 289: ">"-token in bracketed URL !! input [http://www.example.com/ stuff] !! result -

<hello> stuff +

<hello> stuff

!!end @@ -935,7 +935,7 @@ BUG 289: literal ">"-token in bracketed URL !! input [http://www.example.com/html stuff] !! result -

html stuff +

html stuff

!!end @@ -944,7 +944,7 @@ BUG 289: literal double quote at end of URL !! input http://www.example.com/"hello" !! result -

http://www.example.com/"hello" +

http://www.example.com/"hello"

!!end @@ -953,7 +953,7 @@ BUG 289: literal double quote in bracketed URL !! input [http://www.example.com/"hello" stuff] !! result -

"hello" stuff +

"hello" stuff

!!end @@ -962,7 +962,7 @@ External links: multiple legal whitespace is fine, Magnus. Don't break it please !! input [http://www.example.com test] !! result -

test +

test

!! end @@ -971,7 +971,7 @@ External links: wiki links within external link (Bug 3695) !! input [http://example.com [[wikilink]] embedded in ext link] !! result -

wikilink embedded in ext link +

wikilink embedded in ext link

!! end @@ -996,11 +996,11 @@ Bug 2702: Mismatched , and tags are invalid ''Something [http://example.com mixed''''', even bold]''' '''''Now [http://example.com both'''''] !! result -

text -text -Something in italic -Something mixed, even bold -Now both +

text +text +Something in italic +Something mixed, even bold +Now both

!! end @@ -1010,7 +1010,7 @@ Bug 4781: %26 in URL !! input http://www.example.com/?title=AT%26T !! result -

http://www.example.com/?title=AT%26T +

http://www.example.com/?title=AT%26T

!! end @@ -1019,7 +1019,7 @@ Bug 4781, 5267: %26 in URL !! input http://www.example.com/?title=100%25_Bran !! result -

http://www.example.com/?title=100%25_Bran +

http://www.example.com/?title=100%25_Bran

!! end @@ -1028,7 +1028,7 @@ Bug 4781, 5267: %28, %29 in URL !! input http://www.example.com/?title=Ben-Hur_%281959_film%29 !! result -

http://www.example.com/?title=Ben-Hur_%281959_film%29 +

http://www.example.com/?title=Ben-Hur_%281959_film%29

!! end @@ -1038,7 +1038,7 @@ Bug 4781: %26 in autonumber URL !! input [http://www.example.com/?title=AT%26T] !! result -

[1] +

[1]

!! end @@ -1047,7 +1047,7 @@ Bug 4781, 5267: %26 in autonumber URL !! input [http://www.example.com/?title=100%25_Bran] !! result -

[1] +

[1]

!! end @@ -1056,7 +1056,7 @@ Bug 4781, 5267: %28, %29 in autonumber URL !! input [http://www.example.com/?title=Ben-Hur_%281959_film%29] !! result -

[1] +

[1]

!! end @@ -1066,7 +1066,7 @@ Bug 4781: %26 in bracketed URL !! input [http://www.example.com/?title=AT%26T link] !! result -

link +

link

!! end @@ -1075,7 +1075,7 @@ Bug 4781, 5267: %26 in bracketed URL !! input [http://www.example.com/?title=100%25_Bran link] !! result -

link +

link

!! end @@ -1084,7 +1084,7 @@ Bug 4781, 5267: %28, %29 in bracketed URL !! input [http://www.example.com/?title=Ben-Hur_%281959_film%29 link] !! result -

link +

link

!! end @@ -1093,7 +1093,7 @@ External link containing double-single-quotes in text '' (bug 4598 sanity check) !! input Some [http://example.com/ pretty ''italics'' and stuff]! !! result -

Some pretty italics and stuff! +

Some pretty italics and stuff!

!! end @@ -1102,7 +1102,7 @@ External link containing double-single-quotes in text embedded in italics (bug 4 !! input ''Some [http://example.com/ pretty ''italics'' and stuff]!'' !! result -

Some pretty italics and stuff! +

Some pretty italics and stuff!

!! end @@ -1111,7 +1111,7 @@ External link containing double-single-quotes with no space separating the url f !! input [http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm''La muerte de Casagemas'' (1901) en el sitio de [[Museo Picasso (París)|Museo Picasso]].] !! result -

La muerte de Casagemas (1901) en el sitio de Museo Picasso. +

La muerte de Casagemas (1901) en el sitio de Museo Picasso.

!! end @@ -1390,7 +1390,7 @@ Table security: embedded pipes (http://lists.wikimedia.org/mailman/htdig/wikitec !! result - + @@ -1633,7 +1633,7 @@ Plain link to URL !! input [[http://www.example.com]] !! result -

[[1]] +

[[1]]

!! end @@ -1653,7 +1653,7 @@ Piped link to URL !! input Piped link to URL: [[http://www.example.com|an example URL]] !! result -

Piped link to URL: [example URL] +

Piped link to URL: [example URL]

!! end @@ -2195,7 +2195,7 @@ Magic Word: {{SERVER}} !! input {{SERVER}} !! result -

http://Britney-Spears +

http://Britney-Spears

!! end @@ -2360,7 +2360,7 @@ Magic links: RFC (bug 479) !! input RFC 822 !! result -

RFC 822 +

RFC 822

!! end @@ -2378,7 +2378,7 @@ Magic links: PMID incorrectly converts space to underscore !! input PMID 1234 !! result -

PMID 1234 +

PMID 1234

!! end @@ -3541,7 +3541,7 @@ Thumbnail image caption with a free URL !! input [[Image:foobar.jpg|thumb|http://example.com]] !! result - + !! end @@ -3550,7 +3550,7 @@ Thumbnail image caption with a free URL and explicit alt !! input [[Image:foobar.jpg|thumb|http://example.com|alt=Alteration]] !! result - + !! end @@ -3568,7 +3568,7 @@ BUG 1887: A RFC with a thumbnail !! input [[Image:foobar.jpg|thumb|This is RFC 12354]] !! result -
This is RFC 12354
+
This is RFC 12354
!! end @@ -3577,7 +3577,7 @@ BUG 1887: A mailto link with a thumbnail !! input [[Image:foobar.jpg|thumb|Please mailto:nobody@example.com]] !! result - + !! end @@ -3691,7 +3691,7 @@ Bug 3090: External links other than http: in image captions !! input [[Image:Foobar.jpg|thumb|200px|This caption has [irc://example.net irc] and [https://example.com Secure] ext links in it.]] !! result -
This caption has irc and Secure ext links in it.
+
This caption has irc and Secure ext links in it.
!! end @@ -4150,7 +4150,7 @@ BUG 1219 URL next to image (good) !! input http://example.com [[Image:foobar.jpg]] !! result -

http://example.com Foobar.jpg +

http://example.com Foobar.jpg

!!end @@ -4224,7 +4224,7 @@ BUG 1219 URL next to image (broken) !! input http://example.com[[Image:foobar.jpg]] !! result -

http://example.comFoobar.jpg +

http://example.comFoobar.jpg

!!end @@ -4233,7 +4233,7 @@ Bug 1186 news: in the middle of text !! input http://en.wikinews.org/wiki/Wikinews:Workplace !! result -

http://en.wikinews.org/wiki/Wikinews:Workplace +

http://en.wikinews.org/wiki/Wikinews:Workplace

!!end @@ -5389,11 +5389,11 @@ ftp://inlineftp mailto:inline@mail.tld !! result -

[1] [2] [3] -

ftp://inlineftp -

With target -

[4] -

mailto:inline@mail.tld +

[1] [2] [3] +

ftp://inlineftp +

With target +

[4] +

mailto:inline@mail.tld

!! end @@ -5476,7 +5476,7 @@ Fuzz testing: Parser21 !! result
[ftp://%7Cx[ftp://%7Cx ]" onmouseover="alert(document.cookie)">test
- @@ -5492,7 +5492,7 @@ http://===r:::https://b {| !!result -

http://===r:::https://b +

http://===r:::https://b

irc://{{ftp://a" onmouseover="alert('hello world');" + irc://{{ftp://a" onmouseover="alert('hello world');"
@@ -5556,7 +5556,7 @@ Fuzz testing: URL adjacent extension (with space, clean) !! input http://example.com junk !! result -

http://example.com junk +

http://example.com junk

!!end @@ -5566,7 +5566,7 @@ Fuzz testing: URL adjacent extension (no space, dirty; nowiki) !! input http://example.comjunk !! result -

http://example.comjunk +

http://example.comjunk

!!end @@ -5576,7 +5576,7 @@ Fuzz testing: URL adjacent extension (no space, dirty; pre) !! input http://example.com
junk
!! result -http://example.com
junk
+http://example.com
junk
!!end @@ -6602,7 +6602,7 @@ Handling of in URLs !! input **irc:// a !! result -
    • irc://%0Aa + @@ -6709,7 +6709,7 @@ image4 |300px| centre
    • @@ -6876,7 +6876,7 @@ Bug 22905: followed by ISBN followed by !! input (fr) ISBN 2753300917 [http://www.example.com example.com] !! result -

      (fr) ISBN 2753300917 example.com +

      (fr) ISBN 2753300917 example.com

      !! end @@ -6885,7 +6885,7 @@ Double RFC !! input RFC RFC 1234 !! result -

      RFC RFC 1234 +

      RFC RFC 1234

      !! end @@ -6903,7 +6903,7 @@ RFC code coverage !! input RFC 983 987 !! result -

      RFC 983 987 +

      RFC 983 987

      !! end @@ -6997,7 +6997,7 @@ Images with the "|" character in the comment !! input [[image:Foobar.jpg|thumb|An [http://test/?param1=|left|¶m2=|x external] URL]] !! result -
      An external URL
      +
      An external URL
      !!end @@ -8002,7 +8002,7 @@ language=fa !! input [http://en.wikipedia.org/] !! result -

      [Û±] +

      [Û±]

      !! end -- 2.20.1