From a70213071d2bd8214d03c54f67ffbfca1ad3bec6 Mon Sep 17 00:00:00 2001 From: Remember the dot Date: Sun, 12 Jul 2009 23:32:16 +0000 Subject: [PATCH] Removed repetition of URIs in the title attributes (tooltips) of external links. Web browsers typically display the target URIs of links in the status bar, making repeating the URIs in tooltips redundant. Some browsers, like Opera, can be configured to display the URIs in tooltips instead of the status bar without the web page having to supply title attributes at all. As part of this process, I refactored some of Linker.php and removed an unused parameter from getExternalLinkAttributes. --- RELEASE-NOTES | 7 +- includes/Linker.php | 20 ++-- includes/Skin.php | 2 +- includes/parser/Parser.php | 2 +- maintenance/parserTests.txt | 182 ++++++++++++++++++------------------ 5 files changed, 103 insertions(+), 110 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 064cdc6b43..a6e7ec11e3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -119,13 +119,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Leading > is now syntax for
. * (bug 19576) Moved id attribues from anchors accompanying section headers to the section headers themselves, removing the redundant anchor elements. -* Removed name attribute from . * Parser::setFunctionTagHook now can be used to add a new tag which is parsed at preprocesor level. * Added $wgShowArchiveThumbnails, allowing sysadmins to disable thumbnail display for old versions of images. -* Remove five-year-old KHTMLFixes.css, which is unlikely to be relevant anymore - and was causing problems. === Bug fixes in 1.16 === @@ -248,6 +245,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 19602) PubMed Magic links now use updated NIH url * (bug 19637) externallinks have links to self * Don't load Opera 9.5 RTL fixes for Opera 9.6 +* Removed name attribute from . +* Remove five-year-old KHTMLFixes.css, which is unlikely to be relevant anymore + and was causing problems. +* Removed repetition of URIs in the title attributes of external links. == API changes in 1.16 == diff --git a/includes/Linker.php b/includes/Linker.php index 4577c5cf54..a799dceb01 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -21,13 +21,11 @@ class Linker { * Get the appropriate HTML attributes to add to the "a" element of an ex- * ternal link, as created by [wikisyntax]. * - * @param string $title The (unescaped) title text for the link - * @param string $unused Unused * @param string $class The contents of the class attribute; if an empty * string is passed, which is the default value, defaults to 'external'. */ - function getExternalLinkAttributes( $title, $unused = null, $class='' ) { - return $this->getLinkAttributesInternal( $title, $class, 'external' ); + function getExternalLinkAttributes( $class = 'external' ) { + return $this->getLinkAttributesInternal( '', $class ); } /** @@ -40,7 +38,7 @@ class Linker { * @param string $class The contents of the class attribute; if an empty * string is passed, which is the default value, defaults to 'external'. */ - function getInterwikiLinkAttributes( $title, $unused = null, $class='' ) { + function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) { global $wgContLang; # FIXME: We have a whole bunch of handling here that doesn't happen in @@ -49,7 +47,7 @@ class Linker { $title = $wgContLang->checkTitleEncoding( $title ); $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title ); - return $this->getLinkAttributesInternal( $title, $class, 'external' ); + return $this->getLinkAttributesInternal( $title, $class ); } /** @@ -87,14 +85,8 @@ class Linker { /** * Common code for getLinkAttributesX functions */ - private function getLinkAttributesInternal( $title, $class, $classDefault = false ) { + private function getLinkAttributesInternal( $title, $class ) { $title = htmlspecialchars( $title ); - if ( $class === '' and $classDefault !== false ) { - # FIXME: Parameter defaults the hard way! We should just have - # $class = 'external' or whatever as the default in the externally- - # exposed functions, not $class = ''. - $class = $classDefault; - } $class = htmlspecialchars( $class ); $r = ''; if ( $class != '' ) { @@ -749,7 +741,7 @@ class Linker { * hook play with them, *then* expand it all at once. */ function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) { - $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype ); + $attribsText = $this->getExternalLinkAttributes( 'external ' . $linktype ); $url = htmlspecialchars( $url ); if( $escape ) { $text = htmlspecialchars( $text ); diff --git a/includes/Skin.php b/includes/Skin.php index 15842bc752..821b6ea802 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1844,7 +1844,7 @@ END; $text = $wgContLang->getLanguageName( $nt->getInterwiki() ); if ( '' == $text ) { $text = $l; } - $style = $this->getExternalLinkAttributes( $l, $text ); + $style = $this->getExternalLinkAttributes(); $s .= "{$text}"; } if( $wgContLang->isRTL() ) $s .= ''; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 8755157e22..768c9cbab9 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -961,7 +961,7 @@ class Parser } $url = wfMsg( $urlmsg, $id); $sk = $this->mOptions->getSkin(); - $la = $sk->getExternalLinkAttributes( $url, $keyword.$id ); + $la = $sk->getExternalLinkAttributes(); return "{$keyword} {$id}"; } elseif ( isset( $m[5] ) && $m[5] !== '' ) { # ISBN diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 1ce66bf033..7df2c4ee15 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -441,7 +441,7 @@ Definition list with URL link !! input ; http://example.com/ : definition !! result -
http://example.com/ 
definition +
http://example.com/ 
definition
!! end @@ -451,7 +451,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 @@ -472,7 +472,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 @@ -482,7 +482,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 @@ -492,7 +492,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 @@ -527,7 +527,7 @@ External links: non-bracketed !! input Non-bracketed: http://example.com !! result -

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

Non-bracketed: http://example.com

!! end @@ -538,9 +538,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 @@ -549,7 +549,7 @@ External links: specified text !! input Specified text: [http://example.com link] !! result -

Specified text: link +

Specified text: link

!!end @@ -558,7 +558,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 @@ -567,7 +567,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 @@ -576,7 +576,7 @@ External links: dollar sign in URL (named) !! input [http://example.com/1$2345] !! result -

[1] +

[1]

!!end @@ -585,7 +585,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 @@ -594,7 +594,7 @@ External links: open square bracket forbidden in URL (named) (bug 4377) !! input [http://example.com/1[2345] !! result -

[2345 +

[2345

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

''example site'' +

''example site''

!! end @@ -613,7 +613,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 @@ -641,7 +641,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 @@ -650,7 +650,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 @@ -659,7 +659,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 @@ -668,7 +668,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 @@ -677,7 +677,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 @@ -686,7 +686,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 @@ -695,7 +695,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 @@ -704,7 +704,7 @@ External links: raw ampersand !! input Old & use: http://x&y !! result -

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

Old & use: http://x&y

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

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

Old & use: http://x&y

!! end @@ -722,7 +722,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 @@ -731,7 +731,7 @@ External links: [raw ampersand] !! input Old & use: [http://x&y] !! result -

Old & use: [1] +

Old & use: [1]

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

Old & use: [1] +

Old & use: [1]

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

[1] +

[1]

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

[1] +

[1]

!! end @@ -767,7 +767,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 @@ -776,7 +776,7 @@ External links: www.jpeg.org (bug 554) !! input http://www.jpeg.org !!result -

http://www.jpeg.org +

http://www.jpeg.org

!! end @@ -785,7 +785,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 @@ -794,7 +794,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 @@ -803,7 +803,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 @@ -812,7 +812,7 @@ BUG 289: ">"-token in URL-tail !! input http://www.example.com/ !! result -

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

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

!!end @@ -821,7 +821,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 @@ -830,7 +830,7 @@ BUG 289: ">"-token in bracketed URL !! input [http://www.example.com/ stuff] !! result -

<hello> stuff +

<hello> stuff

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

html stuff +

html stuff

!!end @@ -848,7 +848,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 @@ -857,7 +857,7 @@ BUG 289: literal double quote in bracketed URL !! input [http://www.example.com/"hello" stuff] !! result -

"hello" stuff +

"hello" stuff

!!end @@ -869,7 +869,7 @@ disabled !! input [http://www.example.com test] !! result -

[http://www.example.com test] +

[http://www.example.com test]

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

test +

test

!! end @@ -887,7 +887,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 @@ -912,11 +912,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 @@ -926,7 +926,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 @@ -935,7 +935,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 @@ -944,7 +944,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 @@ -954,7 +954,7 @@ Bug 4781: %26 in autonumber URL !! input [http://www.example.com/?title=AT%26T] !! result -

[1] +

[1]

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

[1] +

[1]

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

[1] +

[1]

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

link +

link

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

link +

link

!! end @@ -1000,7 +1000,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 @@ -1009,7 +1009,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 @@ -1018,7 +1018,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 @@ -1499,7 +1499,7 @@ Plain link to URL !! input [[http://www.example.com]] !! result -

[[1]] +

[[1]]

!! end @@ -1510,7 +1510,7 @@ Plain link to URL # ---- # I'm changing it to match the current output--it arguably makes more # sense in the light of the test above. Old expected result was: -#

Piped link to URL: an example URL +#

Piped link to URL: an example URL #

# But I think this test is bordering on "garbage in, garbage out" anyway. # -- wtm @@ -1519,7 +1519,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 @@ -2030,7 +2030,7 @@ Magic Word: {{SERVER}} !! input {{SERVER}} !! result -

http://localhost +

http://localhost

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

RFC 822 +

RFC 822

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

PMID 1234 +

PMID 1234

!! end @@ -3269,7 +3269,7 @@ Thumbnail image caption with a free URL !! input [[Image:foobar.jpg|thumb|http://example.com]] !! result - + !! end @@ -3278,7 +3278,7 @@ Thumbnail image caption with a free URL and explicit alt !! input [[Image:foobar.jpg|thumb|http://example.com|alt=Alteration]] !! result - + !! end @@ -3296,7 +3296,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 @@ -3305,7 +3305,7 @@ BUG 1887: A mailto link with a thumbnail !! input [[Image:foobar.jpg|thumb|Please mailto:nobody@example.com]] !! result - + !! end @@ -3419,7 +3419,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 @@ -3822,7 +3822,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 @@ -3831,7 +3831,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 @@ -3840,7 +3840,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 @@ -4946,11 +4946,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 @@ -5030,7 +5030,7 @@ Fuzz testing: Parser21 !! result - @@ -5045,7 +5045,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');"
@@ -5109,7 +5109,7 @@ Fuzz testing: URL adjacent extension (with space, clean) !! input http://example.com junk !! result -

http://example.com junk +

http://example.com junk

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

http://example.comjunk +

http://example.comjunk

!!end @@ -5129,7 +5129,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 @@ -6137,7 +6137,7 @@ Handling of in URLs !! input **irc:// a !! result - @@ -6312,7 +6312,7 @@ Double RFC !! input RFC RFC 1234 !! result -

RFC RFC 1234 +

RFC RFC 1234

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

RFC 983 987 +

RFC 983 987

!! end @@ -6422,7 +6422,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
+
An external URL
An external URL
!!end @@ -7238,7 +7238,7 @@ language=fa !! input [http://en.wikipedia.org/] !! result -

[Û±] +

[Û±]

!! end -- 2.20.1