r7175 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7174‎ | r7175 | r7176 >
Date:09:58, 19 January 2005
Author:vibber
Status:old
Tags:
Comment:
* Add $wgNoFollowLinks option to add rel="nofollow" on external links (on by default)
Modified paths:
  • /branches/REL1_4/phase3/RELEASE-NOTES (modified) (history)
  • /branches/REL1_4/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/REL1_4/phase3/includes/Skin.php (modified) (history)
  • /branches/REL1_4/phase3/maintenance/parserTests.php (modified) (history)
  • /branches/REL1_4/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: branches/REL1_4/phase3/maintenance/parserTests.txt
@@ -276,7 +276,7 @@
277277 !! input
278278 ; http://example.com/ : definition
279279 !! result
280 -<dl><dt> <a href="http://example.com/" class='external'>http://example.com/</a>&nbsp;</dt><dd> definition
 280+<dl><dt> <a href="http://example.com/" class='external' rel="nofollow">http://example.com/</a>&nbsp;</dt><dd> definition
281281 </dd></dl>
282282
283283 !! end
@@ -286,7 +286,7 @@
287287 !! input
288288 ;[http://www.google.com/ Google]:Number one search engine
289289 !! result
290 -<dl><dt><a href="http://www.google.com/" class='external' title="http://www.google.com/">Google</a><span class='urlexpansion'>&nbsp;(<i>http://www.google.com/</i>)</span></dt><dd>Number one search engine
 290+<dl><dt><a href="http://www.google.com/" class='external' title="http://www.google.com/" rel="nofollow">Google</a><span class='urlexpansion'>&nbsp;(<i>http://www.google.com/</i>)</span></dt><dd>Number one search engine
291291 </dd></dl>
292292
293293 !! end
@@ -307,7 +307,7 @@
308308 !! input
309309 ; news:alt.wikipedia.rox: This isn't even a real newsgroup!
310310 !! result
311 -<dl><dt> <a href="news:alt.wikipedia.rox" class='external'>news:alt.wikipedia.rox</a></dt><dd> This isn't even a real newsgroup!
 311+<dl><dt> <a href="news:alt.wikipedia.rox" class='external' rel="nofollow">news:alt.wikipedia.rox</a></dt><dd> This isn't even a real newsgroup!
312312 </dd></dl>
313313
314314 !! end
@@ -317,7 +317,7 @@
318318 !! input
319319 ; news:alt.wikipedia.rox -- don't crash or enter an infinite loop
320320 !! result
321 -<dl><dt> <a href="news:alt.wikipedia.rox" class='external'>news:alt.wikipedia.rox</a> -- don't crash or enter an infinite loop
 321+<dl><dt> <a href="news:alt.wikipedia.rox" class='external' rel="nofollow">news:alt.wikipedia.rox</a> -- don't crash or enter an infinite loop
322322 </dt></dl>
323323
324324 !! end
@@ -327,7 +327,7 @@
328328 !! input
329329 ; [http://www.wikipedia2.org/ Wikipedia : The Next Generation]: OK, I made that up
330330 !! result
331 -<dl><dt> <a href="http://www.wikipedia2.org/" class='external' title="http://www.wikipedia2.org/">Wikipedia&nbsp;: The Next Generation</a><span class='urlexpansion'>&nbsp;(<i>http://www.wikipedia2.org/</i>)</span></dt><dd> OK, I made that up
 331+<dl><dt> <a href="http://www.wikipedia2.org/" class='external' title="http://www.wikipedia2.org/" rel="nofollow">Wikipedia&nbsp;: The Next Generation</a><span class='urlexpansion'>&nbsp;(<i>http://www.wikipedia2.org/</i>)</span></dt><dd> OK, I made that up
332332 </dd></dl>
333333
334334 !! end
@@ -341,7 +341,7 @@
342342 !! input
343343 Non-bracketed: http://example.com
344344 !! result
345 -<p>Non-bracketed: <a href="http://example.com" class='external'>http://example.com</a>
 345+<p>Non-bracketed: <a href="http://example.com" class='external' rel="nofollow">http://example.com</a>
346346 </p>
347347 !! end
348348
@@ -350,7 +350,7 @@
351351 !! input
352352 Numbered: [http://example.com]
353353 !! result
354 -<p>Numbered: <a href="http://example.com" class='external' title="http://example.com">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
 354+<p>Numbered: <a href="http://example.com" class='external' title="http://example.com" rel="nofollow">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
355355 </p>
356356 !!end
357357
@@ -359,7 +359,7 @@
360360 !! input
361361 Specified text: [http://example.com link]
362362 !! result
363 -<p>Specified text: <a href="http://example.com" class='external' title="http://example.com">link</a><span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
 363+<p>Specified text: <a href="http://example.com" class='external' title="http://example.com" rel="nofollow">link</a><span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
364364 </p>
365365 !!end
366366
@@ -368,7 +368,7 @@
369369 !! input
370370 Trail (not sure if this is meant to work): [http://example.com link]s
371371 !! result
372 -<p>Trail (not sure if this is meant to work): <a href="http://example.com" class='external' title="http://example.com">link</a>s<span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
 372+<p>Trail (not sure if this is meant to work): <a href="http://example.com" class='external' title="http://example.com" rel="nofollow">link</a>s<span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
373373 </p>
374374 !! end
375375
@@ -377,7 +377,7 @@
378378 !! input
379379 http://example.com/1$2345
380380 !! result
381 -<p><a href="http://example.com/1$2345" class='external'>http://example.com/1$2345</a>
 381+<p><a href="http://example.com/1$2345" class='external' rel="nofollow">http://example.com/1$2345</a>
382382 </p>
383383 !! end
384384
@@ -386,7 +386,7 @@
387387 !! input
388388 [http://example.com/1$2345]
389389 !! result
390 -<p><a href="http://example.com/1$2345" class='external' title="http://example.com/1$2345">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://example.com/1$2345</i>)</span>
 390+<p><a href="http://example.com/1$2345" class='external' title="http://example.com/1$2345" rel="nofollow">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://example.com/1$2345</i>)</span>
391391 </p>
392392 !!end
393393
@@ -413,7 +413,7 @@
414414 !! input
415415 Link to non-http image, no img tag: ftp://example.com/test.jpg
416416 !! result
417 -<p>Link to non-http image, no img tag: <a href="ftp://example.com/test.jpg" class='external'>ftp://example.com/test.jpg</a>
 417+<p>Link to non-http image, no img tag: <a href="ftp://example.com/test.jpg" class='external' rel="nofollow">ftp://example.com/test.jpg</a>
418418 </p>
419419 !! end
420420
@@ -422,7 +422,7 @@
423423 !! input
424424 Terminating separator: http://example.com/thing,
425425 !! result
426 -<p>Terminating separator: <a href="http://example.com/thing" class='external'>http://example.com/thing</a>,
 426+<p>Terminating separator: <a href="http://example.com/thing" class='external' rel="nofollow">http://example.com/thing</a>,
427427 </p>
428428 !! end
429429
@@ -431,7 +431,7 @@
432432 !! input
433433 Intervening separator: http://example.com/1,2,3
434434 !! result
435 -<p>Intervening separator: <a href="http://example.com/1,2,3" class='external'>http://example.com/1,2,3</a>
 435+<p>Intervening separator: <a href="http://example.com/1,2,3" class='external' rel="nofollow">http://example.com/1,2,3</a>
436436 </p>
437437 !! end
438438
@@ -440,7 +440,7 @@
441441 !! input
442442 Old bug with URL in query: [http://example.com/thing?url=http://example.com link]
443443 !! result
444 -<p>Old bug with URL in query: <a href="http://example.com/thing?url=http://example.com" class='external' title="http://example.com/thing?url=http://example.com">link</a><span class='urlexpansion'>&nbsp;(<i>http://example.com/thing?url=http://example.com</i>)</span>
 444+<p>Old bug with URL in query: <a href="http://example.com/thing?url=http://example.com" class='external' title="http://example.com/thing?url=http://example.com" rel="nofollow">link</a><span class='urlexpansion'>&nbsp;(<i>http://example.com/thing?url=http://example.com</i>)</span>
445445 </p>
446446 !! end
447447
@@ -449,7 +449,7 @@
450450 !! input
451451 And again with mixed protocols: [ftp://example.com?url=http://example.com link]
452452 !! result
453 -<p>And again with mixed protocols: <a href="ftp://example.com?url=http://example.com" class='external' title="ftp://example.com?url=http://example.com">link</a><span class='urlexpansion'>&nbsp;(<i>ftp://example.com?url=http://example.com</i>)</span>
 453+<p>And again with mixed protocols: <a href="ftp://example.com?url=http://example.com" class='external' title="ftp://example.com?url=http://example.com" rel="nofollow">link</a><span class='urlexpansion'>&nbsp;(<i>ftp://example.com?url=http://example.com</i>)</span>
454454 </p>
455455 !!end
456456
@@ -458,7 +458,7 @@
459459 !! input
460460 URL in text: [http://example.com http://example.com]
461461 !! result
462 -<p>URL in text: <a href="http://example.com" class='external'>http://example.com</a>
 462+<p>URL in text: <a href="http://example.com" class='external' rel="nofollow">http://example.com</a>
463463 </p>
464464 !! end
465465
@@ -467,7 +467,7 @@
468468 !! input
469469 ja-style clickable images: [http://example.com http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png]
470470 !! result
471 -<p>ja-style clickable images: <a href="http://example.com" class='external' title="http://example.com"><img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" /></a><span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
 471+<p>ja-style clickable images: <a href="http://example.com" class='external' title="http://example.com" rel="nofollow"><img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" /></a><span class='urlexpansion'>&nbsp;(<i>http://example.com</i>)</span>
472472 </p>
473473 !!end
474474
@@ -476,7 +476,7 @@
477477 !! input
478478 Old &amp; use: http://x&y
479479 !! result
480 -<p>Old &amp; use: <a href="http://x&amp;y" class='external'>http://x&amp;y</a>
 480+<p>Old &amp; use: <a href="http://x&amp;y" class='external' rel="nofollow">http://x&amp;y</a>
481481 </p>
482482 !! end
483483
@@ -485,7 +485,7 @@
486486 !! input
487487 http://www.jpeg.org
488488 !!result
489 -<p><a href="http://www.jpeg.org" class='external'>http://www.jpeg.org</a>
 489+<p><a href="http://www.jpeg.org" class='external' rel="nofollow">http://www.jpeg.org</a>
490490 </p>
491491 !! end
492492
@@ -494,7 +494,7 @@
495495 !! input
496496 [http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp]
497497 !! result
498 -<p><a href="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp" class='external' title="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp</i>)</span>
 498+<p><a href="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp" class='external' title="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp" rel="nofollow">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp</i>)</span>
499499 </p>
500500 !! end
501501
@@ -503,7 +503,7 @@
504504 !! input
505505 [http://www.example.com/foo http://www.example.com/bar]
506506 !! result
507 -<p><a href="http://www.example.com/foo" class='external' title="http://www.example.com/foo">http://www.example.com/bar</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/foo</i>)</span>
 507+<p><a href="http://www.example.com/foo" class='external' title="http://www.example.com/foo" rel="nofollow">http://www.example.com/bar</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/foo</i>)</span>
508508 </p>
509509 !! end
510510
@@ -512,7 +512,7 @@
513513 !! input
514514 http://www.example.com/<hello>
515515 !! result
516 -<p><a href="http://www.example.com/" class='external'>http://www.example.com/</a>&lt;hello&gt;
 516+<p><a href="http://www.example.com/" class='external' rel="nofollow">http://www.example.com/</a>&lt;hello&gt;
517517 </p>
518518 !!end
519519
@@ -521,7 +521,7 @@
522522 !! input
523523 http://www.example.com/<b>html</b>
524524 !! result
525 -<p><a href="http://www.example.com/" class='external'>http://www.example.com/</a><b >html</b >
 525+<p><a href="http://www.example.com/" class='external' rel="nofollow">http://www.example.com/</a><b >html</b >
526526 </p>
527527 !!end
528528
@@ -530,7 +530,7 @@
531531 !! input
532532 [http://www.example.com/<hello> stuff]
533533 !! result
534 -<p><a href="http://www.example.com/" class='external' title="http://www.example.com/">&lt;hello&gt; stuff</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/</i>)</span>
 534+<p><a href="http://www.example.com/" class='external' title="http://www.example.com/" rel="nofollow">&lt;hello&gt; stuff</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/</i>)</span>
535535 </p>
536536 !!end
537537
@@ -539,7 +539,7 @@
540540 !! input
541541 [http://www.example.com/<b>html</b> stuff]
542542 !! result
543 -<p><a href="http://www.example.com/" class='external' title="http://www.example.com/"><b >html</b > stuff</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/</i>)</span>
 543+<p><a href="http://www.example.com/" class='external' title="http://www.example.com/" rel="nofollow"><b >html</b > stuff</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/</i>)</span>
544544 </p>
545545 !!end
546546
@@ -548,7 +548,7 @@
549549 !! input
550550 http://www.example.com/"hello"
551551 !! result
552 -<p><a href="http://www.example.com/" class='external'>http://www.example.com/</a>"hello"
 552+<p><a href="http://www.example.com/" class='external' rel="nofollow">http://www.example.com/</a>"hello"
553553 </p>
554554 !!end
555555
@@ -557,7 +557,7 @@
558558 !! input
559559 [http://www.example.com/"hello" stuff]
560560 !! result
561 -<p><a href="http://www.example.com/" class='external' title="http://www.example.com/">"hello" stuff</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/</i>)</span>
 561+<p><a href="http://www.example.com/" class='external' title="http://www.example.com/" rel="nofollow">"hello" stuff</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.com/</i>)</span>
562562 </p>
563563 !!end
564564
@@ -566,7 +566,7 @@
567567 !! input
568568 [http://www.example.com test]
569569 !! result
570 -<p>[<a href="http://www.example.com" class='external'>http://www.example.com</a> test]
 570+<p>[<a href="http://www.example.com" class='external' rel="nofollow">http://www.example.com</a> test]
571571 </p>
572572 !! end
573573
@@ -887,7 +887,7 @@
888888 !! input
889889 [[http://www.example.org]]
890890 !! result
891 -<p>[<a href="http://www.example.org" class='external' title="http://www.example.org">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.org</i>)</span>]
 891+<p>[<a href="http://www.example.org" class='external' title="http://www.example.org" rel="nofollow">[1]</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.org</i>)</span>]
892892 </p>
893893 !! end
894894
@@ -907,7 +907,7 @@
908908 !! input
909909 Piped link to URL: [[http://www.example.org|an example URL]]
910910 !! result
911 -<p>Piped link to URL: [<a href="http://www.example.org|an" class='external' title="http://www.example.org|an">example URL</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.org|an</i>)</span>]
 911+<p>Piped link to URL: [<a href="http://www.example.org|an" class='external' title="http://www.example.org|an" rel="nofollow">example URL</a><span class='urlexpansion'>&nbsp;(<i>http://www.example.org|an</i>)</span>]
912912 </p>
913913 !! end
914914
@@ -1488,7 +1488,7 @@
14891489 !! input
14901490 [[Image:foobar.jpg|thumb|http://example.com]]
14911491 !! result
1492 -<div class="thumb tright"><div style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="http://example.com"><img src="/images/3/3a/Foobar.jpg" alt="http://example.com" width="180" height="180" longdesc="/wiki/Image:Foobar.jpg" /></a> <div class="thumbcaption" ><div class="magnify" style="float:right"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="Enlarge" /></a></div><a href="http://example.com" class='external'>http://example.com</a></div></div></div>
 1492+<div class="thumb tright"><div style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="http://example.com"><img src="/images/3/3a/Foobar.jpg" alt="http://example.com" width="180" height="180" longdesc="/wiki/Image:Foobar.jpg" /></a> <div class="thumbcaption" ><div class="magnify" style="float:right"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="Enlarge" /></a></div><a href="http://example.com" class='external' rel="nofollow">http://example.com</a></div></div></div>
14931493
14941494 !! end
14951495
@@ -1773,7 +1773,7 @@
17741774 !! input
17751775 http://example.com [[Image:foobar.jpg]]
17761776 !! result
1777 -<p><a href="http://example.com" class='external'>http://example.com</a> <a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="Image:foobar.jpg"><img src="/images/3/3a/Foobar.jpg" alt="Image:foobar.jpg" longdesc="/wiki/Image:Foobar.jpg" /></a>
 1777+<p><a href="http://example.com" class='external' rel="nofollow">http://example.com</a> <a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="Image:foobar.jpg"><img src="/images/3/3a/Foobar.jpg" alt="Image:foobar.jpg" longdesc="/wiki/Image:Foobar.jpg" /></a>
17781778 </p>
17791779 !!end
17801780
@@ -1782,7 +1782,7 @@
17831783 !! input
17841784 http://example.com[[Image:foobar.jpg]]
17851785 !! result
1786 -<p><a href="http://example.com" class='external'>http://example.com</a><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="Image:foobar.jpg"><img src="/images/3/3a/Foobar.jpg" alt="Image:foobar.jpg" longdesc="/wiki/Image:Foobar.jpg" /></a>
 1786+<p><a href="http://example.com" class='external' rel="nofollow">http://example.com</a><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="Image:foobar.jpg"><img src="/images/3/3a/Foobar.jpg" alt="Image:foobar.jpg" longdesc="/wiki/Image:Foobar.jpg" /></a>
17871787 </p>
17881788 !!end
17891789
@@ -1791,7 +1791,7 @@
17921792 !! input
17931793 http://en.wikinews.org/wiki/Wikinews:Workplace
17941794 !! result
1795 -<p><a href="http://en.wikinews.org/wiki/Wikinews:Workplace" class='external'>http://en.wikinews.org/wiki/Wikinews:Workplace</a>
 1795+<p><a href="http://en.wikinews.org/wiki/Wikinews:Workplace" class='external' rel="nofollow">http://en.wikinews.org/wiki/Wikinews:Workplace</a>
17961796 </p>
17971797 !!end
17981798
Index: branches/REL1_4/phase3/maintenance/parserTests.php
@@ -298,6 +298,7 @@
299299 'wgNamespacesWithSubpages' => array( 0 => preg_match('/\\bsubpage\\b/i', $opts)),
300300 'wgMaxTocLevel' => 999,
301301 'wgCapitalLinks' => true,
 302+ 'wgNoFollowLinks' => true,
302303 );
303304 $this->savedGlobals = array();
304305 foreach( $settings as $var => $val ) {
Index: branches/REL1_4/phase3/includes/DefaultSettings.php
@@ -929,6 +929,14 @@
930930 */
931931 $wgSearchForwardUrl = null;
932932
 933+/**
 934+ * If true, external URL links in wiki text will be given the
 935+ * rel="nofollow" attribute as a hint to search engines that
 936+ * they should not be followed for ranking purposes as they
 937+ * are user-supplied and thus subject to spamming.
 938+ */
 939+$wgNoFollowLinks = true;
 940+
933941 } else {
934942 die();
935943 }
Index: branches/REL1_4/phase3/includes/Skin.php
@@ -1944,6 +1944,10 @@
19451945
19461946 function makeExternalLink( $url, $text, $escape = true ) {
19471947 $style = $this->getExternalLinkAttributes( $url, $text );
 1948+ global $wgNoFollowLinks;
 1949+ if( $wgNoFollowLinks ) {
 1950+ $style .= ' rel="nofollow"';
 1951+ }
19481952 $url = htmlspecialchars( $url );
19491953 if( $escape ) {
19501954 $text = htmlspecialchars( $text );
Index: branches/REL1_4/phase3/RELEASE-NOTES
@@ -256,6 +256,8 @@
257257 * Remove unnecessary initialization and double-caching of parser variables
258258 * Call-tree output mode for profiling
259259 * (bug 730) configurable $wgRCMaxAge; don't try to update purged RC entries
 260+* Add $wgNoFollowLinks option to add rel="nofollow" on external links
 261+ (on by default)
260262
261263 === Caveats ===
262264

Status & tagging log